Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. if False:
  2. from org.python.pydev.editor import PyEdit #@UnresolvedImport
  3. cmd = 'command string'
  4. editor = PyEdit
  5. systemGlobals = {}
  6.  
  7. if cmd == 'onCreateActions':
  8. assert editor is not None
  9.  
  10. MySurroundAction = systemGlobals.get('MySurroundAction')
  11. if MySurroundAction is None:
  12. Action = editor.getActionClass() #from org.eclipse.jface.action import Action #@UnresolvedImport
  13.  
  14. class MySurroundAction(Action):
  15.  
  16. def __init__(self, editor):
  17. self.editor = editor
  18.  
  19. def run(self):
  20. editor = self.editor
  21. sel = editor.createPySelection()
  22. txt = sel.getSelectedText()
  23.  
  24. doc = sel.getDoc()
  25. sel = sel.getTextSelection()
  26. doc.replace(sel.getOffset(), sel.getLength(), 'my_func(%s)' % (txt,))
  27.  
  28. systemGlobals['MySurroundAction'] = MySurroundAction
  29.  
  30. # Change these constants if the default does not suit your needs
  31. ACTIVATION_STRING = 'x'
  32. WAIT_FOR_ENTER = False
  33.  
  34. # Register the extension as an ActionListener.
  35. editor.addOfflineActionListener(ACTIVATION_STRING, MySurroundAction(editor), 'Surround with function', WAIT_FOR_ENTER)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement