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
M5DriverAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

marklorenzCommented:
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
0
M5DriverAuthor Commented:
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
0
marklorenzCommented:
To get the contents in doSave(), try this:

IDocument  doc  = this.getDocumentProvider().getDocument(getEditorInput());

The resulting document has lots of methods to access the text of the editor.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rene_untiCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.