コード例 #1
0
ファイル: editmenu.py プロジェクト: c0ns0le/Pythonista
 def cut(self):
     import clipboard
     i=editor.get_selection()
     t=editor.get_text()
     clipboard.set(t[i[0]:i[1]])
     editor.replace_text(i[0],i[1], '')
     editor.set_selection(i[0],i[0])
コード例 #2
0
ファイル: Tabs.py プロジェクト: c0ns0le/Pythonista
    def open_url(self,sender):
        sv=self.sv
        d=self.d
        current_path = editor.get_path()
        button_title = sender.title
    
        #unselect current tab
        current_tab = self.get_current_tab(current_path)
        if current_tab:
            sv[current_tab['name']].background_color = 'white'
            d[current_tab['name']]['selection']=editor.get_selection()
        
        if not d.has_key(button_title):
            console.hud_alert('missing tab entry for this tab.. ')
        
        new_tab=d[button_title]
        path=new_tab['path']
        if not os.path.isfile(path):
            console.hud_alert('The file for this tab has been moved, renamed, or deleted. the tab will now be removed.', icon = 'error', duration = 3)
            self.close_button(sender)

        else:
            editor.open_file(path)
            def setsel():
                sel=new_tab['selection']

                while editor.get_selection()[0] < sel[0]:
                    import time
                    editor.replace_text(sel[0],sel[0],'')
                    editor.replace_text(sel[0]+400,sel[0]+400,'')
                    time.sleep(0.25)
                editor.set_selection(*sel)
            ui.delay(setsel,1.0)
            sender.background_color = 'orange'
コード例 #3
0
ファイル: Tabs.py プロジェクト: c0ns0le/Pythonista
            def setsel():
                sel=new_tab['selection']

                while editor.get_selection()[0] < sel[0]:
                    import time
                    editor.replace_text(sel[0],sel[0],'')
                    editor.replace_text(sel[0]+400,sel[0]+400,'')
                    time.sleep(0.25)
                editor.set_selection(*sel)
コード例 #4
0
ファイル: Find_and_replace.py プロジェクト: pysmath/editmenu
def replace_it(sender):
    global once_or_all, find_text, replacement
    #global find_text
    #global replacement
    if once_or_all == 'once': # Replace selected instance
        selection = editor.get_selection()
        editor.replace_text(selection[0], selection[1], replacement)
    else: # Replace all instances
        full_text = editor.get_text()
        full_replacement = full_text.replace(find_text, replacement)
        editor.replace_text(0, len(full_text), full_replacement)
コード例 #5
0
def replace_it(sender):
    global once_or_all, find_text, replacement
    #global find_text
    #global replacement
    if once_or_all == 'once':  # Replace selected instance
        selection = editor.get_selection()
        editor.replace_text(selection[0], selection[1], replacement)
    else:  # Replace all instances
        full_text = editor.get_text()
        full_replacement = full_text.replace(find_text, replacement)
        editor.replace_text(0, len(full_text), full_replacement)
コード例 #6
0
ファイル: git.py プロジェクト: RichardPotthoff/stash
def refresh_editor():
    #reload current file in editor
    # TODO: only reload if the file was recently updated...
    try:
        sel=editor.get_selection()
        editor.open_file(editor.get_path())
        import time
        time.sleep(0.5) #let the file load
        editor.replace_text(sel[0],sel[0],'') #force scroll
        editor.set_selection(sel[0],sel[1])
    except:
        print 'Could not refresh editor.  continuing anyway'
コード例 #7
0
ファイル: Tabs.py プロジェクト: c0ns0le/Pythonista
 def add_file(self,sender):
     d=self.d
     current_path = str(editor.get_path())
     name = os.path.split(current_path)[1]
     for item in self.d.itervalues():
         if current_path==item['path']:
             console.hud_alert('There is already a tab for this file', duration = 1)
             return None
     if self.d.has_key(name): #has name, but diff path, still create the tab, but append !#
         suffix_list=[(k+'!').split('!')[1] or '0' for k in self.d.keys() if k.startswith(name) ]
         new_suffix='!'+max([int(m) for m in suffix_list])+1
         name=name+new_suffix
     d[name]={'name':name,'path':current_path,'selection':editor.get_selection()}
     self.add_new_button(name, new = True)
