From d1f35bebdfa167d1dfe679d4b917b5c802ba3244 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 15 Oct 2013 16:23:13 +0530 Subject: [PATCH] Hook up global undo/redo --- src/calibre/gui2/tweak_book/boss.py | 16 ++++++++++++++-- src/calibre/gui2/tweak_book/file_list.py | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 1857e91900..fe7e56ada9 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -87,11 +87,23 @@ class Boss(QObject): set_current_container(nc) self.update_global_history_actions() + def apply_container_update_to_gui(self): + container = current_container() + self.gui.file_list.build(container) + self.update_global_history_actions() + # TODO: Apply to other GUI elements + def do_global_undo(self): - pass + container = self.global_undo.undo() + if container is not None: + set_current_container(container) + self.apply_container_update_to_gui() def do_global_redo(self): - pass + container = self.global_undo.redo() + if container is not None: + set_current_container(container) + self.apply_container_update_to_gui() def delete_requested(self, spine_items, other_items): if not self.check_dirtied(): diff --git a/src/calibre/gui2/tweak_book/file_list.py b/src/calibre/gui2/tweak_book/file_list.py index 910aaaed80..1fc2eb4cb4 100644 --- a/src/calibre/gui2/tweak_book/file_list.py +++ b/src/calibre/gui2/tweak_book/file_list.py @@ -96,11 +96,11 @@ class FileList(QTreeWidget): return s def set_state(self, state): - for category, item in self.categories: + for category, item in self.categories.iteritems(): item.setExpanded(category in state['expanded']) self.verticalScrollBar().setValue(state['pos']) for parent in self.categories.itervalues(): - for c in (parent.child(i) for i in parent.childCount()): + for c in (parent.child(i) for i in xrange(parent.childCount())): name = unicode(c.data(0, NAME_ROLE).toString()) if name in state['selected']: c.setSelected(True)