Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJared Burns2003-04-24 16:43:21 +0000
committerJared Burns2003-04-24 16:43:21 +0000
commitc853fa05071fbbe845cf3f22fa67e47c68d46e3d (patch)
tree682724ee284d87c9116bd9a53b5a706b48146e02
parentad0e7657c1af8765b0b7818d381a39e018a2462a (diff)
downloadeclipse.platform.debug-c853fa05071fbbe845cf3f22fa67e47c68d46e3d.tar.gz
eclipse.platform.debug-c853fa05071fbbe845cf3f22fa67e47c68d46e3d.tar.xz
eclipse.platform.debug-c853fa05071fbbe845cf3f22fa67e47c68d46e3d.zip
Bug 36538 - Add a ${variable} that prompts the user with a dialog
-rw-r--r--org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/ExternalToolsVariableMessages.properties3
-rw-r--r--org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/FilePromptExpander.java36
-rw-r--r--org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/FolderPromptExpander.java37
-rw-r--r--org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/PromptExpanderBase.java102
-rw-r--r--org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/StringPromptExpander.java37
-rw-r--r--org.eclipse.ui.externaltools/plugin.properties3
-rw-r--r--org.eclipse.ui.externaltools/plugin.xml15
7 files changed, 233 insertions, 0 deletions
diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/ExternalToolsVariableMessages.properties b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/ExternalToolsVariableMessages.properties
index af6617eb3..90b28288d 100644
--- a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/ExternalToolsVariableMessages.properties
+++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/ExternalToolsVariableMessages.properties
@@ -22,3 +22,6 @@ ResourceExpander.No_resource=No resource selected.
ResourceNameExpander.No_resource=No resource selected.
WorkingSetExpander.No_working_set=No working set specified.
WorkingSetExpander.No_working_set_found=No working set found with the name {0}.
+StringPromptExpander.Variable_input_1=Variable input
+PromptExpanderBase.Please_input_a_value_for_{0}_1=Please input a value for {0}
+PromptExpanderBase.Please_input_a_value_2=Please input a value
diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/FilePromptExpander.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/FilePromptExpander.java
new file mode 100644
index 000000000..427690aa2
--- /dev/null
+++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/FilePromptExpander.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 Matt Conway and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Matt Conway - initial implementation
+ * IBM Corporation - integration and code cleanup
+ *******************************************************************************/
+package org.eclipse.ui.externaltools.internal.variable;
+
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+
+/**
+ * Prompts the user to choose a file and expands the selection
+ */
+public class FilePromptExpander extends PromptExpanderBase {
+ public FilePromptExpander() {
+ super();
+ }
+
+ /**
+ * Prompts the user to choose a file
+ * @see PromptExpanderBase#prompt()
+ */
+ public void prompt() {
+ FileDialog dialog = new FileDialog(Display.getDefault().getActiveShell());
+ dialog.setText(dialogMessage);
+ dialog.setFileName(lastValue == null ? defaultValue : lastValue);
+ dialogResultString = dialog.open();
+ }
+
+}
diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/FolderPromptExpander.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/FolderPromptExpander.java
new file mode 100644
index 000000000..b7eb5b55f
--- /dev/null
+++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/FolderPromptExpander.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 Matt Conway and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Matt Conway - initial implementation
+ * IBM Corporation - integration and code cleanup
+ *******************************************************************************/
+package org.eclipse.ui.externaltools.internal.variable;
+
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Prompts the user to choose a folder and expands the selection
+ */
+public class FolderPromptExpander extends PromptExpanderBase {
+
+ public FolderPromptExpander() {
+ super();
+ }
+
+ /**
+ * Prompts the user to choose a folder.
+ * @see PromptExpanderBase#prompt()
+ */
+ public void prompt() {
+ DirectoryDialog dialog = new DirectoryDialog(Display.getDefault().getActiveShell());
+ dialog.setText(dialogMessage);
+ dialog.setFilterPath(lastValue == null ? defaultValue : lastValue);
+ dialogResultString = dialog.open();
+ }
+
+}
diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/PromptExpanderBase.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/PromptExpanderBase.java
new file mode 100644
index 000000000..07df523c3
--- /dev/null
+++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/PromptExpanderBase.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 Matt Conway and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Matt Conway - initial implementation
+ * IBM Corporation - integration and code cleanup
+ *******************************************************************************/
+package org.eclipse.ui.externaltools.internal.variable;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Base implementation for variable expanders that prompt the user
+ * for their value.
+ */
+abstract class PromptExpanderBase extends DefaultVariableExpander {
+
+ /**
+ * A hint that helps the user choose their input. If a prompt
+ * hint is provider the user will be prompted:
+ * Please input a value for <code>promptHint</code>
+ */
+ protected String promptHint = null;
+ /**
+ * The prompt displayed to the user.
+ */
+ protected String dialogMessage = null;
+ /**
+ * The default value selected when the prompt is displayed
+ */
+ protected String defaultValue = null;
+ /**
+ * The last value chosen by the user for this variable
+ */
+ protected String lastValue = null;
+ /**
+ * The result returned from the prompt dialog
+ */
+ protected String dialogResultString = null;
+
+ /**
+ * Prompts the user for input and returns a string representation of
+ * the user's selection.
+ */
+ public String getText(String varTag, String varValue, ExpandVariableContext context) throws CoreException {
+ String varText = null;
+ setupDialog(varValue);
+
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ prompt();
+ }
+ });
+ if (dialogResultString != null) {
+ varText = dialogResultString;
+ lastValue = dialogResultString;
+ }
+ return varText;
+ }
+
+ /**
+ * Presents the user with the appropriate prompt for the variable to be expanded
+ * and sets the <code>dialogResultString</code> based on the user's selection.
+ */
+ public abstract void prompt();
+
+ /**
+ * Initializes values displayed when the user is prompted. If
+ * a prompt hint and default value are supplied in the given
+ * variable value, these are extracted for presentation
+ *
+ * @param varValue the value of the variable from which the prompt
+ * hint and default value will be extracted
+ */
+ protected void setupDialog(String varValue) {
+ promptHint = null;
+ defaultValue = null;
+ dialogResultString = null;
+ if (varValue != null) {
+ int idx = varValue.indexOf(':');
+ if (idx != -1) {
+ promptHint = varValue.substring(0, idx);
+ defaultValue = varValue.substring(idx + 1);
+ } else {
+ promptHint = varValue;
+ }
+ }
+
+ if (promptHint != null) {
+ dialogMessage = MessageFormat.format(ExternalToolsVariableMessages.getString("PromptExpanderBase.Please_input_a_value_for_{0}_1"), new String[] {promptHint}); //$NON-NLS-1$
+ } else {
+ dialogMessage = ExternalToolsVariableMessages.getString("PromptExpanderBase.Please_input_a_value_2"); //$NON-NLS-1$
+ }
+ }
+}
diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/StringPromptExpander.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/StringPromptExpander.java
new file mode 100644
index 000000000..2882491b5
--- /dev/null
+++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variable/StringPromptExpander.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 Matt Conway and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Matt Conway - initial implementation
+ * IBM Corporation - integration and code cleanup
+ *******************************************************************************/
+package org.eclipse.ui.externaltools.internal.variable;
+
+import org.eclipse.jface.dialogs.InputDialog;
+
+/**
+ * Prompts the user to input a string and expands to the value entered
+ */
+public class StringPromptExpander extends PromptExpanderBase {
+
+ public StringPromptExpander() {
+ super();
+ }
+
+ /**
+ * Prompts the user to input a string.
+ * @see PromptExpanderBase#prompt()
+ */
+ public void prompt() {
+ InputDialog dialog = new InputDialog(null, ExternalToolsVariableMessages.getString("StringPromptExpander.Variable_input_1"), dialogMessage, lastValue == null ? defaultValue : lastValue, null); //$NON-NLS-1$
+ int dialogResult = dialog.open();
+ if (dialogResult == InputDialog.OK) {
+ dialogResultString = dialog.getValue();
+ }
+ }
+
+}
diff --git a/org.eclipse.ui.externaltools/plugin.properties b/org.eclipse.ui.externaltools/plugin.properties
index dea9943b6..c31299c0b 100644
--- a/org.eclipse.ui.externaltools/plugin.properties
+++ b/org.eclipse.ui.externaltools/plugin.properties
@@ -58,6 +58,9 @@ container_loc.description= Expands to the absolute file system path of the folde
container_path.description= Expands to the full path, relative to the workspace root, of the folder containing the selected resource.
container_name.description= Expands to the name of the folder containing selected resource.
build_type.description= Expands to the type of build, one of "incremental", "full", "auto", or "none".
+string_prompt.description= Opens an input dialog and expands to the value entered.
+file_prompt.description= Opens a file selection dialog and expands to the value of the chosen file.
+folder_prompt.description= Opens a folder selection dialog and expands to the value of the chosen directory.
#refresh variables
workspace.description= Expands to the workspace root.
diff --git a/org.eclipse.ui.externaltools/plugin.xml b/org.eclipse.ui.externaltools/plugin.xml
index e160700e4..e8efd0f55 100644
--- a/org.eclipse.ui.externaltools/plugin.xml
+++ b/org.eclipse.ui.externaltools/plugin.xml
@@ -446,6 +446,21 @@
description="%build_type.description"
expanderClass="org.eclipse.ui.externaltools.internal.variable.BuildTypeExpander">
</variable>
+ <variable
+ tag="string_prompt"
+ description="%string_prompt.description"
+ expanderClass="org.eclipse.ui.externaltools.internal.variable.StringPromptExpander">
+ </variable>
+ <variable
+ tag="file_prompt"
+ description="%file_prompt.description"
+ expanderClass="org.eclipse.ui.externaltools.internal.variable.FilePromptExpander">
+ </variable>
+ <variable
+ tag="folder_prompt"
+ description="%folder_prompt.description"
+ expanderClass="org.eclipse.ui.externaltools.internal.variable.FolderPromptExpander">
+ </variable>
</extension>
<extension point="org.eclipse.ui.externaltools.refreshVariables">

Back to the top