[meld] meldbuffer: Make the reset_buffer() call not recreate MeldBufferData



commit 348c8a1dea79251480da54cfa31fcb0612477521
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Mon Nov 4 06:55:03 2013 +1000

    meldbuffer: Make the reset_buffer() call not recreate MeldBufferData
    
    With this change, there is always one MeldBufferData per MeldBuffer,
    which makes it much easier to reason about connecting signals to it.

 meld/meldbuffer.py |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)
---
diff --git a/meld/meldbuffer.py b/meld/meldbuffer.py
index d9050aa..b91feab 100644
--- a/meld/meldbuffer.py
+++ b/meld/meldbuffer.py
@@ -40,11 +40,10 @@ class MeldBuffer(GtkSource.Buffer):
     def reset_buffer(self, filename):
         """Clear the contents of the buffer and reset its metadata"""
         self.delete(*self.get_bounds())
-
-        new_data = MeldBufferData(filename)
-        if self.data.filename == filename:
-            new_data.label = self.data.label
-        self.data = new_data
+        label = self.data.label if self.data.filename == filename else None
+        self.data.reset()
+        self.data.filename = filename
+        self.data.label = label
 
     def get_iter_at_line_or_eof(self, line):
         """Return a Gtk.TextIter at the given line, or the end of the buffer.
@@ -83,15 +82,19 @@ class MeldBufferData(GObject.GObject):
 
     def __init__(self, filename=None):
         GObject.GObject.__init__(self)
+        self.reset()
+        self._label = self.filename = filename
+
+    def reset(self):
         self.modified = False
         self.writable = True
         self.editable = True
         self._monitor = None
         self._mtime = None
         self._disk_mtime = None
-        self.filename = filename
+        self.filename = None
         self.savefile = None
-        self._label = filename
+        self._label = None
         self.encoding = None
         self.newlines = None
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]