[meld: 42/63] Merge branch 'master' into Gio; includes non-trivial binary open merge
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld: 42/63] Merge branch 'master' into Gio; includes non-trivial binary open merge
- Date: Wed, 16 Dec 2015 21:22:30 +0000 (UTC)
commit 4317f44cb2cb1b2c59c0b124cd7e6fbf2dff6212
Merge: e1d183f 5d21364
Author: Kai Willadsen <kai willadsen gmail com>
Date: Mon Sep 28 06:54:00 2015 +1000
Merge branch 'master' into Gio; includes non-trivial binary open merge
help/C/keyboard-shortcuts.page | 2 +-
meld/dirdiff.py | 4 +-
meld/filediff.py | 23 +
meld/meldapp.py | 6 +
po/es.po | 82 ++--
po/fi.po | 1232 +++++++++++++++++++++++-----------------
po/hu.po | 460 ++++++++--------
po/pl.po | 300 +++++-----
po/sv.po | 403 +++++++------
setup.py | 5 +-
10 files changed, 1389 insertions(+), 1128 deletions(-)
---
diff --cc meld/filediff.py
index 46231db,0aabdba..928ec40
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@@ -1051,46 -1043,113 +1051,69 @@@ class FileDiff(melddoc.MeldDoc, gnomegl
files = [b.data.filename for b in self.textbuffer[:self.num_panes]]
return recent.TYPE_FILE, files
- def _load_files(self, files, textbuffers):
- self.undosequence.clear()
- yield _("[%s] Set num panes") % self.label_text
- self.set_num_panes( len(files) )
- self._disconnect_buffer_handlers()
- self.linediffer.clear()
- self.queue_draw()
- try_codecs = list(settings.get_value('detect-encodings'))
- try_codecs.append('latin1')
- yield _("[%s] Opening files") % self.label_text
- tasks = []
+ def file_loaded(self, loader, result, user_data):
+
+ gfile = loader.get_location()
+ pane = user_data[0]
+
+ success = False
+ try:
+ success = loader.load_finish(result)
+ except GLib.Error as err:
+ # TODO: Find sane error domain constants
+ if err.domain == 'gtk-source-file-loader-error':
+ # TODO: Add custom reload-with-encoding handling for
+ # GtkSource.FileLoaderError.CONVERSION_FALLBACK and
+ # GtkSource.FileLoaderError.ENCODING_AUTO_DETECTION_FAILED
+ pass
+
+ filename = GLib.markup_escape_text(
+ gfile.get_parse_name()).decode('utf-8')
+ primary = _(
+ u"There was a problem opening the file ā%sā." % filename)
+ self.msgarea_mgr[pane].add_dismissable_msg(
+ Gtk.STOCK_DIALOG_ERROR, primary, err.message)
+
+ buf = loader.get_buffer()
+
+ if success:
+ buf.data.encoding = loader.get_encoding()
+ buf.data.newlines = loader.get_newline_type()
- def add_dismissable_msg(pane, icon, primary, secondary):
++ start, end = buf.get_bounds()
++ buffer_text = buf.get_text(start, end, False)
++ if not buf.data.encoding and '\\00' in buffer_text:
++ primary = _("File %s appears to be a binary file.") % filename
++ secondary = _(
++ "Do you want to open the file using the default application?")
+ msgarea = self.msgarea_mgr[pane].new_from_text_and_icon(
- icon, primary, secondary)
++ Gtk.STOCK_DIALOG_WARNING, primary, secondary)
++ msgarea.add_button(_("Open"), Gtk.ResponseType.ACCEPT)
+ msgarea.add_button(_("Hi_de"), Gtk.ResponseType.CLOSE)
- msgarea.connect("response",
- lambda *args: self.msgarea_mgr[pane].clear())
++
++ def make_binary_callback(pane, filename):
++ def on_binary_file_open(msgarea, response_id, *args):
++ self.msgarea_mgr[pane].clear()
++ if response_id == Gtk.ResponseType.ACCEPT:
++ self._open_files([filename])
++ return on_binary_file_open
++ return on_binary_file_open
++
++ msgarea.connect(
++ "response", make_binary_callback(pane, gfile.get_path()))
+ msgarea.show_all()
- return msgarea
-
- for pane, filename in enumerate(files):
- buf = textbuffers[pane]
- if filename:
- try:
- handle = io.open(filename, "r", encoding=try_codecs[0])
- task = TaskEntry(filename, handle, buf, try_codecs[:],
- pane, False)
- tasks.append(task)
- except (IOError, LookupError) as e:
- buf.delete(*buf.get_bounds())
- add_dismissable_msg(pane, Gtk.STOCK_DIALOG_ERROR,
- _("Could not read file"), str(e))
- yield _("[%s] Reading files") % self.label_text
- while len(tasks):
- for t in tasks[:]:
- try:
- nextbit = t.file.read(4096)
- if nextbit.find("\x00") != -1:
- t.buf.delete(*t.buf.get_bounds())
- filename = GObject.markup_escape_text(t.filename)
-
- primary = _("File %s appears to be a binary file.") % filename
- secondary = _("Do you want to open the file using the default application?")
- msgarea = self.msgarea_mgr[t.pane].new_from_text_and_icon(
- Gtk.STOCK_DIALOG_WARNING, primary, secondary)
- msgarea.add_button(_("Open"), Gtk.ResponseType.ACCEPT)
- msgarea.add_button(_("Hi_de"), Gtk.ResponseType.CLOSE)
-
- def make_binary_callback(pane, filename):
- def on_binary_file_open(msgarea, response_id, *args):
- self.msgarea_mgr[pane].clear()
- if response_id == Gtk.ResponseType.ACCEPT:
- self._open_files([filename])
- return on_binary_file_open
- return on_binary_file_open
-
- msgarea.connect("response", make_binary_callback(t.pane, t.filename))
- msgarea.show_all()
- tasks.remove(t)
- continue
- except ValueError as err:
- t.codec.pop(0)
- if len(t.codec):
- t.buf.delete(*t.buf.get_bounds())
- t.file = io.open(t.filename, "r", encoding=t.codec[0])
- else:
- t.buf.delete(*t.buf.get_bounds())
- filename = GObject.markup_escape_text(t.filename)
- add_dismissable_msg(t.pane, Gtk.STOCK_DIALOG_ERROR,
- _("Could not read file"),
- _("%s is not in encodings: %s") %
- (filename, try_codecs))
- tasks.remove(t)
- except IOError as ioerr:
- add_dismissable_msg(t.pane, Gtk.STOCK_DIALOG_ERROR,
- _("Could not read file"), str(ioerr))
- tasks.remove(t)
- else:
- # The handling here avoids inserting split CR/LF pairs into
- # GtkTextBuffers; this is relevant only when universal
- # newline support is unavailable or broken.
- if t.was_cr:
- nextbit = "\r" + nextbit
- t.was_cr = False
- if len(nextbit):
- if nextbit[-1] == "\r" and len(nextbit) > 1:
- t.was_cr = True
- nextbit = nextbit[0:-1]
- t.buf.insert(t.buf.get_end_iter(), nextbit)
- else:
- if t.buf.data.savefile:
- writable = True
- if os.path.exists(t.buf.data.savefile):
- writable = os.access(
- t.buf.data.savefile, os.W_OK)
- else:
- writable = os.access(t.filename, os.W_OK)
- self.set_buffer_writable(t.buf, writable)
- t.buf.data.encoding = t.codec[0]
- if hasattr(t.file, "newlines"):
- t.buf.data.newlines = t.file.newlines
- tasks.remove(t)
- yield 1
- for b in self.textbuffer:
- self.undosequence.checkpoint(b)
- b.data.update_mtime()
++
+ self.update_buffer_writable(buf)
+
+ self.undosequence.checkpoint(buf)
+ buf.data.update_mtime()
+ buf.data.loaded = True
+
+ if all(b.data.loaded for b in self.textbuffer[:self.num_panes]):
+ self.scheduler.add_task(self._compare_files_internal())
+
+ def _merge_files(self):
+ yield 1
def _diff_files(self, refresh=False):
yield _("[%s] Computing differences") % self.label_text
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]