1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.ui.IEditorPart; 14 import org.eclipse.ui.ISaveablePart; 15 import org.eclipse.ui.ISaveablesSource; 16 import org.eclipse.ui.IWorkbenchPage; 17 import org.eclipse.ui.IWorkbenchWindow; 18 19 22 public class SaveAction extends BaseSaveAction implements IBackgroundSaveListener { 23 24 29 public SaveAction(IWorkbenchWindow window) { 30 super(WorkbenchMessages.SaveAction_text, window); 31 setText(WorkbenchMessages.SaveAction_text); 32 setToolTipText(WorkbenchMessages.SaveAction_toolTip); 33 setId("save"); window.getWorkbench().getHelpSystem().setHelp(this, 35 IWorkbenchHelpContextIds.SAVE_ACTION); 36 setImageDescriptor(WorkbenchImages 37 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_SAVE_EDIT)); 38 setDisabledImageDescriptor(WorkbenchImages 39 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_SAVE_EDIT_DISABLED)); 40 setActionDefinitionId("org.eclipse.ui.file.save"); ((WorkbenchWindow)window).addBackgroundSaveListener(this); 42 } 43 44 public void dispose() { 45 ((WorkbenchWindow)getWorkbenchWindow()).removeBackgroundSaveListener(this); 46 super.dispose(); 47 } 48 49 54 public void run() { 55 if (getWorkbenchWindow() == null) { 56 return; 58 } 59 63 ISaveablePart saveView = getSaveableView(); 64 if (saveView != null) { 65 ((WorkbenchPage) getActivePart().getSite().getPage()).savePart( 66 saveView, getActivePart(), false); 67 return; 68 } 69 70 IEditorPart part = getActiveEditor(); 71 if (part != null) { 72 IWorkbenchPage page = part.getSite().getPage(); 73 page.saveEditor(part, false); 74 } 75 } 76 77 80 protected void updateState() { 81 85 ISaveablePart saveable = getSaveableView(); 86 if (saveable == null) { 87 saveable = getActiveEditor(); 88 } 89 90 if (saveable instanceof ISaveablesSource) { 91 ISaveablesSource modelSource = (ISaveablesSource) saveable; 92 setEnabled(SaveableHelper.needsSave(modelSource)); 93 return; 94 } 95 setEnabled(saveable != null && saveable.isDirty()); 96 } 97 98 public void handleBackgroundSaveStarted() { 99 updateState(); 100 } 101 } 102 | Popular Tags |