[meld] filediff, ui.statusbar: Add encoding-changed signal and hook it up



commit 56d4b275a55a768e6d27ce980925f067a9249c96
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Tue Nov 21 06:32:59 2017 +1000

    filediff, ui.statusbar: Add encoding-changed signal and hook it up
    
    With the other API changes and cleanups around file loading, this is now
    straightforward: just add a signal, emit it and have FileDiff listen and
    reload files with their new encoding when it fires.

 meld/filediff.py     |    6 ++++++
 meld/ui/statusbar.py |    6 ++++++
 2 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index f8c12a7..234b93a 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -232,6 +232,12 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                 'encoding', statusbar, 'source-encoding',
                 GObject.BindingFlags.DEFAULT)
 
+            def reload_with_encoding(widget, encoding, pane):
+                self.set_file(pane, self.textbuffer[pane].data.gfile, encoding)
+
+            pane = self.statusbar.index(statusbar)
+            statusbar.connect('encoding-changed', reload_with_encoding, pane)
+
         # Prototype implementation
 
         from meld.gutterrendererchunk import GutterRendererChunkAction, GutterRendererChunkLines
diff --git a/meld/ui/statusbar.py b/meld/ui/statusbar.py
index 4380ffa..f9c0620 100644
--- a/meld/ui/statusbar.py
+++ b/meld/ui/statusbar.py
@@ -101,6 +101,11 @@ class MeldStatusMenuButton(Gtk.MenuButton):
 class MeldStatusBar(Gtk.Statusbar):
     __gtype_name__ = "MeldStatusBar"
 
+    __gsignals__ = {
+        'encoding-changed': (
+            GObject.SignalFlags.RUN_FIRST, None, (GtkSource.Encoding,)),
+    }
+
     source_encoding = GObject.property(
         type=GtkSource.Encoding,
         nick="The file encoding displayed in the status bar",
@@ -142,6 +147,7 @@ class MeldStatusBar(Gtk.Statusbar):
     def construct_encoding_selector(self):
         def change_encoding(selector, encoding):
             self.props.source_encoding = encoding
+            self.emit('encoding-changed', encoding)
             pop.hide()
 
         def set_initial_encoding(selector):


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