gcal-calendars-page: Move new calendar button to bottom toolbar

Currently, if you have lots of calendars you need to scroll all the way
to the bottom of list to have access to the "New Calendar" button.

This commit moves the "New Calendar" button to be on a bottom toolbar
provided by AdwToolbarView. It makes the button always on view and easy
to access.

Closes https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/1051
This commit is contained in:
Felipe Kinoshita
2023-11-29 21:38:53 +00:00
committed by Georges Basile Stavracas Neto
parent c7d2854986
commit a6f3f130ff
2 changed files with 31 additions and 42 deletions
@@ -34,7 +34,6 @@ struct _GcalCalendarsPage
GtkListBoxRow *add_calendar_row;
GtkListBox *listbox;
GtkSizeGroup *sizegroup;
AdwToastOverlay *toast_overlay;
AdwToast *toast;
@@ -118,8 +117,6 @@ make_calendar_row (GcalCalendarsPage *self,
/* parent source name label */
adw_action_row_set_subtitle (ADW_ACTION_ROW (row), parent_name);
gtk_size_group_add_widget (self->sizegroup, row);
return row;
}
@@ -214,12 +211,6 @@ listbox_sort_func (GtkListBoxRow *row1,
self = GCAL_CALENDARS_PAGE (user_data);
/* Keep "Add Calendar" row always at the bottom */
if (row1 == self->add_calendar_row)
return 1;
else if (row2 == self->add_calendar_row)
return -1;
manager = gcal_context_get_manager (self->context);
source1 = g_object_get_data (G_OBJECT (row1), "source");
@@ -256,16 +247,18 @@ on_listbox_row_activated_cb (GtkListBox *listbox,
{
GcalCalendarManagementPage *page = GCAL_CALENDAR_MANAGEMENT_PAGE (self);
if (row == self->add_calendar_row)
{
gcal_calendar_management_page_switch_page (page, "new-calendar", NULL);
}
else
{
GcalCalendar *calendar = g_object_get_data (G_OBJECT (row), "calendar");
GcalCalendar *calendar = g_object_get_data (G_OBJECT (row), "calendar");
gcal_calendar_management_page_switch_page (page, "edit-calendar", calendar);
}
gcal_calendar_management_page_switch_page (page, "edit-calendar", calendar);
}
static void
on_new_calendar_button_clicked_cb (GtkButton *button,
GcalCalendarsPage *self)
{
GcalCalendarManagementPage *page = GCAL_CALENDAR_MANAGEMENT_PAGE (self);
gcal_calendar_management_page_switch_page (page, "new-calendar", NULL);
}
static void
@@ -477,10 +470,10 @@ gcal_calendars_page_class_init (GcalCalendarsPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, GcalCalendarsPage, add_calendar_row);
gtk_widget_class_bind_template_child (widget_class, GcalCalendarsPage, listbox);
gtk_widget_class_bind_template_child (widget_class, GcalCalendarsPage, sizegroup);
gtk_widget_class_bind_template_child (widget_class, GcalCalendarsPage, toast_overlay);
gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_activated_cb);
gtk_widget_class_bind_template_callback (widget_class, on_new_calendar_button_clicked_cb);
}
static void
@@ -42,39 +42,35 @@
<class name="calendars-list"/>
<class name="boxed-list"/>
</style>
<child>
<object class="GtkListBoxRow" id="add_calendar_row">
<child>
<object class="GtkLabel">
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="label" translatable="yes">Add Calendar…</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</property>
<child type="bottom">
<object class="GtkBox">
<property name="hexpand">true</property>
<property name="halign">center</property>
<property name="margin-top">12</property>
<property name="margin-bottom">12</property>
<child>
<object class="GtkButton" id="add_calendar_row">
<property name="label" translatable="yes">Add Calendar…</property>
<signal name="clicked" handler="on_new_calendar_button_clicked_cb" object="GcalCalendarsPage" swapped="no" />
<style>
<class name="pill"/>
<class name="suggested-action"/>
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
<!-- Size group for the listbox rows -->
<object class="GtkSizeGroup" id="sizegroup">
<property name="mode">vertical</property>
<widgets>
<widget name="add_calendar_row" />
</widgets>
</object>
</interface>