Commit 6c2a7bbd authored by Colomban Wendling's avatar Colomban Wendling

Avoid updating the theme too many times when undoing or redoing

Add a new `changed` signal to UndoableStore that gets fired whenever
the data changed, but only once after an undo or redo block.

This provides both a simpler API to watch the model for changes, and
also avoids getting too many change notifications on undo/redo.
parent 9dcde2a2
......@@ -155,6 +155,10 @@ class UndoStack(object):
# FIXME: only save the changed rows, not the whole store
class UndoableStore(Gtk.ListStore):
__gsignals__ = {
'changed': (GObject.SIGNAL_RUN_LAST, None, ())
}
def __init__(self, *args, **kwargs):
self._stack = UndoStack()
self._freeze = False
......@@ -162,7 +166,9 @@ class UndoableStore(Gtk.ListStore):
self._save()
def on_model_changed(model, path, iter=None, data=None):
self._save()
if not self._freeze:
self._save()
self.emit('changed')
self.connect('row-changed', on_model_changed)
self.connect('row-deleted', on_model_changed)
self.connect('row-inserted', on_model_changed)
......@@ -182,6 +188,7 @@ class UndoableStore(Gtk.ListStore):
for row in data:
self.append(row)
self._freeze = False
self.emit('changed')
def can_undo(self):
return self._stack.can_undo()
......@@ -261,13 +268,11 @@ class AppWindow(Gtk.ApplicationWindow):
undo.set_sensitive(self.store.can_undo())
redo.set_sensitive(self.store.can_redo())
def on_model_changed(model, path, iter=None, data=None):
def on_model_changed(model, data=None):
undo.set_sensitive(self.store.can_undo())
redo.set_sensitive(self.store.can_redo())
self.update_theme()
self.store.connect_after('row-changed', on_model_changed)
self.store.connect_after('row-deleted', on_model_changed)
self.store.connect_after('row-inserted', on_model_changed)
self.store.connect('changed', on_model_changed)
def on_row_activated(self, view, path, column, data=None):
iter = self.store.get_iter(path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment