XedWindow cleanup.

This commit is contained in:
Tomasz Gąsior 2018-07-21 22:56:03 +02:00
parent bc381189c7
commit ac9d0a9343
2 changed files with 0 additions and 260 deletions

View File

@ -88,7 +88,6 @@ struct _XedWindowPrivate
GtkActionGroup *close_action_group;
GtkActionGroup *quit_action_group;
GtkActionGroup *panes_action_group;
GtkActionGroup *languages_action_group;
GtkActionGroup *documents_list_action_group;
guint documents_list_menu_ui_id;
GtkWidget *toolbar;

View File

@ -669,265 +669,6 @@ set_sensitivity_according_to_tab (XedWindow *window,
peas_extension_set_call (window->priv->extensions, "update_state");
}
static void
language_toggled (GtkToggleAction *action,
XedWindow *window)
{
XedDocument *doc;
GtkSourceLanguage *lang;
const gchar *lang_id;
if (gtk_toggle_action_get_active (action) == FALSE)
{
return;
}
doc = xed_window_get_active_document (window);
if (doc == NULL)
{
return;
}
lang_id = gtk_action_get_name (GTK_ACTION(action));
if (strcmp (lang_id, LANGUAGE_NONE) == 0)
{
/* Normal (no highlighting) */
lang = NULL;
}
else
{
lang = gtk_source_language_manager_get_language (gtk_source_language_manager_get_default (), lang_id);
if (lang == NULL)
{
g_warning("Could not get language %s\n", lang_id);
}
}
xed_document_set_language (doc, lang);
}
static gchar *
escape_section_name (const gchar *name)
{
gchar *ret;
ret = g_markup_escape_text (name, -1);
/* Replace '/' with '-' to avoid problems in xml paths */
g_strdelimit (ret, "/", '-');
return ret;
}
static void
create_language_menu_item (GtkSourceLanguage *lang,
gint index,
guint ui_id,
XedWindow *window)
{
GtkAction *section_action;
GtkRadioAction *action;
GtkAction *normal_action;
GSList *group;
const gchar *section;
gchar *escaped_section;
const gchar *lang_id;
const 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, escaped_section);
if (section_action == NULL)
{
gchar *section_name;
section_name = xed_utils_escape_underscores (section, -1);
section_action = gtk_action_new (escaped_section, section_name, NULL,
NULL);
g_free (section_name);
gtk_action_group_add_action (window->priv->languages_action_group, section_action);
g_object_unref (section_action);
gtk_ui_manager_add_ui (window->priv->manager, ui_id,
"/MenuBar/ViewMenu/ViewHighlightModeMenu/LanguagesMenuPlaceholder", 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);
lang_id = gtk_source_language_get_id (lang);
escaped_lang_name = xed_utils_escape_underscores (lang_name, -1);
tip = g_strdup_printf (_("Use %s highlight mode"), lang_name);
path = g_strdup_printf ("/MenuBar/ViewMenu/ViewHighlightModeMenu/LanguagesMenuPlaceholder/%s", escaped_section);
action = gtk_radio_action_new (lang_id, escaped_lang_name, tip, NULL, index);
g_free (escaped_lang_name);
/* Action is added with a NULL accel to make the accel overridable */
gtk_action_group_add_action_with_accel (window->priv->languages_action_group, GTK_ACTION(action), NULL);
g_object_unref (action);
/* add the action to the same radio group of the "Normal" action */
normal_action = gtk_action_group_get_action (window->priv->languages_action_group, LANGUAGE_NONE);
group = gtk_radio_action_get_group (GTK_RADIO_ACTION(normal_action));
gtk_radio_action_set_group (action, group);
g_signal_connect(action, "activate", G_CALLBACK (language_toggled), window);
gtk_ui_manager_add_ui (window->priv->manager, ui_id, path, lang_id, lang_id, GTK_UI_MANAGER_MENUITEM, FALSE);
g_free (path);
g_free (tip);
g_free (escaped_section);
}
static gint
language_compare (GtkSourceLanguage *lang1,
GtkSourceLanguage *lang2)
{
const gchar *section1, *section2, *name1, *name2;
gchar *tmp1, *tmp2;
gint ret;
section1 = gtk_source_language_get_section (lang1);
section2 = gtk_source_language_get_section (lang2);
name1 = gtk_source_language_get_name (lang1);
name2 = gtk_source_language_get_name (lang2);
/* we collate the concatenation so that they are
* sorted first by section and then by name */
tmp1 = g_strconcat (section1, "::", name1, NULL);
tmp2 = g_strconcat (section2, "::", name2, NULL);
ret = g_utf8_collate (tmp1, tmp2);
g_free(tmp1);
g_free(tmp2);
return ret;
}
static GSList *
get_languages_sorted_by_section (XedWindow *window)
{
GtkSourceLanguageManager *lm;
const gchar * const *ids;
gint i;
GSList *languages = NULL;
lm = gtk_source_language_manager_get_default ();
ids = gtk_source_language_manager_get_language_ids (lm);
for (i = 0; ids[i] != NULL; i++)
{
GtkSourceLanguage *lang;
lang = gtk_source_language_manager_get_language (lm, ids[i]);
if (!gtk_source_language_get_hidden (lang))
{
languages = g_slist_prepend (languages, lang);
}
}
return g_slist_sort (languages, (GCompareFunc)language_compare);
}
static void
create_languages_menu (XedWindow *window)
{
GtkRadioAction *action_none;
GSList *languages;
GSList *l;
guint id;
gint i;
xed_debug (DEBUG_WINDOW);
/* add the "Plain Text" item before all the others */
/* Translators: "Plain Text" means that no highlight mode is selected in the
* "View->Highlight Mode" submenu and so syntax highlighting is disabled */
action_none = gtk_radio_action_new (LANGUAGE_NONE, _("Plain Text"), _("Disable syntax highlighting"), NULL, -1);
gtk_action_group_add_action (window->priv->languages_action_group, GTK_ACTION(action_none));
g_object_unref (action_none);
g_signal_connect(action_none, "activate", G_CALLBACK (language_toggled), window);
id = gtk_ui_manager_new_merge_id (window->priv->manager);
gtk_ui_manager_add_ui (window->priv->manager, id,
"/MenuBar/ViewMenu/ViewHighlightModeMenu/LanguagesMenuPlaceholder",
LANGUAGE_NONE, LANGUAGE_NONE, GTK_UI_MANAGER_MENUITEM, TRUE);
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION(action_none), TRUE);
/* now add all the known languages */
languages = get_languages_sorted_by_section (window);
for (l = languages, i = 0; l != NULL; l = l->next)
{
create_language_menu_item (l->data, i, id, window);
}
g_slist_free (languages);
}
static void
update_languages_menu (XedWindow *window)
{
XedDocument *doc;
GList *actions;
GList *l;
GtkAction *action;
GtkSourceLanguage *lang;
const gchar *lang_id;
doc = xed_window_get_active_document (window);
if (doc == NULL)
{
return;
}
lang = xed_document_get_language (doc);
if (lang != NULL)
{
lang_id = gtk_source_language_get_id (lang);
}
else
{
lang_id = LANGUAGE_NONE;
}
actions = gtk_action_group_list_actions (window->priv->languages_action_group);
/* prevent recursion */
for (l = actions; l != NULL; l = l->next)
{
g_signal_handlers_block_by_func(GTK_ACTION (l->data), G_CALLBACK (language_toggled), window);
}
action = gtk_action_group_get_action (window->priv->languages_action_group, lang_id);
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION(action), TRUE);
for (l = actions; l != NULL; l = l->next)
{
g_signal_handlers_unblock_by_func(GTK_ACTION (l->data), G_CALLBACK (language_toggled), window);
}
g_list_free (actions);
}
void
_xed_recent_add (XedWindow *window,
GFile *location,