Commit 9acd1718 authored by Kévin Commaille's avatar Kévin Commaille Committed by Isaque Galdino de Araujo
Browse files

Add indent and outdent buttons to editor toolbar

Fixes #22
parent 98e240b7
Pipeline #263002 canceled with stages
in 2 minutes and 9 seconds
......@@ -30,6 +30,18 @@
<property name="icon_name">format-text-strikethrough-symbolic</property>
<property name="icon_size">1</property>
</object>
<object class="GtkImage" id="format-indent-more">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">format-indent-more-symbolic</property>
<property name="icon_size">1</property>
</object>
<object class="GtkImage" id="format-indent-less">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">format-indent-less-symbolic</property>
<property name="icon_size">1</property>
</object>
<template class="BjbEditorToolbar" parent="GtkActionBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
......@@ -142,6 +154,50 @@
<property name="position">1</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="indent_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Indent</property>
<property name="image">format-indent-more</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="on_indent_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="outdent_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Outdent</property>
<property name="image">format-indent-less</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="on_outdent_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">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="position">0</property>
......
......@@ -52,6 +52,9 @@ struct _BjbEditorToolbar
GtkWidget *bullets_button;
GtkWidget *list_button;
GtkWidget *indent_button;
GtkWidget *outdent_button;
};
G_DEFINE_TYPE (BjbEditorToolbar, bjb_editor_toolbar, GTK_TYPE_ACTION_BAR)
......@@ -91,6 +94,20 @@ on_list_clicked (GtkButton *button,
biji_note_obj_editor_apply_format (self->note, BIJI_ORDER_LIST);
}
static void
on_indent_clicked (GtkButton *button,
BjbEditorToolbar *self)
{
biji_note_obj_editor_apply_format (self->note, BIJI_INDENT);
}
static void
on_outdent_clicked (GtkButton *button,
BjbEditorToolbar *self)
{
biji_note_obj_editor_apply_format (self->note, BIJI_OUTDENT);
}
static void
on_link_clicked (GtkButton *button,
BjbEditorToolbar *self)
......@@ -189,6 +206,9 @@ bjb_editor_toolbar_constructed (GObject *object)
gtk_widget_set_sensitive (self->bullets_button, can_format);
gtk_widget_set_sensitive (self->list_button, can_format);
gtk_widget_set_sensitive (self->indent_button, can_format);
gtk_widget_set_sensitive (self->outdent_button, can_format);
}
static void
......@@ -244,12 +264,16 @@ bjb_editor_toolbar_class_init (BjbEditorToolbarClass *klass)
gtk_widget_class_bind_template_child (widget_class, BjbEditorToolbar, strike_button);
gtk_widget_class_bind_template_child (widget_class, BjbEditorToolbar, bullets_button);
gtk_widget_class_bind_template_child (widget_class, BjbEditorToolbar, list_button);
gtk_widget_class_bind_template_child (widget_class, BjbEditorToolbar, indent_button);
gtk_widget_class_bind_template_child (widget_class, BjbEditorToolbar, outdent_button);
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_indent_clicked);
gtk_widget_class_bind_template_callback (widget_class, on_outdent_clicked);
gtk_widget_class_bind_template_callback (widget_class, on_link_clicked);
}
......
......@@ -36,7 +36,9 @@ typedef enum
BIJI_ITALIC,
BIJI_STRIKE,
BIJI_BULLET_LIST,
BIJI_ORDER_LIST
BIJI_ORDER_LIST,
BIJI_INDENT,
BIJI_OUTDENT
} BijiEditorFormat;
#define BIJI_TYPE_NOTE_OBJ (biji_note_obj_get_type ())
......
......@@ -47,7 +47,9 @@ enum {
typedef enum {
BLOCK_FORMAT_NONE,
BLOCK_FORMAT_UNORDERED_LIST,
BLOCK_FORMAT_ORDERED_LIST
BLOCK_FORMAT_ORDERED_LIST,
BLOCK_FORMAT_INDENT,
BLOCK_FORMAT_OUTDENT
} BlockFormat;
static guint biji_editor_signals [EDITOR_SIGNALS] = { 0 };
......@@ -143,6 +145,12 @@ biji_toggle_block_format (BijiWebkitEditor *self,
case BLOCK_FORMAT_ORDERED_LIST:
webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (self), "insertOrderedList");
break;
case BLOCK_FORMAT_INDENT:
webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (self), "indent");
break;
case BLOCK_FORMAT_OUTDENT:
webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (self), "outdent");
break;
default:
g_assert_not_reached ();
}
......@@ -152,6 +160,8 @@ void
biji_webkit_editor_apply_format (BijiWebkitEditor *self, gint format)
{
BijiWebkitEditorPrivate *priv = self->priv;
gboolean has_list = priv->block_format == BLOCK_FORMAT_UNORDERED_LIST
|| priv-> block_format == BLOCK_FORMAT_ORDERED_LIST;
if (priv->has_text)
{
......@@ -180,6 +190,16 @@ biji_webkit_editor_apply_format (BijiWebkitEditor *self, gint format)
biji_toggle_block_format (self, BLOCK_FORMAT_ORDERED_LIST);
break;
case BIJI_INDENT:
if (has_list)
biji_toggle_block_format (self, BLOCK_FORMAT_INDENT);
break;
case BIJI_OUTDENT:
if (has_list)
biji_toggle_block_format (self, BLOCK_FORMAT_OUTDENT);
break;
default:
g_warning ("biji_webkit_editor_apply_format : Invalid format");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment