[gnome-todo] window: Move headerbar to task lists workspace



commit 70e5f62a75216e5686e50776c51a13f44254f743
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Sep 14 15:08:36 2021 -0300

    window: Move headerbar to task lists workspace

 src/gui/gtd-window.c                               | 126 --------------------
 src/gui/gtd-window.ui                              |  65 -----------
 .../gtd-task-lists-workspace.c                     |  25 ++--
 .../gtd-task-lists-workspace.ui                    | 129 +++++++++++----------
 4 files changed, 87 insertions(+), 258 deletions(-)
---
diff --git a/src/gui/gtd-window.c b/src/gui/gtd-window.c
index 279648e9..c516d055 100644
--- a/src/gui/gtd-window.c
+++ b/src/gui/gtd-window.c
@@ -35,7 +35,6 @@
 #include "gtd-panel.h"
 #include "gtd-task.h"
 #include "gtd-task-list.h"
-#include "gtd-theme-selector.h"
 #include "gtd-window.h"
 #include "gtd-workspace.h"
 
@@ -59,25 +58,15 @@ struct _GtdWindow
 {
   AdwApplicationWindow application;
 
-  AdwHeaderBar       *headerbar;
   GtkStack           *stack;
-  GtkMenuButton      *primary_menu_button;
-  GtkBox             *workspace_box_end;
-  GtkBox             *workspace_box_start;
-  GtkListBox         *workspaces_listbox;
-  GtdMenuButton      *workspaces_menu_button;
 
   GtdNotificationWidget *notification_widget;
 
-  GPtrArray          *workspace_header_widgets;
-
   GtdWorkspace       *current_workspace;
   GListStore         *workspaces;
   GVariant           *parameters;
 
   PeasExtensionSet   *workspaces_set;
-
-  guint               toggle_headerbar_revealer_id;
 };
 
 typedef struct
@@ -215,31 +204,6 @@ remove_workspace (GtdWindow    *self,
   g_list_store_remove (self->workspaces, position);
 }
 
