Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2008-11-18
4
Medium Priority
?
1,175 Views
Last Modified: 2013-12-15
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
0
Comment
Question by:M5Driver
  • 2
4 Comments
 
LVL 12

Expert Comment

by:marklorenz
ID: 22990775
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
 

Author Comment

by:M5Driver
ID: 22998214
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
 
LVL 12

Accepted Solution

by:
marklorenz earned 2000 total points
ID: 23000574
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
 

Expert Comment

by:rene_unti
ID: 24490200
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question