From 8a789d303b22a7ac0d0a2b179b2500478eb29a46 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Fri, 1 Jan 2021 18:00:41 +0100 Subject: Remove duplicated code. --- src/modlistcontextmenu.cpp | 58 ++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) (limited to 'src/modlistcontextmenu.cpp') 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(); } -- cgit v1.3.1