-static void
-remove_all_workspace_header_widgets (GtdWindow *self)
-{
-  GtkWidget *parent;
-  GtkWidget *widget;
-  guint i;
-
-  GTD_ENTRY;
-
-  /* remove from the header */
-  for (i = 0; i < self->workspace_header_widgets->len; i++)
-    {
-      widget = g_ptr_array_index (self->workspace_header_widgets, i);
-      parent = gtk_widget_get_parent (widget);
-
-      g_assert (parent == GTK_WIDGET (self->workspace_box_start) ||
-                parent == GTK_WIDGET (self->workspace_box_end));
-      gtk_box_remove (GTK_BOX (parent), widget);
-    }
-
-  g_ptr_array_set_size (self->workspace_header_widgets, 0);
-
-  GTD_EXIT;
-}
-
 
 /*
  * Callbacks
@@ -289,8 +253,6 @@ on_stack_visible_child_cb (GtkStack   *stack,
 
   GTD_ENTRY;
 
-  remove_all_workspace_header_widgets (self);
-
   if (self->current_workspace)
     gtd_workspace_deactivate (self->current_workspace);
 
@@ -303,9 +265,6 @@ on_stack_visible_child_cb (GtkStack   *stack,
   parameters = g_steal_pointer (&self->parameters);
   gtd_workspace_activate (new_workspace, parameters);
 
-  workspace_icon = gtd_workspace_get_icon (new_workspace);
-  gtd_menu_button_set_gicon (self->workspaces_menu_button, workspace_icon);
-
 out:
   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CURRENT_WORKSPACE]);
   GTD_EXIT;
@@ -383,21 +342,6 @@ on_workspace_removed_cb (PeasExtensionSet *extension_set,
   GTD_EXIT;
 }
 
-static void
-on_workspaces_listbox_row_activated_cb (GtkListBox    *workspaces_listbox,
-                                        GtkListBoxRow *row,
-                                        GtdWindow     *self)
-{
-  g_autoptr (GtdWorkspace) workspace = NULL;
-
-  workspace = g_list_model_get_item (G_LIST_MODEL (self->workspaces),
-                                     gtk_list_box_row_get_index (row));
-
-  gtk_stack_set_visible_child (self->stack, GTK_WIDGET (workspace));
-
-  gtd_menu_button_popdown (self->workspaces_menu_button);
-}
-
 static GtkWidget*
 create_workspace_row_func (gpointer item,
                            gpointer user_data)
@@ -475,7 +419,6 @@ gtd_window_finalize (GObject *object)
 {
   GtdWindow *self = GTD_WINDOW (object);
 
-  g_clear_handle_id (&self->toggle_headerbar_revealer_id, g_source_remove);
   g_clear_object (&self->workspaces);
 
   G_OBJECT_CLASS (gtd_window_parent_class)->finalize (object);
@@ -559,26 +502,15 @@ gtd_window_class_init (GtdWindowClass *klass)
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/todo/ui/gtd-window.ui");
 
-  gtk_widget_class_bind_template_child (widget_class, GtdWindow, headerbar);
   gtk_widget_class_bind_template_child (widget_class, GtdWindow, notification_widget);
-  gtk_widget_class_bind_template_child (widget_class, GtdWindow, primary_menu_button);
   gtk_widget_class_bind_template_child (widget_class, GtdWindow, stack);
-  gtk_widget_class_bind_template_child (widget_class, GtdWindow, workspace_box_end);
-  gtk_widget_class_bind_template_child (widget_class, GtdWindow, workspace_box_start);
-  gtk_widget_class_bind_template_child (widget_class, GtdWindow, workspaces_menu_button);
-  gtk_widget_class_bind_template_child (widget_class, GtdWindow, workspaces_listbox);
 
   gtk_widget_class_bind_template_callback (widget_class, on_stack_visible_child_cb);
-  gtk_widget_class_bind_template_callback (widget_class, on_workspaces_listbox_row_activated_cb);
 }
 
 static void
 gtd_window_init (GtdWindow *self)
 {
-  GtkApplication *application;
-  GtkPopover *popover;
-  GMenu *primary_menu;
-
   static const GActionEntry entries[] = {
     { "activate-workspace", on_action_activate_workspace_activated_cb, "(sv)" },
   };
@@ -588,26 +520,10 @@ gtd_window_init (GtdWindow *self)
                                    G_N_ELEMENTS (entries),
                                    self);
 
-  self->workspace_header_widgets = g_ptr_array_new_with_free_func (g_object_unref);
   self->workspaces = g_list_store_new (GTD_TYPE_WORKSPACE);
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
-  gtk_list_box_bind_model (self->workspaces_listbox,
-                           G_LIST_MODEL (self->workspaces),
-                           create_workspace_row_func,
-                           self,
-                           NULL);
-
-  /* Fancy primary menu */
-  application = GTK_APPLICATION (g_application_get_default ());
-  primary_menu = gtk_application_get_menu_by_id (application, "primary-menu");
-  gtk_menu_button_set_menu_model (self->primary_menu_button, G_MENU_MODEL (primary_menu));
-
-  popover = gtk_menu_button_get_popover (self->primary_menu_button);
-  gtk_popover_menu_add_child (GTK_POPOVER_MENU (popover),
-                              gtd_theme_selector_new (),
-                              "theme");
   /* Development build */
   if (is_development_build ())
     setup_development_build (self);
@@ -653,48 +569,6 @@ gtd_window_cancel_notification (GtdWindow       *self,
   gtd_notification_widget_cancel (self->notification_widget, notification);
 }
 
