From 2d52cae4c5ea838a68c192412736a84ed53ae03c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 10 Nov 2013 11:10:55 +0530 Subject: [PATCH] Focus editor when showing it --- src/calibre/gui2/tweak_book/boss.py | 23 ++++++++++++++------ src/calibre/gui2/tweak_book/editor/themes.py | 2 +- src/calibre/gui2/tweak_book/editor/widget.py | 3 +++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 556dd90c7f..b39b7ffd53 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -278,19 +278,28 @@ class Boss(QObject): _('Saving of the book failed. Click "Show Details"' ' 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): editor = editors.get(name, None) if editor is None: 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() with c.open(name) as f: - editor.data = c.decode(f.read()) - editor.modification_state_changed.connect(self.editor_modification_state_changed) - self.gui.central.add_editor(name, editor) - self.gui.central.show_editor(editor) + data = c.decode(f.read()) + self.init_editor(name, editor, data) + self.show_editor(name) + + def show_editor(self, name): + self.gui.central.show_editor(editors[name]) + editors[name].set_focus() def edit_file_requested(self, name, syntax, mime): if name in editors: diff --git a/src/calibre/gui2/tweak_book/editor/themes.py b/src/calibre/gui2/tweak_book/editor/themes.py index fcd35fdad5..ed7cb3b596 100644 --- a/src/calibre/gui2/tweak_book/editor/themes.py +++ b/src/calibre/gui2/tweak_book/editor/themes.py @@ -130,7 +130,7 @@ THEMES = { Error us=wave uc=red '''.format( - cursor_loc='white', + cursor_loc='F8DE7E', identifier='7b5694', comment='a0b0c0', string='4070a0', diff --git a/src/calibre/gui2/tweak_book/editor/widget.py b/src/calibre/gui2/tweak_book/editor/widget.py index 088794b4f0..c8db288195 100644 --- a/src/calibre/gui2/tweak_book/editor/widget.py +++ b/src/calibre/gui2/tweak_book/editor/widget.py @@ -58,6 +58,9 @@ class Editor(QMainWindow): if current != raw: self.editor.replace_text(raw) + def set_focus(self): + self.editor.setFocus(Qt.OtherFocusReason) + def undo(self): self.editor.undo()