001: /*******************************************************************************
002: * Copyright (c) 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.actions;
011:
012: import org.eclipse.jface.action.Action;
013: import org.eclipse.swt.custom.BusyIndicator;
014: import org.eclipse.ui.IWorkbenchPreferenceConstants;
015: import org.eclipse.ui.IWorkbenchWindow;
016: import org.eclipse.ui.PlatformUI;
017: import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
018: import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
019: import org.eclipse.ui.internal.WorkbenchMessages;
020: import org.eclipse.ui.internal.util.PrefUtil;
021:
022: /**
023: * Action to open the dynamic help.
024: *
025: * @since 3.1
026: */
027: public class DynamicHelpAction extends Action implements
028: IWorkbenchAction {
029: /**
030: * The workbench window; or <code>null</code> if this action has been
031: * <code>dispose</code>d.
032: */
033: private IWorkbenchWindow workbenchWindow;
034:
035: /**
036: * Zero-arg constructor to allow cheat sheets to reuse this action.
037: */
038: public DynamicHelpAction() {
039: this (PlatformUI.getWorkbench().getActiveWorkbenchWindow());
040: }
041:
042: /**
043: * Constructor for use by ActionFactory.
044: *
045: * @param window
046: * the window
047: */
048: public DynamicHelpAction(IWorkbenchWindow window) {
049: if (window == null) {
050: throw new IllegalArgumentException();
051: }
052: this .workbenchWindow = window;
053: setActionDefinitionId("org.eclipse.ui.help.dynamicHelp"); //$NON-NLS-1$
054:
055: // support for allowing a product to override the text for the action
056: String overrideText = PrefUtil
057: .getAPIPreferenceStore()
058: .getString(
059: IWorkbenchPreferenceConstants.DYNAMIC_HELP_ACTION_TEXT);
060: if ("".equals(overrideText)) { //$NON-NLS-1$
061: setText(appendAccelerator(WorkbenchMessages.DynamicHelpAction_text));
062: setToolTipText(WorkbenchMessages.DynamicHelpAction_toolTip);
063: } else {
064: setText(appendAccelerator(overrideText));
065: setToolTipText(Action.removeMnemonics(overrideText));
066: }
067: window.getWorkbench().getHelpSystem().setHelp(this ,
068: IWorkbenchHelpContextIds.DYNAMIC_HELP_ACTION);
069: }
070:
071: private String appendAccelerator(String text) {
072: // We know that on Windows context help key is F1
073: // and cannot be changed by the user.
074: //
075: // Commented out due to the problem described in
076: // Bugzilla bug #95057
077:
078: //if (Platform.getWS().equals(Platform.WS_WIN32))
079: // return text + "\t" + KeyStroke.getInstance(SWT.F1).format(); //$NON-NLS-1$
080: return text;
081: }
082:
083: /*
084: * (non-Javadoc) Method declared on IAction.
085: */
086: public void run() {
087: if (workbenchWindow == null) {
088: // action has been disposed
089: return;
090: }
091: // This may take a while, so use the busy indicator
092: BusyIndicator.showWhile(null, new Runnable() {
093: public void run() {
094: workbenchWindow.getWorkbench().getHelpSystem()
095: .displayDynamicHelp();
096: }
097: });
098: }
099:
100: /*
101: * (non-Javadoc) Method declared on ActionFactory.IWorkbenchAction.
102: */
103: public void dispose() {
104: workbenchWindow = null;
105: }
106:
107: }
|