From 784371499513661e188b4d249565f185c498b9f9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 22 Nov 2013 09:36:25 +0530 Subject: [PATCH] Update UI when renaming files --- src/calibre/gui2/tweak_book/boss.py | 6 ++++-- src/calibre/gui2/tweak_book/file_list.py | 5 ++++- src/calibre/gui2/tweak_book/ui.py | 7 +++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index d846bfba77..00e38df3bf 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -266,8 +266,10 @@ class Boss(QObject): det_msg=job.traceback, show=True) self.gui.file_list.build(current_container()) self.gui.action_save.setEnabled(True) - # TODO: Update the rest of the GUI. This means renaming open editors and - # then calling update_editors_from_container() + if oldname in editors: + editors[newname] = editors.pop(oldname) + self.gui.central.rename_editor(editors[newname], newname) + self.apply_container_update_to_gui() # }}} # Global history {{{ diff --git a/src/calibre/gui2/tweak_book/file_list.py b/src/calibre/gui2/tweak_book/file_list.py index 567f827492..b9cbfc1a63 100644 --- a/src/calibre/gui2/tweak_book/file_list.py +++ b/src/calibre/gui2/tweak_book/file_list.py @@ -58,7 +58,10 @@ class ItemDelegate(QStyledItemDelegate): # {{{ if top_level: suffix = '%s(%d)' % (NBSP, index.model().rowCount(index)) else: - suffix = NBSP + human_readable(current_container().filesize(unicode(index.data(NAME_ROLE).toString()))) + try: + suffix = NBSP + human_readable(current_container().filesize(unicode(index.data(NAME_ROLE).toString()))) + except EnvironmentError: + suffix = NBSP + human_readable(0) br = painter.boundingRect(option.rect, Qt.AlignRight|Qt.AlignVCenter, suffix) if top_level and index.row() > 0: option.rect.adjust(0, 5, 0, 0) diff --git a/src/calibre/gui2/tweak_book/ui.py b/src/calibre/gui2/tweak_book/ui.py index 144a8d7593..0e5a240cbe 100644 --- a/src/calibre/gui2/tweak_book/ui.py +++ b/src/calibre/gui2/tweak_book/ui.py @@ -75,6 +75,13 @@ class Central(QStackedWidget): self.editor_tabs.setTabToolTip(index, _('Full path:') + ' ' + name) editor.modification_state_changed.connect(self.editor_modified) + def rename_editor(self, editor, name): + for i in xrange(self.editor_tabs.count()): + if self.editor_tabs.widget(i) is editor: + fname = name.rpartition('/')[2] + self.editor_tabs.setTabText(i, fname) + self.editor_tabs.setTabToolTip(i, _('Full path:') + ' ' + name) + def show_editor(self, editor): self.setCurrentIndex(1) self.editor_tabs.setCurrentWidget(editor)