[meld: 51/63] Use native buffer modified tracking instead of our own weird metadata



commit ee4e37ccdb15b425554caf01390280cdb7a79d29
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Oct 10 10:04:39 2015 +1000

    Use native buffer modified tracking instead of our own weird metadata
    
    This commit keeps us moving away from storing too much of our own
    metadata on the MeldBufferData class, trying to use built-in attributes
    where we can. In this case, there's no real reason to try and track the
    modified attribute, since GtkTextBuffer does a better job than we do.
    
    This patch also highlights the crazy number of places we check this
    stuff for e.g., setting save sensitivity, rather than binding like we
    really should.

 meld/filediff.py   |   21 +++++++++++----------
 meld/filemerge.py  |    1 -
 meld/meldbuffer.py |    1 -
 3 files changed, 11 insertions(+), 12 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 8a4efd1..b72a6d4 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -796,7 +796,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
 
     def check_save_modified(self):
         response = Gtk.ResponseType.OK
-        modified = [b.data.modified for b in self.textbuffer[:self.num_panes]]
+        modified = [b.get_modified() for b in self.textbuffer[:self.num_panes]]
         labels = [b.data.label for b in self.textbuffer[:self.num_panes]]
         if True in modified:
             dialog = gnomeglade.Component("filediff.ui", "check_save_dialog")
@@ -886,7 +886,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
             meldbuffer.BufferDeletionAction(buf, it0.get_offset(), text))
 
     def on_undo_checkpointed(self, undosequence, buf, checkpointed):
-        buf.data.modified = not checkpointed
+        buf.set_modified(not checkpointed)
         self.recompute_label()
 
     @with_focused_pane
@@ -988,10 +988,11 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
 
     def _set_save_action_sensitivity(self):
         pane = self._get_focused_pane()
-        modified = False if pane == -1 else self.textbuffer[pane].data.modified
+        modified = (
+            False if pane == -1 else self.textbuffer[pane].get_modified())
         if self.main_actiongroup:
             self.main_actiongroup.get_action("Save").set_sensitive(modified)
-        any_modified = any(b.data.modified for b in self.textbuffer)
+        any_modified = any(b.get_modified() for b in self.textbuffer)
         self.actiongroup.get_action("SaveAll").set_sensitive(any_modified)
 
     def recompute_label(self):
@@ -1000,9 +1001,9 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         shortnames = misc.shorten_names(*filenames)
 
         for i, buf in enumerate(self.textbuffer[:self.num_panes]):
-            if buf.data.modified:
+            if buf.get_modified():
                 shortnames[i] += "*"
-            self.file_save_button[i].set_sensitive(buf.data.modified)
+            self.file_save_button[i].set_sensitive(buf.get_modified())
             self.file_save_button[i].props.icon_name = (
                 'document-save-symbolic' if buf.data.writable else
                 'document-save-as-symbolic')
@@ -1549,7 +1550,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
             self.meta['middle_saved'] = True
 
         if (self.state == melddoc.STATE_CLOSING and
-                not any(b.data.modified for b in self.textbuffer)):
+                not any(b.get_modified() for b in self.textbuffer)):
             self.on_delete_event()
         else:
             self.state = melddoc.STATE_NORMAL
@@ -1586,7 +1587,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
 
     def on_save_all_activate(self, action):
         for i in range(self.num_panes):
-            if self.textbuffer[i].data.modified:
+            if self.textbuffer[i].get_modified():
                 self.save_file(i)
 
     def on_file_save_button_clicked(self, button):
@@ -1613,7 +1614,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
 
     def on_revert_activate(self, *extra):
         response = Gtk.ResponseType.OK
-        unsaved = [b.data.label for b in self.textbuffer if b.data.modified]
+        unsaved = [b.data.label for b in self.textbuffer if b.get_modified()]
         if unsaved:
             dialog = gnomeglade.Component("filediff.ui", "revert_dialog")
             dialog.widget.set_transient_for(self.widget.get_toplevel())
@@ -1777,7 +1778,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
 
             for i in range(self.num_panes):
                 self.file_save_button[i].set_sensitive(
-                    self.textbuffer[i].data.modified)
+                    self.textbuffer[i].get_modified())
             self.queue_draw()
             self.recompute_label()
 
diff --git a/meld/filemerge.py b/meld/filemerge.py
index c644b61..6ef35c1 100644
--- a/meld/filemerge.py
+++ b/meld/filemerge.py
@@ -43,5 +43,4 @@ class FileMerge(filediff.FileDiff):
             yield 1
         self.linediffer.unresolved = merger.unresolved
         self.textbuffer[1].set_text(merged_text)
-        self.textbuffer[1].data.modified = True
         self.recompute_label()
diff --git a/meld/meldbuffer.py b/meld/meldbuffer.py
index 76254bb..e122a28 100644
--- a/meld/meldbuffer.py
+++ b/meld/meldbuffer.py
@@ -116,7 +116,6 @@ class MeldBufferData(GObject.GObject):
         self.gfile = gfile
         self.label = self._label if same_file else self.filename
         self.loaded = False
-        self.modified = False
         self.savefile = None
         self.encoding = None
         self.newlines = None


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