[meld] undo: Extend the undo API to return the actions that were undone/redone
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] undo: Extend the undo API to return the actions that were undone/redone
- Date: Sat, 2 Apr 2016 21:44:50 +0000 (UTC)
commit 036df602fbd50607a193c7f7b33193e55b15ec8c
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sun Apr 3 07:25:39 2016 +1000
undo: Extend the undo API to return the actions that were undone/redone
Having the actions carried out as part of the API lets other parts of
the stack use action features to add extra front-end behaviours.
meld/meldbuffer.py | 2 ++
meld/undo.py | 14 ++++++++++----
2 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/meld/meldbuffer.py b/meld/meldbuffer.py
index 3c6d38e..f70eaff 100644
--- a/meld/meldbuffer.py
+++ b/meld/meldbuffer.py
@@ -308,10 +308,12 @@ class BufferAction(object):
start = self.buffer.get_iter_at_offset(self.offset)
end = self.buffer.get_iter_at_offset(self.offset + len(self.text))
self.buffer.delete(start, end)
+ return [self]
def insert(self):
start = self.buffer.get_iter_at_offset(self.offset)
self.buffer.insert(start, self.text)
+ return [self]
class BufferInsertionAction(BufferAction):
diff --git a/meld/undo.py b/meld/undo.py
index 777c511..308b81e 100644
--- a/meld/undo.py
+++ b/meld/undo.py
@@ -44,12 +44,16 @@ class GroupAction(object):
self.buffer = seq.actions[0].buffer
def undo(self):
+ actions = []
while self.seq.can_undo():
- self.seq.undo()
+ actions.extend(self.seq.undo())
+ return actions
def redo(self):
+ actions = []
while self.seq.can_redo():
- self.seq.redo()
+ actions.extend(self.seq.redo())
+ return actions
class UndoSequence(GObject.GObject):
@@ -144,7 +148,7 @@ class UndoSequence(GObject.GObject):
self.emit('checkpointed', buf, False)
could_redo = self.can_redo()
self.next_redo -= 1
- self.actions[self.next_redo].undo()
+ actions = self.actions[self.next_redo].undo()
self.busy = False
if not self.can_undo():
self.emit('can-undo', 0)
@@ -152,6 +156,7 @@ class UndoSequence(GObject.GObject):
self.emit('can-redo', 1)
if self.checkpointed(buf):
self.emit('checkpointed', buf, True)
+ return actions
def redo(self):
"""Redo an action.
@@ -166,7 +171,7 @@ class UndoSequence(GObject.GObject):
could_undo = self.can_undo()
a = self.actions[self.next_redo]
self.next_redo += 1
- a.redo()
+ actions = a.redo()
self.busy = False
if not could_undo:
self.emit('can-undo', 1)
@@ -174,6 +179,7 @@ class UndoSequence(GObject.GObject):
self.emit('can-redo', 0)
if self.checkpointed(buf):
self.emit('checkpointed', buf, True)
+ return actions
def checkpoint(self, buf):
start = self.next_redo
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]