Jump to: navigation, search

Difference between revisions of "FAQ Close All Editors On Shutdown"

(FAQ_Close_All_Editors_On_Shutdown)
 
m
 
Line 27: Line 27:
 
final IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
 
final IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
  
 +
final IEditorPart editorPart = IDE.openEditorOnFileStore( activePage, fileStore );
  
//See  FAQ How do I open an editor programmatically?
+
workbench.addWorkbenchListener( new IWorkbenchListener() {
IEditorPart editorPart = IDE.openEditorOnFileStore( activePage, fileStore );
+
     public boolean preShutdown( IWorkbench workbench, boolean forced )    {                             
 
+
         activePage.closeEditor(editorPart, true);
 
+
workbench.addWorkbenchListener( new IWorkbenchListener()
+
{
+
     public boolean preShutdown( IWorkbench workbench, boolean forced )
+
     {                             
+
         activePage.closeEditors( activePage.getEditorReferences(), true);
+
 
         return true;
 
         return true;
 
     }
 
     }

Latest revision as of 04:19, 19 October 2008

The snippet below will close all Editors in the workbench when you close the eclipse application.

IWorkbench workbench = PlatformUI.getWorkbench();
final IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
 
workbench.addWorkbenchListener( new IWorkbenchListener()
{
    public boolean preShutdown( IWorkbench workbench, boolean forced )
    {                            
        activePage.closeEditors( activePage.getEditorReferences(), true);
        return true;
    }
 
    public void postShutdown( IWorkbench workbench )
    {
 
    }
});


The example below shows how to close an editor that is programmatically opened.

IWorkbench workbench = PlatformUI.getWorkbench();
final IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
 
final IEditorPart editorPart = IDE.openEditorOnFileStore( activePage, fileStore );
 
workbench.addWorkbenchListener( new IWorkbenchListener() {
    public boolean preShutdown( IWorkbench workbench, boolean forced )     {                            
        activePage.closeEditor(editorPart, true);
        return true;
    }
 
    public void postShutdown( IWorkbench workbench )
    {
 
    }
});

See Also:



This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.