コード例 #8
0
ファイル: Settings.py プロジェクト: c0ns0le/Pythonista
 def close_settings(self):
     while self.__iR != 0: pass
     if self.settings_file[:7] == 'http://':
         pass
     else:
         sPl = plistlib.writePlistToString(self.settings_dict)
         sN = self.__sA[0:self.__iS] + sPl[:-1] + self.__sA[self.__iF:]
         with open(self.settings_file, 'w') as fS: fS.write(sN)
         if editor.get_path() == self.settings_file:
             tS = editor.get_selection()
             iD = 0 if tS[0] <= self.__iF else len(sN) - len(self.__sA)
             editor.replace_text(0, len(editor.get_text()), sN[:-1])
             editor.set_selection(tS[0] + iD, tS[1] + iD)
         return True
     self.settings_dict = None
コード例 #9
0
ファイル: editmenu.py プロジェクト: c0ns0le/Pythonista
    def finddocstring(self):
        ''' find the docstring at current cursor location
        '''
        import StringIO
        from jedi import Script

        i=editor.get_selection()
        t=editor.get_text()
        (line,txt)=[(line,n) for (line,n) in enumerate(StringIO.StringIO(editor.get_text()[:i[1]]))][-1]
        script = Script(t, line+1, len(txt))

        dfn = script.goto_definitions()
        if dfn:
            doc=dfn[0].doc
            import ui
            v=ui.TextView()
            v.width=100
            v.height=50
            v.text=doc
            editor._set_toolbar(v)
コード例 #10
0
def main():
    text = None
    label = 'Shared text'
    if appex.is_running_extension():
        text = appex.get_text()
    if not text:
        try:
            import editor
            editor_file = editor.get_path()
            if editor_file:
                sel = console.alert('Editor or clipboard?', button1='Editor', button2='Clipboard')
                if sel == 1:
                    editor_text = editor.get_text()
                    sel_st, sel_end = editor.get_selection()
                    label = os.path.basename(editor_file)
                    if sel_end != sel_st:
                        text = editor_text[sel_st:sel_end]
                    elif editor_text:
                        text = editor_text
        except ImportError:
            pass
    if not text:
        label = 'Clipboard'
        text = clipboard.get().strip()
    if text:
        converted = markdown(text)
        html = TEMPLATE.replace('{{CONTENT}}', converted)

        clip = console.alert('Replace clipboard?', button1='Yes', button2='No', hide_cancel_button=True)
        if clip ==1:
            clipboard.set(html)
            console.hud_alert('HTML copied to clipboard.')
        wv = MyWebView(name='Markdown - %s' % label)
        wv.load_html(html)
        wv.present('full_screen')
    else:
        console.hud_alert('No text found.')
        appex.finish()
コード例 #11
0
def main(args):
    if args:
        name = args[0]
    else:
        sel = editor.get_selection() or ""
        seltxt = preformat(editor.get_text()[sel[0]:sel[1]])
        if sel and sel[0] != sel[1] and is_valid_name(seltxt):
            name = seltxt
        else:
            name = console.input_alert("Find Module")
    
    try:
        loc = find_path(name)
    except ValueError:
        console.hud_alert(name + " is not a valid module name", "error")
        return
    
    if loc == "<built-in>":
        console.hud_alert(name + " is a built-in module", "error")
    elif loc == "<string>":
        console.hud_alert("Could not find module " + name, "error")
    else:
        editor.open_file(os.path.relpath(loc, DOCS))
コード例 #12
0
def select_previous(sender):
    full_text = editor.get_text()
    marker = editor.get_selection()[0]
    start = full_text.rfind(find_text, 0, marker)
    force_scroll(start)
    editor.set_selection(start, start + len(find_text))
