Change the trigger shortcut for snippets to Ctrl+J and Ctrl+Tab is often used by the OS

This commit is contained in:
Kovid Goyal 2015-01-09 17:12:55 +05:30
parent 96856c14e1
commit 35f9614f19
3 changed files with 7 additions and 4 deletions

View File

@ -1,7 +1,7 @@
Snippets Snippets
======================== ========================
.. |ct| replace:: ``Ctrl+Tab`` .. |ct| replace:: ``Control+J``
The calibre editor supports *snippets*. A snippet is a The calibre editor supports *snippets*. A snippet is a
piece of text that is either re-used often or contains a lot of redundant piece of text that is either re-used often or contains a lot of redundant

View File

@ -16,6 +16,7 @@ from PyQt5.Qt import (
QToolButton, QIcon, QHBoxLayout, QPushButton, QListWidget, QListWidgetItem, QToolButton, QIcon, QHBoxLayout, QPushButton, QListWidget, QListWidgetItem,
QGridLayout, QPlainTextEdit, QLabel, QFrame, QDialog, QDialogButtonBox) QGridLayout, QPlainTextEdit, QLabel, QFrame, QDialog, QDialogButtonBox)
from calibre.constants import isosx
from calibre.gui2 import error_dialog from calibre.gui2 import error_dialog
from calibre.gui2.tweak_book.editor import all_text_syntaxes from calibre.gui2.tweak_book.editor import all_text_syntaxes
from calibre.gui2.tweak_book.editor.smarts.utils import get_text_before_cursor 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 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 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') SnipKey = namedtuple('SnipKey', 'trigger syntaxes')
def snip_key(trigger, *syntaxes): def snip_key(trigger, *syntaxes):
@ -382,7 +385,7 @@ class SnippetManager(QObject):
def handle_key_press(self, ev): def handle_key_press(self, ev):
editor = self.parent() 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()) at = self.get_active_template(editor.textCursor())
if at is not None: if at is not None:
if at.jump_to_next(editor) is None: if at.jump_to_next(editor) is None:

View File

@ -26,7 +26,7 @@ from calibre.gui2.tweak_book import tprefs, editors, current_container
from calibre.gui2.tweak_book.function_replace import ( from calibre.gui2.tweak_book.function_replace import (
FunctionBox, functions as replace_functions, FunctionEditor, remove_function, Function) FunctionBox, functions as replace_functions, FunctionEditor, remove_function, Function)
from calibre.gui2.tweak_book.widgets import BusyCursor 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 from calibre.utils.icu import primary_contains
@ -88,7 +88,7 @@ class HistoryBox(HistoryComboBox):
self.ignore_snip_expansion = False self.ignore_snip_expansion = False
def event(self, ev): 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: if not self.ignore_snip_expansion:
self.ignore_snip_expansion = True self.ignore_snip_expansion = True
expand_template(self.lineEdit()) expand_template(self.lineEdit())