[gnome-notes] window-base: Implement transition between sidebar and note view
- From: Isaque Galdino de Araujo <igaldino src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-notes] window-base: Implement transition between sidebar and note view
- Date: Tue, 4 May 2021 13:10:20 +0000 (UTC)
commit 7208a11ea02fe012cfcdcd11e2656d4ebe67e15c
Author: Jonathan Kang <jonathankang gnome org>
Date: Wed Aug 19 15:44:26 2020 +0800
window-base: Implement transition between sidebar and note view
When the main leaflet is folded, clicking a note and adding a new note
opens note view. A back button is added to go back to sidebar from
note view.
https://gitlab.gnome.org/GNOME/gnome-notes/-/issues/154
data/resources/bjb-window-base.ui | 35 ++++++++++++++++++----------
src/bjb-application.c | 2 +-
src/bjb-window-base.c | 48 ++++++++++++++++++++++++++++++++-------
src/bjb-window-base.h | 2 +-
4 files changed, 65 insertions(+), 22 deletions(-)
---
diff --git a/data/resources/bjb-window-base.ui b/data/resources/bjb-window-base.ui
index 0979ae2..a2e6b44 100644
--- a/data/resources/bjb-window-base.ui
+++ b/data/resources/bjb-window-base.ui
@@ -6,8 +6,7 @@
<object class="HdyLeaflet" id="main_leaflet">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="mode-transition-type">slide</property>
- <property name="child-transition-type">slide</property>
+ <property name="transition-type">slide</property>
<child>
<object class="GtkBox" id="sidebar_box">
<property name="visible">True</property>
@@ -78,9 +77,8 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">horizontal</property>
- <property name="mode-transition-type" bind-source="main_leaflet"
bind-property="mode-transition-type" bind-flags="bidirectional|sync-create"/>
+ <property name="transition-type">slide</property>
<property name="mode-transition-duration" bind-source="main_leaflet"
bind-property="mode-transition-duration" bind-flags="bidirectional|sync-create"/>
- <property name="child-transition-type" bind-source="main_leaflet"
bind-property="child-transition-type" bind-flags="bidirectional|sync-create"/>
<property name="child-transition-duration" bind-source="main_leaflet"
bind-property="child-transition-duration" bind-flags="bidirectional|sync-create"/>
<signal name="notify::visible-child" handler="notify_header_visible_child_cb" swapped="yes"/>
<signal name="notify::fold" handler="notify_fold_cb" object="BjbWindowBase" after="yes"
swapped="yes"/>
@@ -138,25 +136,38 @@
<property name="transition-type">crossfade</property>
<property name="transition-duration" bind-source="main_leaflet"
bind-property="mode-transition-duration" bind-flags="bidirectional|sync-create"/>
<child>
- <object class="GtkMenuButton" id="menu_button">
+ <object class="GtkButton" id="back_button">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="tooltip-text" translatable="yes">More options</property>
- <property name="popover">menu</property>
+ <signal name="clicked" handler="on_back_button_clicked" swapped="yes"/>
<child>
<object class="GtkImage">
<property name="visible">1</property>
- <property name="icon-name">view-more-symbolic</property>
+ <property name="icon-name">go-previous-symbolic</property>
</object>
</child>
</object>
- <packing>
- <property name="position">0</property>
- <property name="pack-type">end</property>
- </packing>
</child>
</object>
</child>
+ <child>
+ <object class="GtkMenuButton" id="menu_button">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip-text" translatable="yes">More options</property>
+ <property name="popover">menu</property>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">1</property>
+ <property name="icon-name">view-more-symbolic</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/src/bjb-application.c b/src/bjb-application.c
index a502f4f..e364e54 100644
--- a/src/bjb-application.c
+++ b/src/bjb-application.c
@@ -176,7 +176,7 @@ bijiben_open_path (BjbApplication *self,
if (BIJI_IS_NOTE_OBJ (item) || !window)
bijiben_new_window_internal (self, BIJI_NOTE_OBJ (item));
else
- bjb_window_base_switch_to_item (window, item);
+ bjb_window_base_load_note_item (window, item);
return TRUE;
}
diff --git a/src/bjb-window-base.c b/src/bjb-window-base.c
index 1f71357..83d3302 100644
--- a/src/bjb-window-base.c
+++ b/src/bjb-window-base.c
@@ -63,11 +63,15 @@ struct _BjbWindowBase
gboolean is_maximized;
HdyLeaflet *header_box;
+ HdyLeaflet *main_leaflet;
HdyHeaderGroup *header_group;
GtkRevealer *back_revealer;
+ GtkWidget *back_button;
+ GtkWidget *headerbar;
GtkWidget *note_box;
GtkWidget *note_headerbar;
GtkWidget *note_list;
+ GtkWidget *sidebar_box;
GtkWidget *search_bar;
GtkWidget *title_entry;
};
@@ -75,6 +79,20 @@ struct _BjbWindowBase
/* Gobject */
G_DEFINE_TYPE (BjbWindowBase, bjb_window_base, GTK_TYPE_APPLICATION_WINDOW)
+static void
+switch_to_sidebar (BjbWindowBase *self)
+{
+ hdy_leaflet_set_visible_child (self->header_box, self->headerbar);
+ hdy_leaflet_set_visible_child (self->main_leaflet, self->sidebar_box);
+}
+
+static void
+switch_to_note_view (BjbWindowBase *self)
+{
+ hdy_leaflet_set_visible_child (self->header_box, self->note_headerbar);
+ hdy_leaflet_set_visible_child (self->main_leaflet, self->note_box);
+}
+
static void
update_fold_state (BjbWindowBase *self)
{
@@ -132,10 +150,12 @@ on_note_list_row_activated (GtkListBox *box,
if (to_open && BIJI_IS_NOTE_OBJ (to_open))
{
+ switch_to_note_view (self);
+
/* Only open the note if it's not already opened. */
if (!biji_note_obj_is_opened (BIJI_NOTE_OBJ (to_open)))
{
- bjb_window_base_switch_to_item (self, to_open);
+ bjb_window_base_load_note_item (self, to_open);
on_note_renamed (to_open, self);
}
}
@@ -145,6 +165,12 @@ on_note_list_row_activated (GtkListBox *box,
}
}
+static void
+on_back_button_clicked (BjbWindowBase *self)
+{
+ switch_to_sidebar (self);
+}
+
static void
on_new_note_clicked (BjbWindowBase *self)
{
@@ -160,7 +186,8 @@ on_new_note_clicked (BjbWindowBase *self)
bjb_settings_get_default_location (self->settings));
/* Go to that note */
- bjb_window_base_switch_to_item (self, BIJI_ITEM (result));
+ switch_to_note_view (self);
+ bjb_window_base_load_note_item (self, BIJI_ITEM (result));
on_note_renamed (BIJI_ITEM (result), self);
}
@@ -555,7 +582,7 @@ bjb_window_base_constructed (GObject *obj)
if (self->note != NULL)
{
self->detached = TRUE;
- bjb_window_base_switch_to_item (self, BIJI_ITEM (self->note));
+ bjb_window_base_load_note_item (self, BIJI_ITEM (self->note));
}
}
@@ -612,17 +639,22 @@ bjb_window_base_class_init (BjbWindowBaseClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Notes/ui/bjb-window-base.ui");
gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, header_box);
+ gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, main_leaflet);
gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, header_group);
gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, back_revealer);
+ 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, note_box);
gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, note_headerbar);
gtk_widget_class_bind_template_child (widget_class, BjbWindowBase, note_list);
+ 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);
- gtk_widget_class_bind_template_callback(widget_class, notify_header_visible_child_cb);
- gtk_widget_class_bind_template_callback(widget_class, notify_fold_cb);
- gtk_widget_class_bind_template_callback(widget_class, on_new_note_clicked);
- gtk_widget_class_bind_template_callback(widget_class, on_title_changed);
+ gtk_widget_class_bind_template_callback (widget_class, notify_header_visible_child_cb);
+ gtk_widget_class_bind_template_callback (widget_class, notify_fold_cb);
+ gtk_widget_class_bind_template_callback (widget_class, on_back_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_new_note_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_title_changed);
}
@@ -738,7 +770,7 @@ bjb_window_base_switch_to (BjbWindowBase *self, BjbWindowViewType type)
}
void
-bjb_window_base_switch_to_item (BjbWindowBase *self, BijiItem *item)
+bjb_window_base_load_note_item (BjbWindowBase *self, BijiItem *item)
{
GtkWidget *w = GTK_WIDGET (self);
diff --git a/src/bjb-window-base.h b/src/bjb-window-base.h
index 6d1c287..5681b8c 100644
--- a/src/bjb-window-base.h
+++ b/src/bjb-window-base.h
@@ -31,7 +31,7 @@ void bjb_window_base_go_back (BjbWindowBase *self);
void bjb_window_base_switch_to (BjbWindowBase *bwb, BjbWindowViewType type);
-void bjb_window_base_switch_to_item (BjbWindowBase *bwb, BijiItem *item);
+void bjb_window_base_load_note_item (BjbWindowBase *bwb, BijiItem *item);
BjbWindowViewType bjb_window_base_get_view_type (BjbWindowBase *win);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]