From 2b06cffa0dfcd4c0d06382a00ef81017623728d6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 11 Jul 2014 17:07:49 +0530 Subject: [PATCH] Edit Book: Fix live link syntax highlighting not being updated correctly after renaming an open file --- src/calibre/gui2/tweak_book/boss.py | 3 ++- src/calibre/gui2/tweak_book/editor/image.py | 3 +++ src/calibre/gui2/tweak_book/editor/text.py | 4 ++++ src/calibre/gui2/tweak_book/editor/widget.py | 3 +++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index e43fd12a32..a9f8d22519 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -552,7 +552,8 @@ class Boss(QObject): self.set_modified() for oldname, newname in name_map.iteritems(): if oldname in editors: - editors[newname] = editors.pop(oldname) + editors[newname] = ed = editors.pop(oldname) + ed.change_document_name(newname) self.gui.central.rename_editor(editors[newname], newname) if self.gui.preview.current_name == oldname: self.gui.preview.current_name = newname diff --git a/src/calibre/gui2/tweak_book/editor/image.py b/src/calibre/gui2/tweak_book/editor/image.py index a164ceac49..0825efe20a 100644 --- a/src/calibre/gui2/tweak_book/editor/image.py +++ b/src/calibre/gui2/tweak_book/editor/image.py @@ -139,6 +139,9 @@ class Editor(QMainWindow): def pretty_print(self, name): return False + def change_document_name(self, newname): + pass + def get_raw_data(self): return self.canvas.get_image_data(quality=self.quality) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index 96e59a1576..580e363ec3 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -222,6 +222,10 @@ class TextEdit(PlainTextEdit): c = self.textCursor() c.insertText('') + def change_document_name(self, newname): + self.highlighter.doc_name = newname + self.highlighter.rehighlight() # Ensure links are checked w.r.t. to the new name correctly + def replace_text(self, text): c = self.textCursor() pos = c.position() diff --git a/src/calibre/gui2/tweak_book/editor/widget.py b/src/calibre/gui2/tweak_book/editor/widget.py index b896a1454e..8129965162 100644 --- a/src/calibre/gui2/tweak_book/editor/widget.py +++ b/src/calibre/gui2/tweak_book/editor/widget.py @@ -159,6 +159,9 @@ class Editor(QMainWindow): def init_from_template(self, template): self.editor.load_text(template, syntax=self.syntax, process_template=True, doc_name=editor_name(self)) + def change_document_name(self, newname): + self.editor.change_document_name(newname) + def get_raw_data(self): # The EPUB spec requires NFC normalization, see section 1.3.6 of # http://www.idpf.org/epub/20/spec/OPS_2.0.1_draft.htm