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.
This commit is contained in:
committed by
Georges Basile Stavracas Neto
parent
78d9dd1e8e
commit
9444d998ff
@@ -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));
|
||||
}
|
||||
@@ -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
|
||||
@@ -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>
|
||||
+2
-15
@@ -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);
|
||||
|
||||
+4
-10
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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',
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user