コード例 #13
0
ファイル: Snakeyes.py プロジェクト: wizardofozzie/Snakeyes
import editor
full_text = editor.get_text()
cursor = editor.get_selection()[1]
while True:
  try:
    if full_text[cursor - 3] + full_text[cursor - 2] + full_text[cursor - 1] == 'def':
      editor.replace_text(cursor, cursor, ' func_name():')
      editor.set_selection(cursor + 1, cursor + 10)
    if full_text[cursor - 3] + full_text[cursor - 2] + full_text[cursor - 1] == 'ifc':
      editor.replace_text(cursor, cursor, ' condition:')
      editor.set_selection(cursor + 1, cursor + 10)
    if full_text[cursor - 3] + full_text[cursor - 2] + full_text[cursor - 1] == 'wlt':
      editor.replace_text(cursor - 2, cursor, 'hile i < num:')
      editor.set_selection(cursor + 7, cursor + 10)
    if full_text[cursor - 3] + full_text[cursor - 2] + full_text[cursor - 1] == 'fea':
      editor.replace_text(cursor - 2, cursor, 'or entry in array:')
      editor.set_selection(cursor + 10, cursor + 15)
    break
  except:
    pass
コード例 #14
0
ファイル: templates.py プロジェクト: c0ns0le/Pythonista
 def paste(self):
   if self.val :
     sel = editor.get_selection()
     editor.replace_text(sel[0], sel[1], self.val)
コード例 #15
0
ファイル: Find_and_replace.py プロジェクト: pysmath/editmenu
def select_next(sender):
    full_text = editor.get_text()
    marker = editor.get_selection()[1]
    start = full_text.find(find_text, marker)
    editor.set_selection(start, start + len(find_text))
コード例 #16
0
# coding: utf-8

# Put this script into the editor action (wrench) menu.
# Whenever you want to import an Objective-C class,
# you jutst need to  type the classname, select it and invoke this script via the action menu.
# This script will check if a classname with the name you selected exists
# and add ` = ObjcClass(_classname_)` to the end of the line

import editor, console, sys
from objc_util import ObjCClass

selection = editor.get_selection()
line = editor.get_line_selection()

text = editor.get_text()

classname = text[int(selection[0]):int(selection[1])]

try:
	ObjCClass(classname)
	editor.set_selection(selection[1])
	editor.replace_text(selection[1], selection[1], ' = ObjCClass(\'{}\')'.format(classname))
except:
	console.hud_alert(sys.exc_info()[1].message, 'error')
コード例 #17
0
ファイル: editmenu.py プロジェクト: c0ns0le/Pythonista
 def selectstart(self):
     import editor
     i=editor.get_selection()
     editor.set_selection(i[0],i[1]+1)
コード例 #18
0
ファイル: Find_and_replace.py プロジェクト: pysmath/editmenu
def select_previous(sender):
    full_text = editor.get_text()
    marker = editor.get_selection()[0]
    start = full_text.rfind(find_text, 0, marker)
    editor.set_selection(start, start + len(find_text))
コード例 #19
0
ファイル: editmenu.py プロジェクト: c0ns0le/Pythonista
 def paste(self):
     import clipboard
     i=editor.get_selection()
     t=editor.get_text()
     editor.replace_text(i[0],i[1], clipboard.get())
     editor.set_selection(i[0],i[1]-len(t)+len(editor.get_text()))
コード例 #20
0
ファイル: editmenu.py プロジェクト: c0ns0le/Pythonista
 def copy(self):
     import clipboard
     i=editor.get_selection()
     t=editor.get_text()
     clipboard.set(t[i[0]:i[1]])
コード例 #21
0
def insert_action(sender):
	text = sender.superview['textview1'].text
	start, end = editor.get_selection()
	editor.replace_text(start, end, text)
	if not platform.machine().startswith('iPad'):
		view.close()