summaryrefslogtreecommitdiff
path: root/src/modinfodialog.cpp
diff options
context:
space:
mode:
authorAl <gabriel.cortesi@outlook.com>2019-05-29 14:34:24 +0200
committerGitHub <noreply@github.com>2019-05-29 14:34:24 +0200
commit41f8da011d1df7a368e3fb73f972cee1f4efd0c0 (patch)
tree0f8ca16fd068efb54a0cb20a68ddeee43db0cb71 /src/modinfodialog.cpp
parent1e3a10c8b22ac1362b1455de6f9d9f8ba739883b (diff)
parentee92fa9fc89ab047a63716c48e13d3d0a76af4fb (diff)
Merge pull request #739 from isanae/hide-conflict-items
Share context menu between conflict lists
Diffstat (limited to 'src/modinfodialog.cpp')
-rw-r--r--src/modinfodialog.cpp241
1 files changed, 108 insertions, 133 deletions
diff --git a/src/modinfodialog.cpp b/src/modinfodialog.cpp
index 19a03ea7..b6a21705 100644
--- a/src/modinfodialog.cpp
+++ b/src/modinfodialog.cpp
@@ -1326,25 +1326,27 @@ void ModInfoDialog::renameTriggered()
void ModInfoDialog::hideTriggered()
{
- changeFiletreeVisibility(true);
+ changeFiletreeVisibility(false);
}
void ModInfoDialog::unhideTriggered()
{
- changeFiletreeVisibility(false);
+ changeFiletreeVisibility(true);
}
-void ModInfoDialog::changeFiletreeVisibility(bool hide)
+void ModInfoDialog::changeFiletreeVisibility(bool visible)
{
bool changed = false;
bool stop = false;
qDebug().nospace()
- << (hide ? "hiding" : "unhiding") << " "
+ << (visible ? "unhiding" : "hiding") << " "
<< m_FileSelection.size() << " filetree files";
- QFlags<FileRenamer::RenameFlags> flags = (hide ? FileRenamer::HIDE : FileRenamer::UNHIDE);
+ QFlags<FileRenamer::RenameFlags> flags =
+ (visible ? FileRenamer::UNHIDE : FileRenamer::HIDE);
+
if (m_FileSelection.size() > 1) {
flags |= FileRenamer::MULTIPLE;
}
@@ -1359,19 +1361,18 @@ void ModInfoDialog::changeFiletreeVisibility(bool hide)
const QString path = m_FileSystemModel->filePath(index);
auto result = FileRenamer::RESULT_CANCEL;
- if (hide) {
- if (!canHideFile(false, path)) {
- qDebug().nospace() << "cannot hide " << path << ", skipping";
- continue;
- }
- result = hideFile(renamer, path);
-
- } else {
+ if (visible) {
if (!canUnhideFile(false, path)) {
qDebug().nospace() << "cannot unhide " << path << ", skipping";
continue;
}
result = unhideFile(renamer, path);
+ } else {
+ if (!canHideFile(false, path)) {
+ qDebug().nospace() << "cannot hide " << path << ", skipping";
+ continue;
+ }
+ result = hideFile(renamer, path);
}
switch (result) {
@@ -1394,7 +1395,7 @@ void ModInfoDialog::changeFiletreeVisibility(bool hide)
}
}
- qDebug().nospace() << (hide ? "hiding" : "unhiding") << " filetree files done";
+ qDebug().nospace() << (visible ? "unhiding" : "hiding") << " filetree files done";
if (changed) {
qDebug().nospace() << "triggering refresh";
@@ -1636,18 +1637,19 @@ FileRenamer::RenameResults ModInfoDialog::unhideFile(FileRenamer& renamer, const
return renamer.rename(oldName, newName);
}
-void ModInfoDialog::changeConflictFilesVisibility(bool hide)
+void ModInfoDialog::changeConflictItemsVisibility(
+ const QList<QTreeWidgetItem*>& items, bool visible)
{
bool changed = false;
bool stop = false;
- const auto items = ui->overwriteTree->selectedItems();
-
qDebug().nospace()
- << (hide ? "hiding" : "unhiding") << " "
+ << (visible ? "unhiding" : "hiding") << " "
<< items.size() << " conflict files";
- QFlags<FileRenamer::RenameFlags> flags = (hide ? FileRenamer::HIDE : FileRenamer::UNHIDE);
+ QFlags<FileRenamer::RenameFlags> flags =
+ (visible ? FileRenamer::UNHIDE : FileRenamer::HIDE);
+
if (items.size() > 1) {
flags |= FileRenamer::MULTIPLE;
}
@@ -1661,19 +1663,19 @@ void ModInfoDialog::changeConflictFilesVisibility(bool hide)
auto result = FileRenamer::RESULT_CANCEL;
- if (hide) {
- if (!canHideConflictItem(item)) {
- qDebug().nospace() << "cannot hide " << item->text(0) << ", skipping";
+ if (visible) {
+ if (!canUnhideConflictItem(item)) {
+ qDebug().nospace() << "cannot unhide " << item->text(0) << ", skipping";
continue;
}
- result = hideFile(renamer, item->data(0, Qt::UserRole).toString());
+ result = unhideFile(renamer, item->data(0, Qt::UserRole).toString());
} else {
- if (!canUnhideConflictItem(item)) {
- qDebug().nospace() << "cannot unhide " << item->text(0) << ", skipping";
+ if (!canHideConflictItem(item)) {
+ qDebug().nospace() << "cannot hide " << item->text(0) << ", skipping";
continue;
}
- result = unhideFile(renamer, item->data(0, Qt::UserRole).toString());
+ result = hideFile(renamer, item->data(0, Qt::UserRole).toString());
}
switch (result) {
@@ -1696,7 +1698,7 @@ void ModInfoDialog::changeConflictFilesVisibility(bool hide)
}
}
- qDebug().nospace() << (hide ? "hiding" : "unhiding") << " conflict files done";
+ qDebug().nospace() << (visible ? "unhiding" : "hiding") << " conflict files done";
if (changed) {
qDebug().nospace() << "triggering refresh";
@@ -1707,63 +1709,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<QTreeWidgetItem*>& 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<QTreeWidgetItem*>& 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 +1806,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<QTreeWidgetItem*> selection)
+{
+ if (selection.empty()) {
+ return {};
+ }
+
bool enableHide = true;
bool enableUnhide = true;
bool enableOpen = true;
@@ -1866,7 +1880,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 +1917,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)