[evolution] EComposer: Add an option to hide edit toolbar



commit 6d044a1ef475e567a8b380f0eec8632c52bbb320
Author: Cédric Bellegarde <cedric bellegarde adishatz org>
Date:   Tue May 31 11:31:17 2022 +0200

    EComposer: Add an option to hide edit toolbar

 data/org.gnome.evolution.mail.gschema.xml.in |  5 ++++
 src/composer/e-composer-actions.c            | 19 +++++++++++++-
 src/composer/e-composer-actions.h            |  2 ++
 src/composer/e-composer-private.c            |  5 ++++
 src/composer/evolution-composer.ui           |  1 +
 src/e-util/e-html-editor-actions.c           |  2 +-
 src/e-util/e-html-editor.c                   | 39 ++++++++++++++++++++++++++--
 7 files changed, 69 insertions(+), 4 deletions(-)
---
diff --git a/data/org.gnome.evolution.mail.gschema.xml.in b/data/org.gnome.evolution.mail.gschema.xml.in
index dd0fcacfc6..0b67d0bc63 100644
--- a/data/org.gnome.evolution.mail.gschema.xml.in
+++ b/data/org.gnome.evolution.mail.gschema.xml.in
@@ -243,6 +243,11 @@
       <_summary>Number of To and CC recipients to ask “prompt-on-many-to-cc-recips” from</_summary>
       <_description>When to ask, when the number of To and CC recipients reaches this value.</_description>
     </key>
+    <key name="composer-show-edit-toolbar" type="b">
+      <default>true</default>
+      <_summary>Whether to always show edit toolbar</_summary>
+      <_description>If set to “true”, the edit toolbar will be visible.</_description>
+    </key>
     <key name="composer-toolbar-show-sign-encrypt" type="b">
       <default>false</default>
       <_summary>Whether to always show Sign and Encrypt buttons on the toolbar</_summary>
