Action to go to specified line

This commit is contained in:
Kovid Goyal 2013-11-19 11:23:25 +05:30
parent 55a3c77f18
commit 0113271a22
3 changed files with 19 additions and 0 deletions

View File

@ -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

View File

@ -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):

View File

@ -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):