@Override public boolean isDirty() { for (IEditorPart e : innerEditors) { if (e.isDirty()) { return true; } } return false; }
public void propertyChanged(Object source, int propId) { if(!editor.isDirty()) { log.info("Refreshing settings " + fileName); //$NON-NLS-1$ } } });
@Override public IEditorPart[] getDirtyEditors() { List<IEditorPart> dirtyEditors = new ArrayList<>(); for (IEditorReference editorRef : editorReferences) { IEditorPart editor = editorRef.getEditor(false); if (editor != null && editor.isDirty()) { dirtyEditors.add(editor); } } return dirtyEditors.toArray(new IEditorPart[dirtyEditors.size()]); }
/** * The <code>MultiPageEditorPart</code> implementation of this * <code>IEditorPart</code> method returns whether the contents of any of * this multi-page editor's nested editors have changed since the last save. * Pages created with <code>addPage(Control)</code> are ignored. * <p> * Subclasses may extend or reimplement this method. * </p> * * @return <code>true</code> if any of the nested editors are dirty; * <code>false</code> otherwise. */ public boolean isDirty() { // use nestedEditors to avoid SWT requests; see bug 12996 for (Iterator i = _nestedEditors.iterator(); i.hasNext();) { IEditorPart editor = (IEditorPart) i.next(); if (editor.isDirty()) { return true; } } return false; }
/** * The <code>MultiPageEditorPart</code> implementation of this * <code>IEditorPart</code> method returns whether the contents of any of * this multi-page editor's nested editors have changed since the last save. * Pages created with <code>addPage(Control)</code> are ignored. * <p> * Subclasses may extend or reimplement this method. * </p> * * @return <code>true</code> if any of the nested editors are dirty; * <code>false</code> otherwise. */ @Override public boolean isDirty() { // use nestedEditors to avoid SWT requests; see bug 12996 for (Iterator i = nestedEditors.iterator(); i.hasNext();) { IEditorPart editor = (IEditorPart) i.next(); if (editor.isDirty()) { return true; } } return false; }
protected void saveDeclaringEditor(IRenameElementContext context, IWorkbenchPage workbenchPage) { IEditorPart declaringEditor = getOpenEditor(context.getTargetElementURI(), workbenchPage); if (declaringEditor != null && declaringEditor.isDirty()) declaringEditor.doSave(new NullProgressMonitor()); }
/** * Tests whether the editor is dirty by checking all the pages that * implement <code>IFormPage</code>. If none of them is dirty, the method * delegates further processing to <code>super.isDirty()</code>. * * @return <code>true</code> if any of the pages in the editor are dirty, * <code>false</code> otherwise. * @since 3.1 */ @Override public boolean isDirty() { if (pages != null) { for (int i = 0; i < pages.size(); i++) { Object page = pages.get(i); if (page instanceof IFormPage) { IFormPage fpage = (IFormPage) page; if (fpage.isDirty()) return true; } else if (page instanceof IEditorPart) { IEditorPart editor = (IEditorPart) page; if (editor.isDirty()) { return true; } } } } return super.isDirty(); }
/** * Tests whether the editor is dirty by checking all the pages that * implement <code>IFormPage</code>. If none of them is dirty, the method * delegates further processing to <code>super.isDirty()</code>. * * @return <code>true</code> if any of the pages in the editor are dirty, * <code>false</code> otherwise. * @since 3.1 */ @Override public boolean isDirty() { if (pages != null) { for (int i = 0; i < pages.size(); i++) { Object page = pages.get(i); if (page instanceof IFormPage) { IFormPage fpage = (IFormPage) page; if (fpage.isDirty()) return true; } else if (page instanceof IEditorPart) { IEditorPart editor = (IEditorPart) page; if (editor.isDirty()) { return true; } } } } return super.isDirty(); }
/** * Returns an editor that can be re-used. An open compare editor that * has un-saved changes cannot be re-used. * @param page * @return an EditorPart or <code>null</code> if none can be found */ public static IEditorPart findReusableCompareEditor(IWorkbenchPage page) { IEditorReference[] editorRefs = page.getEditorReferences(); for (int i = 0; i < editorRefs.length; i++) { IEditorPart part = editorRefs[i].getEditor(false); if(part != null && (part.getEditorInput() instanceof CompareFileRevisionEditorInput) && part instanceof IReusableEditor) { if(! part.isDirty()) { return part; } } } return null; }
/** * Restores the object state from the given memento. * * @param memento the memento */ @Override public void restoreState(IMemento memento) { IEditorPart part= getEditorPart(); if (part instanceof ITextEditor) { // restore fDocument= getDocument((ITextEditor) part); Integer offset= memento.getInteger(TAG_X); Integer length= memento.getInteger(TAG_Y); String deleted= memento.getString(TAG_INFO); if (offset != null && length != null) { Position p= new Position(offset.intValue(), length.intValue()); if (deleted != null) p.isDeleted= INFO_DELETED.equals(deleted) ? true : false; // activate if (installOnDocument(fDocument, p)) { fPosition= p; if (!part.isDirty()) fSavedPosition= new Position(fPosition.offset, fPosition.length); } } } }
/** * Restores the object state from the given memento. * * @param memento the memento */ @Override public void restoreState(IMemento memento) { IEditorPart part= getEditorPart(); if (part instanceof ITextEditor) { // restore fDocument= getDocument((ITextEditor) part); Integer offset= memento.getInteger(TAG_X); Integer length= memento.getInteger(TAG_Y); String deleted= memento.getString(TAG_INFO); if (offset != null && length != null) { Position p= new Position(offset.intValue(), length.intValue()); if (deleted != null) p.isDeleted= INFO_DELETED.equals(deleted) ? true : false; // activate if (installOnDocument(fDocument, p)) { fPosition= p; if (!part.isDirty()) fSavedPosition= new Position(fPosition.offset, fPosition.length); } } } }
/** * Restores the object state from the given memento. * * @param memento the memento */ public void restoreState(IMemento memento) { IEditorPart part= getEditorPart(); if (part instanceof ITextEditor) { // restore fDocument= getDocument((ITextEditor) part); Integer offset= memento.getInteger(TAG_X); Integer length= memento.getInteger(TAG_Y); String deleted= memento.getString(TAG_INFO); if (offset != null && length != null) { Position p= new Position(offset.intValue(), length.intValue()); if (deleted != null) p.isDeleted= INFO_DELETED.equals(deleted) ? true : false; // activate if (installOnDocument(fDocument, p)) { fPosition= p; if (!part.isDirty()) fSavedPosition= new Position(fPosition.offset, fPosition.length); } } } }
/** * Returns a map from IFile to IDocument for all open, dirty editors. After creation this map * is not modified, so returning a non-synchronized map is ok. * * @return a map from IFile to IDocument for all open, dirty editors */ private Map<IFile, IDocument> evalNonFileBufferDocuments() { Map<IFile, IDocument> result= new HashMap<>(); IWorkbench workbench= SearchPlugin.getDefault().getWorkbench(); IWorkbenchWindow[] windows= workbench.getWorkbenchWindows(); for (IWorkbenchWindow window : windows) { IWorkbenchPage[] pages= window.getPages(); for (IWorkbenchPage page : pages) { IEditorReference[] editorRefs= page.getEditorReferences(); for (IEditorReference editorRef : editorRefs) { IEditorPart ep= editorRef.getEditor(false); if (ep instanceof ITextEditor && ep.isDirty()) { // only dirty editors evaluateTextEditor(result, ep); } } } } return result; }
/** * @return returns a map from IFile to IDocument for all open, dirty editors */ private Map evalNonFileBufferDocuments() { Map result= new HashMap(); IWorkbench workbench= SearchPlugin.getDefault().getWorkbench(); IWorkbenchWindow[] windows= workbench.getWorkbenchWindows(); for (int i= 0; i < windows.length; i++) { IWorkbenchPage[] pages= windows[i].getPages(); for (int x= 0; x < pages.length; x++) { IEditorReference[] editorRefs= pages[x].getEditorReferences(); for (int z= 0; z < editorRefs.length; z++) { IEditorPart ep= editorRefs[z].getEditor(false); if (ep instanceof ITextEditor && ep.isDirty()) { // only dirty editors evaluateTextEditor(result, ep); } } } } return result; }
/** * Sanity-check the public interface of the editor. This is called on every editor after it * is fully initiallized, but before it is actually connected to the editor reference or the * layout. Calls as much of the editor's public interface as possible to test for exceptions, * and tests the return values for glaring faults. This does not need to be an exhaustive conformance * test, as it is called every time an editor is opened and it needs to be efficient. * The part should be unmodified when the method exits. * * @param part */ public static void testEditor(IEditorPart part) throws Exception { testWorkbenchPart(part); Assert.isTrue(part.getEditorSite() == part.getSite(), "The part's editor site must be the same as the part's site"); //$NON-NLS-1$ IEditorInput input = part.getEditorInput(); Assert.isNotNull(input, "The editor input must be non-null"); //$NON-NLS-1$ testEditorInput(input); part.isDirty(); part.isSaveAsAllowed(); part.isSaveOnCloseNeeded(); }
if (part != null && (part.getEditorInput() instanceof SaveableCompareEditorInput) && part instanceof IReusableEditor && !part.isDirty()) { return part;
private static IEditorPart findReusableCompareEditor( CompareEditorInput input, IWorkbenchPage page) { IEditorReference[] editorRefs = page.getEditorReferences(); // first loop looking for an editor with the same input for (int i = 0; i < editorRefs.length; i++) { IEditorPart part = editorRefs[i].getEditor(false); if (part != null && (part.getEditorInput() instanceof GitCompareFileRevisionEditorInput || part.getEditorInput() instanceof GitCompareEditorInput) && part instanceof IReusableEditor && part.getEditorInput().equals(input)) { return part; } } // if none found and "Reuse open compare editors" preference is on use // a non-dirty editor if (isReuseOpenEditor()) { for (int i = 0; i < editorRefs.length; i++) { IEditorPart part = editorRefs[i].getEditor(false); if (part != null && (part.getEditorInput() instanceof SaveableCompareEditorInput) && part instanceof IReusableEditor && !part.isDirty()) { return part; } } } // no re-usable editor found return null; }
/** * Updates the this location. */ public void update() { IEditorPart part= getEditorPart(); if (part instanceof ITextEditor) { ITextEditor textEditor= (ITextEditor) getEditorPart(); if(equalsLocationOf(textEditor)) return; ISelection s= textEditor.getSelectionProvider().getSelection(); if(s == null || s.isEmpty()) return; ITextSelection selection= (ITextSelection) s; if(selection.getOffset() == 0 && selection.getLength() == 0) return; fPosition.offset= selection.getOffset(); fPosition.length= selection.getLength(); fPosition.isDeleted= false; if (!part.isDirty()) fSavedPosition= new Position(fPosition.offset, fPosition.length); } } }
/** * Updates the this location. */ @Override public void update() { IEditorPart part= getEditorPart(); if (part instanceof ITextEditor) { ITextEditor textEditor= (ITextEditor) getEditorPart(); if(equalsLocationOf(textEditor)) return; ISelection s= textEditor.getSelectionProvider().getSelection(); if(s == null || s.isEmpty()) return; ITextSelection selection= (ITextSelection) s; if(selection.getOffset() == 0 && selection.getLength() == 0) return; fPosition.offset= selection.getOffset(); fPosition.length= selection.getLength(); fPosition.isDeleted= false; if (!part.isDirty()) fSavedPosition= new Position(fPosition.offset, fPosition.length); } } }
/** * Updates the this location. */ @Override public void update() { IEditorPart part= getEditorPart(); if (part instanceof ITextEditor) { ITextEditor textEditor= (ITextEditor) getEditorPart(); if(equalsLocationOf(textEditor)) return; ISelection s= textEditor.getSelectionProvider().getSelection(); if(s == null || s.isEmpty()) return; ITextSelection selection= (ITextSelection) s; if(selection.getOffset() == 0 && selection.getLength() == 0) return; fPosition.offset= selection.getOffset(); fPosition.length= selection.getLength(); fPosition.isDeleted= false; if (!part.isDirty()) fSavedPosition= new Position(fPosition.offset, fPosition.length); } } }