-----------------------------------------------------------------------------
| 128 | |
| 129 | //----------------------------------------------------------------------------- |
| 130 | void pqPythonEditorActions::updateScriptsList(pqPythonManager* python_mgr) |
| 131 | { |
| 132 | auto scripts = ::ListFiles(pqPythonScriptEditor::getScriptsDir()); |
| 133 | |
| 134 | this->ScriptActions.clear(); |
| 135 | this->ScriptActions.reserve(scripts.size()); |
| 136 | |
| 137 | for (auto const& script : scripts) |
| 138 | { |
| 139 | const QString filename = script.split(".", PV_QT_SKIP_EMPTY_PARTS).at(0); |
| 140 | this->ScriptActions.emplace_back(); |
| 141 | const std::size_t position = this->ScriptActions.size() - 1; |
| 142 | auto& actions = this->ScriptActions[position]; |
| 143 | |
| 144 | QAction* openAction = &actions[ScriptAction::Type::Open]; |
| 145 | openAction->setText(filename); |
| 146 | QObject::connect(openAction, &QAction::triggered, |
| 147 | [openAction]() |
| 148 | { |
| 149 | const QString openedFilename = |
| 150 | pqPythonScriptEditor::getScriptsDir() + "/" + openAction->text() + ".py"; |
| 151 | auto scriptEditor = pqPythonScriptEditor::getUniqueInstance(); |
| 152 | scriptEditor->open(openedFilename); |
| 153 | }); |
| 154 | |
| 155 | QAction* loadAction = &actions[ScriptAction::Type::Load]; |
| 156 | loadAction->setText(filename); |
| 157 | QObject::connect(loadAction, &QAction::triggered, |
| 158 | [loadAction]() |
| 159 | { |
| 160 | const QString loadedFilename = |
| 161 | pqPythonScriptEditor::getScriptsDir() + "/" + loadAction->text() + ".py"; |
| 162 | auto scriptEditor = pqPythonScriptEditor::getUniqueInstance(); |
| 163 | scriptEditor->load(loadedFilename); |
| 164 | }); |
| 165 | |
| 166 | QAction* deleteAction = &actions[ScriptAction::Type::Delete]; |
| 167 | deleteAction->setText(filename); |
| 168 | QObject::connect(deleteAction, &QAction::triggered, |
| 169 | [deleteAction]() |
| 170 | { |
| 171 | const QString deletedFilename = |
| 172 | pqPythonScriptEditor::getScriptsDir() + "/" + deleteAction->text() + ".py"; |
| 173 | QFile file(deletedFilename); |
| 174 | file.remove(); |
| 175 | pqPythonScriptEditor::getUniqueInstance()->updateScriptList(); |
| 176 | }); |
| 177 | |
| 178 | QAction* runAction = &actions[ScriptAction::Type::Run]; |
| 179 | runAction->setText(filename); |
| 180 | QObject::connect(runAction, &QAction::triggered, |
| 181 | [runAction, python_mgr]() |
| 182 | { |
| 183 | const QString runFilename = |
| 184 | pqPythonScriptEditor::getScriptsDir() + "/" + runAction->text() + ".py"; |
| 185 | python_mgr->executeScriptAndRender(runFilename); |
| 186 | auto scriptEditor = pqPythonScriptEditor::getUniqueInstance(); |
| 187 | scriptEditor->open(runFilename); |