diff --git a/src/composer/e-composer-actions.c b/src/composer/e-composer-actions.c
index 846a6a7c20..3700ddb7d5 100644
--- a/src/composer/e-composer-actions.c
+++ b/src/composer/e-composer-actions.c
@@ -413,6 +413,14 @@ static GtkActionEntry async_entries[] = {
 
 static GtkToggleActionEntry toggle_entries[] = {
 
+       { "toolbar-show-edit",
+         NULL,
+         N_("Edit _toolbar"),
+         NULL,
+         N_("Edit toolbar"),
+         NULL,
+         FALSE },
+
        { "pgp-encrypt",
          NULL,
          N_("PGP _Encrypt"),
@@ -596,6 +604,8 @@ e_composer_actions_init (EMsgComposer *composer)
        EHTMLEditor *editor;
        EContentEditor *cnt_editor;
        gboolean visible;
+       GSettings *settings;
+       GtkAction *action;
        GIcon *gcr_gnupg_icon;
 
        g_return_if_fail (E_IS_MSG_COMPOSER (composer));
@@ -675,13 +685,20 @@ e_composer_actions_init (EMsgComposer *composer)
 
        #undef init_toolbar_option
 
+       settings = e_util_ref_settings ("org.gnome.evolution.mail");
+       action = ACTION (TOOLBAR_SHOW_EDIT);
+       g_settings_bind (
+               settings, "composer-show-edit-toolbar",
+               action, "active",
+               G_SETTINGS_BIND_DEFAULT);
+       g_object_unref (settings);
+
        /* Borrow a GnuPG icon from gcr to distinguish between GPG and S/MIME Sign/Encrypt actions */
        gcr_gnupg_icon = g_themed_icon_new ("gcr-gnupg");
        if (gcr_gnupg_icon) {
                GIcon *temp_icon;
                GIcon *action_icon;
                GEmblem *emblem;
-               GtkAction *action;
 
                emblem = g_emblem_new (gcr_gnupg_icon);
 
diff --git a/src/composer/e-composer-actions.h b/src/composer/e-composer-actions.h
index 9046d00487..2094e09e76 100644
--- a/src/composer/e-composer-actions.h
+++ b/src/composer/e-composer-actions.h
@@ -56,6 +56,8 @@
        E_COMPOSER_ACTION ((composer), "smime-encrypt")
 #define E_COMPOSER_ACTION_SMIME_SIGN(composer) \
        E_COMPOSER_ACTION ((composer), "smime-sign")
+#define E_COMPOSER_ACTION_TOOLBAR_SHOW_EDIT(composer) \
+       E_COMPOSER_ACTION ((composer), "toolbar-show-edit")
 #define E_COMPOSER_ACTION_TOOLBAR_PGP_ENCRYPT(composer) \
        E_COMPOSER_ACTION ((composer), "toolbar-pgp-encrypt")
 #define E_COMPOSER_ACTION_TOOLBAR_PGP_SIGN(composer) \
diff --git a/src/composer/e-composer-private.c b/src/composer/e-composer-private.c
index 020ae6c442..3b4020c5f7 100644
--- a/src/composer/e-composer-private.c
+++ b/src/composer/e-composer-private.c
@@ -448,6 +448,11 @@ e_composer_private_constructed (EMsgComposer *composer)
                G_BINDING_SYNC_CREATE |
                G_BINDING_INVERT_BOOLEAN);
 
+       e_binding_bind_property (
+               E_HTML_EDITOR_ACTION (editor, "paragraph-style-menu"), "visible",
+               ACTION (TOOLBAR_SHOW_EDIT), "sensitive",
+               G_BINDING_SYNC_CREATE);
+
        g_object_unref (settings);
 }
 
diff --git a/src/composer/evolution-composer.ui b/src/composer/evolution-composer.ui
index 55f763d671..c63a417544 100644
--- a/src/composer/evolution-composer.ui
+++ b/src/composer/evolution-composer.ui
@@ -33,6 +33,7 @@
         <menuitem action='view-bcc'/>
         <separator/>
         <menuitem action='picture-gallery'/>
+        <menuitem action='toolbar-show-edit'/>
         <separator/>
         <menuitem action='visually-wrap-long-lines'/>
       </menu>
diff --git a/src/e-util/e-html-editor-actions.c b/src/e-util/e-html-editor-actions.c
index f56e560e32..16b66b6425 100644
--- a/src/e-util/e-html-editor-actions.c
+++ b/src/e-util/e-html-editor-actions.c
@@ -685,7 +685,7 @@ html_editor_actions_notify_mode_cb (EHTMLEditor *editor,
        gtk_widget_set_sensitive (editor->priv->fg_color_combo_box, is_html);
        gtk_widget_set_sensitive (editor->priv->bg_color_combo_box, is_html);
 
-       if (is_html) {
+       if (is_html && gtk_widget_get_visible (editor->priv->edit_toolbar)) {
                gtk_widget_show (editor->priv->html_toolbar);
        } else {
                gtk_widget_hide (editor->priv->html_toolbar);
diff --git a/src/e-util/e-html-editor.c b/src/e-util/e-html-editor.c
index 23f8b18ef2..fc210af6cc 100644
--- a/src/e-util/e-html-editor.c
+++ b/src/e-util/e-html-editor.c
@@ -793,6 +793,25 @@ e_html_editor_mode_to_bool_hide_in_markdown_cb (GBinding *binding,
        return TRUE;
 }
 
+static gboolean
+e_html_editor_edit_html_toolbar_visible_cb (GBinding *binding,
+                                           const GValue *from_value,
+                                           GValue *to_value,
+                                           gpointer user_data)
+{
+       gboolean visible;
+       EHTMLEditor *editor;
+
+       editor = user_data;
+       g_return_val_if_fail (E_IS_HTML_EDITOR (editor), TRUE);
+
+       visible = g_value_get_boolean (from_value);
+
+       g_value_set_boolean (to_value, visible && editor->priv->mode == E_CONTENT_EDITOR_MODE_HTML);
+
+       return TRUE;
+}
+
 static void
 html_editor_set_property (GObject *object,
                           guint property_id,
@@ -906,7 +925,6 @@ html_editor_constructed (GObject *object)
        gtk_toolbar_set_style (GTK_TOOLBAR (widget), GTK_TOOLBAR_BOTH_HORIZ);
        gtk_grid_attach (GTK_GRID (editor), widget, 0, 1, 1, 1);
        priv->html_toolbar = g_object_ref (widget);
-       gtk_widget_show (widget);
 
        /* Construct the activity bar. */
 
@@ -1033,6 +1051,14 @@ html_editor_constructed (GObject *object)
                e_html_editor_mode_to_bool_hide_in_markdown_cb,
                NULL, NULL, NULL);
 
+       e_binding_bind_property_full (
+               priv->edit_toolbar, "visible",
+               priv->html_toolbar, "visible",
+               G_BINDING_SYNC_CREATE,
+               e_html_editor_edit_html_toolbar_visible_cb,
+               NULL, editor, NULL);
+
+
        g_signal_connect_after (object, "realize", G_CALLBACK (html_editor_realize), NULL);
 
        settings = e_util_ref_settings ("org.gnome.evolution.mail");
@@ -1042,6 +1068,11 @@ html_editor_constructed (GObject *object)
                editor, "paste-plain-prefer-pre",
                G_SETTINGS_BIND_GET);
 
+       g_settings_bind (
+               settings, "composer-show-edit-toolbar",
+               priv->edit_toolbar, "visible",
+               G_SETTINGS_BIND_GET);
+
        g_object_unref (settings);
 }
 
@@ -1783,6 +1814,7 @@ e_html_editor_set_mode (EHTMLEditor *editor,
                                if (E_IS_MARKDOWN_EDITOR (editor->priv->use_content_editor)) {
                                        EMarkdownEditor *markdown_editor;
                                        GtkToolbar *toolbar;
+                                       GSettings *settings;
 
                                        markdown_editor = E_MARKDOWN_EDITOR 
(editor->priv->use_content_editor);
 
@@ -1794,7 +1826,10 @@ e_html_editor_set_mode (EHTMLEditor *editor,
                                        toolbar = GTK_TOOLBAR (editor->priv->edit_toolbar);
                                        gtk_toolbar_insert (toolbar, editor->priv->mode_tool_item, 0);
 
-                                       gtk_widget_show (GTK_WIDGET (editor->priv->edit_toolbar));
+                                       settings = e_util_ref_settings ("org.gnome.evolution.mail");
+                                       if (g_settings_get_boolean (settings, "composer-show-edit-toolbar"))
+                                               gtk_widget_show (GTK_WIDGET (editor->priv->edit_toolbar));
+                                       g_object_unref (settings);
                                }
                        }
 


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