Commit 75ec3ad5 authored by Kai Willadsen's avatar Kai Willadsen

Move undo-busy logic into UndoSequence

parent d3265e17
......@@ -568,16 +568,16 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
self.undosequence.end_group()
def on_text_insert_text(self, buffer, it, text, textlen):
if not self.undosequence_busy:
self.undosequence.add_action( BufferInsertionAction(buffer, it.get_offset(), text) )
self.undosequence.add_action(
BufferInsertionAction(buffer, it.get_offset(), text))
def on_text_delete_range(self, buffer, it0, it1):
text = buffer.get_text(it0, it1, 0)
pane = self.textbuffer.index(buffer)
assert self.deleted_lines_pending == -1
self.deleted_lines_pending = text.count("\n")
if not self.undosequence_busy:
self.undosequence.add_action( BufferDeletionAction(buffer, it0.get_offset(), text) )
self.undosequence.add_action(
BufferDeletionAction(buffer, it0.get_offset(), text))
def on_undo_checkpointed(self, undosequence, buf, checkpointed):
self.set_buffer_modified(buf, not checkpointed)
......
......@@ -40,7 +40,6 @@ class MeldDoc(gobject.GObject):
def __init__(self, prefs):
gobject.GObject.__init__(self)
self.undosequence = undo.UndoSequence()
self.undosequence_busy = 0
self.scheduler = task.FifoScheduler()
self.prefs = prefs
self.prefs.notify_add(self.on_preference_changed)
......@@ -73,20 +72,11 @@ class MeldDoc(gobject.GObject):
def on_undo_activate(self):
if self.undosequence.can_undo():
self.undosequence_busy = 1
try:
self.undosequence.undo()
finally:
self.undosequence_busy = 0
self.undosequence.undo()
def on_redo_activate(self):
if self.undosequence.can_redo():
self.undosequence_busy = 1
try:
self.undosequence.redo()
finally:
self.undosequence_busy = 0
self.undosequence_busy = 0
self.undosequence.redo()
def on_refresh_activate(self, *extra):
self.on_reload_activate(self, *extra)
......
......@@ -63,6 +63,7 @@ class UndoSequence(gobject.GObject):
self.next_redo = 0
self.checkpoints = {}
self.group = None
self.busy = False
def clear(self):
"""Remove all undo and redo actions from this sequence
......@@ -102,6 +103,9 @@ class UndoSequence(gobject.GObject):
action -- A class with two callable attributes: 'undo' and 'redo'
which are called by this sequence during an undo or redo.
"""
if self.busy:
return
if self.group is None:
if self.checkpointed(action.buffer):
self.checkpoints[action.buffer][1] = self.next_redo
......@@ -130,12 +134,14 @@ class UndoSequence(gobject.GObject):
Raises an AssertionError if the sequence is not undoable.
"""
assert self.next_redo > 0
self.busy = True
buf = self.actions[self.next_redo - 1].buffer
if self.checkpointed(buf):
self.emit('checkpointed', buf, False)
could_redo = self.can_redo()
self.next_redo -= 1
self.actions[self.next_redo].undo()
self.busy = False
if not self.can_undo():
self.emit('can-undo', 0)
if not could_redo:
......@@ -149,6 +155,7 @@ class UndoSequence(gobject.GObject):
Raises and AssertionError if the sequence is not undoable.
"""
assert self.next_redo < len(self.actions)
self.busy = True
buf = self.actions[self.next_redo].buffer
if self.checkpointed(buf):
self.emit('checkpointed', buf, False)
......@@ -156,6 +163,7 @@ class UndoSequence(gobject.GObject):
a = self.actions[self.next_redo]
self.next_redo += 1
a.redo()
self.busy = False
if not could_undo:
self.emit('can-undo', 1)
if not self.can_redo():
......@@ -192,6 +200,9 @@ class UndoSequence(gobject.GObject):
implemented as a pair of 'delete' and 'create' actions, but
undoing should undo both of them.
"""
if self.busy:
return
if self.group:
self.group.begin_group()
else:
......@@ -203,6 +214,9 @@ class UndoSequence(gobject.GObject):
Raises an AssertionError if there was not a matching call to
begin_group().
"""
if self.busy:
return
assert self.group is not None
if self.group.group is not None:
self.group.end_group()
......@@ -219,6 +233,9 @@ class UndoSequence(gobject.GObject):
Raises an AssertionError if there was no a matching call to begin_group().
"""
if self.busy:
return
assert self.group is not None
if self.group.group is not None:
self.group.abort_group()
......
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