Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurtis D'Entremont2007-03-09 20:17:16 +0000
committerCurtis D'Entremont2007-03-09 20:17:16 +0000
commit4bbe316da619da92d5ba6ad850299761d3ad0bd7 (patch)
tree987317e34cbc36592ca98eb64147085c6667d058 /org.eclipse.ui.cheatsheets/src/org
parent017f48d0bf6fb684e0d3a8fdc244761afdd2db22 (diff)
downloadeclipse.platform.ua-4bbe316da619da92d5ba6ad850299761d3ad0bd7.tar.gz
eclipse.platform.ua-4bbe316da619da92d5ba6ad850299761d3ad0bd7.tar.xz
eclipse.platform.ua-4bbe316da619da92d5ba6ad850299761d3ad0bd7.zip
161988 [Help] Allow linking to cheat sheets from context help
Diffstat (limited to 'org.eclipse.ui.cheatsheets/src/org')
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetAction.java79
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetFromHelpAction.java2
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatsheetSearchParticipant.java2
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/actions/CheatSheetMenu.java2
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/dialogs/CheatSheetCategoryBasedSelectionDialog.java4
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/handlers/OpenCheatSheetHandler.java2
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/handlers/OpenCheatSheetURLHandler.java2
7 files changed, 62 insertions, 31 deletions
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetAction.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetAction.java
index afd9f04a7..b9b2d3f11 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetAction.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetAction.java
@@ -12,11 +12,18 @@ package org.eclipse.ui.cheatsheets;
import java.net.URL;
+import org.eclipse.help.ui.internal.views.HelpTray;
+import org.eclipse.help.ui.internal.views.IHelpPartPage;
+import org.eclipse.help.ui.internal.views.ReusableHelpPart;
import org.eclipse.jface.action.Action;
-import org.eclipse.ui.IWorkbench;
+import org.eclipse.jface.dialogs.TrayDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin;
+import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
+import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetRegistryReader;
+import org.eclipse.ui.internal.cheatsheets.state.DefaultStateManager;
+import org.eclipse.ui.internal.cheatsheets.views.CheatSheetHelpPart;
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetView;
import org.eclipse.ui.internal.cheatsheets.views.ViewUtilities;
@@ -35,6 +42,7 @@ public final class OpenCheatSheetAction extends Action {
private URL url;
private String xml;
private String basePath;
+ private boolean forceView;
/**
* Creates an action that opens the cheat sheet with the given id.
@@ -43,14 +51,16 @@ public final class OpenCheatSheetAction extends Action {
* extension point.
*
* @param id the cheat sheet id
+ * @param forceView to avoid opening in dialogs (e.g. selection dialog itself)
* @exception IllegalArgumentException if <code>id</code>
* is <code>null</code>
*/
- public OpenCheatSheetAction(String id) {
+ public OpenCheatSheetAction(String id, boolean forceView) {
if (id == null) {
throw new IllegalArgumentException();
}
this.id = id;
+ this.forceView = forceView;
}
/**
@@ -60,16 +70,18 @@ public final class OpenCheatSheetAction extends Action {
* @param id the id to give this cheat sheet
* @param name the name to give this cheat sheet
* @param url URL of the cheat sheet content file
+ * @param forceView to avoid opening in dialogs (e.g. selection dialog itself)
* @exception IllegalArgumentException if the parameters
* are <code>null</code>
*/
- public OpenCheatSheetAction(String id, String name, URL url) {
+ public OpenCheatSheetAction(String id, String name, URL url, boolean forceView) {
if (id == null || name == null || url == null) {
throw new IllegalArgumentException();
}
this.id = id;
this.name = name;
this.url = url;
+ this.forceView = forceView;
}
/**
@@ -83,11 +95,12 @@ public final class OpenCheatSheetAction extends Action {
* a composite cheat sheet which has tasks which use path parameters in which
* case the paths will be relative to baseURL. May be <code>null</code>
* if this is not a composite cheat sheet
+ * @param forceView to avoid opening in dialogs (e.g. selection dialog itself)
* @exception IllegalArgumentException if the parameters
* are <code>null</code>
* @since 3.3
*/
- public OpenCheatSheetAction(String id, String name, String xml, URL baseURL) {
+ public OpenCheatSheetAction(String id, String name, String xml, URL baseURL, boolean forceView) {
if (id == null || name == null || xml == null) {
throw new IllegalArgumentException();
}
@@ -97,6 +110,7 @@ public final class OpenCheatSheetAction extends Action {
if (baseURL !=null) {
basePath = baseURL.toExternalForm();
}
+ this.forceView = forceView;
}
@@ -108,25 +122,42 @@ public final class OpenCheatSheetAction extends Action {
* @see IAction#run()
*/
public void run() {
- CheatSheetView view = ViewUtilities.showCheatSheetView();
-
- if (view == null) {
- return;
+ Shell shell = Display.getDefault().getActiveShell();
+ Object data = shell.getData();
+ // are we in a dialog that can show a cheat sheet?
+ if (!forceView && !shell.isFocusControl() && data instanceof TrayDialog) {
+ TrayDialog dialog = (TrayDialog)data;
+ HelpTray tray = (HelpTray)dialog.getTray();
+ if (tray == null) {
+ tray = new HelpTray();
+ dialog.openTray(tray);
+ }
+ ReusableHelpPart helpPart = tray.getHelpPart();
+ IHelpPartPage page = helpPart.createPage(CheatSheetHelpPart.ID, null, null);
+ page.setVerticalSpacing(0);
+ page.setHorizontalMargin(0);
+ CheatSheetElement contentElement = CheatSheetRegistryReader.getInstance().findCheatSheet(id);
+ helpPart.addPart(CheatSheetHelpPart.ID, new CheatSheetHelpPart(helpPart.getForm().getForm().getBody(), helpPart.getForm().getToolkit(), page.getToolBarManager(), contentElement, new DefaultStateManager()));
+ page.addPart(CheatSheetHelpPart.ID, true);
+ helpPart.addPage(page);
+ helpPart.showPage(CheatSheetHelpPart.ID);
}
- // Depending on which constructor was used open the cheat sheet view from a
- // URL, an XML string or based on the id
- if(url != null) {
- view.setInput(id, name, url);
- } else if (xml != null) {
- view.setInputFromXml(id, name, xml, basePath);
- } else {
- view.setInput(id);
+ else {
+ CheatSheetView view = ViewUtilities.showCheatSheetView();
+ if (view == null) {
+ return;
+ }
+ // Depending on which constructor was used open the cheat sheet view from a
+ // URL, an XML string or based on the id
+ if(url != null) {
+ view.setInput(id, name, url);
+ } else if (xml != null) {
+ view.setInputFromXml(id, name, xml, basePath);
+ } else {
+ view.setInput(id);
+ }
+ IWorkbenchPage page = view.getSite().getWorkbenchWindow().getActivePage();
+ page.bringToTop(view);
}
- IWorkbench workbench = CheatSheetPlugin.getPlugin().getWorkbench();
- IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
- IWorkbenchPage page = window.getActivePage();
- page.bringToTop(view);
}
-
-
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetFromHelpAction.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetFromHelpAction.java
index 01a631504..f9acb18f9 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetFromHelpAction.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetFromHelpAction.java
@@ -53,7 +53,7 @@ public final class OpenCheatSheetFromHelpAction implements ILiveHelpAction {
// Active help does not run on the UI thread, so we must use syncExec
Display.getDefault().syncExec(new Runnable() {
public void run() {
- new OpenCheatSheetAction(cheatsheetID).run();
+ new OpenCheatSheetAction(cheatsheetID, false).run();
}
});
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatsheetSearchParticipant.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatsheetSearchParticipant.java
index 212cc031f..6cac9879c 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatsheetSearchParticipant.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatsheetSearchParticipant.java
@@ -121,7 +121,7 @@ public class CheatsheetSearchParticipant extends XMLSearchParticipant {
}
public boolean open(String id) {
- Action openAction = new OpenCheatSheetAction(id);
+ Action openAction = new OpenCheatSheetAction(id, false);
openAction.run();
return true;
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/actions/CheatSheetMenu.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/actions/CheatSheetMenu.java
index c5046605d..c27f225f0 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/actions/CheatSheetMenu.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/actions/CheatSheetMenu.java
@@ -287,7 +287,7 @@ public class CheatSheetMenu extends ContributionItem {
* @param event SelectionEvent - the event send along with the selection callback
*/
protected void run(CheatSheetElement element, SelectionEvent event) {
- new OpenCheatSheetAction(element.getID()).run();
+ new OpenCheatSheetAction(element.getID(), false).run();
}
/* (non-Javadoc)
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/dialogs/CheatSheetCategoryBasedSelectionDialog.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/dialogs/CheatSheetCategoryBasedSelectionDialog.java
index 271c757ce..70dbe9d7b 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/dialogs/CheatSheetCategoryBasedSelectionDialog.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/dialogs/CheatSheetCategoryBasedSelectionDialog.java
@@ -560,7 +560,7 @@ public class CheatSheetCategoryBasedSelectionDialog extends TrayDialog //extends
.getTriggerPoint(ICheatSheetResource.TRIGGER_POINT_ID);
if (WorkbenchActivityHelper.allowUseOf(triggerPoint,
currentSelection)) {
- new OpenCheatSheetAction(currentSelection.getID()).run();
+ new OpenCheatSheetAction(currentSelection.getID(), true).run();
}
}
}
@@ -580,7 +580,7 @@ public class CheatSheetCategoryBasedSelectionDialog extends TrayDialog //extends
try {
File contentFile = new File(selectFileCombo.getText());
url = contentFile.toURL();
- new OpenCheatSheetAction(id, id ,url).run();
+ new OpenCheatSheetAction(id, id ,url, true).run();
opened = true;
} catch (MalformedURLException e) {
opened = false;
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/handlers/OpenCheatSheetHandler.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/handlers/OpenCheatSheetHandler.java
index 8d022f896..09c1aa1fd 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/handlers/OpenCheatSheetHandler.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/handlers/OpenCheatSheetHandler.java
@@ -34,7 +34,7 @@ public class OpenCheatSheetHandler extends AbstractHandler {
CheatSheetCategoryBasedSelectionAction action = new CheatSheetCategoryBasedSelectionAction();
action.run();
} else {
- OpenCheatSheetAction action = new OpenCheatSheetAction(cheatSheetId);
+ OpenCheatSheetAction action = new OpenCheatSheetAction(cheatSheetId, false);
action.run();
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/handlers/OpenCheatSheetURLHandler.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/handlers/OpenCheatSheetURLHandler.java
index 42b3ac004..f5182cb34 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/handlers/OpenCheatSheetURLHandler.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/handlers/OpenCheatSheetURLHandler.java
@@ -56,7 +56,7 @@ public class OpenCheatSheetURLHandler extends AbstractHandler {
}
OpenCheatSheetAction action = new OpenCheatSheetAction(cheatSheetId,
- name, url);
+ name, url, false);
action.run();
return null;

Back to the top