fix(editor): script not reopening after being closed
This commit is contained in:
parent
8c95f3b9fb
commit
c2135b2f8c
3 changed files with 21 additions and 9 deletions
|
@ -572,15 +572,26 @@ std::optional<std::string> MainWindow::openFileDialog(QString filter, QString de
|
|||
return dialog.selectedFiles().front().toStdString();
|
||||
}
|
||||
|
||||
ScriptDocument* MainWindow::findScriptWindow(std::shared_ptr<Script> script) {
|
||||
for (QMdiSubWindow* window : ui->mdiArea->subWindowList()) {
|
||||
ScriptDocument* doc = dynamic_cast<ScriptDocument*>(window);
|
||||
if (doc == nullptr) continue;
|
||||
|
||||
if (doc->getScript() == script)
|
||||
return doc;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MainWindow::openScriptDocument(std::shared_ptr<Script> script) {
|
||||
// Document already exists, don't open it
|
||||
if (scriptDocuments.count(script) > 0) {
|
||||
ui->mdiArea->setActiveSubWindow(scriptDocuments[script]);
|
||||
ScriptDocument* doc = findScriptWindow(script);
|
||||
if (doc != nullptr) {
|
||||
ui->mdiArea->setActiveSubWindow(doc);
|
||||
return;
|
||||
}
|
||||
|
||||
ScriptDocument* doc = new ScriptDocument(script);
|
||||
scriptDocuments[script] = doc;
|
||||
doc = new ScriptDocument(script);
|
||||
doc->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
ui->mdiArea->addSubWindow(doc);
|
||||
ui->mdiArea->setActiveSubWindow(doc);
|
||||
|
@ -588,12 +599,10 @@ void MainWindow::openScriptDocument(std::shared_ptr<Script> script) {
|
|||
}
|
||||
|
||||
void MainWindow::closeScriptDocument(std::shared_ptr<Script> script) {
|
||||
if (scriptDocuments.count(script) == 0) return;
|
||||
|
||||
ScriptDocument* doc = scriptDocuments[script];
|
||||
ScriptDocument* doc = findScriptWindow(script);
|
||||
if (doc == nullptr) return; // Script is not open
|
||||
ui->mdiArea->removeSubWindow(doc);
|
||||
ui->mdiArea->activeSubWindow()->showMaximized();
|
||||
scriptDocuments.erase(script);
|
||||
doc->deleteLater();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <map>
|
||||
#include <memory>
|
||||
#include <qfiledialog.h>
|
||||
#include <qmdisubwindow.h>
|
||||
|
||||
enum SelectedTool {
|
||||
TOOL_SELECT,
|
||||
|
@ -67,10 +68,10 @@ public:
|
|||
friend PlaceDocument;
|
||||
private:
|
||||
PlaceDocument* placeDocument;
|
||||
std::map<std::shared_ptr<Script>, ScriptDocument*> scriptDocuments;
|
||||
|
||||
void updateToolbars();
|
||||
void closeEvent(QCloseEvent* evt) override;
|
||||
ScriptDocument* findScriptWindow(std::shared_ptr<Script>);
|
||||
|
||||
void connectActionHandlers();
|
||||
|
||||
|
|
|
@ -15,4 +15,6 @@ class ScriptDocument : public QMdiSubWindow {
|
|||
public:
|
||||
ScriptDocument(std::shared_ptr<Script> script, QWidget* parent = nullptr);
|
||||
~ScriptDocument() override;
|
||||
|
||||
inline std::shared_ptr<Script> getScript() { return script; }
|
||||
};
|
Loading…
Add table
Reference in a new issue