Commit 9b92209a authored by Kai Willadsen's avatar Kai Willadsen

filediff: Add an encoding kwargs to set_files() that overrides detection

This could be passed through from a file selector change, or some
reload-with-new-encoding UI, or  conceivably from an error-case prompt
(i.e., this failed decoding as UTF-16 do you want to try whatever).
parent 6f91fe06
......@@ -1035,7 +1035,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
self.tooltip_text = self.label_text
def set_files(self, gfiles):
def set_files(self, gfiles, encodings=None):
"""Load the given files
If an element is None, the text of a pane is left as is.
......@@ -1047,16 +1047,33 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
gfiles_enum = [(pane, gfile)
for pane, gfile in enumerate(gfiles) if gfile]
encodings = encodings or ((None,) * len(gfiles))
if not gfiles_enum:
files = [
(pane, gfile, encoding)
for pane, (gfile, encoding) in enumerate(zip(gfiles, encodings))
if gfile
for pane, gfile in gfiles_enum:
self.load_file_in_pane(pane, gfile)
if not files:
def load_file_in_pane(self, pane: int, gfile: Gio.File):
for pane, gfile, encoding in files:
self.load_file_in_pane(pane, gfile, encoding)
def load_file_in_pane(
pane: int,
gfile: Gio.File,
encoding: GtkSource.Encoding = None):
"""Load a file into the given pane
Don't call this directly; use `set_file()` or `set_files()`,
which handle sensitivity and signal connection. Even if you
don't care about those things, you need it because they'll be
unconditionally added after file load, which will cause
duplicate handlers, etc. if you don't do this thing.
# TODO: filentry handling of URIs
......@@ -1074,6 +1091,8 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
loader =,
custom_candidates = get_custom_encoding_candidates()
if encoding:
custom_candidates = [encoding]
if custom_candidates:
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment