summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorPrakash Rangaraj2010-12-14 05:46:01 (EST)
committer Paul Webster2012-05-11 09:50:54 (EDT)
commita936c70e30401da1a936f54a3b95647cc060f8d1 (patch)
tree10f5495a47364979604dae1b1fe3c9c780d7b60c
parent1688fd0512b7cedebee78ce34891113b85f899cf (diff)
downloadeclipse.platform.ui-a936c70e30401da1a936f54a3b95647cc060f8d1.zip
eclipse.platform.ui-a936c70e30401da1a936f54a3b95647cc060f8d1.tar.gz
eclipse.platform.ui-a936c70e30401da1a936f54a3b95647cc060f8d1.tar.bz2
Bug 270007 - [GlobalActions] Registering actions should not be required to use standard org.eclipse.ui commands
Merge in the 3.6 Save action to command
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/actions/ActionFactory.java21
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActiveEditorAction.java206
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/BaseSaveAction.java235
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveAction.java116
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveAllAction.java175
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveAsAction.java86
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/CloseAllSavedHandler.java136
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/SaveAllHandler.java88
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/SaveHandler.java96
-rw-r--r--bundles/org.eclipse.ui/plugin.xml2
10 files changed, 337 insertions, 824 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/actions/ActionFactory.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/actions/ActionFactory.java
index 6e5bfe6..89183dc 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/actions/ActionFactory.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/actions/ActionFactory.java
@@ -22,9 +22,6 @@ import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
import org.eclipse.ui.internal.IntroAction;
import org.eclipse.ui.internal.NavigationHistoryAction;
-import org.eclipse.ui.internal.SaveAction;
-import org.eclipse.ui.internal.SaveAllAction;
-import org.eclipse.ui.internal.SaveAsAction;
import org.eclipse.ui.internal.ToggleEditorsVisibilityAction;
import org.eclipse.ui.internal.WorkbenchImages;
import org.eclipse.ui.internal.WorkbenchMessages;
@@ -1284,8 +1281,12 @@ public abstract class ActionFactory {
if (window == null) {
throw new IllegalArgumentException();
}
- IWorkbenchAction action = new SaveAction(window);
+ WorkbenchCommandAction action = new WorkbenchCommandAction(getCommandId(), window);
+ action.setText(WorkbenchMessages.SaveAction_text);
+ action.setToolTipText(WorkbenchMessages.SaveAction_toolTip);
action.setId(getId());
+ window.getWorkbench().getHelpSystem()
+ .setHelp(action, IWorkbenchHelpContextIds.SAVE_ACTION);
return action;
}
};
@@ -1304,7 +1305,11 @@ public abstract class ActionFactory {
if (window == null) {
throw new IllegalArgumentException();
}
- IWorkbenchAction action = new SaveAllAction(window);
+ IWorkbenchAction action = new WorkbenchCommandAction(getCommandId(), window);
+ action.setText(WorkbenchMessages.SaveAll_text);
+ action.setToolTipText(WorkbenchMessages.SaveAll_toolTip);
+ window.getWorkbench().getHelpSystem()
+ .setHelp(action, IWorkbenchHelpContextIds.SAVE_ALL_ACTION);
action.setId(getId());
return action;
}
@@ -1324,7 +1329,11 @@ public abstract class ActionFactory {
if (window == null) {
throw new IllegalArgumentException();
}
- IWorkbenchAction action = new SaveAsAction(window);
+ IWorkbenchAction action = new WorkbenchCommandAction(getCommandId(), window);
+ action.setText(WorkbenchMessages.SaveAs_text);
+ action.setToolTipText(WorkbenchMessages.SaveAs_toolTip);
+ window.getWorkbench().getHelpSystem()
+ .setHelp(action, IWorkbenchHelpContextIds.SAVE_AS_ACTION);
action.setId(getId());
return action;
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActiveEditorAction.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActiveEditorAction.java
deleted file mode 100644
index 64e138e..0000000
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActiveEditorAction.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.ui.internal;
-
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
-
-/**
- * The abstract superclass for actions that depend on the active editor.
- * This implementation tracks the active editor (see <code>getActiveEditor</code>)
- * and updates the availability of the action when an editor becomes
- * active.
- * <p>
- * Subclasses must implement the following <code>IAction</code> method:
- * <ul>
- * <li><code>run</code> - to do the action's work</li>
- * </ul>
- * </p>
- * <p>
- * Subclasses may extend any of the <code>IPartListener</code> methods if the
- * action availablity needs to be recalculated:
- * <ul>
- * <li><code>partActivated</code></li>
- * <li><code>partDeactivated</code></li>
- * <li><code>partOpened</code></li>
- * <li><code>partClosed</code></li>
- * <li><code>partBroughtToTop</code></li>
- * </ul>
- * </p>
- * <p>
- * Subclasses may extend any of the <code>IPageListener</code> methods if the
- * action availablity needs to be recalculated:
- * <ul>
- * <li><code>pageActivated</code></li>
- * <li><code>pageClosed</code></li>
- * <li><code>pageOpened</code></li>
- * </ul>
- * </p>
- * <p>
- * This method implements the <code>IPartListener</code> and
- * <code>IPageListener</code>interfaces, and automatically registers listeners
- * so that it can keep its enablement state up to date. Ordinarily, the
- * window's references to these listeners will be dropped automatically when
- * the window closes. However, if the client needs to get rid of an action
- * while the window is still open, the client must call
- * {@link IWorkbenchAction#dispose dispose} to give the action an
- * opportunity to deregister its listeners and to perform any other cleanup.
- * </p>
- */
-public abstract class ActiveEditorAction extends PageEventAction {
-
- private IEditorPart activeEditor;
-
- /**
- * Creates a new action with the given text.
- *
- * @param text the string used as the text for the action,
- * or <code>null</code> if there is no text
- * @param window the workbench window this action is
- * registered with.
- */
- protected ActiveEditorAction(String text, IWorkbenchWindow window) {
- super(text, window);
- updateState();
- }
-
- /**
- * Notification that the active editor tracked
- * by the action is being activated.
- *
- * Subclasses may override.
- */
- protected void editorActivated(IEditorPart part) {
- }
-
- /**
- * Notification that the active editor tracked
- * by the action is being deactivated.
- *
- * Subclasses may override.
- */
- protected void editorDeactivated(IEditorPart part) {
- }
-
- /**
- * Return the active editor
- *
- * @return the page's active editor, and <code>null</code>
- * if no active editor or no active page.
- */
- public final IEditorPart getActiveEditor() {
- return activeEditor;
- }
-
- /* (non-Javadoc)
- * Method declared on PageEventAction.
- */
- public void pageActivated(IWorkbenchPage page) {
- super.pageActivated(page);
- updateActiveEditor();
- updateState();
- }
-
- /* (non-Javadoc)
- * Method declared on PageEventAction.
- */
- public void pageClosed(IWorkbenchPage page) {
- super.pageClosed(page);
- updateActiveEditor();
- updateState();
- }
-
- /* (non-Javadoc)
- * Method declared on PartEventAction.
- */
- public void partActivated(IWorkbenchPart part) {
- super.partActivated(part);
- if (part instanceof IEditorPart) {
- updateActiveEditor();
- updateState();
- }
- }
-
- /* (non-Javadoc)
- * Method declared on PartEventAction.
- */
- public void partBroughtToTop(IWorkbenchPart part) {
- super.partBroughtToTop(part);
- if (part instanceof IEditorPart) {
- updateActiveEditor();
- updateState();
- }
- }
-
- /* (non-Javadoc)
- * Method declared on PartEventAction.
- */
- public void partClosed(IWorkbenchPart part) {
- super.partClosed(part);
- if (part instanceof IEditorPart) {
- updateActiveEditor();
- updateState();
- }
- }
-
- /* (non-Javadoc)
- * Method declared on PartEventAction.
- */
- public void partDeactivated(IWorkbenchPart part) {
- super.partDeactivated(part);
- if (part instanceof IEditorPart) {
- updateActiveEditor();
- updateState();
- }
- }
-
- /**
- * Set the active editor
- */
- private void setActiveEditor(IEditorPart part) {
- if (activeEditor == part) {
- return;
- }
- if (activeEditor != null) {
- editorDeactivated(activeEditor);
- }
- activeEditor = part;
- if (activeEditor != null) {
- editorActivated(activeEditor);
- }
- }
-
- /**
- * Update the active editor based on the current
- * active page.
- */
- private void updateActiveEditor() {
- if (getActivePage() == null) {
- setActiveEditor(null);
- } else {
- setActiveEditor(getActivePage().getActiveEditor());
- }
- }
-
- /**
- * Update the state of the action. By default, the action
- * is enabled if there is an active editor.
- *
- * Subclasses may override or extend this method.
- */
- protected void updateState() {
- setEnabled(getActiveEditor() != null);
- }
-
-}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/BaseSaveAction.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/BaseSaveAction.java
deleted file mode 100644
index a6968f3..0000000
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/BaseSaveAction.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.ui.internal;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.ISaveablePart;
-import org.eclipse.ui.IViewPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.internal.util.Util;
-
-/**
- * The abstract superclass for save actions that depend on the active editor.
- */
-public abstract class BaseSaveAction extends ActiveEditorAction {
- /*
- * The view-related code below was added to track the view with focus
- * in order to support save actions from a view (see bug 10234).
- */
-
- /**
- * List of parts (element type: <code>IWorkbenchPart</code>)
- * against which this class has outstanding property listeners registered.
- */
- private List partsWithListeners = new ArrayList(1);
-
- private final IPropertyListener propListener = new IPropertyListener() {
- public void propertyChanged(Object source, int propId) {
- if (source == getActiveEditor()) {
- if (propId == IEditorPart.PROP_DIRTY) {
- updateState();
- }
- }
- }
- };
-
- /**
- * Creates a new action with the given text.
- *
- * @param text the string used as the text for the action,
- * or <code>null</code> if there is no text
- * @param window the workbench window this action is
- * registered with.
- */
- protected BaseSaveAction(String text, IWorkbenchWindow window) {
- super(text, window);
- }
-
- /* (non-Javadoc)
- * Method declared on ActiveEditorAction.
- */
- protected void editorActivated(IEditorPart part) {
- if (part != null) {
- part.addPropertyListener(propListener);
- partsWithListeners.add(part);
- }
- }
-
- /* (non-Javadoc)
- * Method declared on ActiveEditorAction.
- */
- protected void editorDeactivated(IEditorPart part) {
- if (part != null) {
- part.removePropertyListener(propListener);
- partsWithListeners.remove(part);
- }
- }
-
- private IViewPart activeView;
-
- private final IPropertyListener propListener2 = new IPropertyListener() {
- public void propertyChanged(Object source, int propId) {
- if (source == activeView) {
- if (propId == IEditorPart.PROP_DIRTY) {
- updateState();
- }
- }
- }
- };
-
- /** the active saveable part is tracked in order to listen to its dirty events */
- private ISaveablePart activeSaveablePart;
-
- private final IPropertyListener propListener3 = new IPropertyListener() {
- public void propertyChanged(Object source, int propId) {
- if (source == activeSaveablePart) {
- if (propId == IEditorPart.PROP_DIRTY) {
- updateState();
- }
- }
- }
- };
-
- /* (non-Javadoc)
- * Method declared on PageEventAction.
- */
- public void pageActivated(IWorkbenchPage page) {
- super.pageActivated(page);
- updateActiveView();
- updateState();
- }
-
- /* (non-Javadoc)
- * Method declared on PageEventAction.
- */
- public void pageClosed(IWorkbenchPage page) {
- super.pageClosed(page);
- updateActiveView();
- updateState();
- }
-
- /* (non-Javadoc)
- * Method declared on PartEventAction.
- */
- public void partActivated(IWorkbenchPart part) {
- super.partActivated(part);
- if (part instanceof IViewPart) {
- updateActiveView();
- updateState();
- }
- }
-
- /* (non-Javadoc)
- * Method declared on PartEventAction.
- */
- public void partClosed(IWorkbenchPart part) {
- super.partClosed(part);
- if (part instanceof IViewPart) {
- updateActiveView();
- updateState();
- }
- }
-
- /* (non-Javadoc)
- * Method declared on PartEventAction.
- */
- public void partDeactivated(IWorkbenchPart part) {
- super.partDeactivated(part);
- if (part instanceof IViewPart) {
- updateActiveView();
- updateState();
- }
- }
-
- /**
- * Update the active view based on the current
- * active page.
- */
- private void updateActiveView() {
- if (getActivePage() == null) {
- setActiveView(null);
- } else {
- setActiveView(getActivePage().getActivePart());
- }
- }
-
- /**
- *
- */
- private void updateActiveSaveablePart() {
- if (activeSaveablePart instanceof IWorkbenchPart) {
- ((IWorkbenchPart)activeSaveablePart).removePropertyListener(propListener3);
- partsWithListeners.remove(activeSaveablePart);
- }
- activeSaveablePart = getSaveableView();
- if (activeSaveablePart == activeView) {
- // no need to listen to the same part twice
- activeSaveablePart = null;
- }
- if (activeSaveablePart instanceof IWorkbenchPart) {
- ((IWorkbenchPart)activeSaveablePart).addPropertyListener(propListener3);
- partsWithListeners.add(activeSaveablePart);
- }
- }
-
- /**
- * Set the active editor
- */
- private void setActiveView(IWorkbenchPart part) {
- if (activeView == part) {
- return;
- }
- if (activeView != null) {
- activeView.removePropertyListener(propListener2);
- partsWithListeners.remove(activeView);
- }
- if (part instanceof IViewPart) {
- activeView = (IViewPart) part;
- } else {
- activeView = null;
- }
- if (activeView != null) {
- activeView.addPropertyListener(propListener2);
- partsWithListeners.add(activeView);
- }
- updateActiveSaveablePart();
- }
-
- protected final ISaveablePart getSaveableView() {
- if (activeView == null) {
- return null;
- }
-
- return (ISaveablePart) Util.getAdapter(activeView, ISaveablePart.class);
- }
-
- /* (non-Javadoc)
- * Method declared on PageEventAction.
- */
- public void dispose() {
- super.dispose();
- for (Iterator it = partsWithListeners.iterator(); it.hasNext();) {
- IWorkbenchPart part = (IWorkbenchPart) it.next();
- part.removePropertyListener(propListener);
- part.removePropertyListener(propListener2);
- part.removePropertyListener(propListener3);
- }
- partsWithListeners.clear();
- }
-}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveAction.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveAction.java
deleted file mode 100644
index e677c6f..0000000
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveAction.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.ui.internal;
-
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.ISaveablePart;
-import org.eclipse.ui.ISaveablesSource;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.IWorkbenchCommandConstants;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-
-/**
- * Workbench common <code>Save</code> action.
- */
-public class SaveAction extends BaseSaveAction implements IBackgroundSaveListener {
-
- /**
- * Create an instance of this class
- *
- * @param window the window
- */
- public SaveAction(IWorkbenchWindow window) {
- super(WorkbenchMessages.SaveAction_text, window);
- setText(WorkbenchMessages.SaveAction_text);
- setToolTipText(WorkbenchMessages.SaveAction_toolTip);
- setId("save"); //$NON-NLS-1$
- window.getWorkbench().getHelpSystem().setHelp(this,
- IWorkbenchHelpContextIds.SAVE_ACTION);
- setImageDescriptor(WorkbenchImages
- .getImageDescriptor(ISharedImages.IMG_ETOOL_SAVE_EDIT));
- setDisabledImageDescriptor(WorkbenchImages
- .getImageDescriptor(ISharedImages.IMG_ETOOL_SAVE_EDIT_DISABLED));
- setActionDefinitionId(IWorkbenchCommandConstants.FILE_SAVE);
- ((WorkbenchWindow)window).addBackgroundSaveListener(this);
- }
-
- public void dispose() {
- ((WorkbenchWindow)getWorkbenchWindow()).removeBackgroundSaveListener(this);
- super.dispose();
- }
-
- /* (non-Javadoc)
- * Method declared on IAction.
- * Performs the <code>Save</code> action by calling the
- * <code>IEditorPart.doSave</code> method on the active editor.
- */
- public void run() {
- if (getWorkbenchWindow() == null) {
- // action has been disposed
- return;
- }
- /* **********************************************************************************
- * The code below was added to track the view with focus
- * in order to support save actions from a view (see bug 10234).
- */
- ISaveablePart saveView = getSaveableView();
- if (saveView != null) {
- ((WorkbenchPage) getActivePart().getSite().getPage()).saveSaveable(saveView, false,
- false);
- return;
- }
-
- IEditorPart part = getActiveEditor();
- if (part != null) {
- IWorkbenchPage page = part.getSite().getPage();
- page.saveEditor(part, false);
- }
- }
-
- /* (non-Javadoc)
- * Method declared on ActiveEditorAction.
- */
- protected void updateState() {
- /* **********************************************************************************
- * The code below was added to track the view with focus
- * in order to support save actions from a view (see bug 10234).
- */
- ISaveablePart saveable = getSaveableView();
- if (saveable == null) {
- saveable = getActiveEditor();
- }
- /* **********************************************************************************/
- if (saveable instanceof ISaveablesSource) {
- ISaveablesSource modelSource = (ISaveablesSource) saveable;
- setEnabled(SaveableHelper.needsSave(modelSource));
- return;
- }
- setEnabled(saveable != null && saveable.isDirty());
- }
-
- public void handleBackgroundSaveStarted() {
- updateState();
- }
-
- public void setEnabled(boolean enabled) {
- super.setEnabled(enabled);
- IWorkbenchWindow window = getWorkbenchWindow();
- if (window != null) {
- Shell shell = window.getShell();
- if (shell != null && !shell.isDisposed()) {
- shell.setModified(enabled);
- }
- }
- }
-
-}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveAllAction.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveAllAction.java
deleted file mode 100644
index c5d1b3c..0000000
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveAllAction.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.ui.internal;
-
-import org.eclipse.e4.ui.workbench.modeling.EPartService;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.ISaveablePart;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.IWorkbenchCommandConstants;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
-
-/**
- * Global action that saves all targets in the
- * workbench that implement ISaveTarget interface.
- * The action keeps track of opened save targets
- * and their 'save' state. If none of the currently
- * opened targets needs saving, it will disable.
- * This action is somewhat different from all
- * other global actions in that it works on
- * multiple targets at the same time i.e. it
- * does not disconnect from the target when it
- * becomes deactivated.
- */
-public class SaveAllAction extends PageEventAction implements IPropertyListener {
- /**
- * List of parts (element type: <code>IWorkbenchPart</code>)
- * against which this class has outstanding property listeners registered.
- */
- private List partsWithListeners = new ArrayList(1);
- private IWorkbenchPart openPart;
-
- /**
- * The default constructor.
- *
- * @param window the window
- */
- public SaveAllAction(IWorkbenchWindow window) {
- super(WorkbenchMessages.SaveAll_text, window);
- setToolTipText(WorkbenchMessages.SaveAll_toolTip);
- setId("saveAll"); //$NON-NLS-1$
- setEnabled(false);
- window.getWorkbench().getHelpSystem().setHelp(this,
- IWorkbenchHelpContextIds.SAVE_ALL_ACTION);
- setImageDescriptor(WorkbenchImages
- .getImageDescriptor(ISharedImages.IMG_ETOOL_SAVEALL_EDIT));
- setDisabledImageDescriptor(WorkbenchImages
- .getImageDescriptor(ISharedImages.IMG_ETOOL_SAVEALL_EDIT_DISABLED));
- setActionDefinitionId(IWorkbenchCommandConstants.FILE_SAVE_ALL);
- }
-
- /* (non-Javadoc)
- * Method declared on PageEventAction.
- */
- public void pageActivated(IWorkbenchPage page) {
- super.pageActivated(page);
- updateState();
- }
-
- /* (non-Javadoc)
- * Method declared on PageEventAction.
- */
- public void pageClosed(IWorkbenchPage page) {
- super.pageClosed(page);
- updateState();
- }
-
- /* (non-Javadoc)
- * Method declared on PartEventAction.
- */
- public void partClosed(IWorkbenchPart part) {
- super.partClosed(part);
- if (part instanceof ISaveablePart) {
- part.removePropertyListener(this);
- partsWithListeners.remove(part);
- updateState();
- }
- }
-
- /* (non-Javadoc)
- * Method declared on PartEventAction.
- */
- public void partOpened(IWorkbenchPart part) {
- super.partOpened(part);
- if (part instanceof ISaveablePart) {
- part.addPropertyListener(this);
- partsWithListeners.add(part);
- // We need to temporarily cache the opened part
- // because saveable views are not registered
- // with a perspective until after this method
- // is called. We can't pass it through to
- // update because it's protected. An async
- // call to update may be a better approach.
- // See bug 93784 [WorkbenchParts] View not yet added to perspective when partOpened sent
- openPart = part;
- updateState();
- openPart = null;
- }
- }
-
- /* (non-Javadoc)
- * Method declared on IPropertyListener.
- */
- public void propertyChanged(Object source, int propID) {
- if (source instanceof ISaveablePart) {
- if (propID == ISaveablePart.PROP_DIRTY) {
- updateState();
- }
- }
- }
-
- /* (non-Javadoc)
- * Method declared on Action.
- */
- public void run() {
- if (getWorkbenchWindow() == null) {
- // action has been disposed
- return;
- }
- IWorkbenchPage page = getActivePage();
- if (page != null) {
- // FIXME: need to also save saveables from non-part sources, see bug
- // 139004.
- page.saveAllEditors(false);
- updateState();
- }
- }
-
- /**
- * Updates availability depending on number of
- * targets that need saving.
- */
- protected void updateState() {
- // Workaround for bug 93784 [WorkbenchParts] View not yet added to perspective when partOpened sent
- if (openPart != null && openPart.getSite().getPage().equals(getActivePage()) && ((ISaveablePart) openPart).isDirty()) {
- setEnabled(true);
- }
- else {
- IWorkbenchPage page = getActivePage();
- if (page == null) {
- setEnabled(false);
- } else {
- EPartService partService = (EPartService) page.getWorkbenchWindow().getService(
- EPartService.class);
- setEnabled(!partService.getDirtyParts().isEmpty());
- }
- }
- }
-
- /* (non-Javadoc)
- * Method declared on PageEventAction.
- */
- public void dispose() {
- super.dispose();
- for (Iterator it = partsWithListeners.iterator(); it.hasNext();) {
- IWorkbenchPart part = (IWorkbenchPart) it.next();
- part.removePropertyListener(this);
- }
- partsWithListeners.clear();
- }
-
-}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveAsAction.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveAsAction.java
deleted file mode 100644
index b9693cc..0000000
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveAsAction.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.ui.internal;
-
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.ISaveablePart;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.IWorkbenchCommandConstants;
-import org.eclipse.ui.IWorkbenchWindow;
-
-/**
- * Workbench common <code>Save As</code> action.
- */
-public class SaveAsAction extends BaseSaveAction {
-
- /**
- * Create an instance of this class
- *
- * @param window the window
- */
- public SaveAsAction(IWorkbenchWindow window) {
- super(WorkbenchMessages.SaveAs_text, window);
- setActionDefinitionId(IWorkbenchCommandConstants.FILE_SAVE_AS);
- setText(WorkbenchMessages.SaveAs_text);
- setToolTipText(WorkbenchMessages.SaveAs_toolTip);
- setId("saveAs"); //$NON-NLS-1$
- window.getWorkbench().getHelpSystem().setHelp(this,
- IWorkbenchHelpContextIds.SAVE_AS_ACTION);
- setImageDescriptor(WorkbenchImages
- .getImageDescriptor(ISharedImages.IMG_ETOOL_SAVEAS_EDIT));
- setDisabledImageDescriptor(WorkbenchImages
- .getImageDescriptor(ISharedImages.IMG_ETOOL_SAVEAS_EDIT_DISABLED));
- }
-
- /* (non-Javadoc)
- * Method declared on Action.
- */
- public void run() {
- if (getWorkbenchWindow() == null) {
- // action has been disposed
- return;
- }
- /* **********************************************************************************
- * The code below was added to track the view with focus
- * in order to support save actions from a view (see bug 10234).
- */
- ISaveablePart saveView = getSaveableView();
- if (saveView != null) {
- saveView.doSaveAs();
- return;
- }
- /* **********************************************************************************/
-
- IEditorPart editor = getActiveEditor();
- if (editor != null) {
- editor.doSaveAs();
- }
- }
-
- /* (non-Javadoc)
- * Method declared on ActiveEditorAction.
- */
- protected void updateState() {
- /* **********************************************************************************
- * The code below was added to track the view with focus
- * in order to support save actions from a view (see bug 10234).
- */
- ISaveablePart saveView = getSaveableView();
- if (saveView != null) {
- setEnabled(saveView.isSaveAsAllowed());
- return;
- }
- /* **********************************************************************************/
-
- IEditorPart editor = getActiveEditor();
- setEnabled(editor != null && editor.isSaveAsAllowed());
- }
-}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/CloseAllSavedHandler.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/CloseAllSavedHandler.java
new file mode 100644
index 0000000..f7637bd
--- /dev/null
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/CloseAllSavedHandler.java
@@ -0,0 +1,136 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ui.internal.handlers;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.expressions.ExpressionInfo;
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.internal.AbstractEvaluationHandler;
+import org.eclipse.ui.internal.InternalHandlerUtil;
+import org.eclipse.ui.internal.WorkbenchPage;
+import org.eclipse.ui.internal.util.Util;
+
+
+/**
+ *
+ * @author Prakash G.R.
+ * @since 3.7
+ *
+ */
+public class CloseAllSavedHandler extends AbstractEvaluationHandler {
+
+ private Expression enabledWhen;
+ private IWorkbenchPage page;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.internal.AbstractEvaluationHandler#getEnabledWhenExpression
+ * ()
+ */
+ protected Expression getEnabledWhenExpression() {
+ if (enabledWhen == null) {
+ enabledWhen = new Expression() {
+ public EvaluationResult evaluate(IEvaluationContext context) {
+ return CloseAllSavedHandler.this.evaluate(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.expressions.Expression#collectExpressionInfo
+ * (org.eclipse.core.expressions.ExpressionInfo)
+ */
+ public void collectExpressionInfo(ExpressionInfo info) {
+ // We use active part, so that we get evaluated for the part
+ // events
+ info.addVariableNameAccess(ISources.ACTIVE_PART_NAME);
+ }
+ };
+ }
+ return enabledWhen;
+ }
+
+ private EvaluationResult evaluate(IEvaluationContext context) {
+
+ IWorkbenchWindow window = InternalHandlerUtil.getActiveWorkbenchWindow(context);
+
+ setWindow(window);
+
+ return window != null && window.getActivePage() != null ? EvaluationResult.TRUE
+ : EvaluationResult.FALSE;
+ }
+
+ /**
+ * @param window
+ */
+ private void setWindow(IWorkbenchWindow window) {
+
+ if (Util.equals(page, window.getActivePage()))
+ return;
+
+ page = window.getActivePage();
+
+ update();
+ }
+
+ /**
+ * @return Returns the page.
+ */
+ public IWorkbenchPage getActivePage() {
+ return page;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
+ * ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) {
+ IWorkbenchPage page = getActivePage();
+ if (page != null) {
+ ((WorkbenchPage) page).closeAllSavedEditors();
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.internal.handlers.AbstractPageEventHandler#update()
+ */
+ protected void update() {
+ IWorkbenchPage page = getActivePage();
+ if (page == null) {
+ setEnabled(false);
+ return;
+ }
+ IEditorReference editors[] = page.getEditorReferences();
+ for (int i = 0; i < editors.length; i++) {
+ if (!editors[i].isDirty()) {
+ setEnabled(true);
+ return;
+ }
+ }
+ setEnabled(false);
+ }
+
+}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/SaveAllHandler.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/SaveAllHandler.java
new file mode 100644
index 0000000..06deb1d
--- /dev/null
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/SaveAllHandler.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.ui.internal.handlers;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.ui.ISaveablesLifecycleListener;
+import org.eclipse.ui.ISaveablesSource;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.Saveable;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.internal.InternalHandlerUtil;
+import org.eclipse.ui.internal.SaveablesList;
+import org.eclipse.ui.internal.WorkbenchPage;
+
+/**
+ * Saves all active editors
+ * <p>
+ * Replacement for SaveAllAction
+ * </p>
+ *
+ * @since 3.7
+ *
+ */
+public class SaveAllHandler extends AbstractSaveHandler {
+
+ public SaveAllHandler() {
+ registerEnablement();
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchWindow window = HandlerUtil
+ .getActiveWorkbenchWindowChecked(event);
+ IWorkbenchPage page = window.getActivePage();
+ if (page != null) {
+ ((WorkbenchPage) page).saveAllEditors(false, true);
+ }
+
+ return null;
+ }
+
+ protected EvaluationResult evaluate(IEvaluationContext context) {
+
+ IWorkbenchWindow window = InternalHandlerUtil.getActiveWorkbenchWindow(context);
+ // no window? not active
+ if (window == null)
+ return EvaluationResult.FALSE;
+ WorkbenchPage page = (WorkbenchPage) window.getActivePage();
+
+ // no page? not active
+ if (page == null)
+ return EvaluationResult.FALSE;
+
+ // if at least one dirty part, then we are active
+ if (page.getDirtyParts().length > 0)
+ return EvaluationResult.TRUE;
+
+ // Since Save All also saves saveables from non-part sources,
+ // look if any such saveables exist and are dirty.
+ SaveablesList saveablesList = (SaveablesList) window.getWorkbench().getService(
+ ISaveablesLifecycleListener.class);
+ ISaveablesSource[] nonPartSources = saveablesList.getNonPartSources();
+ for (int i = 0; i < nonPartSources.length; i++) {
+ Saveable[] saveables = nonPartSources[i].getSaveables();
+ for (int j = 0; j < saveables.length; j++) {
+ if (saveables[j].isDirty()) {
+ return EvaluationResult.TRUE;
+ }
+ }
+ }
+
+ // if nothing, then we are not active
+ return EvaluationResult.FALSE;
+ }
+
+}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/SaveHandler.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/SaveHandler.java
new file mode 100644
index 0000000..0214be7
--- /dev/null
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/SaveHandler.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.ui.internal.handlers;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.ISaveablePart;
+import org.eclipse.ui.ISaveablesSource;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.internal.InternalHandlerUtil;
+import org.eclipse.ui.internal.SaveableHelper;
+import org.eclipse.ui.internal.WorkbenchPage;
+
+/**
+ * <p>
+ * Replacement for SaveAction
+ * </p>
+ *
+ * @since 3.7
+ *
+ */
+public class SaveHandler extends AbstractSaveHandler {
+
+ public SaveHandler() {
+ registerEnablement();
+ }
+
+ public Object execute(ExecutionEvent event) {
+
+ ISaveablePart saveablePart = getSaveablePart(event);
+
+ // no saveable
+ if (saveablePart == null)
+ return null;
+
+ // if editor
+ if (saveablePart instanceof IEditorPart) {
+ IEditorPart editorPart = (IEditorPart) saveablePart;
+ IWorkbenchPage page = editorPart.getSite().getPage();
+ page.saveEditor(editorPart, false);
+ return null;
+ }
+
+ // if view
+ IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
+ WorkbenchPage page = (WorkbenchPage) activePart.getSite().getPage();
+ page.savePart(saveablePart, activePart, false);
+
+ return null;
+
+ }
+
+ protected EvaluationResult evaluate(IEvaluationContext context) {
+
+ IWorkbenchWindow window = InternalHandlerUtil.getActiveWorkbenchWindow(context);
+ // no window? not active
+ if (window == null)
+ return EvaluationResult.FALSE;
+ WorkbenchPage page = (WorkbenchPage) window.getActivePage();
+
+ // no page? not active
+ if (page == null)
+ return EvaluationResult.FALSE;
+
+ // get saveable part
+ ISaveablePart saveablePart = getSaveablePart(context);
+ if (saveablePart == null)
+ return EvaluationResult.FALSE;
+
+ if (saveablePart instanceof ISaveablesSource) {
+ ISaveablesSource modelSource = (ISaveablesSource) saveablePart;
+ if (SaveableHelper.needsSave(modelSource))
+ return EvaluationResult.TRUE;
+ return EvaluationResult.FALSE;
+ }
+
+ if (saveablePart != null && saveablePart.isDirty())
+ return EvaluationResult.TRUE;
+
+ return EvaluationResult.FALSE;
+ }
+}
diff --git a/bundles/org.eclipse.ui/plugin.xml b/bundles/org.eclipse.ui/plugin.xml
index 07d785a..c988a8b 100644
--- a/bundles/org.eclipse.ui/plugin.xml
+++ b/bundles/org.eclipse.ui/plugin.xml
@@ -843,6 +843,7 @@
name="%command.save.name"
description="%command.save.description"
categoryId="org.eclipse.ui.category.file"
+ defaultHandler="org.eclipse.ui.internal.handlers.SaveHandler"
id="org.eclipse.ui.file.save" />
<command
name="%command.saveAs.name"
@@ -853,6 +854,7 @@
<command
name="%command.saveAll.name"
description="%command.saveAll.description"
+ defaultHandler="org.eclipse.ui.internal.handlers.SaveAllHandler"
categoryId="org.eclipse.ui.category.file"
id="org.eclipse.ui.file.saveAll" />
<command