Reputation: 380
I'm building a plugin for NetBeans and I would like to know how I can perform an action when the user presses Ctrl+S or clicks the "Save …" button.
I searched for this on Google, but I could not come up with some instructions or APIs to use to achieve this goal.
In fact, I want to capture the contents of the NetBeans active editor each time the user saves, and at the same time, compiles the source code.
Would you please give me some hints or resources on how to achieve this?
Thanks in advance! Jeremie
Upvotes: 1
Views: 89
Reputation: 2963
http://wiki.netbeans.org/DevFaqListenForSaveEvents
DataObject.Registry registries = DataObject.getRegistry();
registries.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
System.out.println("ChangedListener: o = " + e.getSource().getClass());
System.out.println("ChangedListener: o.source = " + e.getSource());
}
});
DataObject[] objects = registries.getModified();
for (int i = 0; i < objects.length; i++) {
DataObject dataObj = objects[I];
System.out.println("data object name = " + dataObj.getName());
System.out.println("data object pimary file name = " + dataObj.getPrimaryFile().getName());
Set fss = dataObj.files();
Iterator iter = fss.iterator();
while (iter.hasNext()) {
FileObject fo = (FileObject) iter.next();
System.out.println("\tset file object: " + fo.getName());
}
}
Upvotes: 1