[gnome-notes] window-base: Add notebook selection menu in header bar
- From: Isaque Galdino de Araujo <igaldino src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-notes] window-base: Add notebook selection menu in header bar
- Date: Tue, 4 May 2021 13:10:21 +0000 (UTC)
commit a0ad9b3bde1371b15ca2ec75c4e4aeb1c9a0f673
Author: Jonathan Kang <jonathankang gnome org>
Date: Fri Jan 29 11:13:27 2021 +0800
window-base: Add notebook selection menu in header bar
data/resources/bjb-window-base.ui | 103 ++++++++++++++++++++++++++----
src/bjb-application.c | 16 -----
src/bjb-search-toolbar.c | 8 +++
src/bjb-search-toolbar.h | 2 +
src/bjb-window-base.c | 129 ++++++++++++++++++++++++++++++++++++++
5 files changed, 231 insertions(+), 27 deletions(-)
---
diff --git a/data/resources/bjb-window-base.ui b/data/resources/bjb-window-base.ui
index 9301b11..5ec6c17 100644
--- a/data/resources/bjb-window-base.ui
+++ b/data/resources/bjb-window-base.ui
@@ -13,8 +13,8 @@
<child>
<object class="HdyHeaderBar" id="headerbar">
<property name="visible">True</property>
+ <property name="custom-title">filter_menu_button</property>
<property name="show-close-button">True</property>
- <property name="title" translatable="yes">All Notes</property>
<child>
<object class="GtkButton" id="new_button">
<property name="visible">True</property>
@@ -23,6 +23,34 @@
<signal name="clicked" handler="on_new_note_clicked" swapped="yes"/>
</object>
</child>
+ <child type="title">
+ <object class="GtkMenuButton" id="filter_menu_button">
+ <property name="visible">True</property>
+ <property name="popover">filter_menu</property>
+ <property name="relief">GTK_RELIEF_NONE</property>
+ <property name="valign">center</property>
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="orientation">horizontal</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="filter_label">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">All Notes</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="icon-name">pan-down-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
<child>
<object class="GtkMenuButton" id="main_menu_button">
<property name="visible">True</property>
@@ -112,7 +140,7 @@
<object class="GtkMenuButton" id="menu_button">
<property name="visible">True</property>
<property name="tooltip-text" translatable="yes">More options</property>
- <property name="popover">menu</property>
+ <property name="popover">note-menu</property>
<child>
<object class="GtkImage">
<property name="visible">1</property>
@@ -147,14 +175,6 @@
</object>
</child>
- <child>
- <object class="GtkModelButton">
- <property name="visible">True</property>
- <property name="text" translatable="yes">View Trash</property>
- <property name="action-name">app.view-trash</property>
- </object>
- </child>
-
<child>
<object class="GtkSeparator">
<property name="margin-top">6</property>
@@ -244,7 +264,68 @@
</child>
</object>
- <object class="GtkPopoverMenu" id="menu">
+ <object class="GtkPopover" id="filter_menu">
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="margin">12</property>
+ <property name="orientation">vertical</property>
+
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="text" translatable="yes">All Notes</property>
+ <property name="action-name">win.show-all-notes</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkSeparator">
+ <property name="margin-top">6</property>
+ <property name="margin-bottom">6</property>
+ <property name="visible">True</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="sensitive">False</property>
+ <property name="label" translatable="yes">Notebooks</property>
+ <property name="margin-left">6</property>
+ <property name="margin-bottom">6</property>
+ <property name="xalign">0</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkBox" id="notebooks_box">
+ <property name="visible">True</property>
+ <property name="expand">True</property>
+ <property name="orientation">vertical</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkSeparator">
+ <property name="margin-top">6</property>
+ <property name="margin-bottom">6</property>
+ <property name="visible">True</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="text" translatable="yes">Trash</property>
+ <property name="action-name">win.show-trash</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+
+ <object class="GtkPopoverMenu" id="note-menu">
<child>
<object class="GtkBox">
<property name="visible">True</property>
diff --git a/src/bjb-application.c b/src/bjb-application.c
index 7ee831d..ed413ff 100644
--- a/src/bjb-application.c
+++ b/src/bjb-application.c
@@ -61,10 +61,6 @@ void on_import_notes_cb (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
-void on_view_trash_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data);
-
void on_preferences_cb (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
@@ -284,17 +280,6 @@ on_import_notes_cb (GSimpleAction *action,
bjb_app_import_notes (BJB_APPLICATION (user_data));
}
-void
-on_view_trash_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
-{
- GList *windows = gtk_application_get_windows (GTK_APPLICATION (user_data));
- BjbController *controller = bjb_window_base_get_controller (BJB_WINDOW_BASE (windows->data));
-
- bjb_controller_set_group (controller, BIJI_ARCHIVED_ITEMS);
-}
-
void
on_preferences_cb (GSimpleAction *action,
GVariant *parameter,
@@ -393,7 +378,6 @@ manager_ready_cb (GObject *source,
static GActionEntry app_entries[] = {
{ "import-notes", on_import_notes_cb, NULL, NULL, NULL },
- { "view-trash", on_view_trash_cb, NULL, NULL, NULL },
{ "text-size", NULL, "s", "'medium'", NULL },
{ "preferences", on_preferences_cb, NULL, NULL, NULL },
{ "help", on_help_cb, NULL, NULL, NULL },
diff --git a/src/bjb-search-toolbar.c b/src/bjb-search-toolbar.c
index d573cce..01086f7 100644
--- a/src/bjb-search-toolbar.c
+++ b/src/bjb-search-toolbar.c
@@ -45,6 +45,14 @@ struct _BjbSearchToolbar
G_DEFINE_TYPE (BjbSearchToolbar, bjb_search_toolbar, HDY_TYPE_SEARCH_BAR)
+GtkEntry *
+bjb_search_toolbar_get_entry_widget (BjbSearchToolbar *self)
+{
+ g_return_val_if_fail (BJB_IS_SEARCH_TOOLBAR (self), NULL);
+
+ return self->entry;
+}
+
static void
on_search_changed_cb (GtkEntry *entry,
BjbSearchToolbar *self)
diff --git a/src/bjb-search-toolbar.h b/src/bjb-search-toolbar.h
index bb887b7..e497227 100644
--- a/src/bjb-search-toolbar.h
+++ b/src/bjb-search-toolbar.h
@@ -39,5 +39,7 @@ void bjb_search_toolbar_setup (BjbSearchToolbar *s
GtkWidget *window,
BjbController *controller);
+GtkEntry *bjb_search_toolbar_get_entry_widget (BjbSearchToolbar *self);
+
G_END_DECLS
diff --git a/src/bjb-window-base.c b/src/bjb-window-base.c
index 016f759..5dfaf38 100644
--- a/src/bjb-window-base.c
+++ b/src/bjb-window-base.c
@@ -68,9 +68,12 @@ struct _BjbWindowBase
HdyHeaderGroup *header_group;
GtkStack *main_stack;
GtkWidget *back_button;
+ GtkWidget *filter_label;
+ GtkWidget *filter_menu_button;
GtkWidget *headerbar;
GtkWidget *note_box;
GtkWidget *note_headerbar;
+ GtkWidget *notebooks_box;
GtkWidget *sidebar_box;
GtkWidget *search_bar;
GtkWidget *title_entry;
@@ -225,6 +228,16 @@ bjb_window_base_set_property (GObject *object,
}
}
+static void
+clear_text_in_search_entry (BjbWindowBase *self)
+{
+ GtkEntry *search_entry;
+
+ /* Clear the content in search bar if there is any in it. */
+ search_entry = bjb_search_toolbar_get_entry_widget (BJB_SEARCH_TOOLBAR (self->search_bar));
+ gtk_entry_set_text (search_entry, "");
+}
+
static gboolean
on_key_pressed_cb (BjbWindowBase *self, GdkEvent *event)
{
@@ -389,6 +402,59 @@ on_email_cb (GSimpleAction *action,
on_email_note_callback (note);
}
+static void
+on_show_all_notes_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ BjbWindowBase *self = BJB_WINDOW_BASE (user_data);
+
+ clear_text_in_search_entry (self);
+
+ /* Going back from a notebook. */
+ if (bjb_controller_get_notebook (self->controller) != NULL)
+ bjb_controller_set_notebook (self->controller, NULL);
+
+ bjb_controller_set_group (self->controller, BIJI_LIVING_ITEMS);
+ gtk_label_set_text (GTK_LABEL (self->filter_label), _("All Notes"));
+}
+
+static void
+on_show_notebook_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ const char *note_uuid;
+ const char *title;
+ BjbWindowBase *self = BJB_WINDOW_BASE (user_data);
+ BijiItem *notebook;
+ BijiManager *manager;
+
+ clear_text_in_search_entry (self);
+
+ note_uuid = g_variant_get_string (parameter, NULL);
+ manager = bjb_window_base_get_manager (GTK_WIDGET (self));
+ notebook = biji_manager_get_item_at_path (manager, note_uuid);
+ bjb_controller_set_notebook (self->controller, BIJI_NOTEBOOK (notebook));
+
+ /* Update headerbar title. */
+ title = biji_item_get_title (notebook);
+ gtk_label_set_text (GTK_LABEL (self->filter_label), title);
+}
+
+static void
+on_show_trash_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ BjbWindowBase *self = BJB_WINDOW_BASE (user_data);
+
+ clear_text_in_search_entry (self);
+
+ bjb_controller_set_group (self->controller, BIJI_ARCHIVED_ITEMS);
+ gtk_label_set_text (GTK_LABEL (self->filter_label), _("Trash"));
+}
+
static void
on_trash_cb (GSimpleAction *action,
GVariant *parameter,
@@ -467,6 +533,59 @@ bjb_window_base_configure_event (GtkWidget *widget,
event);
}
+static void
+append_notebook (BijiItem *notebook,
+ BjbWindowBase *self)
+{
+ const char *note_uuid;
+ const char *title;
+ GVariant *variant;
+ GtkWidget *button;
+ GtkWidget *label;
+
+ note_uuid = biji_item_get_uuid (notebook);
+ variant = g_variant_new_string (note_uuid);
+
+ button = gtk_model_button_new ();
+ g_object_set (button,
+ "action-name", "win.show-notebook",
+ "action-target", variant,
+ NULL);
+
+ title = biji_item_get_title (notebook);
+ gtk_button_set_label (GTK_BUTTON (button), title);
+ label = gtk_bin_get_child (GTK_BIN (button));
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+
+ gtk_widget_show (button);
+ gtk_box_pack_end (GTK_BOX (self->notebooks_box), button, TRUE, TRUE, 0);
+}
+
+static int
+compare_notebook (gconstpointer a,
+ gconstpointer b)
+{
+ g_autofree char *up_a = NULL;
+ g_autofree char *up_b = NULL;
+ BijiItem *item_a = (BijiItem *) a;
+ BijiItem *item_b = (BijiItem *) b;
+
+ up_a = g_utf8_casefold (biji_item_get_title (item_a), -1);
+ up_b = g_utf8_casefold (biji_item_get_title (item_b), -1);
+
+ return g_strcmp0 (up_a, up_b);
+}
+
+static void
+get_all_notebooks_cb (GList *notebooks,
+ gpointer user_data)
+{
+ BjbWindowBase *self = BJB_WINDOW_BASE (user_data);
+
+ notebooks = g_list_sort (notebooks, compare_notebook);
+ g_list_foreach (notebooks, (GFunc) append_notebook, self);
+}
+
static GActionEntry win_entries[] = {
{ "detach-window", on_detach_window_cb, NULL, NULL, NULL },
{ "paste", on_paste_cb, NULL, NULL, NULL },
@@ -474,6 +593,9 @@ static GActionEntry win_entries[] = {
{ "redo", on_redo_cb, NULL, NULL, NULL },
{ "view-notebooks", on_view_notebooks_cb, NULL, NULL, NULL },
{ "email", on_email_cb, NULL, NULL, NULL },
+ { "show-all-notes", on_show_all_notes_cb, NULL, NULL, NULL },
+ { "show-notebook", on_show_notebook_cb, "s", NULL, NULL },
+ { "show-trash", on_show_trash_cb, NULL, NULL, NULL },
{ "trash", on_trash_cb, NULL, NULL, NULL },
{ "close", on_close },
};
@@ -482,6 +604,7 @@ static GActionEntry win_entries[] = {
static void
bjb_window_base_constructed (GObject *obj)
{
+ BijiManager *manager;
BjbSearchToolbar *search_bar;
BjbWindowBase *self = BJB_WINDOW_BASE (obj);
GtkListBox *list_box;
@@ -537,6 +660,9 @@ bjb_window_base_constructed (GObject *obj)
gtk_stack_add_named (self->main_stack, GTK_WIDGET (self->note_list), "main-view");
gtk_widget_show (GTK_WIDGET (self->main_stack));
+ /* Populate the filter menu model. */
+ manager = bjb_window_base_get_manager (GTK_WIDGET (self));
+ biji_get_all_notebooks_async (manager, NULL, get_all_notebooks_cb, self);
/* Connection to window signals */
@@ -618,8 +744,11 @@ bjb_window_base_class_init (BjbWindowBaseClass *klass)
gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, main_stack);
gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, back_button);
gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, headerbar);
+ gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, filter_label);
+ gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, filter_menu_button);
gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, note_box);
gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, note_headerbar);
+ gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, notebooks_box);
gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, sidebar_box);
gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, search_bar);
gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, title_entry);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]