From 1b4c07eb20a8951ac72accf8ead302d65c8a2de5 Mon Sep 17 00:00:00 2001 From: TheBloke Date: Fri, 11 Jul 2014 01:46:42 +0100 Subject: - savegameList: Improved save game handling from MainWindow -- Save game deletion now does Recycle Bin delete (wishlist #675) -- Save game deletion now also deletes .skse file (bug #687) -- Can select and delete multiple save games (ExtendedSelection) (wishlist #675) -- Uses new SaveGame->saveFiles() method to get filenames (eg .ess & .skse) -- Context menu - "Fix Mods.." option only appears if 1 save is selected -- Context menu - delete menu option labelled "Delete save" or "Delete saves", according to 1 or >1 saves selected. -- Context menu - delete menu confirmation shows list of all selected saves --- src/mainwindow.cpp | 58 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 17 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9cbe9c40..344173d4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3884,26 +3884,42 @@ void MainWindow::on_categoriesList_itemSelectionChanged() void MainWindow::deleteSavegame_clicked() { - QListWidgetItem *selectedItem = ui->savegameList->item(m_SelectedSaveGame); - if (selectedItem == NULL) { + QItemSelectionModel *selection = ui->savegameList->selectionModel(); + + if (!selection->hasSelection()) return; - } - QString fileName = selectedItem->data(Qt::UserRole).toString(); + int selectedCount = selection->selectedRows().count(); + QString savesMsgLabel; + QRegExp saveSuffix(".ess$"); + QStringList deleteFiles; + + foreach (QModelIndex idx, selection->selectedRows()) { + QString name = idx.data().toString(); + QString filename = idx.data(Qt::UserRole).toString(); + + SaveGame *save = new SaveGame(this, filename); + savesMsgLabel += "
  • " + name.replace(saveSuffix, "") + "
  • "; + deleteFiles << save->saveFiles(); + } - if (QMessageBox::question(this, tr("Confirm"), tr("Really delete \"%1\"?").arg(selectedItem->text()), + if (QMessageBox::question(this, tr("Confirm"), tr("Are you sure you want to remove the following save%1?

    Removed saves will be sent to the Recycle Bin.") + .arg((selectedCount > 1) ? "s" : "") + .arg(savesMsgLabel), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { - shellDelete(QStringList() << fileName); + shellDelete(deleteFiles, true); // recycle bin delete. } } void MainWindow::fixMods_clicked() { - QListWidgetItem *selectedItem = ui->savegameList->item(m_SelectedSaveGame); - if (selectedItem == NULL) { - return; - } + QItemSelectionModel *selection = ui->savegameList->selectionModel(); + + if (!selection->hasSelection() || selection->selectedRows().count() > 1) + return; // Count should never be > 1 because of condition on context menu; check again just for safety. + + QListWidgetItem *selectedItem = ui->savegameList->item(selection->selectedRows().first().row()); // if required, parse the save game if (selectedItem->data(Qt::UserRole).isNull()) { @@ -3994,16 +4010,24 @@ void MainWindow::fixMods_clicked() void MainWindow::on_savegameList_customContextMenuRequested(const QPoint &pos) { - QListWidgetItem *selectedItem = ui->savegameList->itemAt(pos); - if (selectedItem == NULL) { - return; - } + QItemSelection currentSelection = ui->savegameList->selectionModel()->selection(); + + bool enableFixMods = false; + int selectedCount = currentSelection.count(); - m_SelectedSaveGame = ui->savegameList->row(selectedItem); + if ( selectedCount == 0) { + return; + } else if (currentSelection.count() == 1) + enableFixMods = true; QMenu menu; - menu.addAction(tr("Fix Mods..."), this, SLOT(fixMods_clicked())); - menu.addAction(tr("Delete"), this, SLOT(deleteSavegame_clicked())); + + if (enableFixMods) + menu.addAction(tr("Fix Mods..."), this, SLOT(fixMods_clicked())); + + QString deleteMenuLabel = tr("Delete save%1").arg((selectedCount > 1) ? "s" : ""); + + menu.addAction(deleteMenuLabel, this, SLOT(deleteSavegame_clicked())); menu.exec(ui->savegameList->mapToGlobal(pos)); } -- cgit v1.3.1 From 7944bacfd9b7d74d1d45c8bea405a9daf0564002 Mon Sep 17 00:00:00 2001 From: TheBloke Date: Sat, 12 Jul 2014 11:15:34 +0100 Subject: savegameList: A few cleanups and minor code improvements - Slight improvements over previous commits, using more appropriate methods and removing some unnecessary code. No functional changes. --- src/mainwindow.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 344173d4..fc0f8aa1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3889,22 +3889,23 @@ void MainWindow::deleteSavegame_clicked() if (!selection->hasSelection()) return; - int selectedCount = selection->selectedRows().count(); QString savesMsgLabel; QRegExp saveSuffix(".ess$"); QStringList deleteFiles; - foreach (QModelIndex idx, selection->selectedRows()) { + foreach (QModelIndex idx, selection->selectedIndexes()) { QString name = idx.data().toString(); - QString filename = idx.data(Qt::UserRole).toString(); + SaveGame *save = new SaveGame(this, idx.data(Qt::UserRole).toString()); - SaveGame *save = new SaveGame(this, filename); savesMsgLabel += "
  • " + name.replace(saveSuffix, "") + "
  • "; + deleteFiles << save->saveFiles(); } + bool multipleRows = (selection->selectedIndexes().count() > 1); + if (QMessageBox::question(this, tr("Confirm"), tr("Are you sure you want to remove the following save%1?

    Removed saves will be sent to the Recycle Bin.") - .arg((selectedCount > 1) ? "s" : "") + .arg((multipleRows) ? "s" : "") .arg(savesMsgLabel), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { shellDelete(deleteFiles, true); // recycle bin delete. @@ -3914,12 +3915,10 @@ void MainWindow::deleteSavegame_clicked() void MainWindow::fixMods_clicked() { - QItemSelectionModel *selection = ui->savegameList->selectionModel(); + QListWidgetItem *selectedItem = ui->savegameList->currentItem(); - if (!selection->hasSelection() || selection->selectedRows().count() > 1) - return; // Count should never be > 1 because of condition on context menu; check again just for safety. - - QListWidgetItem *selectedItem = ui->savegameList->item(selection->selectedRows().first().row()); + if (selectedItem == NULL) + return; // if required, parse the save game if (selectedItem->data(Qt::UserRole).isNull()) { @@ -4017,7 +4016,7 @@ void MainWindow::on_savegameList_customContextMenuRequested(const QPoint &pos) if ( selectedCount == 0) { return; - } else if (currentSelection.count() == 1) + } else if (selectedCount == 1) enableFixMods = true; QMenu menu; -- cgit v1.3.1 From 9b67e338e10e438112ad6ed03ec39dd1438758e3 Mon Sep 17 00:00:00 2001 From: TheBloke Date: Sun, 13 Jul 2014 15:24:46 +0100 Subject: savegameList: - Context menu bugfix, previous method of getting rows didn't work when items were selected in certain ways, e.g. Control-A - Context menu now uses selectedIndexes(), which always works with all selections. - Renamed enableFixMods to multipleSelected so same value can be used to decide whether to show single or plural version of "Delete save(s)" --- src/mainwindow.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fc0f8aa1..1baf60d4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3884,16 +3884,13 @@ void MainWindow::on_categoriesList_itemSelectionChanged() void MainWindow::deleteSavegame_clicked() { - QItemSelectionModel *selection = ui->savegameList->selectionModel(); - - if (!selection->hasSelection()) - return; + QModelIndexList selectedIndexes = ui->savegameList->selectionModel()->selectedIndexes(); QString savesMsgLabel; QRegExp saveSuffix(".ess$"); QStringList deleteFiles; - foreach (QModelIndex idx, selection->selectedIndexes()) { + foreach (QModelIndex idx, selectedIndexes) { QString name = idx.data().toString(); SaveGame *save = new SaveGame(this, idx.data(Qt::UserRole).toString()); @@ -3902,7 +3899,7 @@ void MainWindow::deleteSavegame_clicked() deleteFiles << save->saveFiles(); } - bool multipleRows = (selection->selectedIndexes().count() > 1); + bool multipleRows = (selectedIndexes.count() > 1); if (QMessageBox::question(this, tr("Confirm"), tr("Are you sure you want to remove the following save%1?
      %2

    Removed saves will be sent to the Recycle Bin.") .arg((multipleRows) ? "s" : "") @@ -4009,22 +4006,23 @@ void MainWindow::fixMods_clicked() void MainWindow::on_savegameList_customContextMenuRequested(const QPoint &pos) { - QItemSelection currentSelection = ui->savegameList->selectionModel()->selection(); + QItemSelectionModel *selection = ui->savegameList->selectionModel(); + QModelIndexList selectedIndexes = selection->selectedIndexes(); - bool enableFixMods = false; - int selectedCount = currentSelection.count(); + bool multipleSelected = false; + int selectedCount = selectedIndexes.count(); - if ( selectedCount == 0) { + if ( !selection->hasSelection()) { return; - } else if (selectedCount == 1) - enableFixMods = true; + } else if (selectedCount > 1) + multipleSelected = true; QMenu menu; - if (enableFixMods) + if (!multipleSelected) menu.addAction(tr("Fix Mods..."), this, SLOT(fixMods_clicked())); - QString deleteMenuLabel = tr("Delete save%1").arg((selectedCount > 1) ? "s" : ""); + QString deleteMenuLabel = tr("Delete save%1").arg((multipleSelected) ? "s" : ""); menu.addAction(deleteMenuLabel, this, SLOT(deleteSavegame_clicked())); -- cgit v1.3.1 From f59f52501c1f4bf160075dc4439f5af883f730e1 Mon Sep 17 00:00:00 2001 From: TheBloke Date: Sun, 13 Jul 2014 15:45:19 +0100 Subject: savegameList: more minor changes - Context Menu - can do same job with fewer variables and assignments - deleteSaveGame_clicked - const reference, not new value, in foreach loop --- src/mainwindow.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1baf60d4..aed95616 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3890,7 +3890,7 @@ void MainWindow::deleteSavegame_clicked() QRegExp saveSuffix(".ess$"); QStringList deleteFiles; - foreach (QModelIndex idx, selectedIndexes) { + foreach (const QModelIndex &idx, selectedIndexes) { QString name = idx.data().toString(); SaveGame *save = new SaveGame(this, idx.data(Qt::UserRole).toString()); @@ -4007,15 +4007,11 @@ void MainWindow::fixMods_clicked() void MainWindow::on_savegameList_customContextMenuRequested(const QPoint &pos) { QItemSelectionModel *selection = ui->savegameList->selectionModel(); - QModelIndexList selectedIndexes = selection->selectedIndexes(); - bool multipleSelected = false; - int selectedCount = selectedIndexes.count(); - - if ( !selection->hasSelection()) { + if (!selection->hasSelection()) return; - } else if (selectedCount > 1) - multipleSelected = true; + + bool multipleSelected = (selection->selectedIndexes().count() > 1); QMenu menu; -- cgit v1.3.1 From bfb3385e4932530928cff5a94ad56d8f30e5babe Mon Sep 17 00:00:00 2001 From: TheBloke Date: Sun, 13 Jul 2014 16:11:30 +0100 Subject: deleteSavegame: - Confirmation question shows number of saves to be deleted, when more than 1 --- src/mainwindow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index aed95616..d6cef2dc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3901,7 +3901,8 @@ void MainWindow::deleteSavegame_clicked() bool multipleRows = (selectedIndexes.count() > 1); - if (QMessageBox::question(this, tr("Confirm"), tr("Are you sure you want to remove the following save%1?
      %2

    Removed saves will be sent to the Recycle Bin.") + if (QMessageBox::question(this, tr("Confirm"), tr("Are you sure you want to remove the following %1save%2?
      %3

    Removed saves will be sent to the Recycle Bin.") + .arg((multipleRows) ? QString::number(selectedIndexes.count()) + " " : "") .arg((multipleRows) ? "s" : "") .arg(savesMsgLabel), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { -- cgit v1.3.1