[evolution/wip/mcrha/webkit-jsc-api: 235/292] Subscript and superscript are mutually exclusive formats



commit 83d10158986e280904795c4ccb2c31f6b9334895
Author: Milan Crha <mcrha redhat com>
Date:   Tue Nov 12 16:07:43 2019 +0100

    Subscript and superscript are mutually exclusive formats

 src/e-util/e-html-editor-actions.c  | 107 +++++++++++++++++++++++++++++++++---
 src/e-util/e-html-editor-manager.ui |   2 +-
 src/e-util/e-html-editor-private.h  |   2 -
 3 files changed, 100 insertions(+), 11 deletions(-)
---
diff --git a/src/e-util/e-html-editor-actions.c b/src/e-util/e-html-editor-actions.c
index df038be1dc..40aa850b95 100644
--- a/src/e-util/e-html-editor-actions.c
+++ b/src/e-util/e-html-editor-actions.c
@@ -957,6 +957,95 @@ action_wrap_lines_cb (GtkAction *action,
                e_content_editor_selection_wrap (cnt_editor);
 }
 
+/* This is when the user toggled the action */
+static void
+manage_format_subsuperscript_toggled (EHTMLEditor *editor,
+                                     GtkToggleAction *changed_action,
+                                     const gchar *prop_name,
+                                     GtkToggleAction *second_action)
+{
+       EContentEditor *cnt_editor = e_html_editor_get_content_editor (editor);
+
+       g_signal_handlers_block_matched (cnt_editor, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, editor);
+       g_signal_handlers_block_matched (changed_action, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, editor);
+       g_signal_handlers_block_matched (second_action, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, editor);
+
+       if (gtk_toggle_action_get_active (changed_action) &&
+           gtk_toggle_action_get_active (second_action))
+               gtk_toggle_action_set_active (second_action, FALSE);
+
+       g_object_set (G_OBJECT (cnt_editor), prop_name, gtk_toggle_action_get_active (changed_action), NULL);
+
+       g_signal_handlers_unblock_matched (second_action, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, editor);
+       g_signal_handlers_unblock_matched (changed_action, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, editor);
+       g_signal_handlers_unblock_matched (cnt_editor, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, editor);
+}
+
+/* This is when the content editor claimed change on the property */
+static void
+manage_format_subsuperscript_notify (EHTMLEditor *editor,
+                                    GtkToggleAction *changed_action,
+                                    const gchar *prop_name,
+                                    GtkToggleAction *second_action)
+{
+       EContentEditor *cnt_editor = e_html_editor_get_content_editor (editor);
+       gboolean value = FALSE;
+
+       g_signal_handlers_block_matched (cnt_editor, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, editor);
+       g_signal_handlers_block_matched (changed_action, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, editor);
+       g_signal_handlers_block_matched (second_action, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, editor);
+
+       g_object_get (G_OBJECT (cnt_editor), prop_name, &value, NULL);
+
+       gtk_toggle_action_set_active (changed_action, value);
+
+       if (gtk_toggle_action_get_active (changed_action) &&
+           gtk_toggle_action_get_active (second_action))
+               gtk_toggle_action_set_active (second_action, FALSE);
+
+       g_signal_handlers_unblock_matched (second_action, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, editor);
+       g_signal_handlers_unblock_matched (changed_action, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, editor);
+       g_signal_handlers_unblock_matched (cnt_editor, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, editor);
+}
+
+static void
+html_editor_actions_subscript_toggled_cb (GtkToggleAction *action,
+                                         EHTMLEditor *editor)
+{
+       g_return_if_fail (E_IS_HTML_EDITOR (editor));
+
+       manage_format_subsuperscript_toggled (editor, GTK_TOGGLE_ACTION (ACTION (SUBSCRIPT)), "subscript", 
GTK_TOGGLE_ACTION (ACTION (SUPERSCRIPT)));
+}
+
+static void
+html_editor_actions_notify_subscript_cb (EContentEditor *cnt_editor,
+                                        GParamSpec *param,
+                                        EHTMLEditor *editor)
+{
+       g_return_if_fail (E_IS_HTML_EDITOR (editor));
+
+       manage_format_subsuperscript_notify (editor, GTK_TOGGLE_ACTION (ACTION (SUBSCRIPT)), "subscript", 
GTK_TOGGLE_ACTION (ACTION (SUPERSCRIPT)));
+}
+
+static void
+html_editor_actions_superscript_toggled_cb (GtkToggleAction *action,
+                                           EHTMLEditor *editor)
+{
+       g_return_if_fail (E_IS_HTML_EDITOR (editor));
+
+       manage_format_subsuperscript_toggled (editor, GTK_TOGGLE_ACTION (ACTION (SUPERSCRIPT)), 
"superscript", GTK_TOGGLE_ACTION (ACTION (SUBSCRIPT)));
+}
+
+static void
+html_editor_actions_notify_superscript_cb (EContentEditor *cnt_editor,
+                                          GParamSpec *param,
+                                          EHTMLEditor *editor)
+{
+       g_return_if_fail (E_IS_HTML_EDITOR (editor));
+
+       manage_format_subsuperscript_notify (editor, GTK_TOGGLE_ACTION (ACTION (SUPERSCRIPT)), "superscript", 
GTK_TOGGLE_ACTION (ACTION (SUBSCRIPT)));
+}
+
 /*****************************************************************************
  * Core Actions
  *
@@ -2207,19 +2296,21 @@ editor_actions_bind (EHTMLEditor *editor)
                cnt_editor, "strikethrough",
                ACTION (STRIKETHROUGH), "active",
                G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
-       e_binding_bind_property (
-               cnt_editor, "subscript",
-               ACTION (SUBSCRIPT), "active",
-               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
-       e_binding_bind_property (
-               cnt_editor, "superscript",
-               ACTION (SUPERSCRIPT), "active",
-               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
        e_binding_bind_property (
                cnt_editor, "underline",
                ACTION (UNDERLINE), "active",
                G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
 
+       /* Cannot use binding, due to subscript and superscript being mutually exclusive */
+       g_signal_connect_object (ACTION (SUBSCRIPT), "toggled",
+               G_CALLBACK (html_editor_actions_subscript_toggled_cb), editor, 0);
+       g_signal_connect_object (cnt_editor, "notify::subscript",
+               G_CALLBACK (html_editor_actions_notify_subscript_cb), editor, 0);
+       g_signal_connect_object (ACTION (SUPERSCRIPT), "toggled",
+               G_CALLBACK (html_editor_actions_superscript_toggled_cb), editor, 0);
+       g_signal_connect_object (cnt_editor, "notify::superscript",
+               G_CALLBACK (html_editor_actions_notify_superscript_cb), editor, 0);
+
        e_binding_bind_property (
                cnt_editor, "html-mode",
                editor->priv->html_actions, "sensitive",
diff --git a/src/e-util/e-html-editor-manager.ui b/src/e-util/e-html-editor-manager.ui
index fa89576d3b..2110cd01a2 100644
--- a/src/e-util/e-html-editor-manager.ui
+++ b/src/e-util/e-html-editor-manager.ui
@@ -60,8 +60,8 @@
         <menuitem action='underline'/>
         <menuitem action='strikethrough'/>
         <separator/>
-        <menuitem action='subscript'/>
         <menuitem action='superscript'/>
+        <menuitem action='subscript'/>
       </menu>
       <menu action='font-size-menu'>
         <menuitem action='size-minus-two'/>
diff --git a/src/e-util/e-html-editor-private.h b/src/e-util/e-html-editor-private.h
index 03e6a65390..d65e565837 100644
--- a/src/e-util/e-html-editor-private.h
+++ b/src/e-util/e-html-editor-private.h
@@ -95,8 +95,6 @@ struct _EHTMLEditorPrivate {
        guint recent_spell_languages_merge_id;
 
        gint editor_layout_row;
-
-       gboolean is_testing;
 };
 
 void           editor_actions_init             (EHTMLEditor *editor);


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