[bijiben] bjb-editor-toolbar: moved UI definition to a template file.
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] bjb-editor-toolbar: moved UI definition to a template file.
- Date: Sat, 25 Feb 2017 22:34:50 +0000 (UTC)
commit 8811ff5003a1129550b2f522a80cd302e91b05e8
Author: Iñigo Martínez <inigomartinez gmail com>
Date: Sat Feb 25 23:34:25 2017 +0100
bjb-editor-toolbar: moved UI definition to a template file.
The UI definition and implementation has been split by moving the
former to a template file.
The code has also been updated by using GTK facilities for class
definitions.
https://bugzilla.gnome.org/show_bug.cgi?id=728859
src/Makefile.am | 1 +
src/bjb-editor-toolbar.c | 460 +++++++++++++++++----------------------
src/bjb-editor-toolbar.h | 26 +--
src/bjb.gresource.xml | 1 +
src/resources/editor-toolbar.ui | 219 +++++++++++++++++++
5 files changed, 430 insertions(+), 277 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 1d3f84f..d152566 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -35,6 +35,7 @@ bijiben_LDFLAGS = \
resource_files = \
resources/Adwaita.css \
resources/app-menu.ui \
+ resources/editor-toolbar.ui \
resources/note-symbolic.svg \
resources/thumbnail-frame.png
diff --git a/src/bjb-editor-toolbar.c b/src/bjb-editor-toolbar.c
index 7ca6dac..8df11aa 100644
--- a/src/bjb-editor-toolbar.c
+++ b/src/bjb-editor-toolbar.c
@@ -17,14 +17,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/* Offset for toolbar related to cursor.
- * (Pixels)
- *
- * X offset might be replaced by something like -(toolbar size/2)
- * Y offset might not be replaced */
-#define EDITOR_TOOLBAR_X_OFFSET -120;
-#define EDITOR_TOOLBAR_Y_OFFSET -15;
-
#include "config.h"
#include <glib.h>
@@ -36,167 +28,148 @@
#include "bjb-editor-toolbar.h"
#include "bjb-window-base.h"
-#define CENTER_BUTTONS_SPACING 6
-
enum
{
PROP_0,
PROP_NOTE,
- PROP_BJB_NOTE_VIEW,
+ PROP_NOTE_VIEW,
NUM_PROPERTIES
};
-static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
-
struct _BjbEditorToolbarPrivate
{
/* Note provide us the WebKitWebView editor */
- BjbNoteView *view;
- BijiNoteObj *note;
-
- GtkAccelGroup *accel;
-
- GtkWidget *box_actions;
-
- GtkWidget *box_center;
- GtkWidget *box_style;
- GtkWidget *box_points;
-
- /* Do not use toggle buttons. uggly there.
- * Paste : the user might want to paste overriding selected text.
- * Other : when no selection the user won't try to bold "null".*/
- GtkWidget *toolbar_cut;
- GtkWidget *toolbar_copy;
- GtkWidget *toolbar_paste;
- GtkWidget *toolbar_bold;
- GtkWidget *toolbar_italic;
- GtkWidget *toolbar_strike;
- GtkWidget *toolbar_bullet;
- GtkWidget *toolbar_list;
- GtkWidget *toolbar_link;
-};
+ BjbNoteView *view;
+ BijiNoteObj *note;
-G_DEFINE_TYPE (BjbEditorToolbar, bjb_editor_toolbar, GTK_TYPE_ACTION_BAR);
+ GtkAccelGroup *accel;
-static void
-bjb_editor_toolbar_init (BjbEditorToolbar *self)
-{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (
- self,
- BJB_TYPE_EDITOR_TOOLBAR,
- BjbEditorToolbarPrivate);
+ GtkWidget *cut_button;
+ GtkWidget *copy_button;
+ GtkWidget *paste_button;
- self->priv->accel = gtk_accel_group_new ();
-}
-
-
-static void
-bjb_editor_toolbar_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- switch (property_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
-}
+ GtkWidget *bold_button;
+ GtkWidget *italic_button;
+ GtkWidget *strike_button;
+ GtkWidget *bullets_button;
+ GtkWidget *list_button;
-static void
-bjb_editor_toolbar_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- BjbEditorToolbar *self = BJB_EDITOR_TOOLBAR (object);
+ GtkWidget *link_button;
+};
- switch (property_id)
- {
- case PROP_BJB_NOTE_VIEW:
- self->priv->view = g_value_get_object (value);
- break;
- case PROP_NOTE:
- self->priv->note = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
-}
+G_DEFINE_TYPE_WITH_PRIVATE (BjbEditorToolbar, bjb_editor_toolbar, GTK_TYPE_ACTION_BAR)
static gboolean
on_release_event (GtkWidget *widget,
GdkEvent *event,
BjbEditorToolbar *self)
{
+ BjbEditorToolbarPrivate *priv;
+
+ priv = bjb_editor_toolbar_get_instance_private (self);
+
gtk_widget_set_visible (GTK_WIDGET (self),
- biji_note_obj_editor_has_selection (self->priv->note));
+ biji_note_obj_editor_has_selection (priv->note));
return FALSE;
}
static void
-on_cut_clicked (GtkWidget *button,
+on_cut_clicked (GtkButton *button,
BjbEditorToolbar *self)
{
- biji_note_obj_editor_cut (self->priv->note);
+ BjbEditorToolbarPrivate *priv;
+
+ priv = bjb_editor_toolbar_get_instance_private (self);
+
+ biji_note_obj_editor_cut (priv->note);
+
+ gtk_widget_hide (GTK_WIDGET (self));
}
static void
-on_copy_clicked (GtkWidget *button,
+on_copy_clicked (GtkButton *button,
BjbEditorToolbar *self)
{
- biji_note_obj_editor_copy (self->priv->note);
+ BjbEditorToolbarPrivate *priv;
+
+ priv = bjb_editor_toolbar_get_instance_private (self);
+
+ biji_note_obj_editor_copy (priv->note);
}
static void
-on_paste_clicked (GtkWidget *button,
+on_paste_clicked (GtkButton *button,
BjbEditorToolbar *self)
{
- biji_note_obj_editor_paste (self->priv->note);
+ BjbEditorToolbarPrivate *priv;
+
+ priv = bjb_editor_toolbar_get_instance_private (self);
+
+ biji_note_obj_editor_paste (priv->note);
+
+ gtk_widget_hide (GTK_WIDGET (self));
}
static void
-bold_button_callback (GtkWidget *button,
- BjbEditorToolbar *self)
+on_bold_clicked (GtkButton *button,
+ BjbEditorToolbar *self)
{
- biji_note_obj_editor_apply_format (self->priv->note, BIJI_BOLD);
+ BjbEditorToolbarPrivate *priv;
+
+ priv = bjb_editor_toolbar_get_instance_private (self);
+
+ biji_note_obj_editor_apply_format (priv->note, BIJI_BOLD);
}
static void
-italic_button_callback (GtkWidget *button,
- BjbEditorToolbar *self)
+on_italic_clicked (GtkButton *button,
+ BjbEditorToolbar *self)
{
- biji_note_obj_editor_apply_format (self->priv->note, BIJI_ITALIC);
+ BjbEditorToolbarPrivate *priv;
+
+ priv = bjb_editor_toolbar_get_instance_private (self);
+
+ biji_note_obj_editor_apply_format (priv->note, BIJI_ITALIC);
}
static void
-strike_button_callback (GtkWidget *button,
- BjbEditorToolbar *self)
+on_strike_clicked (GtkButton *button,
+ BjbEditorToolbar *self)
{
- biji_note_obj_editor_apply_format (self->priv->note, BIJI_STRIKE);
+ BjbEditorToolbarPrivate *priv;
+
+ priv = bjb_editor_toolbar_get_instance_private (self);
+
+ biji_note_obj_editor_apply_format (priv->note, BIJI_STRIKE);
}
static void
-on_bullet_clicked (GtkWidget *button,
- BjbEditorToolbar *self)
+on_bullets_clicked (GtkButton *button,
+ BjbEditorToolbar *self)
{
- biji_note_obj_editor_apply_format (self->priv->note, BIJI_BULLET_LIST);
+ BjbEditorToolbarPrivate *priv;
+
+ priv = bjb_editor_toolbar_get_instance_private (self);
+
+ biji_note_obj_editor_apply_format (priv->note, BIJI_BULLET_LIST);
}
static void
-on_list_clicked (GtkWidget *button,
+on_list_clicked (GtkButton *button,
BjbEditorToolbar *self)
{
- biji_note_obj_editor_apply_format (self->priv->note, BIJI_ORDER_LIST);
+ BjbEditorToolbarPrivate *priv;
+
+ priv = bjb_editor_toolbar_get_instance_private (self);
+
+ biji_note_obj_editor_apply_format (priv->note, BIJI_ORDER_LIST);
}
static void
-link_callback (GtkWidget *button,
- BjbEditorToolbar *self)
+on_link_clicked (GtkButton *button,
+ BjbEditorToolbar *self)
{
BjbSettings *settings;
gchar *link;
@@ -204,7 +177,9 @@ link_callback (GtkWidget *button,
BijiNoteObj *result;
GdkRGBA color;
BijiManager *manager;
- BjbEditorToolbarPrivate *priv = self->priv;
+ BjbEditorToolbarPrivate *priv;
+
+ priv = bjb_editor_toolbar_get_instance_private (self);
link = biji_note_obj_editor_get_selection (priv->note);
@@ -227,7 +202,45 @@ link_callback (GtkWidget *button,
}
static void
-bjb_editor_toolbar_constructed (GObject *obj)
+bjb_editor_toolbar_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+bjb_editor_toolbar_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ BjbEditorToolbarPrivate *priv;
+
+ priv = bjb_editor_toolbar_get_instance_private (BJB_EDITOR_TOOLBAR (object));
+
+ switch (property_id)
+ {
+ case PROP_NOTE:
+ priv->note = g_value_get_object (value);
+ break;
+ case PROP_NOTE_VIEW:
+ priv->view = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+bjb_editor_toolbar_constructed (GObject *object)
{
BjbEditorToolbar *self;
BjbEditorToolbarPrivate *priv;
@@ -235,194 +248,131 @@ bjb_editor_toolbar_constructed (GObject *obj)
GtkWidget *window;
gboolean can_format;
- G_OBJECT_CLASS (bjb_editor_toolbar_parent_class)->constructed (obj);
-
- self = BJB_EDITOR_TOOLBAR (obj);
- priv = self->priv;
- window = bjb_note_view_get_base_window (priv->view);
- can_format = biji_note_obj_can_format (priv->note);
- gtk_window_add_accel_group (GTK_WINDOW (window), priv->accel);
-
- /* Action Bar */
- gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)),
- GTK_STYLE_CLASS_OSD);
-
- priv->box_actions = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_widget_show (priv->box_actions);
- gtk_action_bar_pack_start (GTK_ACTION_BAR (self), priv->box_actions);
-
- /* Cut */
- priv->toolbar_cut = gtk_button_new_with_label (_("Cut"));
- gtk_button_set_use_underline (GTK_BUTTON (priv->toolbar_cut), TRUE);
- gtk_widget_show (priv->toolbar_cut);
- gtk_box_pack_start (GTK_BOX (priv->box_actions), priv->toolbar_cut, TRUE, TRUE, 0);
-
- /* Copy */
- priv->toolbar_copy = gtk_button_new_with_label (_("Copy"));
- gtk_button_set_use_underline (GTK_BUTTON (priv->toolbar_copy), TRUE);
- gtk_widget_show (priv->toolbar_copy);
- gtk_box_pack_start (GTK_BOX (priv->box_actions), priv->toolbar_copy, TRUE, TRUE, 0);
-
- /* 'n paste */
- priv->toolbar_paste = gtk_button_new_with_label (_("Paste"));
- gtk_button_set_use_underline (GTK_BUTTON (priv->toolbar_paste), TRUE);
- gtk_widget_show (priv->toolbar_paste);
- gtk_box_pack_start (GTK_BOX (priv->box_actions), priv->toolbar_paste, TRUE, TRUE, 0);
-
- priv->box_center = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,CENTER_BUTTONS_SPACING);
- gtk_widget_show (priv->box_center);
- gtk_action_bar_set_center_widget (GTK_ACTION_BAR (self), priv->box_center);
-
- priv->box_style = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_widget_show (priv->box_style);
- gtk_box_pack_start (GTK_BOX (priv->box_center), priv->box_style, FALSE, TRUE, 0);
-
- /* Bold */
- priv->toolbar_bold = gtk_button_new_from_icon_name ("format-text-bold-symbolic",
GTK_ICON_SIZE_LARGE_TOOLBAR);
- gtk_button_set_use_underline (GTK_BUTTON (priv->toolbar_bold), TRUE);
- gtk_widget_set_sensitive (priv->toolbar_bold, can_format);
- gtk_widget_show (priv->toolbar_bold);
- gtk_widget_set_tooltip_text (priv->toolbar_bold, _("Bold"));
- gtk_box_pack_start (GTK_BOX (priv->box_style), priv->toolbar_bold, TRUE, TRUE, 0);
-
- /* Italic */
- priv->toolbar_italic = gtk_button_new_from_icon_name ("format-text-italic-symbolic",
GTK_ICON_SIZE_LARGE_TOOLBAR);
- gtk_button_set_use_underline (GTK_BUTTON (priv->toolbar_italic), TRUE);
- gtk_widget_set_sensitive (priv->toolbar_italic, can_format);
- gtk_widget_show (priv->toolbar_italic);
- gtk_widget_set_tooltip_text (priv->toolbar_italic, _("Italic"));
- gtk_box_pack_start (GTK_BOX (priv->box_style), priv->toolbar_italic, TRUE, TRUE, 0);
-
- /* Strike */
- priv->toolbar_strike = gtk_button_new_from_icon_name ("format-text-strikethrough-symbolic",
GTK_ICON_SIZE_LARGE_TOOLBAR);
- gtk_button_set_use_underline (GTK_BUTTON (priv->toolbar_strike), TRUE);
- gtk_widget_set_sensitive (priv->toolbar_strike, can_format);
- gtk_widget_show (priv->toolbar_strike);
- gtk_widget_set_tooltip_text (priv->toolbar_strike, _("Strike"));
- gtk_box_pack_start (GTK_BOX (priv->box_style), priv->toolbar_strike, TRUE, TRUE, 0);
-
- priv->box_points = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_widget_show (priv->box_points);
- gtk_box_pack_start (GTK_BOX (priv->box_center), priv->box_points, FALSE, TRUE, 0);
-
- /* Bullet */
- priv->toolbar_bullet = gtk_button_new_with_label (_("* "));
- gtk_button_set_use_underline (GTK_BUTTON (priv->toolbar_bullet), TRUE);
- gtk_widget_set_sensitive (priv->toolbar_bullet, can_format);
- gtk_widget_show (priv->toolbar_bullet);
- gtk_box_pack_start (GTK_BOX (priv->box_points), priv->toolbar_bullet, TRUE, TRUE, 0);
-
- /* Link */
- priv->toolbar_link = gtk_button_new_from_icon_name ("insert-link", GTK_ICON_SIZE_LARGE_TOOLBAR);
- gtk_button_set_use_underline (GTK_BUTTON (priv->toolbar_link), TRUE);
- gtk_widget_show (priv->toolbar_link);
- gtk_widget_set_tooltip_text (priv->toolbar_link, _("Copy selection to a new note"));
- gtk_action_bar_pack_end (GTK_ACTION_BAR (self), priv->toolbar_link);
-
- /* text selected --> fade in , and not selected --> fade out */
- view = biji_note_obj_get_editor (priv->note);
+ G_OBJECT_CLASS (bjb_editor_toolbar_parent_class)->constructed (object);
- g_signal_connect(view,"button-release-event",
- G_CALLBACK(on_release_event),self);
+ self = BJB_EDITOR_TOOLBAR (object);
- g_signal_connect(view,"key-release-event",
- G_CALLBACK(on_release_event),self);
+ priv = bjb_editor_toolbar_get_instance_private (self);
- /* buttons */
+ window = bjb_note_view_get_base_window (priv->view);
+ gtk_window_add_accel_group (GTK_WINDOW (window), priv->accel);
- g_signal_connect (priv->toolbar_cut,"clicked",
- G_CALLBACK(on_cut_clicked), self);
+ gtk_widget_add_accelerator (priv->bold_button, "clicked", priv->accel,
+ GDK_KEY_b, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
- g_signal_connect (priv->toolbar_copy,"clicked",
- G_CALLBACK(on_copy_clicked), self);
+ gtk_widget_add_accelerator (priv->italic_button, "clicked", priv->accel,
+ GDK_KEY_i, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
- g_signal_connect (priv->toolbar_paste,"clicked",
- G_CALLBACK(on_paste_clicked), self);
+ gtk_widget_add_accelerator (priv->strike_button, "clicked", priv->accel,
+ GDK_KEY_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
- g_signal_connect (priv->toolbar_bullet,"clicked",
- G_CALLBACK(on_bullet_clicked), self);
+ view = biji_note_obj_get_editor (priv->note);
- g_signal_connect (priv->toolbar_list,"clicked",
- G_CALLBACK(on_list_clicked), self);
+ g_signal_connect (view,"button-release-event",
+ G_CALLBACK (on_release_event), self);
- g_signal_connect (priv->toolbar_bold,"clicked",
- G_CALLBACK(bold_button_callback), self);
- gtk_widget_add_accelerator (priv->toolbar_bold,
- "clicked", priv->accel, GDK_KEY_b,
- GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
+ g_signal_connect (view,"key-release-event",
+ G_CALLBACK (on_release_event), self);
- g_signal_connect (priv->toolbar_italic,"clicked",
- G_CALLBACK(italic_button_callback), self);
- gtk_widget_add_accelerator (priv->toolbar_italic,
- "clicked", priv->accel, GDK_KEY_i,
- GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
+ can_format = biji_note_obj_can_format (priv->note);
- g_signal_connect (priv->toolbar_strike,"clicked",
- G_CALLBACK(strike_button_callback), self);
- gtk_widget_add_accelerator (priv->toolbar_strike,
- "clicked", priv->accel, GDK_KEY_s,
- GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
+ gtk_widget_set_sensitive (priv->bold_button, can_format);
+ gtk_widget_set_sensitive (priv->italic_button, can_format);
+ gtk_widget_set_sensitive (priv->strike_button, can_format);
- g_signal_connect (priv->toolbar_link,"clicked",
- G_CALLBACK(link_callback), self);
+ gtk_widget_set_sensitive (priv->bullets_button, can_format);
+ gtk_widget_set_sensitive (priv->list_button, can_format);
}
static void
-bjb_editor_toolbar_finalize (GObject *obj)
+bjb_editor_toolbar_finalize (GObject *object)
{
- BjbEditorToolbar *self = BJB_EDITOR_TOOLBAR (obj);
- BjbEditorToolbarPrivate *priv = self->priv;
+ BjbEditorToolbarPrivate *priv;
GtkWidget *window;
+ priv = bjb_editor_toolbar_get_instance_private (BJB_EDITOR_TOOLBAR (object));
+
window = bjb_note_view_get_base_window (priv->view);
gtk_window_remove_accel_group (GTK_WINDOW (window), priv->accel);
g_object_unref (priv->accel);
- G_OBJECT_CLASS (bjb_editor_toolbar_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (bjb_editor_toolbar_parent_class)->finalize (object);
}
static void
-bjb_editor_toolbar_class_init (BjbEditorToolbarClass *class)
+bjb_editor_toolbar_class_init (BjbEditorToolbarClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GObjectClass *object_class;
+ GtkWidgetClass *widget_class;
- object_class->get_property = bjb_editor_toolbar_get_property ;
- object_class->set_property = bjb_editor_toolbar_set_property ;
- object_class->constructed = bjb_editor_toolbar_constructed ;
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->get_property = bjb_editor_toolbar_get_property;
+ object_class->set_property = bjb_editor_toolbar_set_property;
+ object_class->constructed = bjb_editor_toolbar_constructed;
object_class->finalize = bjb_editor_toolbar_finalize;
+ g_object_class_install_property (object_class,
+ PROP_NOTE,
+ g_param_spec_object ("note",
+ "Note",
+ "Biji Note Obj",
+ BIJI_TYPE_NOTE_OBJ,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
-
- properties[PROP_BJB_NOTE_VIEW] = g_param_spec_object ("bjbnoteview",
- "bjbnoteview",
- "bjbnoteview",
+ g_object_class_install_property (object_class,
+ PROP_NOTE_VIEW,
+ g_param_spec_object ("note-view",
+ "Note View",
+ "Note View",
BJB_TYPE_NOTE_VIEW,
- G_PARAM_READWRITE |
+ G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS);
+ G_PARAM_STATIC_STRINGS));
+
+ widget_class = GTK_WIDGET_CLASS (klass);
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/bijiben/editor-toolbar.ui");
+
+ gtk_widget_class_bind_template_child_private (widget_class, BjbEditorToolbar, cut_button);
+ gtk_widget_class_bind_template_child_private (widget_class, BjbEditorToolbar, copy_button);
+ gtk_widget_class_bind_template_child_private (widget_class, BjbEditorToolbar, paste_button);
+ gtk_widget_class_bind_template_child_private (widget_class, BjbEditorToolbar, bold_button);
+ gtk_widget_class_bind_template_child_private (widget_class, BjbEditorToolbar, italic_button);
+ gtk_widget_class_bind_template_child_private (widget_class, BjbEditorToolbar, strike_button);
+ gtk_widget_class_bind_template_child_private (widget_class, BjbEditorToolbar, bullets_button);
+ gtk_widget_class_bind_template_child_private (widget_class, BjbEditorToolbar, list_button);
+ gtk_widget_class_bind_template_child_private (widget_class, BjbEditorToolbar, link_button);
+
+ gtk_widget_class_bind_template_callback (widget_class, on_cut_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_copy_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_paste_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_bold_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_italic_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_strike_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_bullets_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_list_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_link_clicked);
+}
- g_object_class_install_property (object_class,PROP_BJB_NOTE_VIEW,properties[PROP_BJB_NOTE_VIEW]);
+static void
+bjb_editor_toolbar_init (BjbEditorToolbar *self)
+{
+ BjbEditorToolbarPrivate *priv;
- properties[PROP_NOTE] = g_param_spec_object ("note",
- "Note",
- "Biji Note Obj",
- BIJI_TYPE_NOTE_OBJ,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS);
+ gtk_widget_init_template (GTK_WIDGET (self));
- g_object_class_install_property (object_class,PROP_NOTE,properties[PROP_NOTE]);
+ priv = bjb_editor_toolbar_get_instance_private (self);
- g_type_class_add_private (class, sizeof (BjbEditorToolbarPrivate));
+ priv->accel = gtk_accel_group_new ();
}
-
GtkWidget *
-bjb_editor_toolbar_new (BjbNoteView *bjb_note_view,
- BijiNoteObj *biji_note_obj)
+bjb_editor_toolbar_new (BjbNoteView *bjb_note_view,
+ BijiNoteObj *biji_note_obj)
{
return g_object_new (BJB_TYPE_EDITOR_TOOLBAR,
- "bjbnoteview" , bjb_note_view,
- "note" , biji_note_obj,
+ "note" , biji_note_obj,
+ "note-view", bjb_note_view,
NULL);
}
diff --git a/src/bjb-editor-toolbar.h b/src/bjb-editor-toolbar.h
index 4276665..a5166e1 100644
--- a/src/bjb-editor-toolbar.h
+++ b/src/bjb-editor-toolbar.h
@@ -26,35 +26,17 @@ G_BEGIN_DECLS
#define BJB_TYPE_EDITOR_TOOLBAR (bjb_editor_toolbar_get_type ())
-#define BJB_EDITOR_TOOLBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BJB_TYPE_EDITOR_TOOLBAR,
BjbEditorToolbar))
+G_DECLARE_FINAL_TYPE (BjbEditorToolbar, bjb_editor_toolbar, BJB, EDITOR_TOOLBAR, GtkActionBar);
-#define BJB_EDITOR_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BJB_TYPE_EDITOR_TOOLBAR,
BjbEditorToolbarClass))
-
-#define BJB_IS_EDITOR_TOOLBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BJB_TYPE_EDITOR_TOOLBAR))
-
-#define BJB_IS_EDITOR_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BJB_TYPE_EDITOR_TOOLBAR))
-
-#define BJB_EDITOR_TOOLBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BJB_TYPE_EDITOR_TOOLBAR,
BjbEditorToolbarClass))
-
-typedef struct _BjbEditorToolbar BjbEditorToolbar;
-typedef struct _BjbEditorToolbarClass BjbEditorToolbarClass;
typedef struct _BjbEditorToolbarPrivate BjbEditorToolbarPrivate;
struct _BjbEditorToolbar
{
- GtkActionBar parent_instance;
- BjbEditorToolbarPrivate *priv;
+ GtkActionBar parent;
};
-struct _BjbEditorToolbarClass
-{
- GtkActionBarClass parent_class;
-};
-
-GType bjb_editor_toolbar_get_type (void) G_GNUC_CONST;
-
-GtkWidget *bjb_editor_toolbar_new (BjbNoteView *bjb_note_view,
- BijiNoteObj *biji_note_obj);
+GtkWidget *bjb_editor_toolbar_new (BjbNoteView *bjb_note_view,
+ BijiNoteObj *biji_note_obj);
G_END_DECLS
diff --git a/src/bjb.gresource.xml b/src/bjb.gresource.xml
index 792c555..2283dfc 100644
--- a/src/bjb.gresource.xml
+++ b/src/bjb.gresource.xml
@@ -3,6 +3,7 @@
<gresource prefix="/org/gnome/bijiben">
<file alias="Adwaita.css">resources/Adwaita.css</file>
<file alias="app-menu.ui">resources/app-menu.ui</file>
+ <file alias="editor-toolbar.ui" compressed="true"
preprocess="xml-stripblanks">resources/editor-toolbar.ui</file>
<file alias="thumbnail-frame.png">resources/thumbnail-frame.png</file>
<file alias="note-symbolic.svg">resources/note-symbolic.svg</file>
</gresource>
diff --git a/src/resources/editor-toolbar.ui b/src/resources/editor-toolbar.ui
new file mode 100644
index 0000000..9055c6a
--- /dev/null
+++ b/src/resources/editor-toolbar.ui
@@ -0,0 +1,219 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkImage" id="format-text-bold">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">format-text-bold-symbolic</property>
+ <property name="icon_size">3</property>
+ </object>
+ <object class="GtkImage" id="format-text-italic">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">format-text-italic-symbolic</property>
+ <property name="icon_size">3</property>
+ </object>
+ <object class="GtkImage" id="format-text-strikethrough">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">format-text-strikethrough-symbolic</property>
+ <property name="icon_size">3</property>
+ </object>
+ <object class="GtkImage" id="insert-link">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">insert-link-symbolic</property>
+ <property name="icon_size">3</property>
+ </object>
+ <template class="BjbEditorToolbar" parent="GtkActionBar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <style>
+ <class name="osd" />
+ </style>
+ <child>
+ <object class="GtkButtonBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">expand</property>
+ <child>
+ <object class="GtkButton" id="cut_button">
+ <property name="label" translatable="yes">Cut</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="on_cut_clicked" object="BjbEditorToolbar" swapped="no" />
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="copy_button">
+ <property name="label" translatable="yes">Copy</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="on_copy_clicked" object="BjbEditorToolbar" swapped="no" />
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="paste_button">
+ <property name="label" translatable="yes">Paste</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="on_paste_clicked" object="BjbEditorToolbar" swapped="no" />
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="pack_type">start</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child type="center">
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkButtonBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">expand</property>
+ <child>
+ <object class="GtkButton" id="bold_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Bold</property>
+ <property name="image">format-text-bold</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="on_bold_clicked" object="BjbEditorToolbar" swapped="no" />
+ <accelerator key="b" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="italic_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Italic</property>
+ <property name="image">format-text-italic</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="on_italic_clicked" object="BjbEditorToolbar" swapped="no" />
+ <accelerator key="i" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="strike_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Italic</property>
+ <property name="image">format-text-strikethrough</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="on_strike_clicked" object="BjbEditorToolbar" swapped="no" />
+ <accelerator key="s" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButtonBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">expand</property>
+ <child>
+ <object class="GtkButton" id="bullets_button">
+ <property name="label" translatable="yes">* </property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Bullets</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="on_bullets_clicked" object="BjbEditorToolbar" swapped="no" />
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="list_button">
+ <property name="label" translatable="yes">1.</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">List</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="on_list_clicked" object="BjbEditorToolbar" swapped="no" />
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="link_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Copy selection to a new note</property>
+ <property name="image">insert-link</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="on_link_clicked" object="BjbEditorToolbar" swapped="no" />
+ </object>
+ <packing>
+ <property name="pack_type">end</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </template>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]