[gnome-notes] note-view: Port to template widget
- From: Mohammed Sadiq <pksadiq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-notes] note-view: Port to template widget
- Date: Fri, 14 Oct 2022 10:05:46 +0000 (UTC)
commit 06d9344b6b7894d131fa07209c46578231163058
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date: Wed Jun 1 17:07:24 2022 +0530
note-view: Port to template widget
and use HdyStatusPage to show status
data/bjb.gresource.xml | 1 +
data/resources/bjb-note-view.ui | 34 ++++++++++++++++
src/bjb-note-view.c | 88 ++++++++++++++++++++---------------------
3 files changed, 77 insertions(+), 46 deletions(-)
---
diff --git a/data/bjb.gresource.xml b/data/bjb.gresource.xml
index b358427a..484b9fcf 100644
--- a/data/bjb.gresource.xml
+++ b/data/bjb.gresource.xml
@@ -15,6 +15,7 @@
<gresource prefix="/org/gnome/Notes/ui">
<file alias="bjb-window.ui" preprocess="xml-stripblanks">resources/bjb-window.ui</file>
+ <file alias="bjb-note-view.ui" preprocess="xml-stripblanks">resources/bjb-note-view.ui</file>
<file alias="empty-results-box.ui" preprocess="xml-stripblanks">resources/empty-results-box.ui</file>
<file alias="import-dialog.ui" preprocess="xml-stripblanks">resources/import-dialog.ui</file>
<file alias="list-view.ui" preprocess="xml-stripblanks">resources/list-view.ui</file>
diff --git a/data/resources/bjb-note-view.ui b/data/resources/bjb-note-view.ui
new file mode 100644
index 00000000..a9a4e8c8
--- /dev/null
+++ b/data/resources/bjb-note-view.ui
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="BjbNoteView" parent="GtkOverlay">
+ <child>
+ <object class="GtkStack" id="main_stack">
+ <property name="visible">True</property>
+
+ <child>
+ <object class="HdyStatusPage" id="status_page">
+ <property name="visible">True</property>
+ <property name="icon-name">org.gnome.Notes-symbolic</property>
+ <property name="title" translatable="yes">No note selected</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkBox" id="editor_box">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="BjbEditorToolbar" id="editor_toolbar">
+ <property name="visible">False</property>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
+ </object> <!-- GtkBox ./editor_box -->
+ </child>
+
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/bjb-note-view.c b/src/bjb-note-view.c
index fee132ca..f6807269 100644
--- a/src/bjb-note-view.c
+++ b/src/bjb-note-view.c
@@ -19,6 +19,7 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <libbiji/libbiji.h>
+#include <handy.h>
#include "bjb-application.h"
#include "bjb-editor-toolbar.h"
@@ -28,16 +29,15 @@ struct _BjbNoteView
{
GtkOverlay parent_instance;
+ /* UI */
+ GtkWidget *main_stack;
+ GtkWidget *status_page;
+ GtkWidget *editor_box;
+ GtkWidget *editor_toolbar;
+
/* Data */
GtkWidget *view;
BijiNoteObj *note ;
-
- /* UI */
- BijiWebkitEditor *editor;
- GtkWidget *box;
- GtkWidget *edit_bar;
- GtkWidget *label;
- GtkWidget *stack;
};
G_DEFINE_TYPE (BjbNoteView, bjb_note_view, GTK_TYPE_OVERLAY)
@@ -50,11 +50,13 @@ bjb_note_view_set_detached (BjbNoteView *self,
{
if (detached)
{
- gtk_stack_set_visible_child (GTK_STACK (self->stack), self->label);
+ gtk_stack_set_visible_child (GTK_STACK (self->main_stack), self->status_page);
+ hdy_status_page_set_title (HDY_STATUS_PAGE (self->status_page),
+ _("This note is being viewed in another window"));
}
else
{
- gtk_stack_set_visible_child (GTK_STACK (self->stack), self->box);
+ gtk_stack_set_visible_child (GTK_STACK (self->main_stack), self->editor_box);
}
}
@@ -78,11 +80,6 @@ bjb_note_view_finalize(GObject *object)
G_OBJECT_CLASS (bjb_note_view_parent_class)->finalize (object);
}
-static void
-bjb_note_view_init (BjbNoteView *self)
-{
-}
-
static void
on_note_color_changed_cb (BijiNoteObj *note, BjbNoteView *self)
{
@@ -118,44 +115,35 @@ view_font_changed_cb (BjbNoteView *self,
}
static void
-bjb_note_view_constructed (GObject *obj)
+bjb_note_view_class_init (BjbNoteViewClass *klass)
{
- BjbNoteView *self = BJB_NOTE_VIEW (obj);
- BjbSettings *settings;
-
- settings = bjb_app_get_settings(g_application_get_default());
-
- g_signal_connect_object (settings, "notify::font",
- G_CALLBACK (view_font_changed_cb),
- self, G_CONNECT_SWAPPED);
- view_font_changed_cb (self, NULL, settings);
-
- self->stack = gtk_stack_new ();
- gtk_widget_show (self->stack);
- gtk_container_add (GTK_CONTAINER (self), self->stack);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- /* Label used to indicate that note is opened in another window. */
- self->label = gtk_label_new (_("This note is being viewed in another window."));
- gtk_widget_show (self->label);
- gtk_stack_add_named (GTK_STACK (self->stack), self->label, "label");
+ object_class->finalize = bjb_note_view_finalize;
- self->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_widget_show (self->box);
- gtk_stack_add_named (GTK_STACK (self->stack), self->box, "note-box");
- gtk_stack_set_visible_child (GTK_STACK (self->stack), self->box);
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/Notes"
+ "/ui/bjb-note-view.ui");
- /* Edition Toolbar for text selection */
- self->edit_bar = g_object_new (BJB_TYPE_EDITOR_TOOLBAR, NULL);
- gtk_box_pack_end (GTK_BOX (self->box), self->edit_bar, FALSE, TRUE, 0);
+ gtk_widget_class_bind_template_child (widget_class, BjbNoteView, main_stack);
+ gtk_widget_class_bind_template_child (widget_class, BjbNoteView, status_page);
+ gtk_widget_class_bind_template_child (widget_class, BjbNoteView, editor_box);
+ gtk_widget_class_bind_template_child (widget_class, BjbNoteView, editor_toolbar);
}
static void
-bjb_note_view_class_init (BjbNoteViewClass *klass)
+bjb_note_view_init (BjbNoteView *self)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ BjbSettings *settings;
- object_class->finalize = bjb_note_view_finalize;
- object_class->constructed = bjb_note_view_constructed;
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+ settings = bjb_app_get_settings (g_application_get_default ());
+ g_signal_connect_object (settings, "notify::font",
+ G_CALLBACK (view_font_changed_cb),
+ self, G_CONNECT_SWAPPED);
+ view_font_changed_cb (self, NULL, settings);
}
void
@@ -168,9 +156,9 @@ bjb_note_view_set_note (BjbNoteView *self,
if (self->note == note)
return;
- bjb_editor_toolbar_set_note (BJB_EDITOR_TOOLBAR (self->edit_bar), note);
+ bjb_editor_toolbar_set_note (BJB_EDITOR_TOOLBAR (self->editor_toolbar), note);
if (note)
- gtk_widget_set_visible (self->edit_bar, !biji_note_obj_is_trashed (note));
+ gtk_widget_set_visible (self->editor_toolbar, !biji_note_obj_is_trashed (note));
bjb_note_view_disconnect (self);
self->note = note;
@@ -185,7 +173,7 @@ bjb_note_view_set_note (BjbNoteView *self,
/* Text Editor (WebKitMainView) */
self->view = biji_note_obj_open (note);
gtk_widget_show (self->view);
- gtk_box_pack_start (GTK_BOX (self->box), GTK_WIDGET(self->view), TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (self->editor_box), GTK_WIDGET(self->view), TRUE, TRUE, 0);
if (!biji_note_obj_get_rgba (self->note, &color))
{
@@ -201,5 +189,13 @@ bjb_note_view_set_note (BjbNoteView *self,
G_CALLBACK (on_note_color_changed_cb), self);
gtk_widget_show (self->view);
+
+ gtk_stack_set_visible_child (GTK_STACK (self->main_stack), self->editor_box);
+ }
+ else
+ {
+ gtk_stack_set_visible_child (GTK_STACK (self->main_stack), self->status_page);
+ hdy_status_page_set_title (HDY_STATUS_PAGE (self->status_page),
+ _("No note selected"));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]