summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2019-07-31 09:01:35 -0400
committerLioncash <mathew1800@gmail.com>2019-07-31 09:01:38 -0400
commit4d8d2acae70e58fe4b0b86aa59f2db7af0ef5f87 (patch)
tree67ef86b316cdeb19022f02481ac28c94019d2571 /Source
parent0d406f2bdcf2c403460dd78d9d31164d838af843 (diff)
DolphinQt/Config/ARCodeWidget: Avoid unnecessary disk operations
If a user indicates that they want to clone and edit an AR code, then click cancel on the following dialog, we shouldn't actually clone the code. We also shouldn't resave the codes if the edit dialog is opened and then closed again via cancel, as there's nothing that actually changed. This way we don't perform disk accesses unless they're actually necessary.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/DolphinQt/Config/ARCodeWidget.cpp41
1 files changed, 22 insertions, 19 deletions
diff --git a/Source/Core/DolphinQt/Config/ARCodeWidget.cpp b/Source/Core/DolphinQt/Config/ARCodeWidget.cpp
index 2c045d4fa9..4609209bc5 100644
--- a/Source/Core/DolphinQt/Config/ARCodeWidget.cpp
+++ b/Source/Core/DolphinQt/Config/ARCodeWidget.cpp
@@ -191,40 +191,43 @@ void ARCodeWidget::OnCodeAddClicked()
ar.active = true;
CheatCodeEditor ed(this);
-
ed.SetARCode(&ar);
+ if (ed.exec() == QDialog::Rejected)
+ return;
- if (ed.exec())
- {
- m_ar_codes.push_back(std::move(ar));
+ m_ar_codes.push_back(std::move(ar));
- UpdateList();
- SaveCodes();
- }
+ UpdateList();
+ SaveCodes();
}
void ARCodeWidget::OnCodeEditClicked()
{
- auto items = m_code_list->selectedItems();
-
+ const auto items = m_code_list->selectedItems();
if (items.empty())
return;
- const auto* selected = items[0];
-
+ const auto* const selected = items[0];
auto& current_ar = m_ar_codes[m_code_list->row(selected)];
- bool user_defined = current_ar.user_defined;
-
- ActionReplay::ARCode ar = current_ar;
-
CheatCodeEditor ed(this);
+ if (current_ar.user_defined)
+ {
+ ed.SetARCode(&current_ar);
- ed.SetARCode(user_defined ? &current_ar : &ar);
- ed.exec();
+ if (ed.exec() == QDialog::Rejected)
+ return;
+ }
+ else
+ {
+ ActionReplay::ARCode ar = current_ar;
+ ed.SetARCode(&ar);
+
+ if (ed.exec() == QDialog::Rejected)
+ return;
- if (!user_defined)
- m_ar_codes.push_back(ar);
+ m_ar_codes.push_back(std::move(ar));
+ }
SaveCodes();
UpdateList();