Fix GroovyPad issues
This commit is contained in:
parent
05f2a0be85
commit
8ba500aaa8
|
@ -60,6 +60,8 @@ public class GroovyPad extends JFrame {
|
||||||
tools.setFloatable(true);
|
tools.setFloatable(true);
|
||||||
tools.add(run);
|
tools.add(run);
|
||||||
tools.add(cancel);
|
tools.add(cancel);
|
||||||
|
tools.addSeparator();
|
||||||
|
tools.add(newAction(DEFAULT_SCRIPT, ResourceManager.getIcon("status.info"), evt -> runScript(DEFAULT_SCRIPT)));
|
||||||
c.add(tools, BorderLayout.NORTH);
|
c.add(tools, BorderLayout.NORTH);
|
||||||
|
|
||||||
run.setEnabled(true);
|
run.setEnabled(true);
|
||||||
|
@ -93,15 +95,14 @@ public class GroovyPad extends JFrame {
|
||||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
setLocationByPlatform(true);
|
setLocationByPlatform(true);
|
||||||
setSize(800, 600);
|
setSize(800, 600);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MessageConsole console;
|
protected MessageConsole console;
|
||||||
protected TextEditorPane editor;
|
protected TextEditorPane editor;
|
||||||
protected TextEditorPane output;
|
protected TextEditorPane output;
|
||||||
|
|
||||||
protected JComponent createEditor() throws IOException {
|
protected JComponent createEditor() {
|
||||||
editor = new TextEditorPane(TextEditorPane.INSERT_MODE, false, getFileLocation("pad.groovy"), "UTF-8");
|
editor = new TextEditorPane(TextEditorPane.INSERT_MODE, false);
|
||||||
editor.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_GROOVY);
|
editor.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_GROOVY);
|
||||||
editor.setAutoscrolls(false);
|
editor.setAutoscrolls(false);
|
||||||
editor.setAnimateBracketMatching(false);
|
editor.setAnimateBracketMatching(false);
|
||||||
|
@ -115,8 +116,19 @@ public class GroovyPad extends JFrame {
|
||||||
editor.setRoundedSelectionEdges(false);
|
editor.setRoundedSelectionEdges(false);
|
||||||
editor.setTabsEmulated(false);
|
editor.setTabsEmulated(false);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// use this default value so people can easily submit bug reports with fn:sysinfo logs
|
||||||
|
File pad = ApplicationFolder.AppData.resolve("pad.groovy");
|
||||||
|
|
||||||
|
if (!pad.exists()) {
|
||||||
|
ScriptShellMethods.saveAs(DEFAULT_SCRIPT, pad);
|
||||||
|
}
|
||||||
|
|
||||||
// restore on open
|
// restore on open
|
||||||
editor.reload();
|
editor.load(FileLocation.create(pad), "UTF-8");
|
||||||
|
} catch (Exception e) {
|
||||||
|
debug.log(Level.WARNING, e, e::toString);
|
||||||
|
}
|
||||||
|
|
||||||
return new RTextScrollPane(editor, true);
|
return new RTextScrollPane(editor, true);
|
||||||
}
|
}
|
||||||
|
@ -144,21 +156,6 @@ public class GroovyPad extends JFrame {
|
||||||
return new RTextScrollPane(output, true);
|
return new RTextScrollPane(output, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected FileLocation getFileLocation(String name) {
|
|
||||||
try {
|
|
||||||
// use this default value so people can easily submit bug reports with fn:sysinfo logs
|
|
||||||
File pad = ApplicationFolder.AppData.resolve(name);
|
|
||||||
|
|
||||||
if (!pad.exists()) {
|
|
||||||
ScriptShellMethods.saveAs(DEFAULT_SCRIPT, pad);
|
|
||||||
return FileLocation.create(pad);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
debug.log(Level.WARNING, e, e::toString);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final ScriptShell shell;
|
protected final ScriptShell shell;
|
||||||
|
|
||||||
protected ScriptShell createScriptShell() {
|
protected ScriptShell createScriptShell() {
|
||||||
|
@ -175,14 +172,12 @@ public class GroovyPad extends JFrame {
|
||||||
private Runner currentRunner = null;
|
private Runner currentRunner = null;
|
||||||
|
|
||||||
public void runScript(ActionEvent evt) {
|
public void runScript(ActionEvent evt) {
|
||||||
// persist script file and clear output
|
|
||||||
try {
|
try {
|
||||||
editor.save();
|
editor.save();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
debug.log(Level.WARNING, e, e::getMessage);
|
debug.log(Level.WARNING, e, e::toString);
|
||||||
}
|
}
|
||||||
|
|
||||||
output.setText("");
|
|
||||||
runScript(editor.getText());
|
runScript(editor.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +194,8 @@ public class GroovyPad extends JFrame {
|
||||||
|
|
||||||
run.setEnabled(false);
|
run.setEnabled(false);
|
||||||
cancel.setEnabled(true);
|
cancel.setEnabled(true);
|
||||||
|
output.setText(null);
|
||||||
|
|
||||||
currentRunner.execute();
|
currentRunner.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,12 +104,10 @@ public class MainFrame extends JFrame {
|
||||||
GroovyPad pad = new GroovyPad();
|
GroovyPad pad = new GroovyPad();
|
||||||
|
|
||||||
pad.addWindowListener(new WindowAdapter() {
|
pad.addWindowListener(new WindowAdapter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowOpened(WindowEvent e) {
|
public void windowOpened(WindowEvent e) {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
|
||||||
// run default script on startup
|
|
||||||
pad.runScript(GroovyPad.DEFAULT_SCRIPT);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue