1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
From: Weng Xuetian <wengxt@gmail.com>
Date: Sun, 18 Mar 2018 11:22:50 -0700
Subject: If insertion is failed, do not change the model.
---
gui/shortcutmodel.cpp | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/gui/shortcutmodel.cpp b/gui/shortcutmodel.cpp
index 22f2710..52fc745 100644
--- a/gui/shortcutmodel.cpp
+++ b/gui/shortcutmodel.cpp
@@ -166,20 +166,18 @@ bool ShortcutModel::add(const ShortcutEntry& entry)
{
KkcKeymap* map = kkc_rule_get_keymap(KKC_RULE(m_userRule), entry.mode());
bool result = true;
- do {
- if (kkc_keymap_lookup_key(map, entry.event())) {
- result = false;
- }
+ if (kkc_keymap_lookup_key(map, entry.event())) {
+ result = false;
+ }
+
+ if (result) {
beginInsertRows(QModelIndex(), m_entries.size(), m_entries.size());
m_entries << entry;
kkc_keymap_set(map, entry.event(), entry.command().toUtf8().constData());
endInsertRows();
- } while(0);
- g_object_unref(map);
-
- if (result) {
setNeedSave(true);
}
+ g_object_unref(map);
return result;
}
|