mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Focus editor when showing it
This commit is contained in:
parent
0348bbe41d
commit
2d52cae4c5
@ -278,19 +278,28 @@ 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 init_editor(self, name, editor, data=None):
|
||||||
|
editor.undo_redo_state_changed.connect(self.editor_undo_redo_state_changed)
|
||||||
|
editor.data_changed.connect(self.editor_data_changed)
|
||||||
|
editor.copy_available_state_changed.connect(self.editor_copy_available_state_changed)
|
||||||
|
if data is not None:
|
||||||
|
editor.data = data
|
||||||
|
editor.modification_state_changed.connect(self.editor_modification_state_changed)
|
||||||
|
self.gui.central.add_editor(name, editor)
|
||||||
|
|
||||||
def edit_file(self, name, syntax):
|
def edit_file(self, name, syntax):
|
||||||
editor = editors.get(name, None)
|
editor = editors.get(name, None)
|
||||||
if editor is None:
|
if editor is None:
|
||||||
editor = editors[name] = editor_from_syntax(syntax, self.gui.editor_tabs)
|
editor = editors[name] = editor_from_syntax(syntax, self.gui.editor_tabs)
|
||||||
editor.undo_redo_state_changed.connect(self.editor_undo_redo_state_changed)
|
|
||||||
editor.data_changed.connect(self.editor_data_changed)
|
|
||||||
editor.copy_available_state_changed.connect(self.editor_copy_available_state_changed)
|
|
||||||
c = current_container()
|
c = current_container()
|
||||||
with c.open(name) as f:
|
with c.open(name) as f:
|
||||||
editor.data = c.decode(f.read())
|
data = c.decode(f.read())
|
||||||
editor.modification_state_changed.connect(self.editor_modification_state_changed)
|
self.init_editor(name, editor, data)
|
||||||
self.gui.central.add_editor(name, editor)
|
self.show_editor(name)
|
||||||
self.gui.central.show_editor(editor)
|
|
||||||
|
def show_editor(self, name):
|
||||||
|
self.gui.central.show_editor(editors[name])
|
||||||
|
editors[name].set_focus()
|
||||||
|
|
||||||
def edit_file_requested(self, name, syntax, mime):
|
def edit_file_requested(self, name, syntax, mime):
|
||||||
if name in editors:
|
if name in editors:
|
||||||
|
@ -130,7 +130,7 @@ THEMES = {
|
|||||||
Error us=wave uc=red
|
Error us=wave uc=red
|
||||||
|
|
||||||
'''.format(
|
'''.format(
|
||||||
cursor_loc='white',
|
cursor_loc='F8DE7E',
|
||||||
identifier='7b5694',
|
identifier='7b5694',
|
||||||
comment='a0b0c0',
|
comment='a0b0c0',
|
||||||
string='4070a0',
|
string='4070a0',
|
||||||
|
@ -58,6 +58,9 @@ class Editor(QMainWindow):
|
|||||||
if current != raw:
|
if current != raw:
|
||||||
self.editor.replace_text(raw)
|
self.editor.replace_text(raw)
|
||||||
|
|
||||||
|
def set_focus(self):
|
||||||
|
self.editor.setFocus(Qt.OtherFocusReason)
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self.editor.undo()
|
self.editor.undo()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user