Kill xed-language-manager and use gtksourcelanguagemanager directly

This commit is contained in:
JosephMcc 2017-01-21 13:51:08 -08:00
parent 4a6f1d02b8
commit 6b8c07d90e
10 changed files with 76 additions and 172 deletions

View File

@ -24,7 +24,6 @@
#include <stdio.h>
#include <gtk/gtk.h>
#include <gtksourceview/gtksource.h>
#include <xed/xed-language-manager.h>
#include <xed/xed-debug.h>
#include <xed/xed-settings.h>
#include <xed/xed-utils.h>
@ -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);

View File

@ -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 \

View File

@ -42,7 +42,6 @@
#include <gtk/gtk.h>
#include <gtksourceview/gtksource.h>
#include <libpeas-gtk/peas-gtk-plugin-manager.h>
#include <gtksourceview/gtksourcestyleschememanager.h>
#include "xed-preferences-dialog.h"
#include "xed-utils.h"

View File

@ -37,7 +37,7 @@
#include <glib/gi18n.h>
#include <libpeas/peas-extension-set.h>
#include <gtksourceview/gtksourcestyleschememanager.h>
#include <gtksourceview/gtksource.h>
#include "xed-app.h"
#include "xed-commands.h"

View File

@ -40,13 +40,11 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <gtksourceview/gtksource.h>
#include <gtksourceview/gtksourcestyleschememanager.h>
#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));

View File

@ -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))

View File

@ -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 <string.h>
#include <gtk/gtk.h>
#include <gtksourceview/gtksource.h>
#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);
}

View File

@ -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 <glib-object.h>
#include <gtksourceview/gtksourcelanguagemanager.h>
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__ */

View File

@ -23,7 +23,7 @@
#include <string.h>
#include <gtksourceview/gtksourcestyleschememanager.h>
#include <gtksourceview/gtksource.h>
#include "xed-settings.h"
#include "xed-app.h"

View File

@ -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