[pitivi] prefs: Move the is-changed logic to the shortcuts manager



commit 1a6620d279ca6f3167248d396b952d25fb842c50
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Thu Sep 15 16:02:46 2016 +0200

    prefs: Move the is-changed logic to the shortcuts manager
    
    Reviewed-by: Jakub Brindza <jakub brindza gmail com>
    Differential Revision: https://phabricator.freedesktop.org/D1308

 pitivi/dialogs/prefs.py |   15 +++++----------
 pitivi/shortcuts.py     |   12 ++++++++++++
 2 files changed, 17 insertions(+), 10 deletions(-)
---
diff --git a/pitivi/dialogs/prefs.py b/pitivi/dialogs/prefs.py
index e30b434..091fd7b 100644
--- a/pitivi/dialogs/prefs.py
+++ b/pitivi/dialogs/prefs.py
@@ -255,13 +255,12 @@ class PreferencesDialog(Loggable):
 
     def _create_widget_func(self, item, user_data):
         """Generates and fills up the contents for the model."""
-        defaults = self.app.shortcuts.default_accelerators
-        accel_changed = item.get_accel(formatted=False) not in defaults[item.action_name]
+        accel_changed = self.app.shortcuts.is_changed(item.action_name)
 
         title_label = Gtk.Label()
         accel_label = Gtk.Label()
         title_label.set_text(item.title)
-        accel_label.set_text(item.get_accel(formatted=True))
+        accel_label.set_text(item.get_accel())
         if not accel_changed:
             accel_label.set_state_flags(Gtk.StateFlags.INSENSITIVE, True)
         title_label.props.xalign = 0
@@ -410,19 +409,15 @@ class ModelItem(GObject.Object):
         self.action_name = action_name
         self.title = title
 
-    def get_accel(self, formatted=True):
+    def get_accel(self):
         """Returns the corresponding accelerator in a viewable format."""
         try:
             accels = self.app.get_accels_for_action(self.action_name)[0]
         except IndexError:
             accels = ""
 
-        if formatted:
-            keyval, mods = Gtk.accelerator_parse(accels)
-            accelerator = Gtk.accelerator_get_label(keyval, mods)
-            return accelerator
-        else:
-            return accels
+        keyval, mods = Gtk.accelerator_parse(accels)
+        return Gtk.accelerator_get_label(keyval, mods)
 
 
 class CustomShortcutDialog(Gtk.Dialog):
diff --git a/pitivi/shortcuts.py b/pitivi/shortcuts.py
index 2bd6fd5..31bad52 100644
--- a/pitivi/shortcuts.py
+++ b/pitivi/shortcuts.py
@@ -105,6 +105,18 @@ class ShortcutsManager(GObject.Object):
         self.app.set_accels_for_action(action, accelerators)
         self.emit("accel-changed", action)
 
+    def is_changed(self, action):
+        """Checks whether the accelerators for an action have been changed.
+
+        Args:
+            action (str): The "prefix.name" identifying the action.
+
+        Returns:
+            bool: True iff the current accelerators are not the default ones.
+        """
+        accelerators = self.app.get_accels_for_action(action)
+        return set(accelerators) != set(self.default_accelerators[action])
+
     def register_group(self, action_prefix, title):
         """Registers a group of shortcuts to be displayed.
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]