Skip to content

Commit

Permalink
Merge pull request #147 from cristian64/destruction_confirmation
Browse files Browse the repository at this point in the history
Prompt user before destructive operations of great impact.
  • Loading branch information
dreamsyntax authored May 19, 2024
2 parents dc50134 + 301b755 commit 31d2a0e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Source/GUI/MemWatcher/MemWatchModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void MemWatchModel::clearRoot()
endResetModel();
}

void MemWatchModel::removeNode(const QModelIndex& index)
void MemWatchModel::deleteNode(const QModelIndex& index)
{
if (index.isValid())
{
Expand Down
5 changes: 3 additions & 2 deletions Source/GUI/MemWatcher/MemWatchModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ class MemWatchModel : public QAbstractItemModel

void changeType(const QModelIndex& index, Common::MemType type, size_t length);
static MemWatchEntry* getEntryFromIndex(const QModelIndex& index);
void addNodes(const std::vector<MemWatchTreeNode*>& nodes, const QModelIndex& referenceIndex = QModelIndex{});
void addNodes(const std::vector<MemWatchTreeNode*>& nodes,
const QModelIndex& referenceIndex = QModelIndex{});
void addGroup(const QString& name, const QModelIndex& referenceIndex = QModelIndex{});
void addEntry(MemWatchEntry* entry, const QModelIndex& referenceIndex = QModelIndex{});
void editEntry(MemWatchEntry* entry, const QModelIndex& index);
void clearRoot();
void removeNode(const QModelIndex& index);
void deleteNode(const QModelIndex& index);
void onUpdateTimer();
void onFreezeTimer();
void loadRootFromJsonRecursive(const QJsonObject& json);
Expand Down
14 changes: 10 additions & 4 deletions Source/GUI/MemWatcher/MemWatchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ void MemWatchWidget::cutSelectedWatchesToClipBoard()
if (!cutList.empty())
{
for (const auto& index : cutList)
m_watchModel->removeNode(index);
{
m_watchModel->deleteNode(index);
}

m_hasUnsavedChanges = true;
}
Expand Down Expand Up @@ -585,14 +587,14 @@ void MemWatchWidget::onDeleteSelection()

QMessageBox* confirmationBox =
new QMessageBox(QMessageBox::Question, QString("Deleting confirmation"), confirmationMsg,
QMessageBox::Yes | QMessageBox::No, this);
QMessageBox::Yes | QMessageBox::Cancel, this);
confirmationBox->setDefaultButton(QMessageBox::Yes);
if (confirmationBox->exec() == QMessageBox::Yes)
{
const QModelIndexList toDeleteList{simplifySelection()};
for (const auto& index : toDeleteList)
{
m_watchModel->removeNode(index);
m_watchModel->deleteNode(index);
}

m_hasUnsavedChanges = true;
Expand Down Expand Up @@ -732,7 +734,11 @@ void MemWatchWidget::clearWatchList()
if (!m_watchModel->hasAnyNodes())
return;

if (!warnIfUnsavedChanges())
const QString msg{tr("Are you sure you want to delete these watches and/or groups?")};
QMessageBox box(QMessageBox::Question, tr("Clear watch list confirmation"), msg,
QMessageBox::Yes | QMessageBox::Cancel, this);
box.setDefaultButton(QMessageBox::Yes);
if (box.exec() != QMessageBox::Yes)
return;

m_watchModel->clearRoot();
Expand Down

0 comments on commit 31d2a0e

Please sign in to comment.