diff options
author | Kenneth Chew <kenneth.c0@protonmail.com> | 2022-04-17 12:44:24 -0400 |
---|---|---|
committer | Kenneth Chew <kenneth.c0@protonmail.com> | 2022-04-17 12:44:24 -0400 |
commit | 3acc7614194d4e164bebc1e97c818a99ecdb2607 (patch) | |
tree | 47e692d7be1046f639927000655e1644af3e4903 /launcher | |
parent | 9bad83a551a84e511a21791717dc930189566013 (diff) | |
download | PrismLauncher-3acc7614194d4e164bebc1e97c818a99ecdb2607.tar.gz PrismLauncher-3acc7614194d4e164bebc1e97c818a99ecdb2607.tar.bz2 PrismLauncher-3acc7614194d4e164bebc1e97c818a99ecdb2607.zip |
Fix bugs with instance menu bar options when opening without instances
- The launch option is no longer empty.
- The program now checks on startup whether an instance is selected to decide whether to disable instance options.
Also, get rid of a dynamic cast.
Diffstat (limited to 'launcher')
-rw-r--r-- | launcher/ui/MainWindow.cpp | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 528d2487..2b219aff 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -636,6 +636,8 @@ public: actionLaunchInstance = TranslatedAction(MainWindow); actionLaunchInstance->setObjectName(QStringLiteral("actionLaunchInstance")); + actionLaunchInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&Launch")); + actionLaunchInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Launch the selected instance.")); all_actions.append(&actionLaunchInstance); actionLaunchInstanceOffline = TranslatedAction(MainWindow); @@ -734,6 +736,7 @@ public: actionCopyInstance->setShortcut(QKeySequence(tr("Ctrl+D"))); all_actions.append(&actionCopyInstance); + setInstanceActionsEnabled(false); } void createInstanceToolbar(QMainWindow *MainWindow) @@ -784,7 +787,7 @@ public: MainWindow->addToolBar(Qt::RightToolBarArea, instanceToolBar); } - void setupUi(QMainWindow *MainWindow) + void setupUi(MainWindow *MainWindow) { if (MainWindow->objectName().isEmpty()) { @@ -798,7 +801,7 @@ public: #endif createMainToolbarActions(MainWindow); - createMenuActions(dynamic_cast<class MainWindow *>(MainWindow)); + createMenuActions(MainWindow); createInstanceActions(MainWindow); createMenuBar(MainWindow); @@ -818,6 +821,8 @@ public: createNewsToolbar(MainWindow); createInstanceToolbar(MainWindow); + MainWindow->updateToolsMenu(); + retranslateUi(MainWindow); QMetaObject::connectSlotsByName(MainWindow); @@ -1146,7 +1151,7 @@ void MainWindow::updateToolsMenu() QToolButton *launchButton = dynamic_cast<QToolButton*>(ui->instanceToolBar->widgetForAction(ui->actionLaunchInstance)); QToolButton *launchOfflineButton = dynamic_cast<QToolButton*>(ui->instanceToolBar->widgetForAction(ui->actionLaunchInstanceOffline)); - if(!m_selectedInstance || m_selectedInstance->isRunning()) + if(m_selectedInstance && m_selectedInstance->isRunning()) { ui->actionLaunchInstance->setMenu(nullptr); ui->actionLaunchInstanceOffline->setMenu(nullptr); @@ -1179,14 +1184,20 @@ void MainWindow::updateToolsMenu() normalLaunch->setShortcut(QKeySequence::Open); QAction *normalLaunchOffline = launchOfflineMenu->addAction(tr("Launch Offline")); normalLaunchOffline->setShortcut(QKeySequence(tr("Ctrl+Shift+O"))); - connect(normalLaunch, &QAction::triggered, [this]() - { - APPLICATION->launch(m_selectedInstance, true); - }); - connect(normalLaunchOffline, &QAction::triggered, [this]() - { - APPLICATION->launch(m_selectedInstance, false); - }); + if (m_selectedInstance) + { + connect(normalLaunch, &QAction::triggered, [this]() { + APPLICATION->launch(m_selectedInstance, true); + }); + connect(normalLaunchOffline, &QAction::triggered, [this]() { + APPLICATION->launch(m_selectedInstance, false); + }); + } + else + { + normalLaunch->setDisabled(true); + normalLaunchOffline->setDisabled(true); + } QString profilersTitle = tr("Profilers"); launchMenu->addSeparator()->setText(profilersTitle); launchOfflineMenu->addSeparator()->setText(profilersTitle); @@ -1203,7 +1214,7 @@ void MainWindow::updateToolsMenu() profilerAction->setToolTip(profilerToolTip); profilerOfflineAction->setToolTip(profilerToolTip); } - else + else if (m_selectedInstance) { connect(profilerAction, &QAction::triggered, [this, profiler]() { @@ -1214,6 +1225,11 @@ void MainWindow::updateToolsMenu() APPLICATION->launch(m_selectedInstance, false, profiler.get()); }); } + else + { + profilerAction->setDisabled(true); + profilerOfflineAction->setDisabled(true); + } } ui->actionLaunchInstance->setMenu(launchMenu); ui->actionLaunchInstanceOffline->setMenu(launchOfflineMenu); |