Skip to content

Commit b4486af

Browse files
committed
Added run in background and show console options to external tools settings
1 parent 0a6aaab commit b4486af

4 files changed

Lines changed: 161 additions & 90 deletions

File tree

spin-tools/src/com/maccasoft/propeller/ConsoleView.java

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ int read(byte[] b) throws IOException {
714714
}
715715
}
716716

717-
public void runCommand(List<String> cmd, File outDir, Runnable terminateRunnable) throws IOException {
717+
public void runCommand(List<String> cmd, File outDir, boolean runInBackground, Runnable terminateRunnable) throws IOException {
718718
ProcessBuilder builder = new ProcessBuilder(cmd);
719719
builder.redirectErrorStream(true);
720720
builder.directory(outDir);
@@ -729,56 +729,62 @@ public void runCommand(List<String> cmd, File outDir, Runnable terminateRunnable
729729
sb.append("\n");
730730
write(sb.toString().getBytes());
731731

732-
if (process != null && process.isAlive()) {
733-
process.destroy();
734-
if (process.isAlive()) {
735-
process.destroyForcibly();
736-
}
732+
if (runInBackground) {
733+
Process process = builder.start();
734+
process.onExit().thenRun(() -> display.asyncExec(terminateRunnable));
737735
}
738-
process = builder.start();
736+
else {
737+
if (process != null && process.isAlive()) {
738+
process.destroy();
739+
if (process.isAlive()) {
740+
process.destroyForcibly();
741+
}
742+
}
743+
process = builder.start();
739744

740-
Thread ioThread = new Thread(() -> {
741-
int count;
742-
byte[] buf = new byte[4096];
745+
Thread ioThread = new Thread(() -> {
746+
int count;
747+
byte[] buf = new byte[4096];
743748

744-
try {
745-
InputStream out = process.getInputStream();
746-
OutputStream in = process.getOutputStream();
749+
try {
750+
InputStream out = process.getInputStream();
751+
OutputStream in = process.getOutputStream();
747752

748-
while (consoleThreadRun) {
749-
if (out.available() > 0) {
750-
if ((count = out.read(buf)) == -1) {
753+
while (consoleThreadRun) {
754+
if (out.available() > 0) {
755+
if ((count = out.read(buf)) == -1) {
756+
break;
757+
}
758+
if (count > 0) {
759+
write(buf, 0, count);
760+
}
761+
}
762+
if ((count = read(buf)) == -1) {
751763
break;
752764
}
753765
if (count > 0) {
754-
write(buf, 0, count);
766+
in.write(buf, 0, count);
767+
in.flush();
755768
}
756769
}
757-
if ((count = read(buf)) == -1) {
758-
break;
759-
}
760-
if (count > 0) {
761-
in.write(buf, 0, count);
762-
in.flush();
763-
}
764-
}
765770

766-
if (!consoleThreadRun) {
767-
process.destroy();
768-
if (process.isAlive()) {
769-
process.destroyForcibly();
771+
if (!consoleThreadRun) {
772+
process.destroy();
773+
if (process.isAlive()) {
774+
process.destroyForcibly();
775+
}
770776
}
771-
}
772777

773-
} catch (Exception e) {
774-
e.printStackTrace();
775-
}
778+
} catch (Exception e) {
779+
e.printStackTrace();
780+
}
776781

777-
if (terminateRunnable != null) {
778-
display.asyncExec(terminateRunnable);
779-
}
780-
});
781-
ioThread.start();
782+
if (terminateRunnable != null) {
783+
display.asyncExec(terminateRunnable);
784+
}
785+
});
786+
ioThread.start();
787+
}
782788
}
783789

784790
public Process getProcess() {

spin-tools/src/com/maccasoft/propeller/ExternalToolDialog.java

Lines changed: 74 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
*
55
* This program and the accompanying materials are made available under
66
* the terms of the Eclipse Public License v1.0 which accompanies this
7-
* distribution, and is available at
8-
* http://www.eclipse.org/legal/epl-v10.html
7+
* distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
98
*/
109

1110
package com.maccasoft.propeller;
@@ -59,6 +58,8 @@ public class ExternalToolDialog extends Dialog {
5958
Text program;
6059
Text arguments;
6160
Map<String, Button> editorAction;
61+
Button showConsole;
62+
Button runInBackground;
6263

6364
ExternalTool externalTool;
6465

@@ -211,12 +212,42 @@ protected Control createDialogArea(Composite parent) {
211212
name.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
212213
name.addFocusListener(textFocusListener);
213214

214-
label = new Label(composite, SWT.NONE);
215-
label.setText("Program");
216-
label = new Label(composite, SWT.NONE);
217-
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
215+
createExecutableGroup(composite);
216+
createArgumentsGroup(composite);
217+
createSettingsGroup(composite);
218218

219-
Composite programGroup = new Composite(composite, SWT.NONE);
219+
if (externalTool == null) {
220+
externalTool = new ExternalTool();
221+
}
222+
name.setText(externalTool.getName());
223+
program.setText(externalTool.getProgram());
224+
arguments.setText(externalTool.getArguments());
225+
runInBackground.setSelection(externalTool.isRunInBackground());
226+
showConsole.setSelection(externalTool.isShowConsole());
227+
228+
Button button = editorAction.get(externalTool.getEditorAction());
229+
if (button != null) {
230+
button.setSelection(true);
231+
}
232+
233+
name.addModifyListener(textModifyListener);
234+
program.addModifyListener(textModifyListener);
235+
arguments.addModifyListener(textModifyListener);
236+
237+
return composite;
238+
}
239+
240+
void createExecutableGroup(Composite parent) {
241+
Composite container = new Composite(parent, SWT.NONE);
242+
container.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
243+
GridLayout layout = new GridLayout(1, false);
244+
layout.marginWidth = layout.marginHeight = 0;
245+
container.setLayout(layout);
246+
247+
Label label = new Label(container, SWT.NONE);
248+
label.setText("Executable");
249+
250+
Composite programGroup = new Composite(container, SWT.NONE);
220251
layout = new GridLayout(2, false);
221252
layout.marginWidth = layout.marginHeight = 0;
222253
programGroup.setLayout(layout);
@@ -249,14 +280,20 @@ public void widgetSelected(SelectionEvent e) {
249280
}
250281

251282
});
283+
}
252284

253-
label = new Label(composite, SWT.NONE);
285+
void createArgumentsGroup(Composite parent) {
286+
Composite container = new Composite(parent, SWT.NONE);
287+
container.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
288+
GridLayout layout = new GridLayout(1, false);
289+
layout.marginWidth = layout.marginHeight = 0;
290+
container.setLayout(layout);
291+
292+
Label label = new Label(container, SWT.NONE);
254293
label.setText("Arguments");
255-
label = new Label(composite, SWT.NONE);
256-
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
257294

258-
Composite argumentsGroup = new Composite(composite, SWT.NONE);
259-
argumentsGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
295+
Composite argumentsGroup = new Composite(container, SWT.NONE);
296+
argumentsGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
260297
layout = new GridLayout(1, false);
261298
layout.marginWidth = layout.marginHeight = 0;
262299
layout.verticalSpacing = 0;
@@ -291,12 +328,20 @@ public void widgetSelected(SelectionEvent e) {
291328
adapter.setPropagateKeys(true);
292329
adapter.setAutoActivationDelay(500);
293330
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
331+
}
294332

295-
label = new Label(composite, SWT.NONE);
296-
label.setText("Auto-save Editor");
333+
void createSettingsGroup(Composite parent) {
334+
Composite container = new Composite(parent, SWT.NONE);
335+
container.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
336+
GridLayout layout = new GridLayout(2, false);
337+
layout.marginWidth = layout.marginHeight = 0;
338+
container.setLayout(layout);
339+
340+
Label label = new Label(container, SWT.NONE);
341+
label.setText("Check editor state");
297342
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
298343

299-
Composite radioGroup = new Composite(composite, SWT.NONE);
344+
Composite radioGroup = new Composite(container, SWT.NONE);
300345
radioGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
301346
layout = new GridLayout(3, false);
302347
layout.marginWidth = layout.marginHeight = 0;
@@ -305,37 +350,27 @@ public void widgetSelected(SelectionEvent e) {
305350
editorAction = new HashMap<>();
306351

307352
Button button = new Button(radioGroup, SWT.RADIO);
308-
button.setText("Yes");
309-
button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
310-
editorAction.put(ExternalTool.EDITOR_AUTOSAVE, button);
311-
312-
button = new Button(radioGroup, SWT.RADIO);
313-
button.setText("No");
353+
button.setText("None");
314354
button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
315355
editorAction.put(ExternalTool.EDITOR_NONE, button);
316356

317357
button = new Button(radioGroup, SWT.RADIO);
318-
button.setText("Ask");
358+
button.setText("Warn unsaved");
319359
button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
320360
editorAction.put(ExternalTool.EDITOR_WARN_UNSAVED, button);
321361

322-
if (externalTool == null) {
323-
externalTool = new ExternalTool();
324-
}
325-
name.setText(externalTool.getName());
326-
program.setText(externalTool.getProgram());
327-
arguments.setText(externalTool.getArguments());
328-
329-
button = editorAction.get(externalTool.getEditorAction());
330-
if (button != null) {
331-
button.setSelection(true);
332-
}
362+
button = new Button(radioGroup, SWT.RADIO);
363+
button.setText("Auto-save");
364+
button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
365+
editorAction.put(ExternalTool.EDITOR_AUTOSAVE, button);
333366

334-
name.addModifyListener(textModifyListener);
335-
program.addModifyListener(textModifyListener);
336-
arguments.addModifyListener(textModifyListener);
367+
new Label(container, SWT.NONE);
368+
runInBackground = new Button(container, SWT.CHECK);
369+
runInBackground.setText("Run in Background");
337370

338-
return composite;
371+
new Label(container, SWT.NONE);
372+
showConsole = new Button(container, SWT.CHECK);
373+
showConsole.setText("Show Console when Run");
339374
}
340375

341376
@Override
@@ -375,6 +410,8 @@ protected void okPressed() {
375410
break;
376411
}
377412
}
413+
externalTool.setRunInBackground(runInBackground.getSelection());
414+
externalTool.setShowConsole(showConsole.getSelection());
378415
super.okPressed();
379416
}
380417

spin-tools/src/com/maccasoft/propeller/Preferences.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,23 +574,32 @@ public static class ExternalTool {
574574
public String program;
575575
public String arguments;
576576
public String editorAction;
577+
public boolean showConsole;
578+
public boolean runInBackground;
577579

578580
public ExternalTool() {
579-
581+
this.name = "";
582+
this.program = "";
583+
this.arguments = "";
584+
this.editorAction = DEFAULT_ACTION;
585+
this.showConsole = true;
580586
}
581587

582588
public ExternalTool(ExternalTool other) {
583589
this.name = other.name;
584590
this.program = other.program;
585591
this.arguments = other.arguments;
586592
this.editorAction = other.editorAction;
593+
this.runInBackground = other.runInBackground;
594+
this.showConsole = other.showConsole;
587595
}
588596

589597
public ExternalTool(String name, String program, String arguments) {
590598
this.name = name;
591599
this.program = program;
592600
this.arguments = arguments;
593601
this.editorAction = DEFAULT_ACTION;
602+
this.showConsole = true;
594603
}
595604

596605
public String getName() {
@@ -625,6 +634,22 @@ public void setEditorAction(String editorAction) {
625634
this.editorAction = editorAction;
626635
}
627636

637+
public boolean isShowConsole() {
638+
return showConsole;
639+
}
640+
641+
public void setShowConsole(boolean showConsole) {
642+
this.showConsole = showConsole;
643+
}
644+
645+
public boolean isRunInBackground() {
646+
return runInBackground;
647+
}
648+
649+
public void setRunInBackground(boolean runInBackground) {
650+
this.runInBackground = runInBackground;
651+
}
652+
628653
@Override
629654
public String toString() {
630655
return name;

0 commit comments

Comments
 (0)