diff --git a/application/InstanceWindow.cpp b/application/InstanceWindow.cpp index 3c39491b..c6191a2a 100644 --- a/application/InstanceWindow.cpp +++ b/application/InstanceWindow.cpp @@ -48,6 +48,7 @@ InstanceWindow::InstanceWindow(InstancePtr instance, QWidget *parent) { auto provider = std::make_shared(m_instance); m_container = new PageContainer(provider, "console", this); + m_container->setParentContainer(this); setCentralWidget(m_container); } @@ -213,3 +214,13 @@ void InstanceWindow::refreshContainer() InstanceWindow::~InstanceWindow() { } + +bool InstanceWindow::requestClose() +{ + if(m_container->prepareToClose()) + { + close(); + return true; + } + return false; +} diff --git a/application/InstanceWindow.h b/application/InstanceWindow.h index 7617965e..068c4288 100644 --- a/application/InstanceWindow.h +++ b/application/InstanceWindow.h @@ -40,6 +40,9 @@ public: // save all settings and changes (prepare for launch) bool saveAll(); + // request closing the window (from a page) + bool requestClose() override; + signals: void isClosing(); diff --git a/application/pages/BasePage.h b/application/pages/BasePage.h index 1d6e4bd0..6c580a17 100644 --- a/application/pages/BasePage.h +++ b/application/pages/BasePage.h @@ -33,11 +33,15 @@ public: virtual QString helpPage() const { return QString(); } virtual void opened() {} virtual void closed() {} - virtual void setParentContainer(BasePageContainer *) {}; - + virtual void setParentContainer(BasePageContainer * container) + { + m_container = container; + }; public: int stackIndex = -1; int listIndex = -1; +protected: + BasePageContainer * m_container = nullptr; }; typedef std::shared_ptr BasePagePtr; diff --git a/application/pages/BasePageContainer.h b/application/pages/BasePageContainer.h index 660685d3..ff7315c2 100644 --- a/application/pages/BasePageContainer.h +++ b/application/pages/BasePageContainer.h @@ -6,4 +6,5 @@ public: virtual ~BasePageContainer(){}; virtual bool selectPage(QString pageId) = 0; virtual void refreshContainer() = 0; + virtual bool requestClose() = 0; }; diff --git a/application/pages/LegacyUpgradePage.cpp b/application/pages/LegacyUpgradePage.cpp index c1ad0146..a8f4a08c 100644 --- a/application/pages/LegacyUpgradePage.cpp +++ b/application/pages/LegacyUpgradePage.cpp @@ -27,7 +27,10 @@ void LegacyUpgradePage::runModalTask(Task *task) }); ProgressDialog loadDialog(this); loadDialog.setSkipButton(true, tr("Abort")); - loadDialog.execWithTask(task); + if(loadDialog.execWithTask(task) == QDialog::Accepted) + { + m_container->requestClose(); + } } void LegacyUpgradePage::on_upgradeButton_clicked() diff --git a/application/pages/LogPage.cpp b/application/pages/LogPage.cpp index 75e1df7d..025d902b 100644 --- a/application/pages/LogPage.cpp +++ b/application/pages/LogPage.cpp @@ -218,7 +218,7 @@ void LogPage::on_btnClear_clicked() if(!m_model) return; m_model->clear(); - m_parentContainer->refreshContainer(); + m_container->refreshContainer(); } void LogPage::on_btnBottom_clicked() @@ -262,8 +262,3 @@ void LogPage::findActivated() ui->searchBar->selectAll(); } } - -void LogPage::setParentContainer(BasePageContainer * container) -{ - m_parentContainer = container; -} diff --git a/application/pages/LogPage.h b/application/pages/LogPage.h index 8dceb94f..7346f93f 100644 --- a/application/pages/LogPage.h +++ b/application/pages/LogPage.h @@ -54,7 +54,6 @@ public: return "Minecraft-Logs"; } virtual bool shouldDisplay() const override; - virtual void setParentContainer(BasePageContainer *) override; private slots: void on_btnPaste_clicked(); @@ -77,7 +76,6 @@ private: InstancePtr m_instance; std::shared_ptr m_process; - BasePageContainer * m_parentContainer; LogFormatProxyModel * m_proxy; shared_qobject_ptr m_model; }; diff --git a/application/pages/VersionPage.cpp b/application/pages/VersionPage.cpp index 343e1d2a..c915b42b 100644 --- a/application/pages/VersionPage.cpp +++ b/application/pages/VersionPage.cpp @@ -98,11 +98,6 @@ bool VersionPage::shouldDisplay() const return !m_inst->isRunning(); } -void VersionPage::setParentContainer(BasePageContainer * container) -{ - m_container = container; -} - VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent) : QWidget(parent), ui(new Ui::VersionPage), m_inst(inst) { diff --git a/application/pages/VersionPage.h b/application/pages/VersionPage.h index dff3abd6..0017be5c 100644 --- a/application/pages/VersionPage.h +++ b/application/pages/VersionPage.h @@ -48,8 +48,6 @@ public: } virtual bool shouldDisplay() const override; - virtual void setParentContainer(BasePageContainer *) override; - private slots: void on_forgeBtn_clicked(); void on_liteloaderBtn_clicked(); @@ -85,7 +83,6 @@ private: std::shared_ptr m_profile; MinecraftInstance *m_inst; int currentIdx = 0; - BasePageContainer * m_container = nullptr; public slots: void versionCurrent(const QModelIndex ¤t, const QModelIndex &previous); diff --git a/application/widgets/PageContainer.h b/application/widgets/PageContainer.h index c3d77486..e0a59f6b 100644 --- a/application/widgets/PageContainer.h +++ b/application/widgets/PageContainer.h @@ -47,9 +47,23 @@ public: */ bool prepareToClose(); + /* request close - used by individual pages */ + bool requestClose() override + { + if(m_container) + { + return m_container->requestClose(); + } + return false; + } + virtual bool selectPage(QString pageId) override; void refreshContainer() override; + virtual void setParentContainer(BasePageContainer * container) + { + m_container = container; + }; private: void createUI(); @@ -60,6 +74,7 @@ slots: void help(); private: + BasePageContainer * m_container = nullptr; BasePage * m_currentPage = 0; QSortFilterProxyModel *m_proxyModel; PageModel *m_model;