mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
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 <akurtako@redhat.com>
This commit is contained in:
parent
388d94a963
commit
ba862975c1
6 changed files with 10 additions and 136 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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<String, String> 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<String, String> getOutputs() {
|
||||
return outputs;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected Map<String, String> 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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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$
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue