[pitivi] clipproperties: Hide the obvious Delete keyboard shortcut



commit 29abee1fee1639b74aab0ea2582c8c1b6272750a
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Wed Feb 19 15:29:00 2020 +0100

    clipproperties: Hide the obvious Delete keyboard shortcut
    
    Also fixed the support for hidden actions.

 pitivi/clipproperties.py |  4 +---
 pitivi/shortcuts.py      | 18 ++++++++++--------
 tests/test_shortcuts.py  |  3 ++-
 3 files changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/pitivi/clipproperties.py b/pitivi/clipproperties.py
index c7b5fcb8..38e0cbc6 100644
--- a/pitivi/clipproperties.py
+++ b/pitivi/clipproperties.py
@@ -239,13 +239,11 @@ class EffectProperties(Gtk.Expander, Loggable):
         effects_actions_group = Gio.SimpleActionGroup()
         self.treeview.insert_action_group("clipproperties-effects", effects_actions_group)
         buttons_box.insert_action_group("clipproperties-effects", effects_actions_group)
-        self.app.shortcuts.register_group("clipproperties-effects", _("Clip Effects"), position=60)
 
         self.remove_effect_action = Gio.SimpleAction.new("remove-effect", None)
         self.remove_effect_action.connect("activate", self._remove_effect_cb)
         effects_actions_group.add_action(self.remove_effect_action)
-        self.app.shortcuts.add("clipproperties-effects.remove-effect", ["Delete"],
-                               _("Remove the selected effect"))
+        self.app.set_accels_for_action("clipproperties-effects.remove-effect", ["Delete"])
         self.remove_effect_action.set_enabled(False)
         remove_effect_button.set_action_name("clipproperties-effects.remove-effect")
 
diff --git a/pitivi/shortcuts.py b/pitivi/shortcuts.py
index 454de6ed..34482e91 100644
--- a/pitivi/shortcuts.py
+++ b/pitivi/shortcuts.py
@@ -73,7 +73,7 @@ class ShortcutsManager(GObject.Object):
                     accels = ",".join(self.app.get_accels_for_action(action))
                     conf_file.write(action + ":" + accels + "\n")
 
-    def add(self, action, accelerators, title=None, group=None):
+    def add(self, action, accelerators, title, group=None):
         """Adds an action to be displayed.
 
         Args:
@@ -83,7 +83,7 @@ class ShortcutsManager(GObject.Object):
                 the action. They are set as the accelerators of the action
                 only if no accelerators have been loaded from the config file
                 initially, when the current manager instance has been created.
-            title (Optional(str)): The title of the action.
+            title (str): The title of the action.
             group (Optional[str]): The group id registered with `register_group`
                 to be used instead of that extracted from `action`.
         """
@@ -92,11 +92,8 @@ class ShortcutsManager(GObject.Object):
         if action not in self.__loaded_actions:
             self.app.set_accels_for_action(action, accelerators)
 
-        if title:
-            action_prefix = group or action.split(".")[0]
-            if action_prefix not in self.group_actions:
-                self.group_actions[action_prefix] = []
-            self.group_actions[action_prefix].append((action, title))
+        action_prefix = group or action.split(".")[0]
+        self.group_actions[action_prefix].append((action, title))
 
     def set(self, action, accelerators):
         """Sets accelerators for a shortcut.
@@ -157,6 +154,7 @@ class ShortcutsManager(GObject.Object):
         """
         assert action_prefix not in self.group_titles
         self.group_titles[action_prefix] = title
+        self.group_actions[action_prefix] = []
         self.__groups.append((position, action_prefix))
         self.__groups.sort()
 
@@ -198,9 +196,13 @@ class ShortcutsWindow(Gtk.ShortcutsWindow):
         section = Gtk.ShortcutsSection()
         section.show()
         for group_id in self.app.shortcuts.groups:
+            actions = self.app.shortcuts.group_actions.get(group_id)
+            if not actions:
+                continue
+
             group = Gtk.ShortcutsGroup(title=self.app.shortcuts.group_titles[group_id])
             group.show()
-            for action, title in self.app.shortcuts.group_actions[group_id]:
+            for action, title in actions:
                 # Show only the first accelerator which is the main one.
                 # Don't bother with the others, to keep the dialog pretty.
                 try:
diff --git a/tests/test_shortcuts.py b/tests/test_shortcuts.py
index f6d6d9da..4bfdbed9 100644
--- a/tests/test_shortcuts.py
+++ b/tests/test_shortcuts.py
@@ -65,7 +65,7 @@ class TestShortcutsManager(common.TestCase):
             manager = ShortcutsManager(app)
             # Test the add is calling set_accels_for_action(),
             # since there is no shortcuts.conf in the directory.
-            manager.register_group("general", "General group", position=0)
+            manager.register_group("prefix", "General group", position=0)
             manager.add("prefix.action1", ["<Primary>P"], "Action one")
             self.assertEqual(app.set_accels_for_action.call_count, 1)
             # Save the shortcut to the config file.
@@ -76,6 +76,7 @@ class TestShortcutsManager(common.TestCase):
             # Previously saved shortcut is read from the config file
             # and 'set_accels_for_action' is called.
             self.assertEqual(app.set_accels_for_action.call_count, 1)
+            manager2.register_group("prefix", "General group", position=0)
             manager2.register_group("other", "Other group", position=0)
             app.set_accels_for_action.reset_mock()
             manager2.add("prefix.action1", ["<Primary>P"], "Action one")


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