[meld] meldapp: Fix multiple file open from remote instance (bgo#783989)



commit 4969d14f4ac77a6ff2c4de3682cdae98d8e384b4
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Wed Jun 28 07:24:25 2017 +1000

    meldapp: Fix multiple file open from remote instance (bgo#783989)

 meld/meldapp.py |   44 +++++++++++++++++++++++++++++++++-----------
 1 files changed, 33 insertions(+), 11 deletions(-)
---
diff --git a/meld/meldapp.py b/meld/meldapp.py
index c1bbafc..7e98f67 100644
--- a/meld/meldapp.py
+++ b/meld/meldapp.py
@@ -141,18 +141,22 @@ class MeldApp(Gtk.Application):
     def get_meld_window(self):
         return self.get_active_window().meldwindow
 
-    def open_files(self, files, **kwargs):
-        new_tab = kwargs.pop('new_tab')
-        if new_tab:
-            window = self.get_meld_window()
-        else:
-            window = self.new_window()
+    def open_files(
+            self, files, *, window=None, close_on_error=False, **kwargs):
+        """Open a comparison between files in a Meld window
+
+        :param files: list of Gio.File to be compared
+        :param window: window in which to open comparison tabs; if
+            None, the current window is used
+        :param close_on_error: if true, close window if an error occurs
+        """
+        window = window or self.get_meld_window()
 
         paths = [f.get_path() for f in files]
         try:
             return window.open_paths(paths, **kwargs)
         except ValueError:
-            if not new_tab:
+            if close_on_error:
                 self.remove_window(window.widget)
             raise
 
@@ -320,7 +324,22 @@ class MeldApp(Gtk.Application):
         tab = None
         error = None
         comparisons = [args] + options.diff
-        options.newtab = options.newtab or not command_line.get_is_remote()
+
+        # Every Meld invocation creates at most one window. If there is
+        # no existing application, a window is created in do_startup().
+        # If there is an existing application, then this is a remote
+        # invocation, in which case we'll create a window if and only
+        # if the new-tab flag is not provided.
+        #
+        # In all cases, all tabs newly created here are attached to the
+        # same window, either implicitly by using the most-recently-
+        # focused window, or explicitly as below.
+        window = None
+        close_on_error = False
+        if command_line.get_is_remote() and not options.newtab:
+            window = self.new_window()
+            close_on_error = True
+
         for i, paths in enumerate(comparisons):
             files = [make_file_from_command_line(p) for p in paths]
             auto_merge = options.auto_merge and i == 0
@@ -329,9 +348,12 @@ class MeldApp(Gtk.Application):
                     if f.get_path() is None:
                         raise ValueError(_("invalid path or URI \"%s\"") % p)
                 tab = self.open_files(
-                    files, auto_compare=options.auto_compare,
-                    auto_merge=auto_merge, new_tab=options.newtab,
-                    focus=i == 0)
+                    files, window=window,
+                    close_on_error=close_on_error,
+                    auto_compare=options.auto_compare,
+                    auto_merge=auto_merge,
+                    focus=i == 0,
+                )
             except ValueError as err:
                 error = err
                 log.debug("Couldn't open comparison: %s", error, exc_info=True)


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