[meld] filediff: Break out individual file loading into its own function



commit 6f91fe060bb08e47b030dca81540ed78b6e17a73
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Oct 28 09:02:55 2017 +1000

    filediff: Break out individual file loading into its own function

 meld/filediff.py |   47 ++++++++++++++++++++++++++---------------------
 1 files changed, 26 insertions(+), 21 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index f801b87..f511c4f 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1047,8 +1047,6 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         self.undosequence.clear()
         self.linediffer.clear()
 
-        custom_candidates = get_custom_encoding_candidates()
-
         gfiles_enum = [(pane, gfile)
                        for pane, gfile in enumerate(gfiles) if gfile]
 
@@ -1056,27 +1054,34 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
             self.scheduler.add_task(self._compare_files_internal())
 
         for pane, gfile in gfiles_enum:
-            self.fileentry[pane].set_file(gfile)
-            # TODO: filentry handling of URIs
-            self.fileentry[pane].set_sensitive(gfile.is_native())
-            self.msgarea_mgr[pane].clear()
+            self.load_file_in_pane(pane, gfile)
 
-            buf = self.textbuffer[pane]
-            buf.data.reset(gfile)
+    def load_file_in_pane(self, pane: int, gfile: Gio.File):
 
-            if buf.data.is_special:
-                loader = GtkSource.FileLoader.new_from_stream(
-                    buf, buf.data.sourcefile, buf.data.gfile.read())
-            else:
-                loader = GtkSource.FileLoader.new(buf, buf.data.sourcefile)
-
-            if custom_candidates:
-                loader.set_candidate_encodings(custom_candidates)
-            loader.load_async(
-                GLib.PRIORITY_HIGH,
-                callback=self.file_loaded,
-                user_data=(pane,)
-            )
+        self.fileentry[pane].set_file(gfile)
+        # TODO: filentry handling of URIs
+        self.fileentry[pane].set_sensitive(gfile.is_native())
+
+        self.msgarea_mgr[pane].clear()
+
+        buf = self.textbuffer[pane]
+        buf.data.reset(gfile)
+
+        if buf.data.is_special:
+            loader = GtkSource.FileLoader.new_from_stream(
+                buf, buf.data.sourcefile, buf.data.gfile.read())
+        else:
+            loader = GtkSource.FileLoader.new(buf, buf.data.sourcefile)
+
+        custom_candidates = get_custom_encoding_candidates()
+        if custom_candidates:
+            loader.set_candidate_encodings(custom_candidates)
+
+        loader.load_async(
+            GLib.PRIORITY_HIGH,
+            callback=self.file_loaded,
+            user_data=(pane,)
+        )
 
     def get_comparison(self):
         uris = [b.data.gfile for b in self.textbuffer[:self.num_panes]]


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