[gnome-calendar/wip/cdavis/use-leaflet: 26/28] general: Use GcalToolbarEnd for toolbars
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/cdavis/use-leaflet: 26/28] general: Use GcalToolbarEnd for toolbars
- Date: Fri, 12 Aug 2022 03:00:09 +0000 (UTC)
commit 9444d998ff7733e5dfcdd05995c3cbcb5004c7c6
Author: Christopher Davis <christopherdavis gnome org>
Date: Wed Jul 20 12:18:22 2022 -0400
general: Use GcalToolbarEnd for toolbars
For the sake of smooth adaptivity, we need the toolbar buttons
to be constant in both modes instead of moving places from one
mode to another. Instead of duplicating these groups of
buttons, we can refactor them into an object for toolbars
and use them in multiple places.
This commit takes the widgets from the end of the header bar and
creates `GcalToolbarEnd`, which is used in the header bar and the
mobile action bar.
src/gui/gcal-toolbar-end.c | 47 +++++++++++++++++++++++++++++++++++++++++++++
src/gui/gcal-toolbar-end.h | 32 ++++++++++++++++++++++++++++++
src/gui/gcal-toolbar-end.ui | 27 ++++++++++++++++++++++++++
src/gui/gcal-window.c | 17 ++--------------
src/gui/gcal-window.ui | 14 ++++----------
src/gui/gui.gresource.xml | 1 +
src/gui/meson.build | 1 +
7 files changed, 114 insertions(+), 25 deletions(-)
---
diff --git a/src/gui/gcal-toolbar-end.c b/src/gui/gcal-toolbar-end.c
new file mode 100644
index 00000000..99fe39a2
--- /dev/null
+++ b/src/gui/gcal-toolbar-end.c
@@ -0,0 +1,47 @@
+/* gcal-toolbar-end.c
+ *
+ * Copyright 2022 Christopher Davis <christopherdavis gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "gcal-toolbar-end.h"
+
+#include "gcal-search-button.h"
+
+struct _GcalToolbarEnd
+{
+ AdwBin parent_instance;
+};
+
+G_DEFINE_FINAL_TYPE (GcalToolbarEnd, gcal_toolbar_end, ADW_TYPE_BIN)
+
+static void
+gcal_toolbar_end_class_init (GcalToolbarEndClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/calendar/ui/gui/gcal-toolbar-end.ui");
+}
+
+static void
+gcal_toolbar_end_init (GcalToolbarEnd *self)
+{
+ g_type_ensure (GCAL_TYPE_SEARCH_BUTTON);
+
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/src/gui/gcal-toolbar-end.h b/src/gui/gcal-toolbar-end.h
new file mode 100644
index 00000000..766556f2
--- /dev/null
+++ b/src/gui/gcal-toolbar-end.h
@@ -0,0 +1,32 @@
+/* gcal-toolbar-end.h
+ *
+ * Copyright 2022 Christopher Davis <christopherdavis gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+
+#pragma once
+
+#include <adwaita.h>
+
+G_BEGIN_DECLS
+
+#define GCAL_TYPE_TOOLBAR_END (gcal_toolbar_end_get_type())
+
+G_DECLARE_FINAL_TYPE (GcalToolbarEnd, gcal_toolbar_end, GCAL, TOOLBAR_END, AdwBin)
+
+G_END_DECLS
diff --git a/src/gui/gcal-toolbar-end.ui b/src/gui/gcal-toolbar-end.ui
new file mode 100644
index 00000000..a94caf1d
--- /dev/null
+++ b/src/gui/gcal-toolbar-end.ui
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="GcalToolbarEnd" parent="AdwBin">
+ <property name="child">
+ <object class="GtkBox">
+ <property name="spacing">6</property>
+ <child>
+ <object class="GcalSearchButton">
+ <property name="tooltip_text" translatable="yes" context="tooltip">Search for events</property>
+ <binding name="context">
+ <lookup type="GcalWindow" name="context">
+ <lookup type="GtkWidget" name="root">GcalToolbarEnd</lookup>
+ </lookup>
+ </binding>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton">
+ <property name="icon-name">list-add-symbolic</property>
+ <property name="action-name">win.new-event</property>
+ <property name="tooltip_text" translatable="yes" context="tooltip">Add a new event</property>
+ </object>
+ </child>
+ </object>
+ </property>
+ </template>
+</interface>
diff --git a/src/gui/gcal-window.c b/src/gui/gcal-window.c
index 82e72750..28b06f30 100644
--- a/src/gui/gcal-window.c
+++ b/src/gui/gcal-window.c
@@ -35,6 +35,7 @@
#include "gcal-search-button.h"
#include "gcal-timeline.h"
#include "gcal-timeline-subscriber.h"
+#include "gcal-toolbar-end.h"
#include "gcal-view.h"
#include "gcal-weather-settings.h"
#include "gcal-week-view.h"
@@ -109,15 +110,12 @@ struct _GcalWindow
/* header_bar widets */
GtkWidget *calendars_button;
GtkWidget *menu_button;
- GtkWidget *new_event_button;
GtkWidget *today_button;
GtkWidget *views_switcher;
GcalEventEditorDialog *event_editor;
GtkWindow *import_dialog;
- GcalSearchButton *search_button;
-
/* new event popover widgets */
GtkWidget *quick_add_popover;
@@ -661,22 +659,14 @@ on_folded_notify_cb (AdwLeaflet *leaflet,
if (adw_leaflet_get_folded (leaflet))
{
gtk_header_bar_remove (GTK_HEADER_BAR (self->header_bar), self->today_button);
- gtk_header_bar_remove (GTK_HEADER_BAR (self->header_bar), self->new_event_button);
- gtk_header_bar_remove (GTK_HEADER_BAR (self->header_bar), GTK_WIDGET (self->search_button));
gtk_action_bar_pack_start (GTK_ACTION_BAR (self->action_bar), self->today_button);
- gtk_action_bar_pack_end (GTK_ACTION_BAR (self->action_bar), self->new_event_button);
- gtk_action_bar_pack_end (GTK_ACTION_BAR (self->action_bar), GTK_WIDGET (self->search_button));
}
else
{
gtk_action_bar_remove (GTK_ACTION_BAR (self->action_bar), self->today_button);
- gtk_action_bar_remove (GTK_ACTION_BAR (self->action_bar), self->new_event_button);
- gtk_action_bar_remove (GTK_ACTION_BAR (self->action_bar), GTK_WIDGET (self->search_button));
gtk_header_bar_pack_start (GTK_HEADER_BAR (self->header_bar), self->today_button);
- gtk_header_bar_pack_end (GTK_HEADER_BAR (self->header_bar), self->new_event_button);
- gtk_header_bar_pack_end (GTK_HEADER_BAR (self->header_bar), GTK_WIDGET (self->search_button));
}
}
@@ -870,7 +860,6 @@ gcal_window_constructed (GObject *object)
g_object_bind_property (self, "context", self->date_chooser, "context", G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
g_object_bind_property (self, "context", self->event_editor, "context", G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
g_object_bind_property (self, "context", self->quick_add_popover, "context", G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
- g_object_bind_property (self, "context", self->search_button, "context", G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
/* CSS */
load_css_providers (self);
@@ -1003,7 +992,7 @@ gcal_window_class_init (GcalWindowClass *klass)
g_type_ensure (GCAL_TYPE_MANAGER);
g_type_ensure (GCAL_TYPE_MONTH_VIEW);
g_type_ensure (GCAL_TYPE_QUICK_ADD_POPOVER);
- g_type_ensure (GCAL_TYPE_SEARCH_BUTTON);
+ g_type_ensure (GCAL_TYPE_TOOLBAR_END);
g_type_ensure (GCAL_TYPE_WEATHER_SETTINGS);
g_type_ensure (GCAL_TYPE_WEEK_VIEW);
@@ -1058,9 +1047,7 @@ gcal_window_class_init (GcalWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, GcalWindow, month_view);
gtk_widget_class_bind_template_child (widget_class, GcalWindow, action_bar);
gtk_widget_class_bind_template_child (widget_class, GcalWindow, quick_add_popover);
- gtk_widget_class_bind_template_child (widget_class, GcalWindow, search_button);
gtk_widget_class_bind_template_child (widget_class, GcalWindow, calendar_management_dialog);
- gtk_widget_class_bind_template_child (widget_class, GcalWindow, new_event_button);
gtk_widget_class_bind_template_child (widget_class, GcalWindow, today_button);
gtk_widget_class_bind_template_child (widget_class, GcalWindow, overlay);
gtk_widget_class_bind_template_child (widget_class, GcalWindow, views_stack);
diff --git a/src/gui/gcal-window.ui b/src/gui/gcal-window.ui
index 14b21c62..7130460b 100644
--- a/src/gui/gcal-window.ui
+++ b/src/gui/gcal-window.ui
@@ -147,6 +147,9 @@
<child>
<object class="GtkActionBar" id="action_bar">
<property name="revealed" bind-source="leaflet" bind-property="folded"
bind-flags="sync-create"/>
+ <child type="end">
+ <object class="GcalToolbarEnd"/>
+ </child>
</object>
</child>
</object>
@@ -183,16 +186,7 @@
</object>
</child>
<child type="end">
- <object class="GtkButton" id="new_event_button">
- <property name="icon-name">list-add-symbolic</property>
- <property name="action-name">win.new-event</property>
- <property name="tooltip_text" translatable="yes" context="tooltip">Add a new
event</property>
- </object>
- </child>
- <child type="end">
- <object class="GcalSearchButton" id="search_button">
- <property name="tooltip_text" translatable="yes" context="tooltip">Search for
events</property>
- </object>
+ <object class="GcalToolbarEnd"/>
</child>
</object>
</child>
diff --git a/src/gui/gui.gresource.xml b/src/gui/gui.gresource.xml
index 594a4097..c9b96b98 100644
--- a/src/gui/gui.gresource.xml
+++ b/src/gui/gui.gresource.xml
@@ -8,6 +8,7 @@
<file compressed="true">gcal-quick-add-popover.ui</file>
<file compressed="true">gcal-search-button.ui</file>
<file compressed="true">gcal-search-hit-row.ui</file>
+ <file compressed="true">gcal-toolbar-end.ui</file>
<file compressed="true">gcal-weather-settings.ui</file>
<file compressed="true">gcal-window.ui</file>
</gresource>
diff --git a/src/gui/meson.build b/src/gui/meson.build
index 3b783d19..f5d3cad6 100644
--- a/src/gui/meson.build
+++ b/src/gui/meson.build
@@ -24,6 +24,7 @@ sources += files(
'gcal-quick-add-popover.c',
'gcal-search-button.c',
'gcal-search-hit-row.c',
+ 'gcal-toolbar-end.c',
'gcal-weather-settings.c',
'gcal-window.c',
)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]