Link to home
Start Free TrialLog in
Avatar of M5Driver
M5Driver

asked on

Override Save Action In Basic Text Eclipse Editor - updated for extra step

I have created a class that extends IFileEditorInput that opens a stored file anywhere on my machine and displays the file in the org.eclipse.ui.DefaultTextEditor.  This file is not in the current project, just displayed in an editor window.  

What I would like to do is make it so that if a person wants to edit it and save it back to the temporary location *and* also write that file in a different location, like a database. What class would I need to extend to get that functionality?  Basically if someone right mouse clicks on the file and selects "save" that eclipse will call my method for saving the information in both places instead of the default save action.  Any examples of doing this that you know about?  Thanks in advance
Avatar of marklorenz
marklorenz
Flag of United States of America image

You didn't say what version of Eclipse you're using.  The older way to handle this would be with a Command.  The new way (since 3.3) is an Action.  I'll assume you can use an Action...

Create an ActionSet, associate an Action with that set.  The Action associates the action being taken with an ActionDelegate you define.  The delegate implements IWorkbenchWindowActionDelegate.  You can read more details here:

http://www.geocities.com/bill_beebe/EclipseSupport/Your_First_Plug-In.html
Avatar of M5Driver
M5Driver

ASKER

I am using Eclipse 3.4.  

The only way that I was able to get something close to working was to create a whole new editor by extending the default text editor.  There is a doSave method in the editor class that I can override and is being called when I click on the save dialog on the editor.  So the question now is:

public void doSave(IProgressMonitor monitor){
  String editorcontents = ???
}

How do I get the contents of the editor window so that I can do something with the file info?  I  looked all through the methods available off the editor and can't find anything like getEditorContents or whatever.  Any idea?  Thanks.

Andy
ASKER CERTIFIED SOLUTION
Avatar of marklorenz
marklorenz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Unfortunately I have the same problem but I don't want to solve it with my own editor solution. I want to be able to do it the way marklorenz suggested it. Is there anyone that can give more information about a solution with the
Create an ActionSet, associate an Action with that set.  The Action associates the action being taken with an ActionDelegate you define.  The delegate implements IWorkbenchWindowActionDelegate.

on existing editors?

thanks a lot.