Created
July 16, 2014 03:38
-
-
Save henryiii/ea0d564adc7ee98a4dd0 to your computer and use it in GitHub Desktop.
UI powered text manipulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# perform actions on a selected block of text | |
import editor | |
import ui | |
sel = editor.get_selection() | |
text = editor.get_text() | |
if sel[0]-sel[1]: | |
text = text[sel[0]:sel[1]] | |
def indent(sender): | |
txt=sender.superview['textPreview'].text | |
lines = txt.splitlines() | |
txt = '\t'+'\n\t'.join(lines) | |
sender.superview['textPreview'].text = txt | |
def reload(sender): | |
sender.superview['textPreview'].text = text | |
def save(sender): | |
newtext = sender.superview['textPreview'].text | |
editor.replace_text(sel[0],sel[1],newtext) | |
v = ui.load_view('textmanipui') | |
v['textPreview'].text = text | |
v['buttonInd'].action = indent | |
v['buttonReload'].action = reload | |
sv = ui.ButtonItem() | |
sv.title = 'Save' | |
sv.action = save | |
v.right_button_items = [sv] | |
v.present('sheet') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment