Lii
Lii

Reputation: 12131

Editor specific command state

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?

Information about my specific problem

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.

Thoughts and observations

Upvotes: 0

Views: 35

Answers (1)

greg-449
greg-449

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

Related Questions