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();
|
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) {
|
void MainWindow::openScriptDocument(std::shared_ptr<Script> script) {
|
||||||
// Document already exists, don't open it
|
// Document already exists, don't open it
|
||||||
if (scriptDocuments.count(script) > 0) {
|
ScriptDocument* doc = findScriptWindow(script);
|
||||||
ui->mdiArea->setActiveSubWindow(scriptDocuments[script]);
|
if (doc != nullptr) {
|
||||||
|
ui->mdiArea->setActiveSubWindow(doc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptDocument* doc = new ScriptDocument(script);
|
doc = new ScriptDocument(script);
|
||||||
scriptDocuments[script] = doc;
|
|
||||||
doc->setAttribute(Qt::WA_DeleteOnClose, true);
|
doc->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
ui->mdiArea->addSubWindow(doc);
|
ui->mdiArea->addSubWindow(doc);
|
||||||
ui->mdiArea->setActiveSubWindow(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) {
|
void MainWindow::closeScriptDocument(std::shared_ptr<Script> script) {
|
||||||
if (scriptDocuments.count(script) == 0) return;
|
ScriptDocument* doc = findScriptWindow(script);
|
||||||
|
if (doc == nullptr) return; // Script is not open
|
||||||
ScriptDocument* doc = scriptDocuments[script];
|
|
||||||
ui->mdiArea->removeSubWindow(doc);
|
ui->mdiArea->removeSubWindow(doc);
|
||||||
ui->mdiArea->activeSubWindow()->showMaximized();
|
ui->mdiArea->activeSubWindow()->showMaximized();
|
||||||
scriptDocuments.erase(script);
|
|
||||||
doc->deleteLater();
|
doc->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <qfiledialog.h>
|
#include <qfiledialog.h>
|
||||||
|
#include <qmdisubwindow.h>
|
||||||
|
|
||||||
enum SelectedTool {
|
enum SelectedTool {
|
||||||
TOOL_SELECT,
|
TOOL_SELECT,
|
||||||
|
@ -67,10 +68,10 @@ public:
|
||||||
friend PlaceDocument;
|
friend PlaceDocument;
|
||||||
private:
|
private:
|
||||||
PlaceDocument* placeDocument;
|
PlaceDocument* placeDocument;
|
||||||
std::map<std::shared_ptr<Script>, ScriptDocument*> scriptDocuments;
|
|
||||||
|
|
||||||
void updateToolbars();
|
void updateToolbars();
|
||||||
void closeEvent(QCloseEvent* evt) override;
|
void closeEvent(QCloseEvent* evt) override;
|
||||||
|
ScriptDocument* findScriptWindow(std::shared_ptr<Script>);
|
||||||
|
|
||||||
void connectActionHandlers();
|
void connectActionHandlers();
|
||||||
|
|
||||||
|
|
|
@ -15,4 +15,6 @@ class ScriptDocument : public QMdiSubWindow {
|
||||||
public:
|
public:
|
||||||
ScriptDocument(std::shared_ptr<Script> script, QWidget* parent = nullptr);
|
ScriptDocument(std::shared_ptr<Script> script, QWidget* parent = nullptr);
|
||||||
~ScriptDocument() override;
|
~ScriptDocument() override;
|
||||||
|
|
||||||
|
inline std::shared_ptr<Script> getScript() { return script; }
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue