From ba862975c17bb83e955825359bd2d359d93e5d49 Mon Sep 17 00:00:00 2001 From: Alexander Kurtakov Date: Tue, 17 Nov 2015 09:45:19 +0200 Subject: [PATCH] autotools: Fix dialogs run from Actions to have proper parent. Creating new Shell as parent of every dialog is waste of resources, complicates window management and have negative effects in terms of positioning and stacking of dialogs. While at it remove dead/unused code from these classes. Change-Id: I62f9a6430f230e18e5b2f949afe97b46fb9e4ac1 Signed-off-by: Alexander Kurtakov --- .../ui/actions/InvokeAclocalAction.java | 14 +-- .../autotools/ui/actions/InvokeAction.java | 112 ------------------ .../ui/actions/InvokeAutoheaderAction.java | 3 +- .../ui/actions/InvokeAutomakeAction.java | 3 +- .../ui/actions/InvokeAutoreconfAction.java | 11 +- .../ui/actions/InvokeLibtoolizeAction.java | 3 +- 6 files changed, 10 insertions(+), 136 deletions(-) diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAclocalAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAclocalAction.java index 19f20fbe94e..6a6bf4ba01f 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAclocalAction.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAclocalAction.java @@ -16,7 +16,6 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.action.IAction; -import org.eclipse.swt.widgets.Shell; public class InvokeAclocalAction extends InvokeAction { @@ -35,15 +34,10 @@ public class InvokeAclocalAction extends InvokeAction { IPath execDir = getExecDir(container); String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ - TwoInputDialog optionDialog = new TwoInputDialog( - new Shell(), - cwd, - InvokeMessages - .getString("InvokeAclocalAction.windowTitle.options"), //$NON-NLS-1$ - InvokeMessages - .getString("InvokeAclocalAction.message.options.otherOptions"), //$NON-NLS-1$ - InvokeMessages - .getString("InvokeAclocalAction.message.options.includeDir"), DEFAULT_OPTION, null); //$NON-NLS-1$ + TwoInputDialog optionDialog = new TwoInputDialog(getShell(), cwd, + InvokeMessages.getString("InvokeAclocalAction.windowTitle.options"), //$NON-NLS-1$ + InvokeMessages.getString("InvokeAclocalAction.message.options.otherOptions"), //$NON-NLS-1$ + InvokeMessages.getString("InvokeAclocalAction.message.options.includeDir"), DEFAULT_OPTION, null); //$NON-NLS-1$ optionDialog.open(); diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAction.java index 654cfd470bf..be5e325f239 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAction.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAction.java @@ -10,14 +10,10 @@ *******************************************************************************/ package org.eclipse.cdt.internal.autotools.ui.actions; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.StringTokenizer; import org.eclipse.cdt.autotools.ui.AutotoolsUIPlugin; @@ -48,38 +44,17 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.swt.widgets.Shell; public abstract class InvokeAction extends AbstractTargetAction { public final String SHELL_COMMAND = "sh"; //$NON-NLS-1$ - protected void showInformation(String title, String content) { - MessageDialog.openInformation(new Shell(), title, content); - } - protected void showError(String title, String content) { MessageDialog.openError(new Shell(), title, content); } - protected void showSuccess(String title) { - MessageDialog.openInformation(new Shell(), title, - InvokeMessages.getString("InvokeAction.success")); //$NON-NLS-1$ - } - - protected String showInput(String title, String content, String defaultTxt) { - InputDialog getOptionDialog = new InputDialog(new Shell(), title, - content, defaultTxt, null); - - getOptionDialog.open(); - - return getOptionDialog.getValue(); - } - /** * Separate targets to array from a string. * @@ -227,93 +202,6 @@ public abstract class InvokeAction extends AbstractTargetAction { return cwd; } - private static class ExecuteProgressDialog implements IRunnableWithProgress { - private final IPath command; - private final String[] argumentList; - private final String[] envList; - private final IPath execDir; - private int status; - private Map outputs = null; - - public ExecuteProgressDialog(IPath command, String[] argumentList, - String[] envList, IPath execDir) { - this.command = command; - this.argumentList = argumentList; - this.envList = envList; - this.execDir = execDir; - } - - @Override - public void run(IProgressMonitor monitor) throws InvocationTargetException { - - RemoteCommandLauncher cmdL = new RemoteCommandLauncher(); - outputs = new HashMap<>(); - - // invoke command - try (ByteArrayOutputStream stdout = new ByteArrayOutputStream(); - ByteArrayOutputStream stderr = new ByteArrayOutputStream()) { - monitor.beginTask(InvokeMessages.getFormattedString("InvokeAction.progress.message", // $NON-NLS-1$ - new String[] { command.toOSString() }), IProgressMonitor.UNKNOWN); - monitor.worked(1); - Process process = cmdL.execute(command, argumentList, envList, execDir, new NullProgressMonitor()); - - if (cmdL.waitAndRead(stdout, stderr, new NullProgressMonitor()) == ICommandLauncher.OK) { - try { - status = 0; - monitor.done(); - process.getOutputStream().close(); - } catch (IOException e) { - // ignore - } - } else { - // failed to execute command - status = -1; - monitor.done(); - return; - } - - outputs.put("stdout", stdout.toString()); //$NON-NLS-1$ - outputs.put("stderr", stderr.toString()); //$NON-NLS-1$ - } catch (CoreException | IOException e) { - monitor.done(); - throw new InvocationTargetException(e); - } - } - - public Map getOutputs() { - return outputs; - } - - public int getStatus() { - return status; - } - } - - - protected Map executeCommand(IPath command, - String[] argumentList, String[] envList, IPath execDir) { - try { - ExecuteProgressDialog d = new ExecuteProgressDialog(command, - argumentList, envList, execDir); - new ProgressMonitorDialog(new Shell()).run(false, false, d); - if (d.getStatus() == -1) - showError(InvokeMessages - .getString("InvokeAction.execute.windowTitle.error"), InvokeMessages //$NON-NLS-1$ - .getString("InvokeAction.execute.message") //$NON-NLS-1$ - + command.toOSString()); //$NON-NLS-1$ - return d.getOutputs(); - } catch (InvocationTargetException e) { - showError(InvokeMessages - .getString("InvokeAction.execute.windowTitle.error"), InvokeMessages //$NON-NLS-1$ - .getString("InvokeAction.execute.message") //$NON-NLS-1$ - + command.toOSString()); //$NON-NLS-1$ - AutotoolsUIPlugin.logException(e); - return null; - } catch (InterruptedException e) { - return null; - } - } - protected void executeConsoleCommand(final String actionName, final String command, final String[] argumentList, final IPath execDir) { // We need to use a workspace root scheduling rule because adding MakeTargets diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoheaderAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoheaderAction.java index 8f58c3ca1f6..65fd653475f 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoheaderAction.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoheaderAction.java @@ -17,7 +17,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.swt.widgets.Shell; public class InvokeAutoheaderAction extends InvokeAction { @@ -35,7 +34,7 @@ public class InvokeAutoheaderAction extends InvokeAction { IPath execDir = getExecDir(container); String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ - InputDialog optionDialog = new SingleInputDialog(new Shell(), cwd, + InputDialog optionDialog = new SingleInputDialog(getShell(), cwd, InvokeMessages.getString("InvokeAutoheaderAction.windowTitle.options"), //$NON-NLS-1$ InvokeMessages.getString("InvokeAutoheaderAction.message.options.otherOptions"), //$NON-NLS-1$ DEFAULT_OPTION, null); diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutomakeAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutomakeAction.java index e0ceaa82505..5421e3321b8 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutomakeAction.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutomakeAction.java @@ -16,7 +16,6 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.action.IAction; -import org.eclipse.swt.widgets.Shell; /** @@ -40,7 +39,7 @@ public class InvokeAutomakeAction extends InvokeAction { IPath execDir = getExecDir(container); String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ - TwoInputDialog optionDialog = new TwoInputDialog(new Shell(), cwd, + TwoInputDialog optionDialog = new TwoInputDialog(getShell(), cwd, InvokeMessages.getString("InvokeAutomakeAction.windowTitle.options"), //$NON-NLS-1$ InvokeMessages.getString("InvokeAutomakeAction.message.options.otherOptions"), InvokeMessages //$NON-NLS-1$ .getString("InvokeAutomakeAction.message.options.makeTargets"), //$NON-NLS-1$ diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoreconfAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoreconfAction.java index 731b7c4694d..5749e7b366c 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoreconfAction.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoreconfAction.java @@ -17,7 +17,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.swt.widgets.Shell; public class InvokeAutoreconfAction extends InvokeAction { @@ -36,13 +35,9 @@ public class InvokeAutoreconfAction extends InvokeAction { IPath execDir = getExecDir(container); String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ - InputDialog optionDialog = new SingleInputDialog( - new Shell(), - cwd, - InvokeMessages - .getString("InvokeAutoreconfAction.windowTitle.options"), //$NON-NLS-1$ - InvokeMessages - .getString("InvokeAutoreconfAction.message.options.otherOptions"), //$NON-NLS-1$ + InputDialog optionDialog = new SingleInputDialog(getShell(), cwd, + InvokeMessages.getString("InvokeAutoreconfAction.windowTitle.options"), //$NON-NLS-1$ + InvokeMessages.getString("InvokeAutoreconfAction.message.options.otherOptions"), //$NON-NLS-1$ DEFAULT_OPTION, null); optionDialog.open(); diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeLibtoolizeAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeLibtoolizeAction.java index 0548bcce569..e4f349df8a5 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeLibtoolizeAction.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeLibtoolizeAction.java @@ -17,7 +17,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.swt.widgets.Shell; public class InvokeLibtoolizeAction extends InvokeAction { @@ -36,7 +35,7 @@ public class InvokeLibtoolizeAction extends InvokeAction { IPath execDir = getExecDir(container); String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ - InputDialog optionDialog = new SingleInputDialog(new Shell(), cwd, + InputDialog optionDialog = new SingleInputDialog(getShell(), cwd, InvokeMessages.getString("InvokeLibtoolizeAction.windowTitle.options"), //$NON-NLS-1$ InvokeMessages.getString("InvokeLibtoolizeAction.message.options.otherOptions"), //$NON-NLS-1$ DEFAULT_OPTION, null);