summaryrefslogtreecommitdiff
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
authorChris Bessent <lost.dragonist@gmail.com>2021-04-29 01:57:13 -0700
committerGitHub <noreply@github.com>2021-04-29 01:57:13 -0700
commit1197b562f6c044ace8c78739780cb5829df50c10 (patch)
tree5c60a5bb694804995545f1ddce68f96a7758cc16 /src/mainwindow.cpp
parent7df5329ea09569ef49cd48678e361c54be993de1 (diff)
parentdfbaed0ade533f5e203b16a5126090377cb4657b (diff)
Merge pull request #1496 from LostDragonist/nexus_links
Change the "Visit Nexus" button to support alternate sources
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index e998dd56..78efa182 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1440,12 +1440,36 @@ void MainWindow::registerModPage(IPluginModPage *modPage)
ui->actionModPage->menu()->addAction(action);
}
+bool MainWindow::registerNexusPage(const QString& gameName)
+{
+ // Get the plugin
+ IPluginGame* plugin = m_OrganizerCore.getGame(gameName);
+ if (plugin == nullptr)
+ return false;
+
+ // 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);
+
+ // Add the action
+ ui->actionModPage->menu()->addAction(action);
+
+ return true;
+}
+
void MainWindow::updateModPageMenu()
{
// Clear the menu:
ui->actionModPage->menu()->clear();
- ui->actionModPage->menu()->addAction(ui->actionNexus);
+ // Determine the loaded mod page plugins
std::vector<IPluginModPage*> modPagePlugins = m_PluginContainer.plugins<IPluginModPage>();
// Sort the plugins by display name
@@ -1466,14 +1490,30 @@ void MainWindow::updateModPageMenu()
registerModPage(modPagePlugin);
}
+ // Add the primary game (with a separator)
+ registerNexusPage(m_OrganizerCore.managedGame()->gameShortName());
+ ui->actionModPage->menu()->addSeparator();
+
+ // 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:
- if (modPagePlugins.empty()) {
+ bool keepOriginalAction = modPagePlugins.size() == 0 && !secondaryGameAdded;
+ if (keepOriginalAction) {
ui->toolBar->insertAction(ui->actionAdd_Profile, ui->actionNexus);
}
else {
ui->toolBar->removeAction(ui->actionNexus);
}
- ui->actionModPage->setVisible(!modPagePlugins.empty());
+ ui->actionModPage->setVisible(!keepOriginalAction);
}
void MainWindow::startExeAction()