Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 37 lines (26 sloc) 1.69 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
'''
In this example we bind a simple action, that when run will open a dialog to the user.

The action is binded to the 'OfflineActions' in the PyEdit... The 'offline actions' are those that are
started with Ctrl+2 (yeah, I know the name is nonsense) and after that the user will type what he wants.

In this case, the user will have to press 'Ctrl+2' then 'ex2' then <ENTER> to activate it. It should be clear
in the example below on how to bind any other action (subclass of the IAction interface) to any other text
entered after Ctrl+2.
'''

if False:
    from org.python.pydev.editor import PyEdit #@UnresolvedImport
    cmd = 'command string'
    editor = PyEdit

#--------------------------------------------------------------- REQUIRED LOCALS
#interface: String indicating which command will be executed
#As this script will be watching the PyEdit (that is the actual editor in Pydev), and this script
#will be listening to it, this string can indicate any of the methods of org.python.pydev.editor.IPyEditListener
assert cmd is not None

#interface: PyEdit object: this is the actual editor that we will act upon
assert editor is not None

if cmd == 'onCreateActions':
    from org.eclipse.jface.action import Action #@UnresolvedImport
    from org.eclipse.jface.dialogs import MessageDialog #@UnresolvedImport
    
    class ExampleCommand2(Action):
        def run(self):
            MessageDialog.openInformation(editor.getSite().getShell(), "Example2", "Activated!!");
            
            
    editor.addOfflineActionListener("ex2", ExampleCommand2(), 'Example on how to bind script action', True) #the user can activate this action with: Ctrl+2 ex2<ENTER>
            
Something went wrong with that request. Please try again.