| 83 | } |
| 84 | |
| 85 | void ScriptWindow::onRunScript(wxCommandEvent& ev) |
| 86 | { |
| 87 | // Clear the output window before running |
| 88 | _outView->Clear(); |
| 89 | |
| 90 | // Extract the script from the input window |
| 91 | std::string scriptString = _view->GetValue().ToStdString(); |
| 92 | |
| 93 | if (scriptString.empty()) return; |
| 94 | |
| 95 | UndoableCommand cmd("runScript"); |
| 96 | |
| 97 | // wxWidgets on Windows might produce \r\n, these confuse the python interpreter |
| 98 | string::replace_all(scriptString, "\r\n", "\n"); |
| 99 | |
| 100 | // Run the script |
| 101 | script::ExecutionResultPtr result = GlobalScriptingSystem().executeString(scriptString); |
| 102 | |
| 103 | // Check if the output only consists of whitespace |
| 104 | std::string output = string::replace_all_copy(result->output, "\n", ""); |
| 105 | string::replace_all(output, "\t", ""); |
| 106 | string::replace_all(output, " ", ""); |
| 107 | |
| 108 | if (!result->errorOccurred && output.empty()) |
| 109 | { |
| 110 | // If no output and no error, print at least _something_ |
| 111 | _outView->appendText(_("OK"), wxutil::ConsoleView::ModeStandard); |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | _outView->appendText(result->output, |
| 116 | result->errorOccurred ? wxutil::ConsoleView::ModeError : wxutil::ConsoleView::ModeStandard); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | void ScriptWindow::onPanelActivated() |
| 121 | { |
nothing calls this directly
no test coverage detected