View | Details | Raw Unified | Return to bug 131068 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/texteditor/AbstractTextEditor.java (-1 / +110 lines)
Lines 145-156 Link Here
145
import org.eclipse.ui.IPartListener;
145
import org.eclipse.ui.IPartListener;
146
import org.eclipse.ui.IPartService;
146
import org.eclipse.ui.IPartService;
147
import org.eclipse.ui.IReusableEditor;
147
import org.eclipse.ui.IReusableEditor;
148
import org.eclipse.ui.ISaveablesLifecycleListener;
149
import org.eclipse.ui.Saveable;
150
import org.eclipse.ui.ISaveablesSource;
148
import org.eclipse.ui.IWindowListener;
151
import org.eclipse.ui.IWindowListener;
149
import org.eclipse.ui.IWorkbenchActionConstants;
152
import org.eclipse.ui.IWorkbenchActionConstants;
150
import org.eclipse.ui.IWorkbenchPart;
153
import org.eclipse.ui.IWorkbenchPart;
151
import org.eclipse.ui.IWorkbenchWindow;
154
import org.eclipse.ui.IWorkbenchWindow;
152
import org.eclipse.ui.PartInitException;
155
import org.eclipse.ui.PartInitException;
153
import org.eclipse.ui.PlatformUI;
156
import org.eclipse.ui.PlatformUI;
157
import org.eclipse.ui.SaveablesLifecycleEvent;
154
import org.eclipse.ui.dialogs.PropertyDialogAction;
158
import org.eclipse.ui.dialogs.PropertyDialogAction;
155
import org.eclipse.ui.internal.EditorPluginAction;
159
import org.eclipse.ui.internal.EditorPluginAction;
156
import org.eclipse.ui.internal.texteditor.EditPosition;
160
import org.eclipse.ui.internal.texteditor.EditPosition;
Lines 188-194 Link Here
188
 * If no id is set while in compatibility mode, the menu is registered under
192
 * If no id is set while in compatibility mode, the menu is registered under
189
 * <code>DEFAULT_RULER_CONTEXT_MENU_ID</code>.</p>
193
 * <code>DEFAULT_RULER_CONTEXT_MENU_ID</code>.</p>
190
 */
194
 */
191
public abstract class AbstractTextEditor extends EditorPart implements ITextEditor, IReusableEditor, ITextEditorExtension, ITextEditorExtension2, ITextEditorExtension3, ITextEditorExtension4, INavigationLocationProvider {
195
public abstract class AbstractTextEditor extends EditorPart implements ITextEditor, IReusableEditor, ITextEditorExtension, ITextEditorExtension2, ITextEditorExtension3, ITextEditorExtension4, INavigationLocationProvider, ISaveablesSource {
192
196
193
	/**
197
	/**
194
	 * Tag used in xml configuration files to specify editor action contributions.
198
	 * Tag used in xml configuration files to specify editor action contributions.
Lines 3013-3018 Link Here
3013
		}
3017
		}
3014
3018
3015
		setDocumentProvider(input);
3019
		setDocumentProvider(input);
3020
		
3021
		if (fSaveable != null) {
3022
			// The input has changed. Force recreation of saveable, and notify
3023
			// the ISaveablesLifecycleListener.
3024
			ISaveablesLifecycleListener listener= (ISaveablesLifecycleListener) getSite()
3025
					.getService(ISaveablesLifecycleListener.class);
3026
			listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this,
3027
					SaveablesLifecycleEvent.POST_CLOSE,
3028
					new Saveable[] { fSaveable }, false));
3029
			fSaveable= null;
3030
			// recomputes fSaveable:
3031
			getSaveables();
3032
			listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this,
3033
					SaveablesLifecycleEvent.POST_OPEN,
3034
					new Saveable[] { fSaveable }, false));
3035
		}
3016
3036
3017
		provider= getDocumentProvider();
3037
		provider= getDocumentProvider();
3018
		if (provider != null) {
3038
		if (provider != null) {
Lines 5683-5686 Link Here
5683
	public void showRevisionInformation(RevisionInformation info, String quickDiffProviderId) {
5703
	public void showRevisionInformation(RevisionInformation info, String quickDiffProviderId) {
5684
		// no implementation
5704
		// no implementation
5685
	}
5705
	}
5706
	
5707
	private Saveable fSaveable;
5708
5709
	/*
5710
	 * @since 3.2
5711
	 */
5712
	public Saveable[] getSaveables() {
5713
		if (fSaveable == null) {
5714
			fSaveable= new TextEditorSaveable(getDocumentProvider(), getEditorInput());
5715
		}
5716
		return new Saveable[] { fSaveable };
5717
	}
5718
5719
	/*
5720
	 * @since 3.2
5721
	 */
5722
	public Saveable[] getActiveSaveables() {
5723
		return getSaveables();
5724
	}
5725
	
5726
	private static class TextEditorSaveable extends Saveable {
5727
		private IDocumentProvider documentProvider;
5728
		private IEditorInput editorInput;
5729
5730
		/**
5731
		 * @param documentProvider
5732
		 * @param editorInput
5733
		 */
5734
		public TextEditorSaveable(IDocumentProvider documentProvider, IEditorInput editorInput) {
5735
			this.documentProvider= documentProvider;
5736
			this.editorInput= editorInput;
5737
		}
5738
5739
		public String getName() {
5740
			return editorInput.getName();
5741
		}
5742
5743
		public String getToolTipText() {
5744
			return editorInput.getToolTipText();
5745
		}
5746
5747
		public ImageDescriptor getImageDescriptor() {
5748
			return editorInput.getImageDescriptor();
5749
		}
5750
5751
		public void doSave(IProgressMonitor monitor) throws CoreException {
5752
			documentProvider.aboutToChange(editorInput);
5753
			documentProvider.saveDocument(monitor, editorInput, documentProvider.getDocument(editorInput), false);
5754
		}
5755
5756
		public boolean isDirty() {
5757
			return documentProvider.canSaveDocument(editorInput);
5758
		}
5759
5760
		/* (non-Javadoc)
5761
		 * @see java.lang.Object#hashCode()
5762
		 */
5763
		public int hashCode() {
5764
			final int PRIME= 31;
5765
			int result= 1;
5766
			result= PRIME * result + ((documentProvider == null) ? 0 : documentProvider.hashCode());
5767
			result= PRIME * result + ((editorInput == null) ? 0 : editorInput.hashCode());
5768
			return result;
5769
		}
5770
5771
		/* (non-Javadoc)
5772
		 * @see java.lang.Object#equals(java.lang.Object)
5773
		 */
5774
		public boolean equals(Object obj) {
5775
			if (this == obj)
5776
				return true;
5777
			if (obj == null)
5778
				return false;
5779
			if (getClass() != obj.getClass())
5780
				return false;
5781
			final TextEditorSaveable other= (TextEditorSaveable) obj;
5782
			if (documentProvider == null) {
5783
				if (other.documentProvider != null)
5784
					return false;
5785
			} else if (!documentProvider.equals(other.documentProvider))
5786
				return false;
5787
			if (editorInput == null) {
5788
				if (other.editorInput != null)
5789
					return false;
5790
			} else if (!editorInput.equals(other.editorInput))
5791
				return false;
5792
			return true;
5793
		}
5794
	}
5686
}
5795
}

Return to bug 131068