All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.ui.internal.SaveAsAction Maven / Gradle / Ivy

Go to download

This plug-in contains the bulk of the Workbench implementation, and depends on JFace, SWT, and Core Runtime. It cannot be used independently from org.eclipse.ui. Workbench client plug-ins should not depend directly on this plug-in.

The newest version!
/*******************************************************************************
 * 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.ISaveablePart;
import org.eclipse.ui.IWorkbenchWindow;

/**
 * Workbench common Save As 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("org.eclipse.ui.file.saveAs"); //$NON-NLS-1$
        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(IWorkbenchGraphicConstants.IMG_ETOOL_SAVEAS_EDIT));
        setDisabledImageDescriptor(WorkbenchImages
                .getImageDescriptor(IWorkbenchGraphicConstants.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());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy