[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform] Save handler when editing files not in workspace using eclipse default editor

Hi,

Here's the code that would open an external file (meaning file that does not exist in my workspace) and then edit it using eclipse default editor.


File fileToOpen = new File("external_file.xml");

if (fileToOpen.exists() && fileToOpen.isFile()) {
IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI());
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();


   try {
       IDE.openEditorOnFileStore( page, fileStore );
   } catch ( PartInitException e ) {
       //Put your exception handler here if you wish to
   }
} else {
   //Do something if the file does not exist
}


I wanted to execute a code when the user saves the document by ctrl+s or file->save or by pressing the save icon.


How should I do this?

I tried

editorPart.getEditorSite().getActionBars().setGlobalActionHandler( ActionFactory.SAVE.getId(), myaction );

where myaction is an instance of a class that extends Action class and override s the run method.

But then the run method will never be executed once the document is saved.

I also believe the resource change listener can't be of help either because it's would only track down workspace resources.

What should I do? Please enlighten me gurus.