Find if a file is dirty [message #151915] |
Fri, 31 October 2003 12:16  |
Eclipse User |
|
|
|
Hi,
Is there an easy way to find if the IFile I am dealing with is dirty
(currently open in an editor and the contents have been modified) ? I have
to consider the possibility of multiple workbench windows and multiple pages
within these windows. The IWorkbench.saveAllEditors() method considers all
the files in the workbench and does not serve my purpose.
Thanks,
Sudarshan
|
|
|
|
|
|
Re: Find if a file is dirty [message #152597 is a reply to message #152574] |
Mon, 03 November 2003 17:02  |
Eclipse User |
|
|
|
Dan,
Thats what I finally did. I was looking for a simple method like
saveDirtyEditor(IFile) which will save a file if it is dirty. Since there
was no such method., I implemented it in my plugin using a logic similar to
yours.
Thanks,
Sudarshan
"Dan Kehn" <eclipse.guide@removeMe.andMeToo.earthlink.net> wrote in message
news:bo6d1v$5du$1@eclipse.org...
> Wouldn't something like this work?
>
> public boolean isFileDirty(IFile f) {
> IWorkbenchWindow[] wbWindows =
> PlatformUI.getWorkbench().getWorkbenchWindows();
> for (each window) {
> IWorkbenchPage activePage wbWindow.getActivePage();
> IEditorReferences[] editorRefs = activePage.getEditorReferences();
> for (each editor reference) {
> if (editorRef.isDirty() &&
> editorRef instanceof IFileEditorInput &&
> editorRef.getFile().equals(f) &&
> return true;
> }
> }
> return false;
> }
>
> I left out required casts, assignments, etc. I haven't tested this but
it's
> basically all copied code. BTW, you don't have to consider multiple pages
> for each window since there is only one editor reference set for all
> perspectives within a given window.
>
> -- Dan
>
> ---------------------------------------------------
> co-author "The Java Developer's Guide to Eclipse"
> http://www.amazon.com/exec/obidos/ASIN/0321159640
>
> "Sudarshan Raghavan" <bali_n@yahoo.com> wrote in message
> news:bnu5bh$iqn$1@eclipse.org...
> > Hi,
> >
> > Is there an easy way to find if the IFile I am dealing with is dirty
> > (currently open in an editor and the contents have been modified) ? I
have
> > to consider the possibility of multiple workbench windows and multiple
> pages
> > within these windows. The IWorkbench.saveAllEditors() method considers
all
> > the files in the workbench and does not serve my purpose.
> >
> > Thanks,
> > Sudarshan
> >
> >
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.08630 seconds