/** * Saves a debug log to a file. * * @param parent Parent window used for dialogs. * @param text The debug log to save. */ public static void save(final Window parent, final String text) { final LastDirFileChooser chooser = new LastDirFileChooser(); if (chooser.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) { final File outputFile = chooser.getSelectedFile(); if (outputFile != null) { try { FileUtils.writeTextFile(outputFile, text); } catch (final IOException e) { CUtilityFunctions.logException(e); } } } }
/** * Executes a script file without displaying it in the dialog. * * @param scriptFile The file to execute. */ private void executeScriptFile(final File scriptFile) { final List<Pair<String, Object>> bindings = toPairList(m_bindings); final ScriptEngineManager manager = new ScriptEngineManager(); final ScriptEngine engine = manager.getEngineByExtension(FileUtils.getFileExtension(scriptFile)); final IScriptConsole console = new ConsoleWriter(new StringWriter()); engine.getContext().setWriter(console.getWriter()); bindings.add(new Pair<String, Object>("SCRIPT_CONSOLE", console)); final ScriptThread thread = new ScriptThread(engine, scriptFile, bindings); CProgressDialog.showEndless( getOwner(), String.format("Executing '%s'", scriptFile.getAbsolutePath()), thread); if (thread.getException() != null) { CUtilityFunctions.logException(thread.getException()); final String message = "E00108: " + "Script file could not be executed"; final String description = CUtilityFunctions.createDescription( String.format( "The script file '%s' could not be executed.", scriptFile.getAbsolutePath()), new String[] { "The script file is in use by another program and can not be read.", "You do not have sufficient rights to read the file", "The script contains a bug that caused an exception." }, new String[] {"BinNavi can not read the script file."}); NaviErrorDialog.show(CScriptingDialog.this, message, description, thread.getException()); } final IScriptPanel panel = (IScriptPanel) scriptTab.getSelectedComponent(); panel.setOutput(console.getOutput()); toFront(); }