[console/zbrown/term-intent-2: 3/4] window: make tabs optional [WIP]




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

    window: make tabs optional [WIP]

 src/kgx-application.c |  2 ++
 src/kgx-window.c      | 26 ++++++++++++++++++++++++++
 src/kgx-window.ui     |  2 +-
 3 files changed, 29 insertions(+), 1 deletion(-)
---
diff --git a/src/kgx-application.c b/src/kgx-application.c
index 0e63927..5ce0d4d 100644
--- a/src/kgx-application.c
+++ b/src/kgx-application.c
@@ -420,12 +420,14 @@ handle_launch (XdgTerminal1          *xdg_term,
     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 {
     window = g_object_new (KGX_TYPE_WINDOW,
                            "application", self,
+                           "can-have-tabs", FALSE,
                            NULL);
 
     title = g_path_get_basename (exec[0]);
diff --git a/src/kgx-window.c b/src/kgx-window.c
index afc1679..c7f00b7 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,8 @@ 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]