Commit 8b3a691a authored by HarishFulara07's avatar HarishFulara07
Browse files

shortcuts: Make newly added shortcuts available

Closes #2211
parent 455114f0
Pipeline #16545 passed with stage
in 47 minutes and 47 seconds
......@@ -43,7 +43,7 @@ class ShortcutsManager(GObject.Object): # pylint: disable=too-many-instance-att
self.titles = {}
self.config_path = os.path.sep.join([xdg_config_home(),
self.__loaded = self.__load()
self.__loaded_actions = list(self.__load())
def groups(self):
......@@ -53,17 +53,17 @@ class ShortcutsManager(GObject.Object): # pylint: disable=too-many-instance-att
def __load(self):
"""Loads the shortcuts from the config file and sets them.
bool: Whether the config file exists.
string: The shortcuts loaded from the config file.
if not os.path.isfile(self.config_path):
return False
for line in open(self.config_path, "r"):
action_name, accelerators = line.split(":", 1)
accelerators = accelerators.strip("\n").split(","), accelerators)
return True
yield action_name
def save(self):
"""Saves the accelerators for each action to the config file.
......@@ -92,7 +92,7 @@ class ShortcutsManager(GObject.Object): # pylint: disable=too-many-instance-att
self.default_accelerators[action] = accelerators
self.titles[action] = title
if not self.__loaded:
if action not in self.__loaded_actions:, accelerators)
if title:
......@@ -163,6 +163,7 @@ class ShortcutsManager(GObject.Object): # pylint: disable=too-many-instance-att
self.__groups.append((position, action_prefix))
# pylint: disable=redefined-argument-from-local
def reset_accels(self, action=None):
"""Resets accelerators to their default values.
......@@ -17,7 +17,6 @@
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
"""Test the keyboard shortcuts."""
import os
import tempfile
from unittest import mock
......@@ -71,17 +70,21 @@ class TestShortcutsManager(common.TestCase):
manager.register_group("general", "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.
# Create the temporary shortcuts.conf file
# and test that add is not calling set_accels_for_action()
open(os.path.sep.join([temp_dir, "shortcuts.conf"]), "w").close()
manager2 = ShortcutsManager(app)
# 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("other", "Other group", position=0)
manager2.add("prefix.action4", ["<Primary>W"],
"Action addition not invoking set_accels_for_action")
# No. of calls to set_accels_for_action should be unchanged now
# because calling set_accels_for_action isn't allowed with .conf existing
manager2.add("prefix.action1", ["<Primary>P"], "Action one")
# Above shortcut has been already loaded from the config file
# and hence 'set_accels_for_action' is not called.
self.assertEqual(app.set_accels_for_action.call_count, 0)
manager2.add("prefix.action2", ["<Primary>W"], "Action two")
self.assertEqual(app.set_accels_for_action.call_count, 1)
def test_load_save(self):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment