From eac71735007aef39af605748da41441302c62994 Mon Sep 17 00:00:00 2001 From: Leonx254 Date: Wed, 26 Jun 2024 02:21:38 -0300 Subject: [PATCH] Menus are aware --- RetroEDv2/mainwindow.cpp | 26 +++++++++++++++++++++++++- RetroEDv2/mainwindow.hpp | 9 +++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/RetroEDv2/mainwindow.cpp b/RetroEDv2/mainwindow.cpp index 724200d..4141009 100644 --- a/RetroEDv2/mainwindow.cpp +++ b/RetroEDv2/mainwindow.cpp @@ -23,6 +23,14 @@ SceneEditorv5 *v5Editor = nullptr; QIcon playPauseIco[2]; +void MainWindow::SetMenuStates(bool newEnabled, bool openEnabled, bool saveEnabled, bool saveAsEnabled) +{ + file->actions().at(0)->setEnabled(newEnabled); + file->actions().at(1)->setEnabled(openEnabled); + file->actions().at(2)->setEnabled(saveEnabled); + file->actions().at(3)->setEnabled(saveAsEnabled); +} + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); @@ -39,6 +47,17 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi connect(ui->toolTabs, &QTabWidget::currentChanged, [this](int) { scnEditor = qobject_cast(ui->toolTabs->currentWidget()); v5Editor = qobject_cast(ui->toolTabs->currentWidget()); + SetMenuStates(); + if (ui->toolTabs->count()){ + QString tabTool = ui->toolTabs->currentWidget()->objectName(); + QString tabName = ui->toolTabs->tabText(ui->toolTabs->currentIndex()); + if (tabName == "Scene Editor" || tabName == "Scene Editor (v5)" || tabName == "Animation Editor" + || tabName == "Palette Editor" || tabName == "Model Manager") { + SetMenuStates(true, true, false, false); + } else if (tabTool != "ScriptCompiler" && tabTool != "RSDKUnpacker") { + SetMenuStates(true, true, true, true); + } + } }); QShortcut *closeTab = new QShortcut(ui->toolTabs); @@ -75,7 +94,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi }; connect(ui->toolTabs, &QTabWidget::currentChanged, focusChangeEvent); - QMenu *file = new QMenu("File"); + file = new QMenu("File"); auto newAction = [this] { if (!ui->toolTabs->currentWidget()) return; @@ -112,6 +131,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi }; file->addAction("Save As", saveAsAction); + file->actions().at(0)->setDisabled(true); + file->actions().at(1)->setDisabled(true); + file->actions().at(2)->setDisabled(true); + file->actions().at(3)->setDisabled(true); + #if RE_USE_UNSTABLE auto UndoAction = [this] { if (!ui->toolTabs->currentWidget()) diff --git a/RetroEDv2/mainwindow.hpp b/RetroEDv2/mainwindow.hpp index bd6b035..ebee4ce 100644 --- a/RetroEDv2/mainwindow.hpp +++ b/RetroEDv2/mainwindow.hpp @@ -31,6 +31,10 @@ class MainWindow : public QMainWindow return reply == QMessageBox::Yes; } + QMenu *file = nullptr; + void SetMenuStates(bool newEnabled = false, bool openEnabled = false, bool saveEnabled = false, bool saveAsEnabled = false); + + protected: bool event(QEvent *event); @@ -62,6 +66,11 @@ class MainWindow : public QMainWindow int i = GetTab(tab); if (i >= 0) toolTabs->setTabText(i, t); + + if (t != "Scene Editor" && t != "Scene Editor (v5)" && t != "Animation Editor" && + t != "Palette Editor" && t != "Model Manager") + { SetMenuStates(true,true,true,true); } + else { SetMenuStates(true,true,false,false); } }); tab->setWindowTitle(name);