From 35f9614f197b7d4f700a9cae252ff1229b817142 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 9 Jan 2015 17:12:55 +0530 Subject: [PATCH] Change the trigger shortcut for snippets to Ctrl+J and Ctrl+Tab is often used by the OS --- manual/snippets.rst | 2 +- src/calibre/gui2/tweak_book/editor/snippets.py | 5 ++++- src/calibre/gui2/tweak_book/search.py | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/manual/snippets.rst b/manual/snippets.rst index 19badc0b5b..e1bedf34c0 100644 --- a/manual/snippets.rst +++ b/manual/snippets.rst @@ -1,7 +1,7 @@ Snippets ======================== -.. |ct| replace:: ``Ctrl+Tab`` +.. |ct| replace:: ``Control+J`` The calibre editor supports *snippets*. A snippet is a piece of text that is either re-used often or contains a lot of redundant diff --git a/src/calibre/gui2/tweak_book/editor/snippets.py b/src/calibre/gui2/tweak_book/editor/snippets.py index 8820d90b0b..a257f43acc 100644 --- a/src/calibre/gui2/tweak_book/editor/snippets.py +++ b/src/calibre/gui2/tweak_book/editor/snippets.py @@ -16,6 +16,7 @@ from PyQt5.Qt import ( QToolButton, QIcon, QHBoxLayout, QPushButton, QListWidget, QListWidgetItem, QGridLayout, QPlainTextEdit, QLabel, QFrame, QDialog, QDialogButtonBox) +from calibre.constants import isosx from calibre.gui2 import error_dialog from calibre.gui2.tweak_book.editor import all_text_syntaxes from calibre.gui2.tweak_book.editor.smarts.utils import get_text_before_cursor @@ -25,6 +26,8 @@ from calibre.utils.icu import string_length as strlen from calibre.utils.localization import localize_user_manual_link string_length = lambda x: strlen(unicode(x)) # Needed on narrow python builds, as subclasses of unicode dont work +KEY = Qt.Key_J +MODIFIER = Qt.META if isosx else Qt.CTRL SnipKey = namedtuple('SnipKey', 'trigger syntaxes') def snip_key(trigger, *syntaxes): @@ -382,7 +385,7 @@ class SnippetManager(QObject): def handle_key_press(self, ev): editor = self.parent() - if ev.key() == Qt.Key_Tab and ev.modifiers() & Qt.CTRL: + if ev.key() == KEY and ev.modifiers() & MODIFIER: at = self.get_active_template(editor.textCursor()) if at is not None: if at.jump_to_next(editor) is None: diff --git a/src/calibre/gui2/tweak_book/search.py b/src/calibre/gui2/tweak_book/search.py index 0c559171cc..dc587b7e81 100644 --- a/src/calibre/gui2/tweak_book/search.py +++ b/src/calibre/gui2/tweak_book/search.py @@ -26,7 +26,7 @@ from calibre.gui2.tweak_book import tprefs, editors, current_container from calibre.gui2.tweak_book.function_replace import ( FunctionBox, functions as replace_functions, FunctionEditor, remove_function, Function) from calibre.gui2.tweak_book.widgets import BusyCursor -from calibre.gui2.tweak_book.editor.snippets import find_matching_snip, parse_template, string_length, SnippetTextEdit +from calibre.gui2.tweak_book.editor.snippets import find_matching_snip, parse_template, string_length, SnippetTextEdit, MODIFIER, KEY from calibre.utils.icu import primary_contains @@ -88,7 +88,7 @@ class HistoryBox(HistoryComboBox): self.ignore_snip_expansion = False def event(self, ev): - if ev.type() in (ev.ShortcutOverride, ev.KeyPress) and ev.key() == Qt.Key_Tab and ev.modifiers() & Qt.CTRL: + if ev.type() in (ev.ShortcutOverride, ev.KeyPress) and ev.key() == KEY and ev.modifiers() & MODIFIER: if not self.ignore_snip_expansion: self.ignore_snip_expansion = True expand_template(self.lineEdit())