Index: gedit-utils.c =================================================================== RCS file: /cvs/gnome/gedit/gedit/gedit-utils.c,v retrieving revision 1.68 diff -u -p -r1.68 gedit-utils.c --- gedit-utils.c 12 Dec 2005 17:27:56 -0000 1.68 +++ gedit-utils.c 29 Dec 2005 13:36:17 -0000 @@ -495,6 +495,83 @@ gedit_warning (GtkWindow *parent, const g_free (str); } +/* + * Doubles underscore to avoid spurious menu accels. + */ +gchar * +gedit_utils_escape_underscores (const gchar* text) +{ + GString *str; + gint length; + const gchar *p; + const gchar *end; + + g_return_val_if_fail (text != NULL, NULL); + + length = strlen (text); + + str = g_string_sized_new (length); + + p = text; + end = text + length; + + while (p != end) + { + const gchar *next; + next = g_utf8_next_char (p); + + switch (*p) + { + case '_': + g_string_append (str, "__"); + break; + default: + g_string_append_len (str, p, next - p); + break; + } + + p = next; + } + + return g_string_free (str, FALSE); +} + +/* + * Replaces '/' with '-' to avoid problems in xml paths. + */ +gchar * +gedit_utils_escape_slashes (const gchar *text) +{ + GString *str; + gint length; + const gchar *p; + const gchar *end; + + g_return_val_if_fail (text != NULL, NULL); + + length = strlen (text); + + str = g_string_sized_new (length); + + p = text; + end = text + length; + + while (p != end) + { + const gchar *next; + next = g_utf8_next_char (p); + + if (*p == '/') + g_string_append (str, "-"); + else + g_string_append_len (str, p, next - p); + + p = next; + } + + return g_string_free (str, FALSE); +} + /* the following functions are taken from eel */ gchar * Index: gedit-utils.h =================================================================== RCS file: /cvs/gnome/gedit/gedit/gedit-utils.h,v retrieving revision 1.35 diff -u -p -r1.35 gedit-utils.h --- gedit-utils.h 12 Dec 2005 17:27:56 -0000 1.35 +++ gedit-utils.h 29 Dec 2005 13:36:17 -0000 @@ -69,6 +69,10 @@ GtkWidget *gedit_dialog_add_button (Gtk const gchar *stock_id, gint response_id); +gchar *gedit_utils_escape_underscores (const gchar* text); + +gchar *gedit_utils_escape_slashes (const gchar* text); + gchar *gedit_utils_str_middle_truncate (const gchar *string, guint truncate_length); Index: gedit-window.c =================================================================== RCS file: /cvs/gnome/gedit/gedit/gedit-window.c,v retrieving revision 1.6 diff -u -p -r1.6 gedit-window.c --- gedit-window.c 14 Dec 2005 17:25:12 -0000 1.6 +++ gedit-window.c 29 Dec 2005 13:36:20 -0000 @@ -594,6 +594,20 @@ language_toggled (GtkToggleAction *actio gedit_document_set_language (doc, (GtkSourceLanguage *) lang); } +static gchar * +escape_section_name (gchar *name) +{ + gchar *tmp; + gchar *ret; + + tmp = g_markup_escape_text (name, -1); + ret = gedit_utils_escape_slashes (tmp); + + g_free (tmp); + + return ret; +} + static void create_language_menu_item (GtkSourceLanguage *lang, gint index, @@ -605,20 +619,22 @@ create_language_menu_item (GtkSourceLang GtkAction *normal_action; GSList *group; gchar *section; + gchar *escaped_section; gchar *lang_name; + gchar *escaped_lang_name; gchar *tip; gchar *path; section = gtk_source_language_get_section (lang); + escaped_section = escape_section_name (section); /* check if the section submenu exists or create it */ section_action = gtk_action_group_get_action (window->priv->languages_action_group, - section); + escaped_section); if (section_action == NULL) { - // CHECK: escaping strings - section_action = gtk_action_new (section, + section_action = gtk_action_new (escaped_section, section, NULL, NULL); @@ -630,19 +646,21 @@ create_language_menu_item (GtkSourceLang gtk_ui_manager_add_ui (window->priv->manager, ui_id, "/MenuBar/ViewMenu/ViewHighlightModeMenu/LanguagesMenuPlaceholder", - section, section, + escaped_section, escaped_section, GTK_UI_MANAGER_MENU, FALSE); } /* now add the language item to the section */ lang_name = gtk_source_language_get_name (lang); + + escaped_lang_name = g_markup_escape_text (lang_name, -1); + tip = g_strdup_printf (_("Use %s highlight mode"), lang_name); path = g_strdup_printf ("/MenuBar/ViewMenu/ViewHighlightModeMenu/LanguagesMenuPlaceholder/%s", - section); + escaped_section); - // CHECK: escaping strings - action = gtk_radio_action_new (lang_name, + action = gtk_radio_action_new (escaped_lang_name, lang_name, tip, NULL, @@ -666,14 +684,16 @@ create_language_menu_item (GtkSourceLang gtk_ui_manager_add_ui (window->priv->manager, ui_id, path, - lang_name, lang_name, + escaped_lang_name, escaped_lang_name, GTK_UI_MANAGER_MENUITEM, FALSE); g_free (path); g_free (tip); g_free (lang_name); + g_free (escaped_lang_name); g_free (section); + g_free (escaped_section); } static void @@ -734,6 +754,7 @@ update_languages_menu (GeditWindow *wind GtkAction *action; GtkSourceLanguage *lang; gchar *lang_name; + gchar *escaped_lang_name; doc = gedit_window_get_active_document (window); if (doc == NULL) @@ -745,6 +766,8 @@ update_languages_menu (GeditWindow *wind else lang_name = g_strdup ("LangNormal"); + escaped_lang_name = g_markup_escape_text (lang_name, -1); + actions = gtk_action_group_list_actions (window->priv->languages_action_group); /* prevent recursion */ @@ -756,7 +779,7 @@ update_languages_menu (GeditWindow *wind } action = gtk_action_group_get_action (window->priv->languages_action_group, - lang_name); + escaped_lang_name); gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE); @@ -769,6 +792,7 @@ update_languages_menu (GeditWindow *wind g_list_free (actions); g_free (lang_name); + g_free (escaped_lang_name); } static void @@ -1116,8 +1140,9 @@ update_documents_list_menu (GeditWindow GtkWidget *tab; GtkRadioAction *action; gchar *action_name; - gchar *tab_name; //CHECK: must escape underscores and gmarkup - gchar *tip; // ditto as above + gchar *tab_name; + gchar *name; + gchar *tip; gchar *accel; tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (p->notebook), i); @@ -1131,13 +1156,14 @@ update_documents_list_menu (GeditWindow */ action_name = g_strdup_printf ("Tab_%d", i); tab_name = _gedit_tab_get_name (GEDIT_TAB (tab)); + name = gedit_utils_escape_underscores (tab_name); tip = g_strdup_printf (_("Activate %s"), tab_name); /* alt + 1, 2, 3... 0 to switch to the first ten tabs */ accel = (i < 10) ? g_strdup_printf ("%d", (i + 1) % 10) : NULL; action = gtk_radio_action_new (action_name, - tab_name, + name, tip, NULL, i); @@ -1171,6 +1197,7 @@ update_documents_list_menu (GeditWindow g_free (action_name); g_free (tab_name); + g_free (name); g_free (tip); g_free (accel); } @@ -2272,7 +2299,7 @@ notebook_tab_close_request (GeditNoteboo GeditTab *tab, GtkWindow *window) { - /* CHECK: we are destroying the tab before the default handler + /* Note: we are destroying the tab before the default handler * seems to be ok, but we need to keep an eye on this. */ _gedit_cmd_file_close_tab (tab, GEDIT_WINDOW (window)); } @@ -2746,7 +2773,6 @@ gedit_window_close_tab (GeditWindow *win tab); } -// CHECK: these should be priv? pbor. void gedit_window_close_all_tabs (GeditWindow *window) {