How can I register for a notification of changed text in a PyDev Jython script?
I'd like to write a Jython script for PyDev that will analyse the text in the editor and then add some comments to the text under certain circumstances. Every time the user types something, the analysis should run again.
I read through the introduction to Jython scripting in PyDev, and I looked at the example scripts, but they all seem to trigger from a command key. I looked at the PyEdit class, and it looks like I should register for IPyEditListener3's onInputChanged event.
I tried the script below, but it doesn't seem to call my event handler. What did I miss?
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
assert cmd is not None
#interface: PyEdit object: this is the actual editor that we will act upon
assert editor is not None
print 'command is:', cmd, ' file is:', editor.getEditorFile().getName()
if cmd == 'onCreateActions':
from org.python.pydev.editor import IPyEditListener #@UnresolvedImport
from org.python.pydev.editor import IPyEditListener3 #@UnresolvedImport
class PyEditListener(IPyEditListener, IPyEditListener3):
def onInputChanged(self,
edit,
oldInput,
newInput,
monitor):
print 'onInputChanged'
try:
editor.addPyeditListener(PyEditListener())
except Exception, ex:
print ex
print 'finished.'