### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.workbench.texteditor Index: src/org/eclipse/ui/texteditor/AbstractTextEditor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java,v retrieving revision 1.196 diff -u -r1.196 AbstractTextEditor.java --- src/org/eclipse/ui/texteditor/AbstractTextEditor.java 10 Apr 2006 12:39:24 -0000 1.196 +++ src/org/eclipse/ui/texteditor/AbstractTextEditor.java 12 Apr 2006 21:21:45 -0000 @@ -145,12 +145,16 @@ import org.eclipse.ui.IPartListener; import org.eclipse.ui.IPartService; import org.eclipse.ui.IReusableEditor; +import org.eclipse.ui.ISaveablesLifecycleListener; +import org.eclipse.ui.Saveable; +import org.eclipse.ui.ISaveablesSource; import org.eclipse.ui.IWindowListener; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.SaveablesLifecycleEvent; import org.eclipse.ui.dialogs.PropertyDialogAction; import org.eclipse.ui.internal.EditorPluginAction; import org.eclipse.ui.internal.texteditor.EditPosition; @@ -188,7 +192,7 @@ * If no id is set while in compatibility mode, the menu is registered under * DEFAULT_RULER_CONTEXT_MENU_ID.

*/ -public abstract class AbstractTextEditor extends EditorPart implements ITextEditor, IReusableEditor, ITextEditorExtension, ITextEditorExtension2, ITextEditorExtension3, ITextEditorExtension4, INavigationLocationProvider { +public abstract class AbstractTextEditor extends EditorPart implements ITextEditor, IReusableEditor, ITextEditorExtension, ITextEditorExtension2, ITextEditorExtension3, ITextEditorExtension4, INavigationLocationProvider, ISaveablesSource { /** * Tag used in xml configuration files to specify editor action contributions. @@ -3013,6 +3017,22 @@ } setDocumentProvider(input); + + if (fSaveable != null) { + // The input has changed. Force recreation of saveable, and notify + // the ISaveablesLifecycleListener. + ISaveablesLifecycleListener listener= (ISaveablesLifecycleListener) getSite() + .getService(ISaveablesLifecycleListener.class); + listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, + SaveablesLifecycleEvent.POST_CLOSE, + new Saveable[] { fSaveable }, false)); + fSaveable= null; + // recomputes fSaveable: + getSaveables(); + listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, + SaveablesLifecycleEvent.POST_OPEN, + new Saveable[] { fSaveable }, false)); + } provider= getDocumentProvider(); if (provider != null) { @@ -5683,4 +5703,93 @@ public void showRevisionInformation(RevisionInformation info, String quickDiffProviderId) { // no implementation } + + private Saveable fSaveable; + + /* + * @since 3.2 + */ + public Saveable[] getSaveables() { + if (fSaveable == null) { + fSaveable= new TextEditorSaveable(getDocumentProvider(), getEditorInput()); + } + return new Saveable[] { fSaveable }; + } + + /* + * @since 3.2 + */ + public Saveable[] getActiveSaveables() { + return getSaveables(); + } + + private static class TextEditorSaveable extends Saveable { + private IDocumentProvider documentProvider; + private IEditorInput editorInput; + + /** + * @param documentProvider + * @param editorInput + */ + public TextEditorSaveable(IDocumentProvider documentProvider, IEditorInput editorInput) { + this.documentProvider= documentProvider; + this.editorInput= editorInput; + } + + public String getName() { + return editorInput.getName(); + } + + public String getToolTipText() { + return editorInput.getToolTipText(); + } + + public ImageDescriptor getImageDescriptor() { + return editorInput.getImageDescriptor(); + } + + public void doSave(IProgressMonitor monitor) throws CoreException { + documentProvider.aboutToChange(editorInput); + documentProvider.saveDocument(monitor, editorInput, documentProvider.getDocument(editorInput), false); + } + + public boolean isDirty() { + return documentProvider.canSaveDocument(editorInput); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + final int PRIME= 31; + int result= 1; + result= PRIME * result + ((documentProvider == null) ? 0 : documentProvider.hashCode()); + result= PRIME * result + ((editorInput == null) ? 0 : editorInput.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final TextEditorSaveable other= (TextEditorSaveable) obj; + if (documentProvider == null) { + if (other.documentProvider != null) + return false; + } else if (!documentProvider.equals(other.documentProvider)) + return false; + if (editorInput == null) { + if (other.editorInput != null) + return false; + } else if (!editorInput.equals(other.editorInput)) + return false; + return true; + } + } }