Jump to: navigation, search

Difference between revisions of "FAQ How do I enable the Save and Revert actions?"

 
(See Also:)
Line 54: Line 54:
 
== See Also: ==
 
== See Also: ==
  
[[FAQ_How_do_I_enable_global_actions_such_as_%3Cb%3ECut%3C%2Fb%3E%2C_%3Cb%3EPaste%3C%2Fb%3E%2C_and_%3Cb%3EPrint%3C%2Fb%3E_in_my_editor%3F]]'Cut''', '''Paste''', and '''Print''' in my editor?''
+
[[FAQ How do I enable global actions such as %3Cb%3ECut%3C%2Fb%3E%2C %3Cb%3EPaste%3C%2Fb%3E%2C and %3Cb%3EPrint%3C%2Fb%3E in my editor?]]
  
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>

Revision as of 11:32, 26 February 2007

An editor with unsaved changes is said to be dirty. If an editor is closed while dirty, changes made in the editor since the last save should be discarded. The framework asks an editor whether it is dirty by calling the IEditorPart method isDirty. When the dirty state of an editor changes, it lets the world know by firing a property change event, IEditorPart.PROP_DIRTY, on the property. Here are the relevant minimal-editor example sections that control the dirty state:

   public class MinimalEditor extends EditorPart {
      protected boolean dirty = false;
      ...
      public boolean isDirty() {
         return dirty;
      }
      protected void setDirty(boolean value) {
         dirty = value;
         firePropertyChange(PROP_DIRTY);
      }
   }
	


The editor Save action should persist the current editor contents and then set the dirty state to false. Unlike most actions that are defined within an instance of IAction, the editor Save and Save As... actions are built directly into the editor part. These actions are always enabled when the editor is in a dirty state. The editor must support these actions by implementing the methods on ISaveablePart, which is extended by IEditorPart. Here are trivial implementations of these methods from the minimal-editor example:

   public void doSave(IProgressMonitor monitor) {
      setDirty(false);
   }
   public void doSaveAs() {
      doSave(null);
   }
   public boolean isSaveAsAllowed() {
      return false;
   }


Unlike the Save action, the Revert action is not built into the editor framework. The Revert action is one of the standard workbench global actions and is entirely optional for editors to implement. The global action is hooked in just like other global actions. The Revert action should be equivalent to closing an editor without saving, then reopening on the previously saved contents. Like the Save action, it should change the dirty state to false and fire a property change event on IEditorPart.PROP_DIRTY when it completes successfully.


See Also:

[[FAQ How do I enable global actions such as %3Cb%3ECut%3C%2Fb%3E%2C %3Cb%3EPaste%3C%2Fb%3E%2C and %3Cb%3EPrint%3C%2Fb%3E in my editor?]]


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.