diff options
| author | Chris Bessent <lost.dragonist@gmail.com> | 2021-04-25 04:45:35 -0700 |
|---|---|---|
| committer | Chris Bessent <lost.dragonist@gmail.com> | 2021-04-25 04:45:35 -0700 |
| commit | dfbaed0ade533f5e203b16a5126090377cb4657b (patch) | |
| tree | b37d58c33fd94f759fdad70e1cf220ca51dfece6 /src | |
| parent | e475893ff45c187d89ffa6ad8f43eaee1cd61c1f (diff) | |
Add a separator after the primary game and sort the secondary games
Diffstat (limited to 'src')
| -rw-r--r-- | src/mainwindow.cpp | 57 | ||||
| -rw-r--r-- | src/mainwindow.h | 2 |
2 files changed, 33 insertions, 26 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 93f1198f..1f0788f9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1440,28 +1440,28 @@ void MainWindow::registerModPage(IPluginModPage *modPage) ui->actionModPage->menu()->addAction(action); } -void MainWindow::registerNexusPages(const QStringList& gamePluginNames) +bool MainWindow::registerNexusPage(const QString& gameName) { - for (QString gameName : gamePluginNames) { - // Get the plugin - IPluginGame* plugin = m_OrganizerCore.getGame(gameName); - if (plugin == nullptr) - continue; + // Get the plugin + IPluginGame* plugin = m_OrganizerCore.getGame(gameName); + if (plugin == nullptr) + return false; - // Create an action - QAction* action = new QAction( - plugin ? plugin->gameIcon() : QIcon(), - QObject::tr("Visit %1 on Nexus").arg(plugin ? plugin->gameName() : gameName), - this); + // Create an action + QAction* action = new QAction( + plugin->gameIcon(), + QObject::tr("Visit %1 on Nexus").arg(plugin->gameName()), + this); - // Bind the action - connect(action, &QAction::triggered, this, [this, gameName]() { - shell::Open(QUrl(NexusInterface::instance().getGameURL(gameName))); - }, Qt::QueuedConnection); + // Bind the action + connect(action, &QAction::triggered, this, [this, gameName]() { + shell::Open(QUrl(NexusInterface::instance().getGameURL(gameName))); + }, Qt::QueuedConnection); - // Add the action - ui->actionModPage->menu()->addAction(action); - } + // Add the action + ui->actionModPage->menu()->addAction(action); + + return true; } void MainWindow::updateModPageMenu() @@ -1490,16 +1490,23 @@ void MainWindow::updateModPageMenu() registerModPage(modPagePlugin); } - // Determine the applicable game plugins - QStringList gamePluginNames; - gamePluginNames.append(m_OrganizerCore.managedGame()->gameShortName()); - gamePluginNames.append(m_OrganizerCore.managedGame()->validShortNames()); + // Add the primary game (with a separator) + registerNexusPage(m_OrganizerCore.managedGame()->gameShortName()); + ui->actionModPage->menu()->addSeparator(); - // Register Nexus pages - registerNexusPages(gamePluginNames); + // Add the secondary games (sorted) + bool secondaryGameAdded = false; + QStringList secondaryGames = m_OrganizerCore.managedGame()->validShortNames(); + secondaryGames.sort(Qt::CaseInsensitive); + for (auto gameName : secondaryGames) + { + if (registerNexusPage(gameName)) { + secondaryGameAdded = true; + } + } // No mod page plugin and the menu was visible: - bool keepOriginalAction = modPagePlugins.size() == 0 && gamePluginNames.count() <= 1; + bool keepOriginalAction = modPagePlugins.size() == 0 && !secondaryGameAdded; if (keepOriginalAction) { ui->toolBar->insertAction(ui->actionAdd_Profile, ui->actionNexus); } diff --git a/src/mainwindow.h b/src/mainwindow.h index ee2446af..6626bf51 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -187,7 +187,7 @@ private: void setToolbarButtonStyle(Qt::ToolButtonStyle s); void registerModPage(MOBase::IPluginModPage* modPage); - void registerNexusPages(const QStringList& gamePluginNames); + bool registerNexusPage(const QString& gameName); void registerPluginTool(MOBase::IPluginTool* tool, QString name = QString(), QMenu* menu = nullptr); void updateToolbarMenu(); |
