01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal;
11:
12: import org.eclipse.ui.IEditorPart;
13: import org.eclipse.ui.ISaveablePart;
14: import org.eclipse.ui.IWorkbenchWindow;
15:
16: /**
17: * Workbench common <code>Save As</code> action.
18: */
19: public class SaveAsAction extends BaseSaveAction {
20:
21: /**
22: * Create an instance of this class
23: *
24: * @param window the window
25: */
26: public SaveAsAction(IWorkbenchWindow window) {
27: super (WorkbenchMessages.SaveAs_text, window);
28: setActionDefinitionId("org.eclipse.ui.file.saveAs"); //$NON-NLS-1$
29: setText(WorkbenchMessages.SaveAs_text);
30: setToolTipText(WorkbenchMessages.SaveAs_toolTip);
31: setId("saveAs"); //$NON-NLS-1$
32: window.getWorkbench().getHelpSystem().setHelp(this ,
33: IWorkbenchHelpContextIds.SAVE_AS_ACTION);
34: setImageDescriptor(WorkbenchImages
35: .getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_SAVEAS_EDIT));
36: setDisabledImageDescriptor(WorkbenchImages
37: .getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_SAVEAS_EDIT_DISABLED));
38: }
39:
40: /* (non-Javadoc)
41: * Method declared on Action.
42: */
43: public void run() {
44: if (getWorkbenchWindow() == null) {
45: // action has been disposed
46: return;
47: }
48: /* **********************************************************************************
49: * The code below was added to track the view with focus
50: * in order to support save actions from a view (see bug 10234).
51: */
52: ISaveablePart saveView = getSaveableView();
53: if (saveView != null) {
54: saveView.doSaveAs();
55: return;
56: }
57: /* **********************************************************************************/
58:
59: IEditorPart editor = getActiveEditor();
60: if (editor != null) {
61: editor.doSaveAs();
62: }
63: }
64:
65: /* (non-Javadoc)
66: * Method declared on ActiveEditorAction.
67: */
68: protected void updateState() {
69: /* **********************************************************************************
70: * The code below was added to track the view with focus
71: * in order to support save actions from a view (see bug 10234).
72: */
73: ISaveablePart saveView = getSaveableView();
74: if (saveView != null) {
75: setEnabled(saveView.isSaveAsAllowed());
76: return;
77: }
78: /* **********************************************************************************/
79:
80: IEditorPart editor = getActiveEditor();
81: setEnabled(editor != null && editor.isSaveAsAllowed());
82: }
83: }
|