From 2d52299743d056ae6da3c98ca9dc34abca3138bf Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 27 May 2019 12:07:10 -0400 Subject: multiple selection for noconflict and overwritten lists set uniformRowHeights for all three lists for faster rendering, all items are text only all three lists use the same code for the context menu: - createConflictMenuActions() returns a struct with the QActions that are valid for the selection - showConflictMenu() plugs in the handlers and shows the menu --- src/modinfodialog.cpp | 190 +++++++++++++++++++++----------------------------- 1 file changed, 81 insertions(+), 109 deletions(-) (limited to 'src/modinfodialog.cpp') diff --git a/src/modinfodialog.cpp b/src/modinfodialog.cpp index 19a03ea7..024679f3 100644 --- a/src/modinfodialog.cpp +++ b/src/modinfodialog.cpp @@ -1636,13 +1636,12 @@ FileRenamer::RenameResults ModInfoDialog::unhideFile(FileRenamer& renamer, const return renamer.rename(oldName, newName); } -void ModInfoDialog::changeConflictFilesVisibility(bool hide) +void ModInfoDialog::changeConflictItemsVisibility( + const QList& items, bool hide) { bool changed = false; bool stop = false; - const auto items = ui->overwriteTree->selectedItems(); - qDebug().nospace() << (hide ? "hiding" : "unhiding") << " " << items.size() << " conflict files"; @@ -1707,63 +1706,21 @@ void ModInfoDialog::changeConflictFilesVisibility(bool hide) } } -void ModInfoDialog::hideConflictFiles() -{ - changeConflictFilesVisibility(true); -} - -void ModInfoDialog::unhideConflictFiles() -{ - changeConflictFilesVisibility(false); -} - -void ModInfoDialog::previewOverwriteDataFile() -{ - // the menu item is only shown for a single selection, but check just in case - const auto selection = ui->overwriteTree->selectedItems(); - if (!selection.empty()) { - previewDataFile(selection[0]); - } -} - -void ModInfoDialog::openOverwriteDataFile() +void ModInfoDialog::openConflictItems(const QList& items) { - // the menu item is only shown for a single selection, but check just in case - const auto selection = ui->overwriteTree->selectedItems(); - if (!selection.empty()) { - openDataFile(selection[0]); + // the menu item is only shown for a single selection, but handle all of them + // in case this changes + for (auto* item : items) { + openDataFile(item); } } -void ModInfoDialog::previewOverwrittenDataFile() +void ModInfoDialog::previewConflictItems(const QList& items) { - const auto selection = ui->overwrittenTree->selectedItems(); - if (!selection.empty()) { - previewDataFile(selection[0]); - } -} - -void ModInfoDialog::openOverwrittenDataFile() -{ - const auto selection = ui->overwrittenTree->selectedItems(); - if (!selection.empty()) { - openDataFile(selection[0]); - } -} - -void ModInfoDialog::previewNoConflictDataFile() -{ - const auto selection = ui->noConflictTree->selectedItems(); - if (!selection.empty()) { - previewDataFile(selection[0]); - } -} - -void ModInfoDialog::openNoConflictDataFile() -{ - const auto selection = ui->noConflictTree->selectedItems(); - if (!selection.empty()) { - openDataFile(selection[0]); + // the menu item is only shown for a single selection, but handle all of them + // in case this changes + for (auto* item : items) { + previewDataFile(item); } } @@ -1846,17 +1803,71 @@ bool ModInfoDialog::canPreviewConflictItem(const QTreeWidgetItem* item) const void ModInfoDialog::on_overwriteTree_customContextMenuRequested(const QPoint &pos) { - const auto selection = ui->overwriteTree->selectedItems(); - if (selection.empty()) { + showConflictMenu(pos, ui->overwriteTree); +} + +void ModInfoDialog::on_overwrittenTree_customContextMenuRequested(const QPoint &pos) +{ + showConflictMenu(pos, ui->overwrittenTree); +} + +void ModInfoDialog::on_noConflictTree_customContextMenuRequested(const QPoint &pos) +{ + showConflictMenu(pos, ui->noConflictTree); +} + +void ModInfoDialog::showConflictMenu(const QPoint &pos, QTreeWidget* tree) +{ + auto actions = createConflictMenuActions(tree->selectedItems()); + + QMenu menu; + + if (actions.open) { + connect(actions.open, &QAction::triggered, [&]{ + openConflictItems(tree->selectedItems()); + }); + + menu.addAction(actions.open); + } + + if (actions.preview) { + connect(actions.preview, &QAction::triggered, [&]{ + previewConflictItems(tree->selectedItems()); + }); + + menu.addAction(actions.preview); + } + + if (actions.hide) { + connect(actions.hide, &QAction::triggered, [&]{ + changeConflictItemsVisibility(tree->selectedItems(), false); + }); + + menu.addAction(actions.hide); + } + + if (actions.unhide) { + connect(actions.unhide, &QAction::triggered, [&]{ + changeConflictItemsVisibility(tree->selectedItems(), true); + }); + + menu.addAction(actions.unhide); + } + + if (menu.isEmpty()) { return; } - // for a single selection, hide/unhide is not shown for files from - // archives and whether the action is hide or unhide depends on the current - // state - // - // for multiple selection, both actions are shown unconditionally and - // handled in hideConflictFiles() and unhideConflictFiles() + menu.exec(tree->viewport()->mapToGlobal(pos)); +} + +ModInfoDialog::ConflictActions ModInfoDialog::createConflictMenuActions( + const QList selection) +{ + if (selection.empty()) { + return {}; + } + bool enableHide = true; bool enableUnhide = true; bool enableOpen = true; @@ -1866,7 +1877,7 @@ void ModInfoDialog::on_overwriteTree_customContextMenuRequested(const QPoint &po // this is a single selection const auto* item = selection[0]; if (!item) { - return; + return {}; } enableHide = canHideConflictItem(item); @@ -1903,66 +1914,27 @@ void ModInfoDialog::on_overwriteTree_customContextMenuRequested(const QPoint &po } } - - QMenu menu; + ConflictActions actions; if (enableHide) { - menu.addAction(tr("Hide"), this, SLOT(hideConflictFiles())); + actions.hide = new QAction(tr("Hide")); } // note that it is possible for hidden files to appear if they override other // hidden files from another mod if (enableUnhide) { - menu.addAction(tr("Unhide"), this, SLOT(unhideConflictFiles())); + actions.unhide = new QAction(tr("Unhide")); } if (enableOpen) { - menu.addAction(tr("Open/Execute"), this, SLOT(openOverwriteDataFile())); + actions.open = new QAction(tr("Open/Execute")); } if (enablePreview) { - menu.addAction(tr("Preview"), this, SLOT(previewOverwriteDataFile())); + actions.preview = new QAction(tr("Preview")); } - menu.exec(ui->overwriteTree->viewport()->mapToGlobal(pos)); -} - -void ModInfoDialog::on_overwrittenTree_customContextMenuRequested(const QPoint &pos) -{ - auto* item = ui->overwrittenTree->itemAt(pos.x(), pos.y()); - - if (item != nullptr) { - if (!item->data(1, Qt::UserRole + 2).toBool()) { - QMenu menu; - - menu.addAction(tr("Open/Execute"), this, SLOT(openOverwrittenDataFile())); - - if (canPreviewConflictItem(item)) { - menu.addAction(tr("Preview"), this, SLOT(previewOverwrittenDataFile())); - } - - menu.exec(ui->overwrittenTree->viewport()->mapToGlobal(pos)); - } - } -} - -void ModInfoDialog::on_noConflictTree_customContextMenuRequested(const QPoint &pos) -{ - auto* item = ui->noConflictTree->itemAt(pos.x(), pos.y()); - - if (item != nullptr) { - if (!item->data(1, Qt::UserRole + 2).toBool()) { - QMenu menu; - - menu.addAction(tr("Open/Execute"), this, SLOT(openNoConflictDataFile())); - - if (canPreviewConflictItem(item)) { - menu.addAction(tr("Preview"), this, SLOT(previewNoConflictDataFile())); - } - - menu.exec(ui->noConflictTree->viewport()->mapToGlobal(pos)); - } - } + return actions; } void ModInfoDialog::on_overwrittenTree_itemDoubleClicked(QTreeWidgetItem *item, int) -- cgit v1.3.1