mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Action to go to specified line
This commit is contained in:
parent
55a3c77f18
commit
0113271a22
@ -493,6 +493,14 @@ class Boss(QObject):
|
|||||||
_('Saving of the book failed. Click "Show Details"'
|
_('Saving of the book failed. Click "Show Details"'
|
||||||
' for more information.'), det_msg=tb, show=True)
|
' 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):
|
def sync_editor_to_preview(self, name, lnum):
|
||||||
editor = self.edit_file(name, 'html')
|
editor = self.edit_file(name, 'html')
|
||||||
editor.current_line = lnum
|
editor.current_line = lnum
|
||||||
@ -597,6 +605,7 @@ class Boss(QObject):
|
|||||||
actions['editor-save'].setEnabled(ed.is_modified)
|
actions['editor-save'].setEnabled(ed.is_modified)
|
||||||
actions['editor-cut'].setEnabled(ed.copy_available)
|
actions['editor-cut'].setEnabled(ed.copy_available)
|
||||||
actions['editor-copy'].setEnabled(ed.cut_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)
|
self.gui.keyboard.set_mode(ed.syntax)
|
||||||
name = None
|
name = None
|
||||||
for n, x in editors.iteritems():
|
for n, x in editors.iteritems():
|
||||||
@ -607,6 +616,7 @@ class Boss(QObject):
|
|||||||
self.gui.preview.show(name)
|
self.gui.preview.show(name)
|
||||||
else:
|
else:
|
||||||
self.gui.keyboard.set_mode('other')
|
self.gui.keyboard.set_mode('other')
|
||||||
|
actions['go-to-line-number'].setEnabled(False)
|
||||||
|
|
||||||
def editor_close_requested(self, editor):
|
def editor_close_requested(self, editor):
|
||||||
name = None
|
name = None
|
||||||
|
@ -15,6 +15,8 @@ from calibre.gui2.tweak_book.editor.text import TextEdit
|
|||||||
|
|
||||||
class Editor(QMainWindow):
|
class Editor(QMainWindow):
|
||||||
|
|
||||||
|
has_line_numbers = True
|
||||||
|
|
||||||
modification_state_changed = pyqtSignal(object)
|
modification_state_changed = pyqtSignal(object)
|
||||||
undo_redo_state_changed = pyqtSignal(object, object)
|
undo_redo_state_changed = pyqtSignal(object, object)
|
||||||
copy_available_state_changed = pyqtSignal(object)
|
copy_available_state_changed = pyqtSignal(object)
|
||||||
@ -47,6 +49,10 @@ class Editor(QMainWindow):
|
|||||||
self.editor.go_to_line(val)
|
self.editor.go_to_line(val)
|
||||||
return property(fget=fget, fset=fset)
|
return property(fget=fget, fset=fset)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def number_of_lines(self):
|
||||||
|
return self.editor.blockCount()
|
||||||
|
|
||||||
@dynamic_property
|
@dynamic_property
|
||||||
def data(self):
|
def data(self):
|
||||||
def fget(self):
|
def fget(self):
|
||||||
|
@ -244,6 +244,7 @@ class Main(MainWindow):
|
|||||||
self.action_count = sreg('count-matches', _('&Count all'),
|
self.action_count = sreg('count-matches', _('&Count all'),
|
||||||
'count', keys=('Ctrl+N'), description=_('Count number of matches'))
|
'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_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
|
# Miscellaneous actions
|
||||||
group = _('Miscellaneous')
|
group = _('Miscellaneous')
|
||||||
@ -302,6 +303,8 @@ class Main(MainWindow):
|
|||||||
a(self.action_count)
|
a(self.action_count)
|
||||||
e.addSeparator()
|
e.addSeparator()
|
||||||
a(self.action_mark)
|
a(self.action_mark)
|
||||||
|
e.addSeparator()
|
||||||
|
a(self.action_go_to_line)
|
||||||
|
|
||||||
def create_toolbars(self):
|
def create_toolbars(self):
|
||||||
def create(text, name):
|
def create(text, name):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user