summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2021-01-01 18:00:41 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-02 15:38:19 +0100
commit8a789d303b22a7ac0d0a2b179b2500478eb29a46 (patch)
tree2ca5e1854b3624040d56715fc47a5a79369e7c4f
parent011e4d522ed7b0df52cdeb014608e9881f8bc76b (diff)
Remove duplicated code.
-rw-r--r--src/modlistcontextmenu.cpp58
-rw-r--r--src/modlistcontextmenu.h8
2 files changed, 29 insertions, 37 deletions
diff --git a/src/modlistcontextmenu.cpp b/src/modlistcontextmenu.cpp
index 19b5fba4..e557d7a0 100644
--- a/src/modlistcontextmenu.cpp
+++ b/src/modlistcontextmenu.cpp
@@ -221,7 +221,7 @@ void ModListContextMenu::addMenuAsPushButton(QMenu* menu)
addAction(action);
}
-QMenu* ModListContextMenu::createSendToContextMenu()
+void ModListContextMenu::addSendToContextMenu()
{
QMenu* menu = new QMenu(m_view);
menu->setTitle(tr("Send to... "));
@@ -229,25 +229,11 @@ QMenu* ModListContextMenu::createSendToContextMenu()
menu->addAction(tr("Bottom"), [=]() { m_actions.sendModsToBottom(m_selected); });
menu->addAction(tr("Priority..."), [=]() { m_actions.sendModsToPriority(m_selected); });
menu->addAction(tr("Separator..."), [=]() { m_actions.sendModsToSeparator(m_selected); });
- return menu;
+ addMenu(menu);
}
-void ModListContextMenu::addOverwriteActions(ModInfo::Ptr mod)
-{
- if (QDir(mod->absolutePath()).count() > 2) {
- addAction(tr("Sync to Mods..."), [=]() { m_core.syncOverwrite(); });
- addAction(tr("Create Mod..."), [=]() { m_actions.createModFromOverwrite(); });
- addAction(tr("Move content to Mod..."), [=]() { m_actions.moveOverwriteContentToExistingMod(); });
- addAction(tr("Clear Overwrite..."), [=]() { m_actions.clearOverwrite(); });
- }
- addAction(tr("Open in Explorer"), [=]() { m_actions.openExplorer(m_selected); });
-}
-
-void ModListContextMenu::addSeparatorActions(ModInfo::Ptr mod)
+void ModListContextMenu::addCategoryContextMenus(ModInfo::Ptr mod)
{
- addSeparator();
-
- // categories
ModListChangeCategoryMenu* categoriesMenu = new ModListChangeCategoryMenu(m_categories, mod, this);
connect(categoriesMenu, &QMenu::aboutToHide, [=]() {
m_actions.setCategories(m_selected, m_index, categoriesMenu->categories());
@@ -262,6 +248,22 @@ void ModListContextMenu::addSeparatorActions(ModInfo::Ptr mod)
}
});
addMenuAsPushButton(primaryCategoryMenu);
+}
+
+void ModListContextMenu::addOverwriteActions(ModInfo::Ptr mod)
+{
+ if (QDir(mod->absolutePath()).count() > 2) {
+ addAction(tr("Sync to Mods..."), [=]() { m_core.syncOverwrite(); });
+ addAction(tr("Create Mod..."), [=]() { m_actions.createModFromOverwrite(); });
+ addAction(tr("Move content to Mod..."), [=]() { m_actions.moveOverwriteContentToExistingMod(); });
+ addAction(tr("Clear Overwrite..."), [=]() { m_actions.clearOverwrite(); });
+ }
+ addAction(tr("Open in Explorer"), [=]() { m_actions.openExplorer(m_selected); });
+}
+
+void ModListContextMenu::addSeparatorActions(ModInfo::Ptr mod)
+{
+ addCategoryContextMenus(mod);
addSeparator();
@@ -270,7 +272,7 @@ void ModListContextMenu::addSeparatorActions(ModInfo::Ptr mod)
addSeparator();
if (m_view->sortColumn() == ModList::COL_PRIORITY) {
- addMenu(createSendToContextMenu());
+ addSendToContextMenu();
addSeparator();
}
addAction(tr("Select Color..."), [=]() { m_actions.setColor(m_selected, m_index); });
@@ -285,7 +287,7 @@ void ModListContextMenu::addSeparatorActions(ModInfo::Ptr mod)
void ModListContextMenu::addForeignActions(ModInfo::Ptr mod)
{
if (m_view->sortColumn() == ModList::COL_PRIORITY) {
- addMenu(createSendToContextMenu());
+ addSendToContextMenu();
}
}
@@ -318,21 +320,7 @@ void ModListContextMenu::addRegularActions(ModInfo::Ptr mod)
{
auto flags = mod->getFlags();
- // categories
- ModListChangeCategoryMenu* categoriesMenu = new ModListChangeCategoryMenu(m_categories, mod, this);
- connect(categoriesMenu, &QMenu::aboutToHide, [=]() {
- m_actions.setCategories(m_selected, m_index, categoriesMenu->categories());
- });
- addMenuAsPushButton(categoriesMenu);
-
- ModListPrimaryCategoryMenu* primaryCategoryMenu = new ModListPrimaryCategoryMenu(m_categories, mod, this);
- connect(primaryCategoryMenu, &QMenu::aboutToHide, [=]() {
- int category = primaryCategoryMenu->primaryCategory();
- if (category != -1) {
- m_actions.setPrimaryCategory(m_selected, category);
- }
- });
- addMenuAsPushButton(primaryCategoryMenu);
+ addCategoryContextMenus(mod);
addSeparator();
if (mod->downgradeAvailable()) {
@@ -358,7 +346,7 @@ void ModListContextMenu::addRegularActions(ModInfo::Ptr mod)
if (m_view->sortColumn() == ModList::COL_PRIORITY) {
- addMenu(createSendToContextMenu());
+ addSendToContextMenu();
addSeparator();
}
diff --git a/src/modlistcontextmenu.h b/src/modlistcontextmenu.h
index aa9d4c2b..565aac97 100644
--- a/src/modlistcontextmenu.h
+++ b/src/modlistcontextmenu.h
@@ -80,9 +80,13 @@ public:
private:
- // create the "Send to... " context menu
+ // adds the "Send to... " context menu
//
- QMenu* createSendToContextMenu();
+ void addSendToContextMenu();
+
+ // adds the categories menu (change/primary)
+ //
+ void addCategoryContextMenus(ModInfo::Ptr mod);
// special menu for categories
//