Reputation: 12131
I have created a command and a handler that interacts with text editors (objects implementing ITextEditor
). For each editor that the handler interacts with I'd like to store some data that the handler has access to.
What is the best way to do this?
My command modifies the selection of text of the active editor. When the command is executed I want to store information about the previous selection. Another command should be able read this information and restore the previous selection.
<state>
plugin.xml
tag, but I don't understand how to get one piece of state for each editor. But maybe there is a way?IAction
) could be used? But aren't they an old mechanism that has been substituted by commands?IAction
object which as an reference to the stack using the ITextEditor.setAction
.Upvotes: 0
Views: 35
Reputation: 111217
If you are using Eclipse 4 you could use the transient data of the MPart
object associated with the IEditorPart
.
To get the MPart
from an IEditorPart
use:
MPart part = editor.getSite().getService(MPart.class);
Map<String, Object> transientData = part.getTransientData();
You can store anything you like in the transient data, use a key unique to your handler for the map key. The data is discarded when the editor closes.
Upvotes: 1