Lines 145-150
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.ISaveableModel; |
149 |
import org.eclipse.ui.ISaveableModelSource; |
148 |
import org.eclipse.ui.IWindowListener; |
150 |
import org.eclipse.ui.IWindowListener; |
149 |
import org.eclipse.ui.IWorkbenchActionConstants; |
151 |
import org.eclipse.ui.IWorkbenchActionConstants; |
150 |
import org.eclipse.ui.IWorkbenchPart; |
152 |
import org.eclipse.ui.IWorkbenchPart; |
Lines 188-194
Link Here
|
188 |
* If no id is set while in compatibility mode, the menu is registered under |
190 |
* If no id is set while in compatibility mode, the menu is registered under |
189 |
* <code>DEFAULT_RULER_CONTEXT_MENU_ID</code>.</p> |
191 |
* <code>DEFAULT_RULER_CONTEXT_MENU_ID</code>.</p> |
190 |
*/ |
192 |
*/ |
191 |
public abstract class AbstractTextEditor extends EditorPart implements ITextEditor, IReusableEditor, ITextEditorExtension, ITextEditorExtension2, ITextEditorExtension3, ITextEditorExtension4, INavigationLocationProvider { |
193 |
public abstract class AbstractTextEditor extends EditorPart implements ITextEditor, IReusableEditor, ITextEditorExtension, ITextEditorExtension2, ITextEditorExtension3, ITextEditorExtension4, INavigationLocationProvider, ISaveableModelSource { |
192 |
|
194 |
|
193 |
/** |
195 |
/** |
194 |
* Tag used in xml configuration files to specify editor action contributions. |
196 |
* Tag used in xml configuration files to specify editor action contributions. |
Lines 5686-5689
Link Here
|
5686 |
public void showRevisionInformation(RevisionInformation info, String quickDiffProviderId) { |
5688 |
public void showRevisionInformation(RevisionInformation info, String quickDiffProviderId) { |
5687 |
// no implementation |
5689 |
// no implementation |
5688 |
} |
5690 |
} |
|
|
5691 |
|
5692 |
private ISaveableModel fSaveableModel; |
5693 |
|
5694 |
/* |
5695 |
* @since 3.2 |
5696 |
*/ |
5697 |
public ISaveableModel[] getModels() { |
5698 |
// TODO need to react when the document provider or the editor input changes. |
5699 |
if (fSaveableModel == null) { |
5700 |
fSaveableModel = new TextEditorSaveableModel(getDocumentProvider(), getEditorInput()); |
5701 |
} |
5702 |
return new ISaveableModel[] { fSaveableModel }; |
5703 |
} |
5704 |
|
5705 |
/* |
5706 |
* @since 3.2 |
5707 |
*/ |
5708 |
public ISaveableModel[] getActiveModels() { |
5709 |
return getModels(); |
5710 |
} |
5711 |
|
5712 |
private static class TextEditorSaveableModel implements ISaveableModel { |
5713 |
private IDocumentProvider documentProvider; |
5714 |
private IEditorInput editorInput; |
5715 |
|
5716 |
/** |
5717 |
* @param documentProvider |
5718 |
* @param editorInput |
5719 |
*/ |
5720 |
public TextEditorSaveableModel(IDocumentProvider documentProvider, IEditorInput editorInput) { |
5721 |
this.documentProvider = documentProvider; |
5722 |
this.editorInput = editorInput; |
5723 |
} |
5724 |
|
5725 |
public String getName() { |
5726 |
return editorInput.getName(); |
5727 |
} |
5728 |
|
5729 |
public String getToolTipText() { |
5730 |
return editorInput.getToolTipText(); |
5731 |
} |
5732 |
|
5733 |
public ImageDescriptor getImageDescriptor() { |
5734 |
return editorInput.getImageDescriptor(); |
5735 |
} |
5736 |
|
5737 |
public void doSave(IProgressMonitor monitor) throws CoreException { |
5738 |
documentProvider.aboutToChange(editorInput); |
5739 |
documentProvider.saveDocument(monitor, editorInput, documentProvider.getDocument(editorInput), false); |
5740 |
} |
5741 |
|
5742 |
public boolean isDirty() { |
5743 |
return documentProvider.canSaveDocument(editorInput); |
5744 |
} |
5745 |
|
5746 |
/* (non-Javadoc) |
5747 |
* @see java.lang.Object#hashCode() |
5748 |
*/ |
5749 |
public int hashCode() { |
5750 |
final int PRIME = 31; |
5751 |
int result = 1; |
5752 |
result = PRIME * result + ((documentProvider == null) ? 0 : documentProvider.hashCode()); |
5753 |
result = PRIME * result + ((editorInput == null) ? 0 : editorInput.hashCode()); |
5754 |
return result; |
5755 |
} |
5756 |
|
5757 |
/* (non-Javadoc) |
5758 |
* @see java.lang.Object#equals(java.lang.Object) |
5759 |
*/ |
5760 |
public boolean equals(Object obj) { |
5761 |
if (this == obj) |
5762 |
return true; |
5763 |
if (obj == null) |
5764 |
return false; |
5765 |
if (getClass() != obj.getClass()) |
5766 |
return false; |
5767 |
final TextEditorSaveableModel other = (TextEditorSaveableModel) obj; |
5768 |
if (documentProvider == null) { |
5769 |
if (other.documentProvider != null) |
5770 |
return false; |
5771 |
} else if (!documentProvider.equals(other.documentProvider)) |
5772 |
return false; |
5773 |
if (editorInput == null) { |
5774 |
if (other.editorInput != null) |
5775 |
return false; |
5776 |
} else if (!editorInput.equals(other.editorInput)) |
5777 |
return false; |
5778 |
return true; |
5779 |
} |
5780 |
} |
5689 |
} |
5781 |
} |