Skip to content

Commit

Permalink
Merge pull request #112 from Leonx254/Menu
Browse files Browse the repository at this point in the history
Update File Menu depending of current tab
  • Loading branch information
Leonx254 authored Jun 27, 2024
2 parents d85b760 + eac7173 commit 66ba14c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
26 changes: 25 additions & 1 deletion RetroEDv2/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -39,6 +47,17 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
connect(ui->toolTabs, &QTabWidget::currentChanged, [this](int) {
scnEditor = qobject_cast<SceneEditor *>(ui->toolTabs->currentWidget());
v5Editor = qobject_cast<SceneEditorv5 *>(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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
9 changes: 9 additions & 0 deletions RetroEDv2/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 66ba14c

Please sign in to comment.