[gnome-notes/wip-re-add-indent-outdent] Re-add indent and outdent buttons to editor toolbar




commit 487dd294b3ad54035fd219a7b2707c0d9ed16409
Author: Kévin Commaille <zecakeh pm me>
Date:   Sat Feb 27 10:25:27 2021 +0100

    Re-add indent and outdent buttons to editor toolbar
    
    Fixes #22

 data/resources/editor-toolbar.ui        | 56 +++++++++++++++++++++++++++++++++
 src/bjb-editor-toolbar.c                | 24 ++++++++++++++
 src/libbiji/biji-note-obj.h             |  4 ++-
 src/libbiji/editor/biji-webkit-editor.c | 22 ++++++++++++-
 4 files changed, 104 insertions(+), 2 deletions(-)
---
diff --git a/data/resources/editor-toolbar.ui b/data/resources/editor-toolbar.ui
index 6c69d85..c8fe367 100644
--- a/data/resources/editor-toolbar.ui
+++ b/data/resources/editor-toolbar.ui
@@ -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>
diff --git a/src/bjb-editor-toolbar.c b/src/bjb-editor-toolbar.c
index 945b3e6..a95b801 100644
--- a/src/bjb-editor-toolbar.c
+++ b/src/bjb-editor-toolbar.c
@@ -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);
 }
 
diff --git a/src/libbiji/biji-note-obj.h b/src/libbiji/biji-note-obj.h
index 20187c3..2ec07a2 100644
--- a/src/libbiji/biji-note-obj.h
+++ b/src/libbiji/biji-note-obj.h
@@ -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 ())
diff --git a/src/libbiji/editor/biji-webkit-editor.c b/src/libbiji/editor/biji-webkit-editor.c
index a4827dd..cf22ee7 100644
--- a/src/libbiji/editor/biji-webkit-editor.c
+++ b/src/libbiji/editor/biji-webkit-editor.c
@@ -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;
 
   switch (format)
   {
@@ -178,6 +188,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");
   }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]