[gnome-text-editor] openpopover: show "No Recent Documents" if there are none
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] openpopover: show "No Recent Documents" if there are none
- Date: Mon, 26 Jul 2021 22:39:57 +0000 (UTC)
commit 0428ffb3003607025c6dd0cd02ba98fb47218aed
Author: Christian Hergert <chergert redhat com>
Date: Mon Jul 26 15:39:50 2021 -0700
openpopover: show "No Recent Documents" if there are none
Fixes #85
src/editor-open-popover.c | 30 ++++++++++++++++++++++++++++
src/editor-open-popover.ui | 49 ++++++++++++++++++++++++++++++----------------
2 files changed, 62 insertions(+), 17 deletions(-)
---
diff --git a/src/editor-open-popover.c b/src/editor-open-popover.c
index 9ee8023..d241120 100644
--- a/src/editor-open-popover.c
+++ b/src/editor-open-popover.c
@@ -37,6 +37,9 @@ struct _EditorOpenPopover
GtkListView *list_view;
GtkWidget *box;
GtkSearchEntry *search_entry;
+ GtkStack *stack;
+ GtkWidget *empty;
+ GtkWidget *recent;
};
G_DEFINE_TYPE (EditorOpenPopover, editor_open_popover, GTK_TYPE_POPOVER)
@@ -284,8 +287,11 @@ editor_open_popover_class_init (EditorOpenPopoverClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/TextEditor/ui/editor-open-popover.ui");
gtk_widget_class_bind_template_child (widget_class, EditorOpenPopover, box);
+ gtk_widget_class_bind_template_child (widget_class, EditorOpenPopover, empty);
gtk_widget_class_bind_template_child (widget_class, EditorOpenPopover, search_entry);
gtk_widget_class_bind_template_child (widget_class, EditorOpenPopover, list_view);
+ gtk_widget_class_bind_template_child (widget_class, EditorOpenPopover, recent);
+ gtk_widget_class_bind_template_child (widget_class, EditorOpenPopover, stack);
gtk_widget_class_bind_template_callback (widget_class, on_list_item_bind_cb);
gtk_widget_class_bind_template_callback (widget_class, on_list_item_unbind_cb);
gtk_widget_class_bind_template_callback (widget_class, on_list_view_activate_cb);
@@ -305,6 +311,22 @@ _editor_open_popover_get_model (EditorOpenPopover *self)
return self->model;
}
+static void
+editor_open_popover_items_changed_cb (EditorOpenPopover *self,
+ guint position,
+ guint removed,
+ guint added,
+ GListModel *model)
+{
+ g_assert (EDITOR_IS_OPEN_POPOVER (self));
+ g_assert (G_IS_LIST_MODEL (model));
+
+ if (added || g_list_model_get_n_items (model))
+ gtk_stack_set_visible_child (self->stack, self->recent);
+ else
+ gtk_stack_set_visible_child (self->stack, self->empty);
+}
+
void
_editor_open_popover_set_model (EditorOpenPopover *self,
GListModel *model)
@@ -318,8 +340,16 @@ _editor_open_popover_set_model (EditorOpenPopover *self,
if (model != NULL)
{
+ g_signal_connect_object (model,
+ "items-changed",
+ G_CALLBACK (editor_open_popover_items_changed_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
selection = gtk_single_selection_new (g_object_ref (model));
gtk_single_selection_set_autoselect (selection, FALSE);
+
+ editor_open_popover_items_changed_cb (self, 0, 0, 0, model);
}
gtk_list_view_set_model (self->list_view, GTK_SELECTION_MODEL (selection));
diff --git a/src/editor-open-popover.ui b/src/editor-open-popover.ui
index 38cf1a1..8cb852c 100644
--- a/src/editor-open-popover.ui
+++ b/src/editor-open-popover.ui
@@ -36,25 +36,40 @@
<child>
<object class="GtkFrame">
<child>
- <object class="GtkScrolledWindow">
- <property name="hexpand">True</property>
- <property name="hscrollbar-policy">never</property>
- <property name="max-content-height">600</property>
- <property name="max-content-width">500</property>
- <property name="propagate-natural-height">True</property>
- <property name="propagate-natural-width">True</property>
- <property name="vexpand">True</property>
+ <object class="GtkStack" id="stack">
+ <property name="vhomogeneous">false</property>
+ <property name="hhomogeneous">false</property>
<child>
- <object class="GtkListView" id="list_view">
- <signal name="activate" handler="on_list_view_activate_cb" swapped="true"
object="EditorOpenPopover"/>
- <property name="orientation">vertical</property>
- <property name="single-click-activate">True</property>
- <property name="factory">
- <object class="GtkSignalListItemFactory">
- <signal name="bind" handler="on_list_item_bind_cb" swapped="true"
object="EditorOpenPopover"/>
- <signal name="unbind" handler="on_list_item_unbind_cb" swapped="true"
object="EditorOpenPopover"/>
+ <object class="GtkLabel" id="empty">
+ <property name="label" translatable="yes">No Recent Documents</property>
+ <property name="margin-start">6</property>
+ <property name="margin-top">12</property>
+ <property name="margin-bottom">12</property>
+ <property name="margin-end">6</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="recent">
+ <property name="hexpand">True</property>
+ <property name="hscrollbar-policy">never</property>
+ <property name="max-content-height">600</property>
+ <property name="max-content-width">500</property>
+ <property name="propagate-natural-height">True</property>
+ <property name="propagate-natural-width">True</property>
+ <property name="vexpand">True</property>
+ <child>
+ <object class="GtkListView" id="list_view">
+ <signal name="activate" handler="on_list_view_activate_cb" swapped="true"
object="EditorOpenPopover"/>
+ <property name="orientation">vertical</property>
+ <property name="single-click-activate">True</property>
+ <property name="factory">
+ <object class="GtkSignalListItemFactory">
+ <signal name="bind" handler="on_list_item_bind_cb" swapped="true"
object="EditorOpenPopover"/>
+ <signal name="unbind" handler="on_list_item_unbind_cb" swapped="true"
object="EditorOpenPopover"/>
+ </object>
+ </property>
</object>
- </property>
+ </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]