Use preexisting actions in the menu bar

The code is now much cleaner.

Because the actions already present are enabled elsewhere even when the menu bar is hidden, keyboard shortcuts added to them automatically work regardless of whether the menu bar is visible. This means that the hacky workaround related to this can be removed.
This commit is contained in:
Kenneth Chew 2022-04-16 03:32:08 -04:00
parent e59d3a339f
commit 6a97ac603a
No known key found for this signature in database
GPG Key ID: F17D3E14A07739DA
2 changed files with 307 additions and 424 deletions

View File

@ -247,38 +247,20 @@ public:
QMenuBar *menuBar = nullptr; QMenuBar *menuBar = nullptr;
QMenu *fileMenu; QMenu *fileMenu;
QMenu *editMenu; QMenu *editMenu;
QMenu *viewMenu;
QMenu *profileMenu; QMenu *profileMenu;
QAction *newAct;
QAction *openAct; QAction *actionCloseWindow;
QAction *openOfflineAct;
QAction *editInstanceAct; QAction *actionUndo;
QAction *editNotesAct; QAction *actionRedo;
QAction *editModsAct; QAction *actionCut;
QAction *editWorldsAct; QAction *actionCopy;
QAction *manageScreenshotsAct; QAction *actionPaste;
QAction *changeGroupAct; QAction *actionSelectAll;
QAction *openMCFolderAct;
QAction *openConfigFolderAct; QAction *actionWiki;
QAction *openInstanceFolderAct; QAction *actionNewsMenuBar;
QAction *exportInstanceAct;
QAction *deleteInstanceAct;
QAction *duplicateInstanceAct;
QAction *closeAct;
QAction *undoAct;
QAction *redoAct;
QAction *cutAct;
QAction *copyAct;
QAction *pasteAct;
QAction *selectAllAct;
QAction *manageAccountAct;
QAction *aboutAct;
QAction *settingsAct;
QAction *wikiAct;
QAction *newsAct;
QAction *reportBugAct;
QAction *matrixAct;
QAction *discordAct;
QAction *redditAct;
TranslatedToolbar mainToolBar; TranslatedToolbar mainToolBar;
TranslatedToolbar instanceToolBar; TranslatedToolbar instanceToolBar;
@ -290,12 +272,12 @@ public:
{ {
if(m_kill) if(m_kill)
{ {
actionLaunchInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Kill")); actionLaunchInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&Kill"));
actionLaunchInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Kill the running instance")); actionLaunchInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Kill the running instance"));
} }
else else
{ {
actionLaunchInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Launch")); actionLaunchInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&Launch"));
actionLaunchInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Launch the selected instance.")); actionLaunchInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Launch the selected instance."));
} }
actionLaunchInstance.retranslate(); actionLaunchInstance.retranslate();
@ -306,6 +288,131 @@ public:
updateLaunchAction(); updateLaunchAction();
} }
void createMainToolbarActions(QMainWindow *MainWindow)
{
actionAddInstance = TranslatedAction(MainWindow);
actionAddInstance->setObjectName(QStringLiteral("actionAddInstance"));
actionAddInstance->setIcon(APPLICATION->getThemedIcon("new"));
actionAddInstance->setIconVisibleInMenu(false);
actionAddInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Add Instanc&e..."));
actionAddInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Add a new instance."));
actionAddInstance->setShortcut(QKeySequence::New);
all_actions.append(&actionAddInstance);
actionViewInstanceFolder = TranslatedAction(MainWindow);
actionViewInstanceFolder->setObjectName(QStringLiteral("actionViewInstanceFolder"));
actionViewInstanceFolder->setIcon(APPLICATION->getThemedIcon("viewfolder"));
actionViewInstanceFolder.setTextId(QT_TRANSLATE_NOOP("MainWindow", "View Instance Folder"));
actionViewInstanceFolder.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the instance folder in a file browser."));
all_actions.append(&actionViewInstanceFolder);
actionViewCentralModsFolder = TranslatedAction(MainWindow);
actionViewCentralModsFolder->setObjectName(QStringLiteral("actionViewCentralModsFolder"));
actionViewCentralModsFolder->setIcon(APPLICATION->getThemedIcon("centralmods"));
actionViewCentralModsFolder.setTextId(QT_TRANSLATE_NOOP("MainWindow", "View Central Mods Folder"));
actionViewCentralModsFolder.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the central mods folder in a file browser."));
all_actions.append(&actionViewCentralModsFolder);
foldersMenu = new QMenu(MainWindow);
foldersMenu->setTitle(tr("F&olders"));
foldersMenu->setToolTipsVisible(true);
foldersMenu->addAction(actionViewInstanceFolder);
foldersMenu->addAction(actionViewCentralModsFolder);
foldersMenuButton = TranslatedToolButton(MainWindow);
foldersMenuButton.setTextId(QT_TRANSLATE_NOOP("MainWindow", "F&olders"));
foldersMenuButton.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open one of the folders shared between instances."));
foldersMenuButton->setMenu(foldersMenu);
foldersMenuButton->setPopupMode(QToolButton::InstantPopup);
foldersMenuButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
foldersMenuButton->setIcon(APPLICATION->getThemedIcon("viewfolder"));
foldersMenuButton->setFocusPolicy(Qt::NoFocus);
all_toolbuttons.append(&foldersMenuButton);
actionSettings = TranslatedAction(MainWindow);
actionSettings->setObjectName(QStringLiteral("actionSettings"));
actionSettings->setIcon(APPLICATION->getThemedIcon("settings"));
actionSettings->setMenuRole(QAction::PreferencesRole);
actionSettings.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Settings..."));
actionSettings.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Change settings."));
actionSettings->setShortcut(QKeySequence::Preferences);
all_actions.append(&actionSettings);
if (!BuildConfig.BUG_TRACKER_URL.isEmpty()) {
actionReportBug = TranslatedAction(MainWindow);
actionReportBug->setObjectName(QStringLiteral("actionReportBug"));
actionReportBug->setIcon(APPLICATION->getThemedIcon("bug"));
actionReportBug.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Report a &Bug..."));
actionReportBug.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the bug tracker to report a bug with %1."));
all_actions.append(&actionReportBug);
}
if(!BuildConfig.MATRIX_URL.isEmpty()) {
actionMATRIX = TranslatedAction(MainWindow);
actionMATRIX->setObjectName(QStringLiteral("actionMATRIX"));
actionMATRIX->setIcon(APPLICATION->getThemedIcon("matrix"));
actionMATRIX.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&Matrix Space"));
actionMATRIX.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open %1 Matrix space"));
all_actions.append(&actionMATRIX);
}
if (!BuildConfig.DISCORD_URL.isEmpty()) {
actionDISCORD = TranslatedAction(MainWindow);
actionDISCORD->setObjectName(QStringLiteral("actionDISCORD"));
actionDISCORD->setIcon(APPLICATION->getThemedIcon("discord"));
actionDISCORD.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&Discord Guild"));
actionDISCORD.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open %1 Discord guild."));
all_actions.append(&actionDISCORD);
}
if (!BuildConfig.SUBREDDIT_URL.isEmpty()) {
actionREDDIT = TranslatedAction(MainWindow);
actionREDDIT->setObjectName(QStringLiteral("actionREDDIT"));
actionREDDIT->setIcon(APPLICATION->getThemedIcon("reddit-alien"));
actionREDDIT.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Sub&reddit"));
actionREDDIT.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open %1 subreddit."));
all_actions.append(&actionREDDIT);
}
actionAbout = TranslatedAction(MainWindow);
actionAbout->setObjectName(QStringLiteral("actionAbout"));
actionAbout->setIcon(APPLICATION->getThemedIcon("about"));
actionAbout->setMenuRole(QAction::AboutRole);
actionAbout.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&About %1"));
actionAbout.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "View information about %1."));
all_actions.append(&actionAbout);
if(BuildConfig.UPDATER_ENABLED)
{
actionCheckUpdate = TranslatedAction(MainWindow);
actionCheckUpdate->setObjectName(QStringLiteral("actionCheckUpdate"));
actionCheckUpdate->setIcon(APPLICATION->getThemedIcon("checkupdate"));
actionCheckUpdate.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&Update..."));
actionCheckUpdate.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Check for new updates for %1."));
actionCheckUpdate->setMenuRole(QAction::ApplicationSpecificRole);
all_actions.append(&actionCheckUpdate);
}
actionCAT = TranslatedAction(MainWindow);
actionCAT->setObjectName(QStringLiteral("actionCAT"));
actionCAT->setCheckable(true);
actionCAT->setIcon(APPLICATION->getThemedIcon("cat"));
actionCAT.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&Meow"));
actionCAT.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "It's a fluffy kitty :3"));
actionCAT->setPriority(QAction::LowPriority);
all_actions.append(&actionCAT);
// profile menu and its actions
actionManageAccounts = TranslatedAction(MainWindow);
actionManageAccounts->setObjectName(QStringLiteral("actionManageAccounts"));
actionManageAccounts.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&Manage Accounts..."));
// FIXME: no tooltip!
actionManageAccounts->setCheckable(false);
actionManageAccounts->setIcon(APPLICATION->getThemedIcon("accounts"));
all_actions.append(&actionManageAccounts);
}
void createMainToolbar(QMainWindow *MainWindow) void createMainToolbar(QMainWindow *MainWindow)
{ {
mainToolBar = TranslatedToolbar(MainWindow); mainToolBar = TranslatedToolbar(MainWindow);
@ -317,107 +424,35 @@ public:
mainToolBar->setFloatable(false); mainToolBar->setFloatable(false);
mainToolBar.setWindowTitleId(QT_TRANSLATE_NOOP("MainWindow", "Main Toolbar")); mainToolBar.setWindowTitleId(QT_TRANSLATE_NOOP("MainWindow", "Main Toolbar"));
actionAddInstance = TranslatedAction(MainWindow);
actionAddInstance->setObjectName(QStringLiteral("actionAddInstance"));
actionAddInstance->setIcon(APPLICATION->getThemedIcon("new"));
actionAddInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Add Instance"));
actionAddInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Add a new instance."));
all_actions.append(&actionAddInstance);
mainToolBar->addAction(actionAddInstance); mainToolBar->addAction(actionAddInstance);
mainToolBar->addSeparator(); mainToolBar->addSeparator();
foldersMenu = new QMenu(MainWindow);
foldersMenu->setToolTipsVisible(true);
actionViewInstanceFolder = TranslatedAction(MainWindow);
actionViewInstanceFolder->setObjectName(QStringLiteral("actionViewInstanceFolder"));
actionViewInstanceFolder->setIcon(APPLICATION->getThemedIcon("viewfolder"));
actionViewInstanceFolder.setTextId(QT_TRANSLATE_NOOP("MainWindow", "View Instance Folder"));
actionViewInstanceFolder.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the instance folder in a file browser."));
all_actions.append(&actionViewInstanceFolder);
foldersMenu->addAction(actionViewInstanceFolder);
actionViewCentralModsFolder = TranslatedAction(MainWindow);
actionViewCentralModsFolder->setObjectName(QStringLiteral("actionViewCentralModsFolder"));
actionViewCentralModsFolder->setIcon(APPLICATION->getThemedIcon("centralmods"));
actionViewCentralModsFolder.setTextId(QT_TRANSLATE_NOOP("MainWindow", "View Central Mods Folder"));
actionViewCentralModsFolder.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the central mods folder in a file browser."));
all_actions.append(&actionViewCentralModsFolder);
foldersMenu->addAction(actionViewCentralModsFolder);
foldersMenuButton = TranslatedToolButton(MainWindow);
foldersMenuButton.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Folders"));
foldersMenuButton.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open one of the folders shared between instances."));
foldersMenuButton->setMenu(foldersMenu);
foldersMenuButton->setPopupMode(QToolButton::InstantPopup);
foldersMenuButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
foldersMenuButton->setIcon(APPLICATION->getThemedIcon("viewfolder"));
foldersMenuButton->setFocusPolicy(Qt::NoFocus);
all_toolbuttons.append(&foldersMenuButton);
QWidgetAction* foldersButtonAction = new QWidgetAction(MainWindow); QWidgetAction* foldersButtonAction = new QWidgetAction(MainWindow);
foldersButtonAction->setDefaultWidget(foldersMenuButton); foldersButtonAction->setDefaultWidget(foldersMenuButton);
mainToolBar->addAction(foldersButtonAction); mainToolBar->addAction(foldersButtonAction);
actionSettings = TranslatedAction(MainWindow);
actionSettings->setObjectName(QStringLiteral("actionSettings"));
actionSettings->setIcon(APPLICATION->getThemedIcon("settings"));
actionSettings->setMenuRole(QAction::PreferencesRole);
actionSettings.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Settings"));
actionSettings.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Change settings."));
all_actions.append(&actionSettings);
mainToolBar->addAction(actionSettings); mainToolBar->addAction(actionSettings);
helpMenu = new QMenu(MainWindow); helpMenu = new QMenu(MainWindow);
helpMenu->setToolTipsVisible(true); helpMenu->setToolTipsVisible(true);
if (!BuildConfig.BUG_TRACKER_URL.isEmpty()) { if (!BuildConfig.BUG_TRACKER_URL.isEmpty()) {
actionReportBug = TranslatedAction(MainWindow);
actionReportBug->setObjectName(QStringLiteral("actionReportBug"));
actionReportBug->setIcon(APPLICATION->getThemedIcon("bug"));
actionReportBug.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Report a Bug"));
actionReportBug.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the bug tracker to report a bug with %1."));
all_actions.append(&actionReportBug);
helpMenu->addAction(actionReportBug); helpMenu->addAction(actionReportBug);
} }
if(!BuildConfig.MATRIX_URL.isEmpty()) { if(!BuildConfig.MATRIX_URL.isEmpty()) {
actionMATRIX = TranslatedAction(MainWindow);
actionMATRIX->setObjectName(QStringLiteral("actionMATRIX"));
actionMATRIX->setIcon(APPLICATION->getThemedIcon("matrix"));
actionMATRIX.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Matrix space"));
actionMATRIX.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open %1 Matrix space"));
all_actions.append(&actionMATRIX);
helpMenu->addAction(actionMATRIX); helpMenu->addAction(actionMATRIX);
} }
if (!BuildConfig.DISCORD_URL.isEmpty()) { if (!BuildConfig.DISCORD_URL.isEmpty()) {
actionDISCORD = TranslatedAction(MainWindow);
actionDISCORD->setObjectName(QStringLiteral("actionDISCORD"));
actionDISCORD->setIcon(APPLICATION->getThemedIcon("discord"));
actionDISCORD.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Discord guild"));
actionDISCORD.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open %1 Discord guild."));
all_actions.append(&actionDISCORD);
helpMenu->addAction(actionDISCORD); helpMenu->addAction(actionDISCORD);
} }
if (!BuildConfig.SUBREDDIT_URL.isEmpty()) { if (!BuildConfig.SUBREDDIT_URL.isEmpty()) {
actionREDDIT = TranslatedAction(MainWindow);
actionREDDIT->setObjectName(QStringLiteral("actionREDDIT"));
actionREDDIT->setIcon(APPLICATION->getThemedIcon("reddit-alien"));
actionREDDIT.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Subreddit"));
actionREDDIT.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open %1 subreddit."));
all_actions.append(&actionREDDIT);
helpMenu->addAction(actionREDDIT); helpMenu->addAction(actionREDDIT);
} }
actionAbout = TranslatedAction(MainWindow);
actionAbout->setObjectName(QStringLiteral("actionAbout"));
actionAbout->setIcon(APPLICATION->getThemedIcon("about"));
actionAbout->setMenuRole(QAction::AboutRole);
actionAbout.setTextId(QT_TRANSLATE_NOOP("MainWindow", "About %1"));
actionAbout.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "View information about %1."));
all_actions.append(&actionAbout);
helpMenu->addAction(actionAbout); helpMenu->addAction(actionAbout);
helpMenuButton = TranslatedToolButton(MainWindow); helpMenuButton = TranslatedToolButton(MainWindow);
@ -435,36 +470,13 @@ public:
if(BuildConfig.UPDATER_ENABLED) if(BuildConfig.UPDATER_ENABLED)
{ {
actionCheckUpdate = TranslatedAction(MainWindow);
actionCheckUpdate->setObjectName(QStringLiteral("actionCheckUpdate"));
actionCheckUpdate->setIcon(APPLICATION->getThemedIcon("checkupdate"));
actionCheckUpdate.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Update"));
actionCheckUpdate.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Check for new updates for %1."));
all_actions.append(&actionCheckUpdate);
mainToolBar->addAction(actionCheckUpdate); mainToolBar->addAction(actionCheckUpdate);
} }
mainToolBar->addSeparator(); mainToolBar->addSeparator();
actionCAT = TranslatedAction(MainWindow);
actionCAT->setObjectName(QStringLiteral("actionCAT"));
actionCAT->setCheckable(true);
actionCAT->setIcon(APPLICATION->getThemedIcon("cat"));
actionCAT.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Meow"));
actionCAT.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "It's a fluffy kitty :3"));
actionCAT->setPriority(QAction::LowPriority);
all_actions.append(&actionCAT);
mainToolBar->addAction(actionCAT); mainToolBar->addAction(actionCAT);
// profile menu and its actions
actionManageAccounts = TranslatedAction(MainWindow);
actionManageAccounts->setObjectName(QStringLiteral("actionManageAccounts"));
actionManageAccounts.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Manage Accounts"));
// FIXME: no tooltip!
actionManageAccounts->setCheckable(false);
actionManageAccounts->setIcon(APPLICATION->getThemedIcon("accounts"));
all_actions.append(&actionManageAccounts);
all_toolbars.append(&mainToolBar); all_toolbars.append(&mainToolBar);
MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar); MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
} }
@ -475,233 +487,132 @@ public:
menuBar->setVisible(APPLICATION->settings()->get("MenuBarInsteadOfToolBar").toBool()); menuBar->setVisible(APPLICATION->settings()->get("MenuBarInsteadOfToolBar").toBool());
createMenuActions(MainWindow); createMenuActions(MainWindow);
// TODO: only enable options while an instance is selected (if applicable)
fileMenu = menuBar->addMenu(tr("&File")); fileMenu = menuBar->addMenu(tr("&File"));
fileMenu->addAction(newAct); fileMenu->addAction(actionAddInstance);
fileMenu->addAction(openAct); fileMenu->addAction(actionLaunchInstance);
fileMenu->addAction(openOfflineAct); fileMenu->addAction(actionLaunchInstanceOffline);
fileMenu->addAction(closeAct); fileMenu->addAction(actionCloseWindow);
fileMenu->addSeparator(); fileMenu->addSeparator();
fileMenu->addAction(editInstanceAct); fileMenu->addAction(actionEditInstance);
fileMenu->addAction(editNotesAct); fileMenu->addAction(actionEditInstNotes);
fileMenu->addAction(editModsAct); fileMenu->addAction(actionMods);
fileMenu->addAction(editWorldsAct); fileMenu->addAction(actionWorlds);
fileMenu->addAction(manageScreenshotsAct); fileMenu->addAction(actionScreenshots);
fileMenu->addAction(changeGroupAct); fileMenu->addAction(actionChangeInstGroup);
fileMenu->addSeparator(); fileMenu->addSeparator();
fileMenu->addAction(openMCFolderAct); fileMenu->addAction(actionViewSelectedMCFolder);
fileMenu->addAction(openConfigFolderAct); fileMenu->addAction(actionConfig_Folder);
fileMenu->addAction(openInstanceFolderAct); fileMenu->addAction(actionViewSelectedInstFolder);
fileMenu->addSeparator(); fileMenu->addSeparator();
fileMenu->addAction(exportInstanceAct); fileMenu->addAction(actionExportInstance);
fileMenu->addAction(deleteInstanceAct); fileMenu->addAction(actionDeleteInstance);
fileMenu->addAction(duplicateInstanceAct); fileMenu->addAction(actionCopyInstance);
fileMenu->addSeparator(); fileMenu->addSeparator();
// TODO: functionality for edit actions. They're intended to be used where you can type text, e.g. notes. // TODO: functionality for edit actions. They're intended to be used where you can type text, e.g. notes.
editMenu = menuBar->addMenu(tr("&Edit")); editMenu = menuBar->addMenu(tr("&Edit"));
editMenu->addAction(undoAct); editMenu->addAction(actionUndo);
editMenu->addAction(redoAct); editMenu->addAction(actionRedo);
editMenu->addSeparator(); editMenu->addSeparator();
editMenu->addAction(cutAct); editMenu->addAction(actionCut);
editMenu->addAction(copyAct); editMenu->addAction(actionCopy);
editMenu->addAction(pasteAct); editMenu->addAction(actionPaste);
editMenu->addAction(selectAllAct); editMenu->addAction(actionSelectAll);
editMenu->addSeparator(); editMenu->addSeparator();
editMenu->addAction(settingsAct); editMenu->addAction(actionSettings);
viewMenu = menuBar->addMenu(tr("&View"));
viewMenu->addAction(actionCAT);
viewMenu->addSeparator();
menuBar->addMenu(foldersMenu);
profileMenu = menuBar->addMenu(tr("&Profiles")); profileMenu = menuBar->addMenu(tr("&Profiles"));
profileMenu->addAction(manageAccountAct); profileMenu->addAction(actionManageAccounts);
helpMenu = menuBar->addMenu(tr("&Help")); helpMenu = menuBar->addMenu(tr("&Help"));
helpMenu->addAction(aboutAct); helpMenu->addAction(actionAbout);
helpMenu->addAction(wikiAct); helpMenu->addAction(actionWiki);
helpMenu->addAction(newsAct); helpMenu->addAction(actionNewsMenuBar);
helpMenu->addSeparator(); helpMenu->addSeparator();
helpMenu->addAction(reportBugAct); if (!BuildConfig.BUG_TRACKER_URL.isEmpty())
helpMenu->addAction(matrixAct); helpMenu->addAction(actionReportBug);
helpMenu->addAction(discordAct); if (!BuildConfig.MATRIX_URL.isEmpty())
helpMenu->addAction(redditAct); helpMenu->addAction(actionMATRIX);
if (!BuildConfig.DISCORD_URL.isEmpty())
helpMenu->addAction(actionDISCORD);
if (!BuildConfig.SUBREDDIT_URL.isEmpty())
helpMenu->addAction(actionREDDIT);
helpMenu->addSeparator();
if(BuildConfig.UPDATER_ENABLED)
helpMenu->addAction(actionCheckUpdate);
MainWindow->setMenuBar(menuBar); MainWindow->setMenuBar(menuBar);
} }
// If a keyboard shortcut is changed here, it must be changed below in keyPressEvent as well
void createMenuActions(MainWindow *MainWindow) void createMenuActions(MainWindow *MainWindow)
{ {
newAct = new QAction(tr("&New Instance..."), MainWindow); actionCloseWindow = new QAction(tr("Close &Window"), MainWindow);
newAct->setShortcuts(QKeySequence::New); actionCloseWindow->setShortcut(QKeySequence::Close);
newAct->setStatusTip(tr("Create a new instance")); actionCloseWindow->setStatusTip(tr("Close the current window"));
connect(newAct, &QAction::triggered, MainWindow, &MainWindow::on_actionAddInstance_triggered); connect(actionCloseWindow, &QAction::triggered, APPLICATION, &Application::closeCurrentWindow);
openAct = new QAction(tr("&Launch"), MainWindow); actionUndo = new QAction(tr("&Undo"), MainWindow);
openAct->setShortcuts(QKeySequence::Open); actionUndo->setShortcuts(QKeySequence::Undo);
openAct->setStatusTip(tr("Launch the selected instance")); actionUndo->setStatusTip(tr("Undo"));
openAct->setEnabled(false); actionUndo->setEnabled(false);
connect(openAct, &QAction::triggered, MainWindow, &MainWindow::on_actionLaunchInstance_triggered);
openOfflineAct = new QAction(tr("Launch &Offline"), MainWindow); actionRedo = new QAction(tr("&Redo"), MainWindow);
openOfflineAct->setShortcut(QKeySequence(tr("Ctrl+Shift+O"))); actionRedo->setShortcuts(QKeySequence::Redo);
openOfflineAct->setStatusTip(tr("Launch the selected instance in offline mode")); actionRedo->setStatusTip(tr("Redo"));
openOfflineAct->setEnabled(false); actionRedo->setEnabled(false);
connect(openOfflineAct, &QAction::triggered, MainWindow, &MainWindow::on_actionLaunchInstanceOffline_triggered);
editInstanceAct = new QAction(tr("Edit Inst&ance..."), MainWindow); actionCut = new QAction(tr("Cu&t"), MainWindow);
editInstanceAct->setShortcut(QKeySequence(tr("Ctrl+I"))); actionCut->setShortcuts(QKeySequence::Cut);
editInstanceAct->setStatusTip(tr("Edit the selected instance")); actionCut->setStatusTip(tr("Cut"));
editInstanceAct->setEnabled(false); actionCut->setEnabled(false);
connect(editInstanceAct, &QAction::triggered, MainWindow, &MainWindow::on_actionEditInstance_triggered);
editNotesAct = new QAction(tr("E&dit Notes..."), MainWindow); actionCopy = new QAction(tr("&Copy"), MainWindow);
editNotesAct->setStatusTip(tr("Edit the selected instance's notes")); actionCopy->setShortcuts(QKeySequence::Copy);
editNotesAct->setEnabled(false); actionCopy->setStatusTip(tr("Copy"));
connect(editNotesAct, &QAction::triggered, MainWindow, &MainWindow::on_actionEditInstNotes_triggered); actionCopy->setEnabled(false);
editModsAct = new QAction(tr("View &Mods"), MainWindow); actionPaste = new QAction(tr("&Paste"), MainWindow);
editModsAct->setStatusTip(tr("View the selected instance's mods")); actionPaste->setShortcuts(QKeySequence::Paste);
editModsAct->setEnabled(false); actionPaste->setStatusTip(tr("Paste"));
connect(editModsAct, &QAction::triggered, MainWindow, &MainWindow::on_actionMods_triggered); actionPaste->setEnabled(false);
editWorldsAct = new QAction(tr("&View Worlds"), MainWindow); actionSelectAll = new QAction(tr("Select &All"), MainWindow);
editWorldsAct->setStatusTip(tr("View the selected instance's worlds")); actionSelectAll->setShortcuts(QKeySequence::SelectAll);
editWorldsAct->setEnabled(false); actionSelectAll->setStatusTip(tr("Select all"));
connect(editWorldsAct, &QAction::triggered, MainWindow, &MainWindow::on_actionWorlds_triggered); actionSelectAll->setEnabled(false);
manageScreenshotsAct = new QAction(tr("Manage &Screenshots"), MainWindow); actionWiki = new QAction(tr("%1 He&lp").arg(BuildConfig.LAUNCHER_NAME), MainWindow);
manageScreenshotsAct->setStatusTip(tr("Manage the selected instance's screenshots")); actionWiki->setStatusTip(tr("Open the %1 wiki").arg(BuildConfig.LAUNCHER_NAME));
manageScreenshotsAct->setEnabled(false); connect(actionWiki, &QAction::triggered, MainWindow, &MainWindow::on_actionOpenWiki_triggered);
connect(manageScreenshotsAct, &QAction::triggered, MainWindow, &MainWindow::on_actionScreenshots_triggered);
changeGroupAct = new QAction(tr("&Change Group..."), MainWindow); actionNewsMenuBar = new QAction(tr("&%1 &News").arg(BuildConfig.LAUNCHER_NAME), MainWindow);
changeGroupAct->setShortcut(QKeySequence(tr("Ctrl+G"))); actionNewsMenuBar->setStatusTip(tr("Open the development blog to read more news about %1.").arg(BuildConfig.LAUNCHER_NAME));
changeGroupAct->setStatusTip(tr("Change the selected instance's group")); connect(actionNewsMenuBar, &QAction::triggered, MainWindow, &MainWindow::on_actionMoreNews_triggered);
changeGroupAct->setEnabled(false);
connect(changeGroupAct, &QAction::triggered, MainWindow, &MainWindow::on_actionChangeInstGroup_triggered);
openMCFolderAct = new QAction(tr("Open Minec&raft Folder"), MainWindow);
openMCFolderAct->setShortcut(QKeySequence(tr("Ctrl+M")));
openMCFolderAct->setStatusTip(tr("Open the selected instance's Minecraft folder"));
openMCFolderAct->setEnabled(false);
connect(openMCFolderAct, &QAction::triggered, MainWindow, &MainWindow::on_actionViewSelectedMCFolder_triggered);
openConfigFolderAct = new QAction(tr("&Open Confi&g Folder"), MainWindow);
openConfigFolderAct->setStatusTip(tr("Open the selected instance's config folder"));
openConfigFolderAct->setEnabled(false);
connect(openConfigFolderAct, &QAction::triggered, MainWindow, &MainWindow::on_actionConfig_Folder_triggered);
openInstanceFolderAct = new QAction(tr("&Open &Instance Folder"), MainWindow);
openInstanceFolderAct->setStatusTip(tr("Open the selected instance's main folder"));
openInstanceFolderAct->setEnabled(false);
connect(openInstanceFolderAct, &QAction::triggered, MainWindow, &MainWindow::on_actionViewInstanceFolder_triggered);
exportInstanceAct = new QAction(tr("E&xport Instance..."), MainWindow);
exportInstanceAct->setShortcut(QKeySequence(tr("Ctrl+E")));
exportInstanceAct->setStatusTip(tr("Export the selected instance"));
exportInstanceAct->setEnabled(false);
connect(exportInstanceAct, &QAction::triggered, MainWindow, &MainWindow::on_actionExportInstance_triggered);
deleteInstanceAct = new QAction(tr("Dele&te Instance..."), MainWindow);
deleteInstanceAct->setShortcuts({QKeySequence(tr("Backspace")), QKeySequence::Delete});
deleteInstanceAct->setStatusTip(tr("Delete the selected instance"));
deleteInstanceAct->setEnabled(false);
connect(deleteInstanceAct, &QAction::triggered, MainWindow, &MainWindow::on_actionDeleteInstance_triggered);
duplicateInstanceAct = new QAction(tr("Cop&y Instance..."), MainWindow);
duplicateInstanceAct->setShortcut(QKeySequence(tr("Ctrl+D")));
duplicateInstanceAct->setStatusTip(tr("Duplicate the selected instance"));
duplicateInstanceAct->setEnabled(false);
connect(duplicateInstanceAct, &QAction::triggered, MainWindow, &MainWindow::on_actionCopyInstance_triggered);
closeAct = new QAction(tr("Close &Window"), MainWindow);
closeAct->setShortcut(QKeySequence::Close);
closeAct->setStatusTip(tr("Close the current window"));
connect(closeAct, &QAction::triggered, APPLICATION, &Application::closeCurrentWindow);
undoAct = new QAction(tr("&Undo"), MainWindow);
undoAct->setShortcuts(QKeySequence::Undo);
undoAct->setStatusTip(tr("Undo"));
undoAct->setEnabled(false);
redoAct = new QAction(tr("&Redo"), MainWindow);
redoAct->setShortcuts(QKeySequence::Redo);
redoAct->setStatusTip(tr("Redo"));
redoAct->setEnabled(false);
cutAct = new QAction(tr("Cu&t"), MainWindow);
cutAct->setShortcuts(QKeySequence::Cut);
cutAct->setStatusTip(tr("Cut"));
cutAct->setEnabled(false);
copyAct = new QAction(tr("&Copy"), MainWindow);
copyAct->setShortcuts(QKeySequence::Copy);
copyAct->setStatusTip(tr("Copy"));
copyAct->setEnabled(false);
pasteAct = new QAction(tr("&Paste"), MainWindow);
pasteAct->setShortcuts(QKeySequence::Paste);
pasteAct->setStatusTip(tr("Paste"));
pasteAct->setEnabled(false);
selectAllAct = new QAction(tr("Select &All"), MainWindow);
selectAllAct->setShortcuts(QKeySequence::SelectAll);
selectAllAct->setStatusTip(tr("Select all"));
selectAllAct->setEnabled(false);
settingsAct = new QAction(tr("&Settings..."), MainWindow);
settingsAct->setShortcut(QKeySequence::Preferences);
settingsAct->setStatusTip(tr("Change %1 settings").arg(BuildConfig.LAUNCHER_NAME));
connect(settingsAct, &QAction::triggered, MainWindow, &MainWindow::on_actionSettings_triggered);
manageAccountAct = new QAction(tr("&Manage Accounts..."), MainWindow);
manageAccountAct->setStatusTip(tr("Open account manager"));
connect(manageAccountAct, &QAction::triggered, MainWindow, &MainWindow::on_actionManageAccounts_triggered);
aboutAct = new QAction(tr("&About"), MainWindow);
aboutAct->setStatusTip(tr("About %1").arg(BuildConfig.LAUNCHER_NAME));
connect(aboutAct, &QAction::triggered, MainWindow, &MainWindow::on_actionAbout_triggered);
wikiAct = new QAction(tr("%1 He&lp").arg(BuildConfig.LAUNCHER_NAME), MainWindow);
wikiAct->setStatusTip(tr("Open %1's wiki").arg(BuildConfig.LAUNCHER_NAME));
connect(wikiAct, &QAction::triggered, MainWindow, &MainWindow::on_actionOpenWiki_triggered);
newsAct = new QAction(tr("&%1 &News").arg(BuildConfig.LAUNCHER_NAME), MainWindow);
newsAct->setStatusTip(tr("Open %1's news").arg(BuildConfig.LAUNCHER_NAME));
connect(newsAct, &QAction::triggered, MainWindow, &MainWindow::on_actionMoreNews_triggered);
reportBugAct = new QAction(tr("Report &Bugs..."), MainWindow);
reportBugAct->setStatusTip(tr("Report bugs to the developers"));
connect(reportBugAct, &QAction::triggered, MainWindow, &MainWindow::on_actionReportBug_triggered);
matrixAct = new QAction(tr("&Matrix"), MainWindow);
matrixAct->setStatusTip(tr("Open %1's Matrix space").arg(BuildConfig.LAUNCHER_NAME));
connect(matrixAct, &QAction::triggered, MainWindow, &MainWindow::on_actionMATRIX_triggered);
discordAct = new QAction(tr("&Discord"), MainWindow);
discordAct->setStatusTip(tr("Open %1's Discord guild").arg(BuildConfig.LAUNCHER_NAME));
connect(discordAct, &QAction::triggered, MainWindow, &MainWindow::on_actionDISCORD_triggered);
redditAct = new QAction(tr("&Reddit"), MainWindow);
redditAct->setStatusTip(tr("Open %1's subreddit").arg(BuildConfig.LAUNCHER_NAME));
connect(redditAct, &QAction::triggered, MainWindow, &MainWindow::on_actionREDDIT_triggered);
} }
// "Instance actions" are actions that require an instance to be selected (i.e. "new instance" is not here) // "Instance actions" are actions that require an instance to be selected (i.e. "new instance" is not here)
void setInstanceActionsEnabled(bool enabled) const void setInstanceActionsEnabled(bool enabled)
{ {
openAct->setEnabled(enabled); actionLaunchInstance->setEnabled(enabled);
openOfflineAct->setEnabled(enabled); actionLaunchInstanceOffline->setEnabled(enabled);
editInstanceAct->setEnabled(enabled); actionEditInstance->setEnabled(enabled);
editNotesAct->setEnabled(enabled); actionEditInstNotes->setEnabled(enabled);
editModsAct->setEnabled(enabled); actionMods->setEnabled(enabled);
editWorldsAct->setEnabled(enabled); actionWorlds->setEnabled(enabled);
manageScreenshotsAct->setEnabled(enabled); actionScreenshots->setEnabled(enabled);
changeGroupAct->setEnabled(enabled); actionChangeInstGroup->setEnabled(enabled);
openMCFolderAct->setEnabled(enabled); actionViewSelectedMCFolder->setEnabled(enabled);
openConfigFolderAct->setEnabled(enabled); actionConfig_Folder->setEnabled(enabled);
openInstanceFolderAct->setEnabled(enabled); actionViewSelectedInstFolder->setEnabled(enabled);
exportInstanceAct->setEnabled(enabled); actionExportInstance->setEnabled(enabled);
deleteInstanceAct->setEnabled(enabled); actionDeleteInstance->setEnabled(enabled);
duplicateInstanceAct->setEnabled(enabled); actionCopyInstance->setEnabled(enabled);
} }
void createStatusBar(QMainWindow *MainWindow) void createStatusBar(QMainWindow *MainWindow)
@ -734,18 +645,8 @@ public:
MainWindow->addToolBar(Qt::BottomToolBarArea, newsToolBar); MainWindow->addToolBar(Qt::BottomToolBarArea, newsToolBar);
} }
void createInstanceToolbar(QMainWindow *MainWindow) void createInstanceActions(QMainWindow *MainWindow)
{ {
instanceToolBar = TranslatedToolbar(MainWindow);
instanceToolBar->setObjectName(QStringLiteral("instanceToolBar"));
// disabled until we have an instance selected
instanceToolBar->setEnabled(false);
instanceToolBar->setMovable(true);
instanceToolBar->setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea);
instanceToolBar->setToolButtonStyle(Qt::ToolButtonTextOnly);
instanceToolBar->setFloatable(false);
instanceToolBar->setWindowTitle(QT_TRANSLATE_NOOP("MainWindow", "Instance Toolbar"));
// NOTE: not added to toolbar, but used for instance context menu (right click) // NOTE: not added to toolbar, but used for instance context menu (right click)
actionChangeInstIcon = TranslatedAction(MainWindow); actionChangeInstIcon = TranslatedAction(MainWindow);
actionChangeInstIcon->setObjectName(QStringLiteral("actionChangeInstIcon")); actionChangeInstIcon->setObjectName(QStringLiteral("actionChangeInstIcon"));
@ -760,7 +661,6 @@ public:
changeIconButton->setIcon(APPLICATION->getThemedIcon("news")); changeIconButton->setIcon(APPLICATION->getThemedIcon("news"));
changeIconButton->setToolTip(actionChangeInstIcon->toolTip()); changeIconButton->setToolTip(actionChangeInstIcon->toolTip());
changeIconButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); changeIconButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
instanceToolBar->addWidget(changeIconButton);
// NOTE: not added to toolbar, but used for instance context menu (right click) // NOTE: not added to toolbar, but used for instance context menu (right click)
actionRenameInstance = TranslatedAction(MainWindow); actionRenameInstance = TranslatedAction(MainWindow);
@ -774,74 +674,61 @@ public:
renameButton->setObjectName(QStringLiteral("renameButton")); renameButton->setObjectName(QStringLiteral("renameButton"));
renameButton->setToolTip(actionRenameInstance->toolTip()); renameButton->setToolTip(actionRenameInstance->toolTip());
renameButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); renameButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
instanceToolBar->addWidget(renameButton);
instanceToolBar->addSeparator();
actionLaunchInstance = TranslatedAction(MainWindow); actionLaunchInstance = TranslatedAction(MainWindow);
actionLaunchInstance->setObjectName(QStringLiteral("actionLaunchInstance")); actionLaunchInstance->setObjectName(QStringLiteral("actionLaunchInstance"));
all_actions.append(&actionLaunchInstance); all_actions.append(&actionLaunchInstance);
instanceToolBar->addAction(actionLaunchInstance);
actionLaunchInstanceOffline = TranslatedAction(MainWindow); actionLaunchInstanceOffline = TranslatedAction(MainWindow);
actionLaunchInstanceOffline->setObjectName(QStringLiteral("actionLaunchInstanceOffline")); actionLaunchInstanceOffline->setObjectName(QStringLiteral("actionLaunchInstanceOffline"));
actionLaunchInstanceOffline.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Launch Offline")); actionLaunchInstanceOffline.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Launch &Offline"));
actionLaunchInstanceOffline.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Launch the selected instance in offline mode.")); actionLaunchInstanceOffline.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Launch the selected instance in offline mode."));
all_actions.append(&actionLaunchInstanceOffline); all_actions.append(&actionLaunchInstanceOffline);
instanceToolBar->addAction(actionLaunchInstanceOffline);
instanceToolBar->addSeparator();
actionEditInstance = TranslatedAction(MainWindow); actionEditInstance = TranslatedAction(MainWindow);
actionEditInstance->setObjectName(QStringLiteral("actionEditInstance")); actionEditInstance->setObjectName(QStringLiteral("actionEditInstance"));
actionEditInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Edit Instance")); actionEditInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Edit Inst&ance..."));
actionEditInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Change the instance settings, mods and versions.")); actionEditInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Change the instance settings, mods and versions."));
actionEditInstance->setShortcut(QKeySequence(tr("Ctrl+I")));
all_actions.append(&actionEditInstance); all_actions.append(&actionEditInstance);
instanceToolBar->addAction(actionEditInstance);
actionEditInstNotes = TranslatedAction(MainWindow); actionEditInstNotes = TranslatedAction(MainWindow);
actionEditInstNotes->setObjectName(QStringLiteral("actionEditInstNotes")); actionEditInstNotes->setObjectName(QStringLiteral("actionEditInstNotes"));
actionEditInstNotes.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Edit Notes")); actionEditInstNotes.setTextId(QT_TRANSLATE_NOOP("MainWindow", "E&dit Notes..."));
actionEditInstNotes.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Edit the notes for the selected instance.")); actionEditInstNotes.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Edit the notes for the selected instance."));
all_actions.append(&actionEditInstNotes); all_actions.append(&actionEditInstNotes);
instanceToolBar->addAction(actionEditInstNotes);
actionMods = TranslatedAction(MainWindow); actionMods = TranslatedAction(MainWindow);
actionMods->setObjectName(QStringLiteral("actionMods")); actionMods->setObjectName(QStringLiteral("actionMods"));
actionMods.setTextId(QT_TRANSLATE_NOOP("MainWindow", "View Mods")); actionMods.setTextId(QT_TRANSLATE_NOOP("MainWindow", "View &Mods"));
actionMods.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "View the mods of this instance.")); actionMods.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "View the mods of this instance."));
all_actions.append(&actionMods); all_actions.append(&actionMods);
instanceToolBar->addAction(actionMods);
actionWorlds = TranslatedAction(MainWindow); actionWorlds = TranslatedAction(MainWindow);
actionWorlds->setObjectName(QStringLiteral("actionWorlds")); actionWorlds->setObjectName(QStringLiteral("actionWorlds"));
actionWorlds.setTextId(QT_TRANSLATE_NOOP("MainWindow", "View Worlds")); actionWorlds.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&View Worlds"));
actionWorlds.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "View the worlds of this instance.")); actionWorlds.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "View the worlds of this instance."));
all_actions.append(&actionWorlds); all_actions.append(&actionWorlds);
instanceToolBar->addAction(actionWorlds);
actionScreenshots = TranslatedAction(MainWindow); actionScreenshots = TranslatedAction(MainWindow);
actionScreenshots->setObjectName(QStringLiteral("actionScreenshots")); actionScreenshots->setObjectName(QStringLiteral("actionScreenshots"));
actionScreenshots.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Manage Screenshots")); actionScreenshots.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Manage &Screenshots"));
actionScreenshots.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "View and upload screenshots for this instance.")); actionScreenshots.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "View and upload screenshots for this instance."));
all_actions.append(&actionScreenshots); all_actions.append(&actionScreenshots);
instanceToolBar->addAction(actionScreenshots);
actionChangeInstGroup = TranslatedAction(MainWindow); actionChangeInstGroup = TranslatedAction(MainWindow);
actionChangeInstGroup->setObjectName(QStringLiteral("actionChangeInstGroup")); actionChangeInstGroup->setObjectName(QStringLiteral("actionChangeInstGroup"));
actionChangeInstGroup.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Change Group")); actionChangeInstGroup.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&Change Group..."));
actionChangeInstGroup.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Change the selected instance's group.")); actionChangeInstGroup.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Change the selected instance's group."));
actionChangeInstGroup->setShortcut(QKeySequence(tr("Ctrl+G")));
all_actions.append(&actionChangeInstGroup); all_actions.append(&actionChangeInstGroup);
instanceToolBar->addAction(actionChangeInstGroup);
instanceToolBar->addSeparator();
actionViewSelectedMCFolder = TranslatedAction(MainWindow); actionViewSelectedMCFolder = TranslatedAction(MainWindow);
actionViewSelectedMCFolder->setObjectName(QStringLiteral("actionViewSelectedMCFolder")); actionViewSelectedMCFolder->setObjectName(QStringLiteral("actionViewSelectedMCFolder"));
actionViewSelectedMCFolder.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Minecraft Folder")); actionViewSelectedMCFolder.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Minec&raft Folder"));
actionViewSelectedMCFolder.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the selected instance's Minecraft folder in a file browser.")); actionViewSelectedMCFolder.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the selected instance's Minecraft folder in a file browser."));
actionViewSelectedMCFolder->setShortcut(QKeySequence(tr("Ctrl+M")));
all_actions.append(&actionViewSelectedMCFolder); all_actions.append(&actionViewSelectedMCFolder);
instanceToolBar->addAction(actionViewSelectedMCFolder);
/* /*
actionViewSelectedModsFolder = TranslatedAction(MainWindow); actionViewSelectedModsFolder = TranslatedAction(MainWindow);
@ -849,45 +736,89 @@ public:
actionViewSelectedModsFolder.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Mods Folder")); actionViewSelectedModsFolder.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Mods Folder"));
actionViewSelectedModsFolder.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the selected instance's mods folder in a file browser.")); actionViewSelectedModsFolder.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the selected instance's mods folder in a file browser."));
all_actions.append(&actionViewSelectedModsFolder); all_actions.append(&actionViewSelectedModsFolder);
instanceToolBar->addAction(actionViewSelectedModsFolder);
*/ */
actionConfig_Folder = TranslatedAction(MainWindow); actionConfig_Folder = TranslatedAction(MainWindow);
actionConfig_Folder->setObjectName(QStringLiteral("actionConfig_Folder")); actionConfig_Folder->setObjectName(QStringLiteral("actionConfig_Folder"));
actionConfig_Folder.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Config Folder")); actionConfig_Folder.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Confi&g Folder"));
actionConfig_Folder.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the instance's config folder.")); actionConfig_Folder.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the instance's config folder."));
// Qt on macOS is "smart" and will eat up this action when added to the menu bar because it starts with the word "config"...
// Docs: https://doc.qt.io/qt-5/qmenubar.html#qmenubar-as-a-global-menu-bar
actionConfig_Folder->setMenuRole(QAction::NoRole);
all_actions.append(&actionConfig_Folder); all_actions.append(&actionConfig_Folder);
instanceToolBar->addAction(actionConfig_Folder);
actionViewSelectedInstFolder = TranslatedAction(MainWindow); actionViewSelectedInstFolder = TranslatedAction(MainWindow);
actionViewSelectedInstFolder->setObjectName(QStringLiteral("actionViewSelectedInstFolder")); actionViewSelectedInstFolder->setObjectName(QStringLiteral("actionViewSelectedInstFolder"));
actionViewSelectedInstFolder.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Instance Folder")); actionViewSelectedInstFolder.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&Instance Folder"));
actionViewSelectedInstFolder.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the selected instance's root folder in a file browser.")); actionViewSelectedInstFolder.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the selected instance's root folder in a file browser."));
all_actions.append(&actionViewSelectedInstFolder); all_actions.append(&actionViewSelectedInstFolder);
instanceToolBar->addAction(actionViewSelectedInstFolder);
instanceToolBar->addSeparator();
actionExportInstance = TranslatedAction(MainWindow); actionExportInstance = TranslatedAction(MainWindow);
actionExportInstance->setObjectName(QStringLiteral("actionExportInstance")); actionExportInstance->setObjectName(QStringLiteral("actionExportInstance"));
actionExportInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Export Instance")); actionExportInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "E&xport Instance..."));
actionExportInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Export the selected instance as a zip file.")); actionExportInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Export the selected instance as a zip file."));
actionExportInstance->setShortcut(QKeySequence(tr("Ctrl+E")));
all_actions.append(&actionExportInstance); all_actions.append(&actionExportInstance);
instanceToolBar->addAction(actionExportInstance);
actionDeleteInstance = TranslatedAction(MainWindow); actionDeleteInstance = TranslatedAction(MainWindow);
actionDeleteInstance->setObjectName(QStringLiteral("actionDeleteInstance")); actionDeleteInstance->setObjectName(QStringLiteral("actionDeleteInstance"));
actionDeleteInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Delete Instance")); actionDeleteInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Dele&te Instance..."));
actionDeleteInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Delete the selected instance.")); actionDeleteInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Delete the selected instance."));
actionDeleteInstance->setShortcuts({QKeySequence(tr("Backspace")), QKeySequence::Delete});
all_actions.append(&actionDeleteInstance); all_actions.append(&actionDeleteInstance);
instanceToolBar->addAction(actionDeleteInstance);
actionCopyInstance = TranslatedAction(MainWindow); actionCopyInstance = TranslatedAction(MainWindow);
actionCopyInstance->setObjectName(QStringLiteral("actionCopyInstance")); actionCopyInstance->setObjectName(QStringLiteral("actionCopyInstance"));
actionCopyInstance->setIcon(APPLICATION->getThemedIcon("copy")); actionCopyInstance->setIcon(APPLICATION->getThemedIcon("copy"));
actionCopyInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Copy Instance")); actionCopyInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Cop&y Instance..."));
actionCopyInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Copy the selected instance.")); actionCopyInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Copy the selected instance."));
actionCopyInstance->setShortcut(QKeySequence(tr("Ctrl+D")));
all_actions.append(&actionCopyInstance); all_actions.append(&actionCopyInstance);
}
void createInstanceToolbar(QMainWindow *MainWindow)
{
instanceToolBar = TranslatedToolbar(MainWindow);
instanceToolBar->setObjectName(QStringLiteral("instanceToolBar"));
// disabled until we have an instance selected
instanceToolBar->setEnabled(false);
instanceToolBar->setMovable(true);
instanceToolBar->setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea);
instanceToolBar->setToolButtonStyle(Qt::ToolButtonTextOnly);
instanceToolBar->setFloatable(false);
instanceToolBar->setWindowTitle(QT_TRANSLATE_NOOP("MainWindow", "Instance Toolbar"));
instanceToolBar->addWidget(changeIconButton);
instanceToolBar->addWidget(renameButton);
instanceToolBar->addSeparator();
instanceToolBar->addAction(actionLaunchInstance);
instanceToolBar->addAction(actionLaunchInstanceOffline);
instanceToolBar->addSeparator();
instanceToolBar->addAction(actionEditInstance);
instanceToolBar->addAction(actionEditInstNotes);
instanceToolBar->addAction(actionMods);
instanceToolBar->addAction(actionWorlds);
instanceToolBar->addAction(actionScreenshots);
instanceToolBar->addAction(actionChangeInstGroup);
instanceToolBar->addSeparator();
instanceToolBar->addAction(actionViewSelectedMCFolder);
/*
instanceToolBar->addAction(actionViewSelectedModsFolder);
*/
instanceToolBar->addAction(actionConfig_Folder);
instanceToolBar->addAction(actionViewSelectedInstFolder);
instanceToolBar->addSeparator();
instanceToolBar->addAction(actionExportInstance);
instanceToolBar->addAction(actionDeleteInstance);
instanceToolBar->addAction(actionCopyInstance); instanceToolBar->addAction(actionCopyInstance);
all_toolbars.append(&instanceToolBar); all_toolbars.append(&instanceToolBar);
@ -907,6 +838,9 @@ public:
MainWindow->setAccessibleName(BuildConfig.LAUNCHER_NAME); MainWindow->setAccessibleName(BuildConfig.LAUNCHER_NAME);
#endif #endif
createMainToolbarActions(MainWindow);
createInstanceActions(MainWindow);
createMenuBar(dynamic_cast<class MainWindow *>(MainWindow)); createMenuBar(dynamic_cast<class MainWindow *>(MainWindow));
createMainToolbar(MainWindow); createMainToolbar(MainWindow);
@ -1138,57 +1072,6 @@ void MainWindow::keyReleaseEvent(QKeyEvent *event)
else else
QMainWindow::keyReleaseEvent(event); QMainWindow::keyReleaseEvent(event);
} }
// FIXME: This is a hack because keyboard shortcuts do nothing while menu bar is hidden on systems without native menu bar
// If a keyboard shortcut is changed above in `createMenuActions`, it must be changed here as well
void MainWindow::keyPressEvent(QKeyEvent *event)
{
if(ui->menuBar->isVisible() || ui->menuBar->isNativeMenuBar())
{
QMainWindow::keyPressEvent(event);
return; // let the menu bar handle the keyboard shortcuts
}
if(event->modifiers().testFlag(Qt::ControlModifier))
{
switch(event->key())
{
case Qt::Key_N:
on_actionAddInstance_triggered();
return;
case Qt::Key_O:
if(event->modifiers().testFlag(Qt::ShiftModifier))
on_actionLaunchInstanceOffline_triggered();
else
on_actionLaunchInstance_triggered();
return;
case Qt::Key_I:
on_actionEditInstance_triggered();
return;
case Qt::Key_G:
on_actionChangeInstGroup_triggered();
return;
case Qt::Key_M:
on_actionViewSelectedMCFolder_triggered();
return;
case Qt::Key_E:
on_actionExportInstance_triggered();
return;
case Qt::Key_Delete:
on_actionDeleteInstance_triggered();
return;
case Qt::Key_D:
on_actionCopyInstance_triggered();
return;
case Qt::Key_W:
close();
return;
// Text editing shortcuts are handled by the OS, so they do not need to be implemented here again
default:
return;
}
}
}
#endif #endif
void MainWindow::retranslateUi() void MainWindow::retranslateUi()
@ -1333,7 +1216,9 @@ void MainWindow::updateToolsMenu()
} }
QAction *normalLaunch = launchMenu->addAction(tr("Launch")); QAction *normalLaunch = launchMenu->addAction(tr("Launch"));
normalLaunch->setShortcut(QKeySequence::Open);
QAction *normalLaunchOffline = launchOfflineMenu->addAction(tr("Launch Offline")); QAction *normalLaunchOffline = launchOfflineMenu->addAction(tr("Launch Offline"));
normalLaunchOffline->setShortcut(QKeySequence(tr("Ctrl+Shift+O")));
connect(normalLaunch, &QAction::triggered, [this]() connect(normalLaunch, &QAction::triggered, [this]()
{ {
APPLICATION->launch(m_selectedInstance, true); APPLICATION->launch(m_selectedInstance, true);
@ -1454,7 +1339,7 @@ void MainWindow::repopulateAccountsMenu()
accountMenu->addSeparator(); accountMenu->addSeparator();
ui->profileMenu->addSeparator(); ui->profileMenu->addSeparator();
accountMenu->addAction(ui->actionManageAccounts); accountMenu->addAction(ui->actionManageAccounts);
ui->profileMenu->addAction(ui->manageAccountAct); ui->profileMenu->addAction(ui->actionManageAccounts);
} }
void MainWindow::updatesAllowedChanged(bool allowed) void MainWindow::updatesAllowedChanged(bool allowed)

View File

@ -190,8 +190,6 @@ private slots:
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
void keyReleaseEvent(QKeyEvent *event) override; void keyReleaseEvent(QKeyEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
#endif #endif
private: private: