[console/zbrown/term-intent-2: 21/24] custom id wip




commit 714c166b7f4a281ef380c82366b5e77863805ae8
Author: Zander Brown <zbrown gnome org>
Date:   Thu Dec 9 11:47:59 2021 +0000

    custom id wip

 src/kgx-application.c | 45 ++++++++++++++++++++++++++++++++++++++-------
 src/kgx-window.c      | 27 +++++++++++++++++++++++++++
 src/kgx-window.ui     |  2 +-
 3 files changed, 66 insertions(+), 8 deletions(-)
---
diff --git a/src/kgx-application.c b/src/kgx-application.c
index c1352db..845fcb1 100644
--- a/src/kgx-application.c
+++ b/src/kgx-application.c
@@ -29,6 +29,7 @@
 #include "kgx-config.h"
 
 #include <glib/gi18n.h>
+#include <gio/gdesktopappinfo.h>
 #include <vte/vte.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
@@ -37,6 +38,7 @@
 
 #include "kgx-application.h"
 #include "kgx-window.h"
+#include "kgx-term-app-window.h"
 #include "kgx-pages.h"
 #include "kgx-simple-tab.h"
 #include "kgx-resources.h"
@@ -398,16 +400,45 @@ handle_launch (XdgTerminal1          *xdg_term,
                GVariant              *platform_data,
                KgxApplication        *self)
 {
-  /* TODO: entry - new instance? title? */
+  g_autofree char *title = NULL;
+  g_autoptr (GFile) working = NULL;
+  KgxWindow *window = NULL;
+  guint32 timezone = GDK_CURRENT_TIME;
+
+  if (working_directory) {
+    working = g_file_new_for_path (working_directory);
+  }
+
   /* TODO: env */
   /* TODO: options - keep open? */
 
-  kgx_application_add_terminal (self,
-                                NULL,
-                                -1,
-                                g_file_new_for_path (working_directory),
-                                exec,
-                                NULL);
+  if (desktop_entry && desktop_entry[0] != '\0') {
+    g_autoptr (GDesktopAppInfo) entry = NULL;
+
+    entry = g_desktop_app_info_new_from_filename (desktop_entry);
+
+    window = g_object_new (KGX_TYPE_TERM_APP_WINDOW,
+                           "application", self,
+                           "desktop-entry", entry,
+                           "can-have-tabs", FALSE,
+                           NULL);
+
+    title = g_strdup (g_app_info_get_name (G_APP_INFO (entry)));
+  } else {
+    g_auto (GStrv) parts = NULL;
+    g_autoptr (GError) error = NULL;
+
+    g_shell_parse_argv (exec, NULL, &parts, &error);
+
+    window = g_object_new (KGX_TYPE_WINDOW,
+                           "application", self,
+                           "can-have-tabs", FALSE,
+                           NULL);
+
+    title = g_path_get_basename (parts[0]);
+  }
+
+  kgx_application_add_terminal (self, window, timezone, working, exec, title);
 
   xdg_terminal1_complete_launch_command (xdg_term, invocation);
 }
diff --git a/src/kgx-window.c b/src/kgx-window.c
index afc1679..eb3b711 100644
--- a/src/kgx-window.c
+++ b/src/kgx-window.c
@@ -65,10 +65,12 @@ struct _KgxWindowPrivate {
   GtkWidget            *tab_switcher;
   GtkWidget            *pages;
   GMenu                *primary_menu;
+  GtkWidget            *new_tab;
 
   int                   current_width;
   int                   current_height;
   gboolean              is_maximized_or_tiled;
+  gboolean              can_have_tabs;
 
   GActionMap           *tab_actions;
 };
@@ -79,6 +81,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (KgxWindow, kgx_window, ADW_TYPE_APPLICATION_WINDOW)
 enum {
   PROP_0,
   PROP_APPLICATION,
+  PROP_CAN_HAVE_TABS,
   LAST_PROP
 };
 
