[gnome-builder/wip/gtk4-port] libide/terminal: add helper to compare terminals



commit 54b7ff5f00ba6692fbc28ff321dedc8c0336eecd
Author: Christian Hergert <chergert redhat com>
Date:   Fri May 6 16:53:46 2022 -0700

    libide/terminal: add helper to compare terminals
    
    We can use this to determine if we can copy the cwd to a new launcher or
    if it is likely to fail/cause the terminal to not be able to spawn.

 src/libide/terminal/ide-terminal-launcher.c | 31 +++++++++++++++++++++++++++++
 src/libide/terminal/ide-terminal-page.c     | 16 +++++++++++++++
 src/libide/terminal/ide-terminal-page.h     |  2 ++
 src/libide/terminal/ide-terminal-private.h  |  6 +++++-
 4 files changed, 54 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/terminal/ide-terminal-launcher.c b/src/libide/terminal/ide-terminal-launcher.c
index 2f13cebb1..28ab4d4e6 100644
--- a/src/libide/terminal/ide-terminal-launcher.c
+++ b/src/libide/terminal/ide-terminal-launcher.c
@@ -934,3 +934,34 @@ ide_terminal_launcher_set_args (IdeTerminalLauncher *self,
       g_strfreev (freeme);
     }
 }
+
+gboolean
+_ide_terminal_launcher_are_similar (IdeTerminalLauncher *a,
+                                    IdeTerminalLauncher *b)
+{
+  g_return_val_if_fail (IDE_IS_TERMINAL_LAUNCHER (a), FALSE);
+  g_return_val_if_fail (IDE_IS_TERMINAL_LAUNCHER (b), FALSE);
+
+  if (a->kind != b->kind)
+    return FALSE;
+
+  switch (a->kind)
+    {
+      case LAUNCHER_KIND_HOST:
+      case LAUNCHER_KIND_DEBUG:
+        return TRUE;
+
+      case LAUNCHER_KIND_RUNTIME:
+      case LAUNCHER_KIND_RUNNER:
+        return a->runtime == b->runtime;
+
+      case LAUNCHER_KIND_CONFIG:
+        return a->config == b->config;
+
+      case LAUNCHER_KIND_LAUNCHER:
+        return FALSE;
+
+      default:
+        return FALSE;
+    }
+}
diff --git a/src/libide/terminal/ide-terminal-page.c b/src/libide/terminal/ide-terminal-page.c
index 99a59e547..6b77069f5 100644
--- a/src/libide/terminal/ide-terminal-page.c
+++ b/src/libide/terminal/ide-terminal-page.c
@@ -607,3 +607,19 @@ ide_terminal_page_get_current_directory_uri (IdeTerminalPage *self)
 
   return vte_terminal_get_current_directory_uri (VTE_TERMINAL (self->terminal));
 }
+
+/**
+ * ide_terminal_page_get_launcher:
+ * @self: a #IdeTerminalPage
+ *
+ * Gets the launcher for the page.
+ *
+ * Returns: (transfer none) (nullable): an #IdeTerminalLauncher or %NULL
+ */
+IdeTerminalLauncher *
+ide_terminal_page_get_launcher (IdeTerminalPage *self)
+{
+  g_return_val_if_fail (IDE_IS_TERMINAL_PAGE (self), NULL);
+
+  return self->launcher;
+}
diff --git a/src/libide/terminal/ide-terminal-page.h b/src/libide/terminal/ide-terminal-page.h
index 5e2211a4d..1da69b9d1 100644
--- a/src/libide/terminal/ide-terminal-page.h
+++ b/src/libide/terminal/ide-terminal-page.h
@@ -40,6 +40,8 @@ G_DECLARE_FINAL_TYPE (IdeTerminalPage, ide_terminal_page, IDE, TERMINAL_PAGE, Id
 IDE_AVAILABLE_IN_3_34
 void         ide_terminal_page_set_launcher              (IdeTerminalPage     *self,
                                                           IdeTerminalLauncher *launcher);
+IDE_AVAILABLE_IN_ALL
+IdeTerminalLauncher *ide_terminal_page_get_launcher (IdeTerminalPage *self);
 IDE_AVAILABLE_IN_3_32
 void         ide_terminal_page_set_pty                   (IdeTerminalPage     *self,
                                                           VtePty              *pty);
diff --git a/src/libide/terminal/ide-terminal-private.h b/src/libide/terminal/ide-terminal-private.h
index d9015f5b6..9eb7f1d05 100644
--- a/src/libide/terminal/ide-terminal-private.h
+++ b/src/libide/terminal/ide-terminal-private.h
@@ -22,8 +22,12 @@
 
 #include <glib.h>
 
+#include "ide-terminal-launcher.h"
+
 G_BEGIN_DECLS
 
-void _ide_terminal_init (void);
+void     _ide_terminal_init                 (void);
+gboolean _ide_terminal_launcher_are_similar (IdeTerminalLauncher *a,
+                                             IdeTerminalLauncher *b);
 
 G_END_DECLS


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