[meld] Simplify and reformat BufferAction helper classes
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] Simplify and reformat BufferAction helper classes
- Date: Tue, 24 Aug 2010 09:51:02 +0000 (UTC)
commit 7fbfc98a50be4a94c87523432947c475f032f014
Author: Kai Willadsen <kai willadsen gmail com>
Date: Thu Aug 13 15:39:01 2009 +1000
Simplify and reformat BufferAction helper classes
meld/filediff.py | 32 +++++++++++++++-----------------
1 files changed, 15 insertions(+), 17 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 7fe99c4..f6b68fd 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1474,32 +1474,30 @@ class MeldBufferData(object):
self.encoding = None
self.newlines = None
-################################################################################
-#
-# BufferAction
-#
-################################################################################
+
class BufferAction(object):
"""A helper to undo/redo text insertion/deletion into/from a text buffer"""
+
def __init__(self, buf, offset, text):
self.buffer = buf
self.offset = offset
self.text = text
+
def delete(self):
- b = self.buffer
- b.delete(b.get_iter_at_offset(self.offset), b.get_iter_at_offset(self.offset + len(self.text)))
+ 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)
+
def insert(self):
- b = self.buffer
- b.insert(b.get_iter_at_offset(self.offset), self.text)
+ start = self.buffer.get_iter_at_offset(self.offset)
+ self.buffer.insert(start, self.text)
+
class BufferInsertionAction(BufferAction):
- def __init__(self, buf, offset, text):
- super(BufferInsertionAction, self).__init__(buf, offset, text)
- self.undo = self.delete
- self.redo = self.insert
+ undo = BufferAction.delete
+ redo = BufferAction.insert
+
class BufferDeletionAction(BufferAction):
- def __init__(self, buf, offset, text):
- super(BufferDeletionAction, self).__init__(buf, offset, text)
- self.undo = self.insert
- self.redo = self.delete
+ undo = BufferAction.insert
+ redo = BufferAction.delete
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]