@@ -119,6 +122,7 @@ kgx_window_constructed (GObject *object)
   KgxWindowPrivate *priv = kgx_window_get_instance_private (self);
   GtkApplication *application = NULL;
   AdwStyleManager *style_manager;
+  GAction *action;
 
   G_OBJECT_CLASS (kgx_window_parent_class)->constructed (object);
 
@@ -154,6 +158,11 @@ kgx_window_constructed (GObject *object)
                            0);
 
   update_zoom (self, KGX_APPLICATION (application));
+
+  action = g_action_map_lookup_action (G_ACTION_MAP (self), "new-tab");
+  g_simple_action_set_enabled (G_SIMPLE_ACTION (action), priv->can_have_tabs);
+
+  gtk_widget_set_visible (priv->new_tab, priv->can_have_tabs);
 }
 
 
@@ -176,12 +185,16 @@ kgx_window_set_property (GObject      *object,
                          GParamSpec   *pspec)
 {
   KgxWindow *self = KGX_WINDOW (object);
+  KgxWindowPrivate *priv = kgx_window_get_instance_private (self);
 
   switch (property_id) {
     case PROP_APPLICATION:
       gtk_window_set_application (GTK_WINDOW (self),
                                   g_value_get_object (value));
       break;
+    case PROP_CAN_HAVE_TABS:
+      priv->can_have_tabs = g_value_get_boolean (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -196,12 +209,16 @@ kgx_window_get_property (GObject    *object,
                          GParamSpec *pspec)
 {
   KgxWindow *self = KGX_WINDOW (object);
+  KgxWindowPrivate *priv = kgx_window_get_instance_private (self);
 
   switch (property_id) {
     case PROP_APPLICATION:
       g_value_set_object (value,
                           gtk_window_get_application (GTK_WINDOW (self)));
       break;
+    case PROP_CAN_HAVE_TABS:
+      g_value_set_boolean (value, priv->can_have_tabs);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -428,6 +445,12 @@ kgx_window_class_init (KgxWindowClass *klass)
                          KGX_TYPE_APPLICATION,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
 
+  pspecs[PROP_CAN_HAVE_TABS] =
+    g_param_spec_boolean ("can-have-tabs", "Can have tabs",
+                          "Can this window contain multiple tabs",
+                          TRUE,
+                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+
   g_object_class_install_properties (object_class, LAST_PROP, pspecs);
 
   gtk_widget_class_set_template_from_resource (widget_class,
@@ -443,6 +466,7 @@ kgx_window_class_init (KgxWindowClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, KgxWindow, tab_switcher);
   gtk_widget_class_bind_template_child_private (widget_class, KgxWindow, pages);
   gtk_widget_class_bind_template_child_private (widget_class, KgxWindow, primary_menu);
+  gtk_widget_class_bind_template_child_private (widget_class, KgxWindow, new_tab);
 
   gtk_widget_class_bind_template_callback (widget_class, active_changed);
 
@@ -644,6 +668,9 @@ kgx_window_init (KgxWindow *self)
   g_type_ensure (KGX_TYPE_TAB_SWITCHER);
   g_type_ensure (KGX_TYPE_THEME_SWITCHER);
 
+  priv->can_have_tabs = TRUE;
+
+
   gtk_widget_init_template (GTK_WIDGET (self));
 
   g_action_map_add_action_entries (G_ACTION_MAP (self),
diff --git a/src/kgx-window.ui b/src/kgx-window.ui
index 9c44f25..87109ea 100644
--- a/src/kgx-window.ui
+++ b/src/kgx-window.ui
@@ -124,7 +124,7 @@
                   </object>
                 </child>
                 <child type="end">
-                  <object class="GtkButton">
+                  <object class="GtkButton" id="new_tab">
                     <property name="visible" bind-source="tab_switcher" bind-property="narrow" 
bind-flags="sync-create|invert-boolean"/>
                     <property name="can-focus">0</property>
                     <property name="receives-default">0</property>


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