Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
c6561cec
by lovetox at 2021-12-10T22:46:48+01:00
4 changed files:
- gajim/application.py
- gajim/common/configpaths.py
- gajim/common/helpers.py
- + gajim/data/other/shortcuts.json
Changes:
| ... | ... | @@ -55,6 +55,7 @@ |
| 55 | 55 |
from gajim.common.storage.archive import MessageArchiveStorage
|
| 56 | 56 |
from gajim.common.settings import Settings
|
| 57 | 57 |
from gajim.common.settings import LegacyConfig
|
| 58 |
+from gajim.common.helpers import load_json
|
|
| 58 | 59 |
|
| 59 | 60 |
|
| 60 | 61 |
class GajimApplication(Gtk.Application):
|
| ... | ... | @@ -209,7 +210,7 @@ def _startup(self, _application): |
| 209 | 210 |
self.interface = Interface()
|
| 210 | 211 |
self.interface.run(self)
|
| 211 | 212 |
self.add_actions()
|
| 212 |
- self._set_shortcuts()
|
|
| 213 |
+ self._load_shortcuts()
|
|
| 213 | 214 |
from gajim import gui_menu_builder
|
| 214 | 215 |
gui_menu_builder.build_accounts_menu()
|
| 215 | 216 |
self.update_app_actions_state()
|
| ... | ... | @@ -470,41 +471,18 @@ def update_app_actions_state(self): |
| 470 | 471 |
enabled_accounts = app.settings.get_active_accounts()
|
| 471 | 472 |
self.lookup_action('start-chat').set_enabled(enabled_accounts)
|
| 472 | 473 |
|
| 473 |
- def _set_shortcuts(self):
|
|
| 474 |
- shortcuts = {
|
|
| 475 |
- 'app.quit': ['<Primary>Q'],
|
|
| 476 |
- 'app.shortcuts': ['<Primary>question'],
|
|
| 477 |
- 'app.preferences': ['<Primary>P'],
|
|
| 478 |
- 'app.plugins': ['<Primary>E'],
|
|
| 479 |
- 'app.xml-console': ['<Primary><Shift>X'],
|
|
| 480 |
- 'app.file-transfer': ['<Primary>T'],
|
|
| 481 |
- 'app.ipython': ['<Primary><Alt>I'],
|
|
| 482 |
- 'app.start-chat::': ['<Primary>N'],
|
|
| 483 |
- 'app.create-groupchat::': ['<Primary>G'],
|
|
| 484 |
- 'win.change-nickname': ['<Primary><Shift>N'],
|
|
| 485 |
- 'win.change-subject': ['<Primary><Shift>S'],
|
|
| 486 |
- 'win.escape': ['Escape'],
|
|
| 487 |
- 'win.send-file': ['<Primary>F'],
|
|
| 488 |
- 'win.show-contact-info': ['<Primary>I'],
|
|
| 489 |
- 'win.show-emoji-chooser': ['<Primary><Shift>M'],
|
|
| 490 |
- 'win.clear-chat': ['<Primary>L'],
|
|
| 491 |
- 'win.delete-line': ['<Primary>U'],
|
|
| 492 |
- 'win.close-tab': ['<Primary>W'],
|
|
| 493 |
- 'win.switch-next-tab': ['<Primary>Page_Down'],
|
|
| 494 |
- 'win.switch-prev-tab': ['<Primary>Page_Up'],
|
|
| 495 |
- 'win.switch-next-unread-tab': ['<Primary>Tab'],
|
|
| 496 |
- 'win.switch-prev-unread-tab': ['<Primary>ISO_Left_Tab'],
|
|
| 497 |
- 'win.switch-tab-1': ['<Alt>1', '<Alt>KP_1'],
|
|
| 498 |
- 'win.switch-tab-2': ['<Alt>2', '<Alt>KP_2'],
|
|
| 499 |
- 'win.switch-tab-3': ['<Alt>3', '<Alt>KP_3'],
|
|
| 500 |
- 'win.switch-tab-4': ['<Alt>4', '<Alt>KP_4'],
|
|
| 501 |
- 'win.switch-tab-5': ['<Alt>5', '<Alt>KP_5'],
|
|
| 502 |
- 'win.switch-tab-6': ['<Alt>6', '<Alt>KP_6'],
|
|
| 503 |
- 'win.switch-tab-7': ['<Alt>7', '<Alt>KP_7'],
|
|
| 504 |
- 'win.switch-tab-8': ['<Alt>8', '<Alt>KP_8'],
|
|
| 505 |
- 'win.switch-tab-9': ['<Alt>9', '<Alt>KP_9'],
|
|
| 506 |
- 'win.search-history': ['<Primary>H'],
|
|
| 507 |
- }
|
|
| 474 |
+ def _load_shortcuts(self):
|
|
| 475 |
+ default_path = configpaths.get('DATA') / 'other' / 'shortcuts.json'
|
|
| 476 |
+ shortcuts = load_json(default_path)
|
|
| 477 |
+ assert shortcuts is not None
|
|
| 478 |
+ |
|
| 479 |
+ user_path = configpaths.get('MY_SHORTCUTS')
|
|
| 480 |
+ user_shortcuts = {}
|
|
| 481 |
+ if user_path.exists():
|
|
| 482 |
+ app.log('app').info('Load user shortcuts')
|
|
| 483 |
+ user_shortcuts = load_json(user_path, default={})
|
|
| 484 |
+ |
|
| 485 |
+ shortcuts.update(user_shortcuts)
|
|
| 508 | 486 |
|
| 509 | 487 |
for action, accels in shortcuts.items():
|
| 510 | 488 |
self.set_accels_for_action(action, accels)
|
| ... | ... | @@ -200,6 +200,7 @@ def init(self): |
| 200 | 200 |
('PLUGINS_CONFIG_DIR',
|
| 201 | 201 |
'pluginsconfig', PathLocation.CONFIG, PathType.FOLDER),
|
| 202 | 202 |
('MY_CERT', 'localcerts', PathLocation.CONFIG, PathType.FOLDER),
|
| 203 |
+ ('MY_SHORTCUTS', 'shortcuts.json', PathLocation.CONFIG, PathType.FILE),
|
|
| 203 | 204 |
]
|
| 204 | 205 |
|
| 205 | 206 |
for path in unique_profile_paths:
|
| ... | ... | @@ -812,7 +812,9 @@ def helper(self, restart=False): |
| 812 | 812 |
return func(self)
|
| 813 | 813 |
return helper
|
| 814 | 814 |
|
| 815 |
-def load_json(path, key=None, default=None):
|
|
| 815 |
+def load_json(path: Path,
|
|
| 816 |
+ key: Optional[str] = None,
|
|
| 817 |
+ default: Optional[Any] = None) -> Any:
|
|
| 816 | 818 |
try:
|
| 817 | 819 |
with path.open('r') as file:
|
| 818 | 820 |
json_dict = json.loads(file.read())
|
| 1 |
+{
|
|
| 2 |
+ "app.quit": ["<Primary>Q"],
|
|
| 3 |
+ "app.shortcuts": ["<Primary>question"],
|
|
| 4 |
+ "app.preferences": ["<Primary>P"],
|
|
| 5 |
+ "app.plugins": ["<Primary>E"],
|
|
| 6 |
+ "app.xml-console": ["<Primary><Shift>X"],
|
|
| 7 |
+ "app.file-transfer": ["<Primary>T"],
|
|
| 8 |
+ "app.ipython": ["<Primary><Alt>I"],
|
|
| 9 |
+ "app.start-chat::": ["<Primary>N"],
|
|
| 10 |
+ "app.create-groupchat::": ["<Primary>G"],
|
|
| 11 |
+ "win.change-nickname": ["<Primary><Shift>N"],
|
|
| 12 |
+ "win.change-subject": ["<Primary><Shift>S"],
|
|
| 13 |
+ "win.escape": ["Escape"],
|
|
| 14 |
+ "win.send-file": ["<Primary>F"],
|
|
| 15 |
+ "win.show-contact-info": ["<Primary>I"],
|
|
| 16 |
+ "win.show-emoji-chooser": ["<Primary><Shift>M"],
|
|
| 17 |
+ "win.clear-chat": ["<Primary>L"],
|
|
| 18 |
+ "win.delete-line": ["<Primary>U"],
|
|
| 19 |
+ "win.close-tab": ["<Primary>W"],
|
|
| 20 |
+ "win.switch-next-tab": ["<Primary>Page_Down"],
|
|
| 21 |
+ "win.switch-prev-tab": ["<Primary>Page_Up"],
|
|
| 22 |
+ "win.switch-next-unread-tab": ["<Primary>Tab"],
|
|
| 23 |
+ "win.switch-prev-unread-tab": ["<Primary>ISO_Left_Tab"],
|
|
| 24 |
+ "win.switch-tab-1": ["<Alt>1", "<Alt>KP_1"],
|
|
| 25 |
+ "win.switch-tab-2": ["<Alt>2", "<Alt>KP_2"],
|
|
| 26 |
+ "win.switch-tab-3": ["<Alt>3", "<Alt>KP_3"],
|
|
| 27 |
+ "win.switch-tab-4": ["<Alt>4", "<Alt>KP_4"],
|
|
| 28 |
+ "win.switch-tab-5": ["<Alt>5", "<Alt>KP_5"],
|
|
| 29 |
+ "win.switch-tab-6": ["<Alt>6", "<Alt>KP_6"],
|
|
| 30 |
+ "win.switch-tab-7": ["<Alt>7", "<Alt>KP_7"],
|
|
| 31 |
+ "win.switch-tab-8": ["<Alt>8", "<Alt>KP_8"],
|
|
| 32 |
+ "win.switch-tab-9": ["<Alt>9", "<Alt>KP_9"],
|
|
| 33 |
+ "win.search-history": ["<Primary>H"]
|
|
| 34 |
+}
|