[evolution/wip/webkit2] Bug 754872 - Escape underscores in Search menu rule names



commit 86cecbcbfa06356208392582562427d0dcf65b9b
Author: Milan Crha <mcrha redhat com>
Date:   Tue Mar 1 14:21:11 2016 +0100

    Bug 754872 - Escape underscores in Search menu rule names

 e-util/e-html-editor-actions.c |   22 +++++++++++++++++++---
 shell/e-shell-window-actions.c |   11 +++++++++--
 2 files changed, 28 insertions(+), 5 deletions(-)
---
diff --git a/e-util/e-html-editor-actions.c b/e-util/e-html-editor-actions.c
index 08765cd..b43e8c1 100644
--- a/e-util/e-html-editor-actions.c
+++ b/e-util/e-html-editor-actions.c
@@ -1537,13 +1537,22 @@ editor_actions_setup_languages_menu (EHTMLEditor *editor)
        for (link = list; link != NULL; link = g_list_next (link)) {
                ESpellDictionary *dictionary = link->data;
                GtkToggleAction *action;
+               const gchar *language_name;
+               GString *escaped_name = NULL;
                gboolean active = FALSE;
 
+               language_name = e_spell_dictionary_get_name (dictionary);
+               if (language_name && strchr (language_name, '_') != NULL)
+                       escaped_name = e_str_replace_string (language_name, "_", "__");
+
                action = gtk_toggle_action_new (
                        e_spell_dictionary_get_code (dictionary),
-                       e_spell_dictionary_get_name (dictionary),
+                       escaped_name ? escaped_name->str : language_name,
                        NULL, NULL);
 
+               if (escaped_name)
+                       g_string_free (escaped_name, TRUE);
+
                /* Do this BEFORE connecting to the "toggled" signal.
                 * We're not prepared to invoke the signal handler yet.
                 * The "Add Word To" actions have not yet been added. */
@@ -1593,6 +1602,7 @@ editor_actions_setup_spell_check_menu (EHTMLEditor *editor)
                GtkAction *action;
                const gchar *code;
                const gchar *name;
+               GString *escaped_name = NULL;
                gchar *action_label;
                gchar *action_name;
 
@@ -1603,7 +1613,10 @@ editor_actions_setup_spell_check_menu (EHTMLEditor *editor)
                action_name = g_strdup_printf (
                        "context-spell-suggest-%s-menu", code);
 
-               action = gtk_action_new (action_name, name, NULL, NULL);
+               if (name && strchr (name, '_') != NULL)
+                       escaped_name = e_str_replace_string (name, "_", "__");
+
+               action = gtk_action_new (action_name, escaped_name ? escaped_name->str : name, NULL, NULL);
                gtk_action_group_add_action (action_group, action);
                g_object_unref (action);
 
@@ -1620,7 +1633,7 @@ editor_actions_setup_spell_check_menu (EHTMLEditor *editor)
                /* Translators: %s will be replaced with the actual dictionary
                 * name, where a user can add a word to. This is part of an
                 * "Add Word To" submenu. */
-               action_label = g_strdup_printf (_("%s Dictionary"), name);
+               action_label = g_strdup_printf (_("%s Dictionary"), escaped_name ? escaped_name->str : name);
 
                action = gtk_action_new (
                        action_name, action_label, NULL, NULL);
@@ -1645,6 +1658,9 @@ editor_actions_setup_spell_check_menu (EHTMLEditor *editor)
 
                g_free (action_label);
                g_free (action_name);
+
+               if (escaped_name)
+                       g_string_free (escaped_name, TRUE);
        }
 
        g_list_free (available_dicts);
diff --git a/shell/e-shell-window-actions.c b/shell/e-shell-window-actions.c
index 4590afc..5665821 100644
--- a/shell/e-shell-window-actions.c
+++ b/shell/e-shell-window-actions.c
@@ -1726,15 +1726,22 @@ e_shell_window_update_search_menu (EShellWindow *shell_window)
        rule = e_rule_context_next_rule (context, NULL, source);
        while (rule != NULL) {
                GtkAction *action;
+               GString *escaped_name = NULL;
                gchar *action_name;
                gchar *action_label;
 
+               if (rule->name && strchr (rule->name, '_') != NULL)
+                       escaped_name = e_str_replace_string (rule->name, "_", "__");
+
                action_name = g_strdup_printf ("custom-rule-%d", ii++);
                if (ii < 10)
                        action_label = g_strdup_printf (
-                               "_%d. %s", ii, rule->name);
+                               "_%d. %s", ii, escaped_name ? escaped_name->str : rule->name);
                else
-                       action_label = g_strdup (rule->name);
+                       action_label = g_strdup (escaped_name ? escaped_name->str : rule->name);
+
+               if (escaped_name)
+                       g_string_free (escaped_name, TRUE);
 
                action = gtk_action_new (
                        action_name, action_label,


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