MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / onRunScript

Method onRunScript

radiant/ui/script/ScriptWindow.cpp:85–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85void 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
120void ScriptWindow::onPanelActivated()
121{

Callers

nothing calls this directly

Calls 8

replace_allFunction · 0.85
replace_all_copyFunction · 0.85
appendTextMethod · 0.80
_Function · 0.50
ClearMethod · 0.45
GetValueMethod · 0.45
emptyMethod · 0.45
executeStringMethod · 0.45

Tested by

no test coverage detected