From 6b8c07d90e28af1f319e1b481167e0f794cf4927 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 21 Jan 2017 13:51:08 -0800 Subject: [PATCH] Kill xed-language-manager and use gtksourcelanguagemanager directly --- plugins/modelines/modeline-parser.c | 3 +- xed/Makefile.am | 2 - xed/dialogs/xed-preferences-dialog.c | 1 - xed/xed-app.c | 2 +- xed/xed-document.c | 9 ++- xed/xed-file-chooser-dialog.c | 3 +- xed/xed-language-manager.c | 90 ---------------------------- xed/xed-language-manager.h | 48 --------------- xed/xed-settings.c | 2 +- xed/xed-window.c | 88 ++++++++++++++++++++------- 10 files changed, 76 insertions(+), 172 deletions(-) delete mode 100644 xed/xed-language-manager.c delete mode 100644 xed/xed-language-manager.h diff --git a/plugins/modelines/modeline-parser.c b/plugins/modelines/modeline-parser.c index c900eab..3b9133e 100644 --- a/plugins/modelines/modeline-parser.c +++ b/plugins/modelines/modeline-parser.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -752,7 +751,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) GtkSourceLanguageManager *manager; GtkSourceLanguage *language; - manager = xed_get_language_manager (); + manager = gtk_source_language_manager_get_default (); language = gtk_source_language_manager_get_language (manager, options.language_id); diff --git a/xed/Makefile.am b/xed/Makefile.am index b8339aa..0c6399e 100644 --- a/xed/Makefile.am +++ b/xed/Makefile.am @@ -53,7 +53,6 @@ NOINST_H_FILES = \ xed-documents-panel.h \ xed-history-entry.h \ xed-io-error-message-area.h \ - xed-language-manager.h \ xed-plugins-engine.h \ xed-print-job.h \ xed-print-preview.h \ @@ -126,7 +125,6 @@ libxed_c_files = \ xed-help.c \ xed-history-entry.c \ xed-io-error-message-area.c \ - xed-language-manager.c \ xed-message-bus.c \ xed-message-type.c \ xed-message.c \ diff --git a/xed/dialogs/xed-preferences-dialog.c b/xed/dialogs/xed-preferences-dialog.c index 68a75d3..7f31a51 100755 --- a/xed/dialogs/xed-preferences-dialog.c +++ b/xed/dialogs/xed-preferences-dialog.c @@ -42,7 +42,6 @@ #include #include #include -#include #include "xed-preferences-dialog.h" #include "xed-utils.h" diff --git a/xed/xed-app.c b/xed/xed-app.c index f23a567..fe71b44 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include "xed-app.h" #include "xed-commands.h" diff --git a/xed/xed-document.c b/xed/xed-document.c index 3035d02..694b3c7 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -40,13 +40,11 @@ #include #include #include -#include #include "xed-settings.h" #include "xed-document.h" #include "xed-debug.h" #include "xed-utils.h" -#include "xed-language-manager.h" #include "xed-document-loader.h" #include "xed-document-saver.h" #include "xed-marshal.h" @@ -815,7 +813,7 @@ guess_language (XedDocument *doc, if (strcmp (data, "_NORMAL_") != 0) { - language = gtk_source_language_manager_get_language (xed_get_language_manager (), data); + language = gtk_source_language_manager_get_language (gtk_source_language_manager_get_default (), data); } g_free (data); @@ -837,7 +835,8 @@ guess_language (XedDocument *doc, basename = g_strdup (doc->priv->short_name); } - language = gtk_source_language_manager_guess_language (xed_get_language_manager (), basename, content_type); + language = gtk_source_language_manager_guess_language (gtk_source_language_manager_get_default (), + basename, content_type); g_free (basename); @@ -1646,7 +1645,7 @@ xed_document_save_as (XedDocument *doc, const XedEncoding *encoding, XedDocumentSaveFlags flags) { - GError *error; + GError *error = NULL; g_return_if_fail (XED_IS_DOCUMENT (doc)); g_return_if_fail (G_IS_FILE (location)); diff --git a/xed/xed-file-chooser-dialog.c b/xed/xed-file-chooser-dialog.c index 909a05b..bed9ea1 100644 --- a/xed/xed-file-chooser-dialog.c +++ b/xed/xed-file-chooser-dialog.c @@ -43,7 +43,6 @@ #include "xed-file-chooser-dialog.h" #include "xed-encodings-combo-box.h" -#include "xed-language-manager.h" #include "xed-debug.h" #include "xed-enum-types.h" #include "xed-settings.h" @@ -256,7 +255,7 @@ all_text_files_filter (const GtkFileFilterInfo *filter_info, GtkSourceLanguageManager *lm; const gchar * const *languages; - lm = xed_get_language_manager (); + lm = gtk_source_language_manager_get_default (); languages = gtk_source_language_manager_get_language_ids (lm); while ((languages != NULL) && (*languages != NULL)) diff --git a/xed/xed-language-manager.c b/xed/xed-language-manager.c deleted file mode 100644 index 6ae2e44..0000000 --- a/xed/xed-language-manager.c +++ /dev/null @@ -1,90 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * xed-languages-manager.c - * This file is part of xed - * - * Copyright (C) 2003-2006 - Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2003-2006. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#include -#include -#include -#include "xed-language-manager.h" -#include "xed-utils.h" -#include "xed-debug.h" - -static GtkSourceLanguageManager *language_manager = NULL; - -GtkSourceLanguageManager * -xed_get_language_manager (void) -{ - if (language_manager == NULL) - { - language_manager = gtk_source_language_manager_new (); - } - - return language_manager; -} - -static gint -language_compare (gconstpointer a, gconstpointer b) -{ - GtkSourceLanguage *lang_a = (GtkSourceLanguage *)a; - GtkSourceLanguage *lang_b = (GtkSourceLanguage *)b; - const gchar *name_a = gtk_source_language_get_name (lang_a); - const gchar *name_b = gtk_source_language_get_name (lang_b); - - return g_utf8_collate (name_a, name_b); -} - -GSList * -xed_language_manager_list_languages_sorted (GtkSourceLanguageManager *lm, - gboolean include_hidden) -{ - GSList *languages = NULL; - const gchar * const *ids; - - ids = gtk_source_language_manager_get_language_ids (lm); - if (ids == NULL) - return NULL; - - while (*ids != NULL) - { - GtkSourceLanguage *lang; - - lang = gtk_source_language_manager_get_language (lm, *ids); - g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (lang), NULL); - ++ids; - - if (include_hidden || !gtk_source_language_get_hidden (lang)) - { - languages = g_slist_prepend (languages, lang); - } - } - - return g_slist_sort (languages, (GCompareFunc)language_compare); -} - diff --git a/xed/xed-language-manager.h b/xed/xed-language-manager.h deleted file mode 100644 index 9c48bae..0000000 --- a/xed/xed-language-manager.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * xed-languages-manager.h - * This file is part of xed - * - * Copyright (C) 2003-2005 - Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2003-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifndef __XED_LANGUAGES_MANAGER_H__ -#define __XED_LANGUAGES_MANAGER_H__ - -#include -#include - -G_BEGIN_DECLS - -GtkSourceLanguageManager *xed_get_language_manager (void); - -GSList *xed_language_manager_list_languages_sorted - (GtkSourceLanguageManager *lm, - gboolean include_hidden); - -G_END_DECLS - -#endif /* __XED_LANGUAGES_MANAGER_H__ */ diff --git a/xed/xed-settings.c b/xed/xed-settings.c index a5052f9..64686d7 100644 --- a/xed/xed-settings.c +++ b/xed/xed-settings.c @@ -23,7 +23,7 @@ #include -#include +#include #include "xed-settings.h" #include "xed-app.h" diff --git a/xed/xed-window.c b/xed/xed-window.c index 6419cbc..c0ce65a 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -22,7 +22,6 @@ #include "xed-utils.h" #include "xed-commands.h" #include "xed-debug.h" -#include "xed-language-manager.h" #include "xed-panel.h" #include "xed-documents-panel.h" #include "xed-plugins-engine.h" @@ -707,7 +706,7 @@ language_toggled (GtkToggleAction *action, } else { - lang = gtk_source_language_manager_get_language (xed_get_language_manager (), lang_id); + 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); @@ -799,6 +798,54 @@ create_language_menu_item (GtkSourceLanguage *lang, 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]); + languages = g_slist_prepend (languages, lang); + } + + return g_slist_sort (languages, (GCompareFunc)language_compare); +} + static void create_languages_menu (XedWindow *window) { @@ -830,9 +877,9 @@ create_languages_menu (XedWindow *window) gtk_toggle_action_set_active (GTK_TOGGLE_ACTION(action_none), TRUE); /* now add all the known languages */ - languages = xed_language_manager_list_languages_sorted (xed_get_language_manager (), FALSE); + languages = get_languages_sorted_by_section (window); - for (l = languages, i = 0; l != NULL; l = l->next, ++i) + for (l = languages, i = 0; l != NULL; l = l->next) { create_language_menu_item (l->data, i, id, window); } @@ -1625,35 +1672,36 @@ fill_tab_width_combo (XedWindow *window) static void fill_language_combo (XedWindow *window) { - GtkSourceLanguageManager *manager; - GSList *languages; - GSList *item; - GtkWidget *menu_item; + GtkSourceLanguageManager *lm; + const gchar * const *ids; const gchar *name; - - manager = xed_get_language_manager (); - languages = xed_language_manager_list_languages_sorted (manager, FALSE); + GtkWidget *menu_item; + gint i; name = _("Plain Text"); menu_item = gtk_menu_item_new_with_label (name); gtk_widget_show (menu_item); g_object_set_data (G_OBJECT(menu_item), LANGUAGE_DATA, NULL); - xed_status_combo_box_add_item (XED_STATUS_COMBO_BOX(window->priv->language_combo), GTK_MENU_ITEM(menu_item), name); + xed_status_combo_box_add_item (XED_STATUS_COMBO_BOX (window->priv->language_combo), GTK_MENU_ITEM (menu_item), name); - for (item = languages; item; item = item->next) + 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 = GTK_SOURCE_LANGUAGE(item->data); + GtkSourceLanguage *lang; + + lang = gtk_source_language_manager_get_language (lm, ids[i]); name = gtk_source_language_get_name (lang); menu_item = gtk_menu_item_new_with_label (name); gtk_widget_show (menu_item); - g_object_set_data_full (G_OBJECT(menu_item), LANGUAGE_DATA, g_object_ref (lang), - (GDestroyNotify) g_object_unref); - xed_status_combo_box_add_item (XED_STATUS_COMBO_BOX(window->priv->language_combo), - GTK_MENU_ITEM(menu_item), name); - } - g_slist_free (languages); + g_object_set_data_full (G_OBJECT (menu_item), LANGUAGE_DATA, g_object_ref (lang), + (GDestroyNotify) g_object_unref); + xed_status_combo_box_add_item (XED_STATUS_COMBO_BOX (window->priv->language_combo), + GTK_MENU_ITEM (menu_item), name); + } } static void