[console/zbrown/term-intent: 4/6] custom id wip




commit 3ac5e474b2cdd563e926568e6a1b2fd31dfe4d59
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      | 29 ++++++++++++++++++++++++++++-
 src/kgx-window.ui     |  2 +-
 3 files changed, 67 insertions(+), 9 deletions(-)
---
diff --git a/src/kgx-application.c b/src/kgx-application.c
index e146ad3..aff83e6 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"
@@ -435,16 +437,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 d23f38e..30520de 100644
--- a/src/kgx-window.c
+++ b/src/kgx-window.c
@@ -69,10 +69,12 @@ struct _KgxWindowPrivate {
   GtkWidget            *tab_button;
   GtkWidget            *tab_switcher;
   GtkWidget            *pages;
+  GtkWidget            *new_tab;
 
   int                   current_width;
   int                   current_height;
   gboolean              is_maximized_or_tiled;
+  gboolean              can_have_tabs;
 
   GActionMap           *tab_actions;
 };
@@ -83,6 +85,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (KgxWindow, kgx_window, HDY_TYPE_APPLICATION_WINDOW)
 enum {
   PROP_0,
   PROP_APPLICATION,
+  PROP_CAN_HAVE_TABS,
   LAST_PROP
 };
 
@@ -123,6 +126,7 @@ kgx_window_constructed (GObject *object)
   KgxWindowPrivate *priv = kgx_window_get_instance_private (self);
   GtkApplication *application;
   HdyStyleManager *style_manager;
+  GAction *action;
 
   G_OBJECT_CLASS (kgx_window_parent_class)->constructed (object);
 
@@ -158,6 +162,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);
 }
 
 
@@ -180,12 +189,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;
@@ -200,12 +213,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;
@@ -467,6 +484,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,
@@ -481,7 +504,8 @@ kgx_window_class_init (KgxWindowClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, KgxWindow, tab_button);
   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, new_tab);
+ 
   gtk_widget_class_bind_template_callback (widget_class, active_changed);
   gtk_widget_class_bind_template_callback (widget_class, key_press_event);
 
@@ -685,6 +709,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 be7ad83..3c2348c 100644
--- a/src/kgx-window.ui
+++ b/src/kgx-window.ui
@@ -160,7 +160,7 @@
                   </packing>
                 </child>
                 <child>
-                  <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]