-/**
- * gtd_window_embed_widget_in_header:
- * @self: a #GtdWindow
- * @widget: a #GtkWidget
- * @position: either @GTK_POS_LEFT or @GTK_POS_RIGHT
- *
- * Embeds @widget into @self's header bar.
- */
-void
-gtd_window_embed_widget_in_header (GtdWindow       *self,
-                                   GtkWidget       *widget,
-                                   GtkPositionType  position)
-{
-  g_return_if_fail (GTD_IS_WINDOW (self));
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-
-  GTD_ENTRY;
-
-  /* add to header */
-  switch (position)
-    {
-    case GTK_POS_RIGHT:
-      gtk_box_append (self->workspace_box_end, widget);
-      break;
-
-    case GTK_POS_LEFT:
-      gtk_box_append (self->workspace_box_start, widget);
-      break;
-
-    case GTK_POS_TOP:
-    case GTK_POS_BOTTOM:
-    default:
-      g_warning ("Invalid position passed");
-      return;
-    }
-
-  g_ptr_array_add (self->workspace_header_widgets, g_object_ref (widget));
-
-  GTD_EXIT;
-
-}
-
 GtdWorkspace*
 gtd_window_get_current_workspace (GtdWindow *self)
 {
diff --git a/src/gui/gtd-window.ui b/src/gui/gtd-window.ui
index 25545da1..8e87532b 100644
--- a/src/gui/gtd-window.ui
+++ b/src/gui/gtd-window.ui
@@ -28,47 +28,6 @@
             <property name="orientation">vertical</property>
             <property name="hexpand">true</property>
 
-            <child>
-              <object class="AdwHeaderBar" id="headerbar">
-                <property name="hexpand">1</property>
-                <property name="show-end-title-buttons">1</property>
-
-                <!-- Workspace Button -->
-                <child>
-                  <object class="GtdMenuButton" id="workspaces_menu_button">
-                    <property name="visible">false</property>
-                    <property name="can_focus">1</property>
-                    <property name="popover">workspaces_popover</property>
-                  </object>
-                </child>
-
-                <child>
-                  <object class="GtkBox" id="workspace_box_start">
-                    <property name="spacing">6</property>
-                  </object>
-                </child>
-
-                <!-- Omni Area -->
-                <child type="title">
-                  <object class="GtdOmniArea" id="omni_area">
-                  </object>
-                </child>
-
-
-                <child type="end">
-                  <object class="GtkMenuButton" id="primary_menu_button">
-                    <property name="icon-name">open-menu-symbolic</property>
-                  </object>
-                </child>
-
-                <child type="end">
-                  <object class="GtkBox" id="workspace_box_end">
-                    <property name="spacing">6</property>
-                  </object>
-                </child>
-              </object>
-            </child>
-
             <child>
               <object class="GtkOverlay" id="overlay">
                 <child type="overlay">
@@ -103,28 +62,4 @@
     </child>
 
   </template>
-
-  <!-- Workspaces Popover -->
-  <object class="GtkPopover" id="workspaces_popover">
-    <style>
-      <class name="custom-menu" />
-    </style>
-    <child>
-      <object class="GtkBox">
-        <property name="width-request">150</property>
-
-        <child>
-          <object class="GtkListBox" id="workspaces_listbox">
-            <property name="hexpand">true</property>
-            <property name="selection-mode">none</property>
-            <signal name="row-activated" handler="on_workspaces_listbox_row_activated_cb" object="GtdWindow" 
swapped="no" />
-            <style>
-              <class name="transparent" />
-            </style>
-          </object>
-        </child>
-
-      </object>
-    </child>
-  </object>
 </interface>
diff --git a/src/plugins/task-lists-workspace/gtd-task-lists-workspace.c 
b/src/plugins/task-lists-workspace/gtd-task-lists-workspace.c
index afc17ec6..58566183 100644
--- a/src/plugins/task-lists-workspace/gtd-task-lists-workspace.c
+++ b/src/plugins/task-lists-workspace/gtd-task-lists-workspace.c
@@ -26,6 +26,7 @@
 #include "task-lists-workspace.h"
 #include "gtd-sidebar.h"
 #include "gtd-task-list-panel.h"
+#include "gtd-theme-selector.h"
 
 #include <libpeas/peas.h>
 #include <glib/gi18n.h>
@@ -35,13 +36,12 @@ struct _GtdTaskListsWorkspace
   GtkBox              parent;
 
   GtkWidget          *back_button;
-  GtkWidget          *end_box;
   GtkMenuButton      *gear_menu_button;
   GtkWidget          *new_list_button;
   GtkBox             *panel_box_end;
   GtkBox             *panel_box_start;
+  GtkMenuButton      *primary_menu_button;
   GtkStack           *stack;
-  GtkWidget          *start_box;
   GtdSidebar         *sidebar;
   GtkWidget          *toggle_sidebar_button;
 
@@ -320,10 +320,6 @@ gtd_task_lists_workspace_activate (GtdWorkspace *workspace,
                                    GVariant     *parameters)
 {
   GtdTaskListsWorkspace *self = GTD_TASK_LISTS_WORKSPACE (workspace);
-  GtdWindow *window = GTD_WINDOW (gtk_widget_get_root (GTK_WIDGET (self)));
-
-  gtd_window_embed_widget_in_header (window, self->start_box, GTK_POS_LEFT);
-  gtd_window_embed_widget_in_header (window, self->end_box, GTK_POS_RIGHT);
 
   if (parameters)
     {
@@ -490,14 +486,13 @@ gtd_task_lists_workspace_class_init (GtdTaskListsWorkspaceClass *klass)
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/todo/plugins/task-lists-workspace/gtd-task-lists-workspace.ui");
 
   gtk_widget_class_bind_template_child (widget_class, GtdTaskListsWorkspace, back_button);
-  gtk_widget_class_bind_template_child (widget_class, GtdTaskListsWorkspace, end_box);
   gtk_widget_class_bind_template_child (widget_class, GtdTaskListsWorkspace, gear_menu_button);
   gtk_widget_class_bind_template_child (widget_class, GtdTaskListsWorkspace, new_list_button);
   gtk_widget_class_bind_template_child (widget_class, GtdTaskListsWorkspace, panel_box_end);
   gtk_widget_class_bind_template_child (widget_class, GtdTaskListsWorkspace, panel_box_start);
+  gtk_widget_class_bind_template_child (widget_class, GtdTaskListsWorkspace, primary_menu_button);
   gtk_widget_class_bind_template_child (widget_class, GtdTaskListsWorkspace, sidebar);
   gtk_widget_class_bind_template_child (widget_class, GtdTaskListsWorkspace, stack);
-  gtk_widget_class_bind_template_child (widget_class, GtdTaskListsWorkspace, start_box);
   gtk_widget_class_bind_template_child (widget_class, GtdTaskListsWorkspace, toggle_sidebar_button);
 
   gtk_widget_class_bind_template_callback (widget_class, on_back_button_clicked_cb);
@@ -507,6 +502,10 @@ gtd_task_lists_workspace_class_init (GtdTaskListsWorkspaceClass *klass)
 static void
 gtd_task_lists_workspace_init (GtdTaskListsWorkspace *self)
 {
+  GtkApplication *application;
+  GtkPopover *popover;
+  GMenu *primary_menu;
+
   static const GActionEntry entries[] = {
     { "activate-panel", on_action_activate_panel_activated_cb, "(sv)" },
     { "toggle-archive", on_action_toggle_archive_activated_cb, "b" },
@@ -534,6 +533,16 @@ gtd_task_lists_workspace_init (GtdTaskListsWorkspace *self)
   gtd_sidebar_set_panel_stack (self->sidebar, self->stack);
   gtd_sidebar_set_task_list_panel (self->sidebar, self->task_list_panel);
 
+  /* Fancy primary menu */
+  application = GTK_APPLICATION (g_application_get_default ());
+  primary_menu = gtk_application_get_menu_by_id (application, "primary-menu");
+  gtk_menu_button_set_menu_model (self->primary_menu_button, G_MENU_MODEL (primary_menu));
+
+  popover = gtk_menu_button_get_popover (self->primary_menu_button);
+  gtk_popover_menu_add_child (GTK_POPOVER_MENU (popover),
+                              gtd_theme_selector_new (),
+                              "theme");
+
 }
 
 GtdWorkspace*
diff --git a/src/plugins/task-lists-workspace/gtd-task-lists-workspace.ui 
b/src/plugins/task-lists-workspace/gtd-task-lists-workspace.ui
index 8c98506e..57f7c1f0 100644
--- a/src/plugins/task-lists-workspace/gtd-task-lists-workspace.ui
+++ b/src/plugins/task-lists-workspace/gtd-task-lists-workspace.ui
@@ -1,6 +1,76 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <template class="GtdTaskListsWorkspace" parent="GtkBox">
+    <property name="orientation">vertical</property>
+
+    <child>
+      <object class="AdwHeaderBar" id="headerbar">
+        <property name="hexpand">1</property>
+        <property name="show-end-title-buttons">1</property>
+
+        <!-- New List -->
+        <child>
+          <object class="GtkMenuButton" id="new_list_button">
+            <property name="can_focus">1</property>
+            <property name="label" translatable="yes">New List</property>
+            <property name="receives_default">1</property>
+            <property name="popover">new_list_popover</property>
+            <property name="halign">start</property>
+          </object>
+        </child>
+
+        <child>
+          <object class="GtkButton" id="back_button">
+            <property name="visible" bind-source="new_list_button" bind-property="visible" 
bind-flags="sync-create|invert-boolean" />
+            <property name="can_focus">1</property>
+            <property name="receives_default">1</property>
+            <property name="halign">start</property>
+            <property name="icon-name">go-previous-symbolic</property>
+            <signal name="clicked" handler="on_back_button_clicked_cb" object="GtdTaskListsWorkspace" 
swapped="no" />
+          </object>
+        </child>
+
+        <child>
+          <object class="GtkToggleButton" id="toggle_sidebar_button">
+            <property name="can_focus">1</property>
+            <property name="icon-name">builder-view-left-pane-symbolic</property>
+            <property name="active" bind-source="flap" bind-property="reveal-flap" 
bind-flags="sync-create|bidirectional"/>
+          </object>
+        </child>
+
+        <child>
+          <object class="GtkBox" id="panel_box_start">
+            <property name="spacing">6</property>
+          </object>
+        </child>
+
+        <!-- Omni Area -->
+        <child type="title">
+          <object class="GtdOmniArea" id="omni_area">
+          </object>
+        </child>
+
+        <child type="end">
+          <object class="GtkMenuButton" id="primary_menu_button">
+            <property name="icon-name">open-menu-symbolic</property>
+          </object>
+        </child>
+
+        <child type="end">
+          <object class="GtkMenuButton" id="gear_menu_button">
+            <property name="can_focus">1</property>
+            <property name="icon-name">view-more-symbolic</property>
+          </object>
+        </child>
+
+        <child type="end">
+          <object class="GtkBox" id="panel_box_end">
+            <property name="spacing">6</property>
+          </object>
+        </child>
+
+      </object>
+    </child>
 
     <child>
       <object class="AdwFlap" id="flap">
@@ -37,65 +107,6 @@
 
   </template>
 
-  <!-- Start -->
-  <object class="GtkBox" id="start_box">
-    <property name="spacing">6</property>
-
-    <!-- New List -->
-    <child>
-      <object class="GtkMenuButton" id="new_list_button">
-        <property name="can_focus">1</property>
-        <property name="label" translatable="yes">New List</property>
-        <property name="receives_default">1</property>
-        <property name="popover">new_list_popover</property>
-        <property name="halign">start</property>
-      </object>
-    </child>
-
-    <child>
-      <object class="GtkButton" id="back_button">
-        <property name="visible" bind-source="new_list_button" bind-property="visible" 
bind-flags="sync-create|invert-boolean" />
-        <property name="can_focus">1</property>
-        <property name="receives_default">1</property>
-        <property name="halign">start</property>
-        <property name="icon-name">go-previous-symbolic</property>
-        <signal name="clicked" handler="on_back_button_clicked_cb" object="GtdTaskListsWorkspace" 
swapped="no" />
-      </object>
-    </child>
-
-    <child>
-      <object class="GtkToggleButton" id="toggle_sidebar_button">
-        <property name="can_focus">1</property>
-        <property name="icon-name">builder-view-left-pane-symbolic</property>
-        <property name="active" bind-source="flap" bind-property="reveal-flap" 
bind-flags="sync-create|bidirectional"/>
-      </object>
-    </child>
-
-    <child>
-      <object class="GtkBox" id="panel_box_start">
-        <property name="spacing">6</property>
-      </object>
-    </child>
-  </object>
-
-  <!-- End -->
-  <object class="GtkBox" id="end_box">
-    <property name="spacing">6</property>
-
-    <child>
-      <object class="GtkMenuButton" id="gear_menu_button">
-        <property name="can_focus">1</property>
-        <property name="icon-name">view-more-symbolic</property>
-      </object>
-    </child>
-
-    <child>
-      <object class="GtkBox" id="panel_box_end">
-        <property name="spacing">6</property>
-      </object>
-    </child>
-  </object>
-
   <object class="GtdProviderPopover" id="new_list_popover">
     <property name="position">bottom</property>
   </object>


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