From 0113271a22b1fff615570c04fa3d7e2b6094385e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 19 Nov 2013 11:23:25 +0530 Subject: [PATCH] Action to go to specified line --- src/calibre/gui2/tweak_book/boss.py | 10 ++++++++++ src/calibre/gui2/tweak_book/editor/widget.py | 6 ++++++ src/calibre/gui2/tweak_book/ui.py | 3 +++ 3 files changed, 19 insertions(+) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index af9d7e4efc..a2618f4ebe 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -493,6 +493,14 @@ class Boss(QObject): _('Saving of the book failed. Click "Show Details"' ' for more information.'), det_msg=tb, show=True) + def go_to_line_number(self): + ed = self.gui.central.current_editor + if ed is None or not ed.has_line_numbers: + return + num, ok = QInputDialog.getInt(self.gui, _('Enter line number'), ('Line number:'), ed.current_line, 1, max(100000, ed.number_of_lines)) + if ok: + ed.current_line = num + def sync_editor_to_preview(self, name, lnum): editor = self.edit_file(name, 'html') editor.current_line = lnum @@ -597,6 +605,7 @@ class Boss(QObject): actions['editor-save'].setEnabled(ed.is_modified) actions['editor-cut'].setEnabled(ed.copy_available) actions['editor-copy'].setEnabled(ed.cut_available) + actions['go-to-line-number'].setEnabled(ed.has_line_numbers) self.gui.keyboard.set_mode(ed.syntax) name = None for n, x in editors.iteritems(): @@ -607,6 +616,7 @@ class Boss(QObject): self.gui.preview.show(name) else: self.gui.keyboard.set_mode('other') + actions['go-to-line-number'].setEnabled(False) def editor_close_requested(self, editor): name = None diff --git a/src/calibre/gui2/tweak_book/editor/widget.py b/src/calibre/gui2/tweak_book/editor/widget.py index d79d67a12f..ef42c76b19 100644 --- a/src/calibre/gui2/tweak_book/editor/widget.py +++ b/src/calibre/gui2/tweak_book/editor/widget.py @@ -15,6 +15,8 @@ from calibre.gui2.tweak_book.editor.text import TextEdit class Editor(QMainWindow): + has_line_numbers = True + modification_state_changed = pyqtSignal(object) undo_redo_state_changed = pyqtSignal(object, object) copy_available_state_changed = pyqtSignal(object) @@ -47,6 +49,10 @@ class Editor(QMainWindow): self.editor.go_to_line(val) return property(fget=fget, fset=fset) + @property + def number_of_lines(self): + return self.editor.blockCount() + @dynamic_property def data(self): def fget(self): diff --git a/src/calibre/gui2/tweak_book/ui.py b/src/calibre/gui2/tweak_book/ui.py index 32a29f6956..d3882fba52 100644 --- a/src/calibre/gui2/tweak_book/ui.py +++ b/src/calibre/gui2/tweak_book/ui.py @@ -244,6 +244,7 @@ class Main(MainWindow): self.action_count = sreg('count-matches', _('&Count all'), 'count', keys=('Ctrl+N'), description=_('Count number of matches')) self.action_mark = reg(None, _('&Mark selected text'), self.boss.mark_selected_text, 'mark-selected-text', ('Ctrl+Shift+M',), _('Mark selected text')) + self.action_go_to_line = reg(None, _('Go to &line'), self.boss.go_to_line_number, 'go-to-line-number', ('Ctrl+.',), _('Go to line number')) # Miscellaneous actions group = _('Miscellaneous') @@ -302,6 +303,8 @@ class Main(MainWindow): a(self.action_count) e.addSeparator() a(self.action_mark) + e.addSeparator() + a(self.action_go_to_line) def create_toolbars(self): def create(text, name):