diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index 49387b546c..66e4148b79 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -560,3 +560,11 @@ class TextEdit(QPlainTextEdit): if repl != ent: c.setPosition(c.position() + m.start(), c.KeepAnchor) c.insertText(repl) + + def select_all(self): + c = self.textCursor() + c.clearSelection() + c.setPosition(0) + c.movePosition(c.End, c.KeepAnchor) + self.setTextCursor(c) + diff --git a/src/calibre/gui2/tweak_book/editor/widget.py b/src/calibre/gui2/tweak_book/editor/widget.py index 0b92d02577..b5f1b95997 100644 --- a/src/calibre/gui2/tweak_book/editor/widget.py +++ b/src/calibre/gui2/tweak_book/editor/widget.py @@ -8,7 +8,7 @@ __copyright__ = '2013, Kovid Goyal ' import unicodedata -from PyQt4.Qt import QMainWindow, Qt, QApplication, pyqtSignal +from PyQt4.Qt import QMainWindow, Qt, QApplication, pyqtSignal, QMenu from calibre.gui2 import error_dialog from calibre.gui2.tweak_book import actions, current_container @@ -56,6 +56,8 @@ class Editor(QMainWindow): self.is_synced_to_container = False self.syntax = syntax self.editor = TextEdit(self) + self.editor.setContextMenuPolicy(Qt.CustomContextMenu) + self.editor.customContextMenuRequested.connect(self.show_context_menu) self.setCentralWidget(self.editor) self.create_toolbars() self.undo_available = False @@ -255,6 +257,20 @@ class Editor(QMainWindow): return True return False + def show_context_menu(self, pos): + m = QMenu(self) + a = m.addAction + for x in ('undo', 'redo'): + a(actions['editor-%s' % x]) + m.addSeparator() + for x in ('cut', 'copy', 'paste'): + a(actions['editor-' + x]) + m.addSeparator() + m.addAction(_('&Select all'), self.editor.select_all) + m.addAction(actions['mark-selected-text']) + m.exec_(self.editor.mapToGlobal(pos)) + + def launch_editor(path_to_edit, path_is_raw=False, syntax='html'): from calibre.gui2.tweak_book.main import option_parser from calibre.gui2.tweak_book.ui import Main