xed/pluma/pluma-language-manager.c

98 lines
2.6 KiB
C
Raw Normal View History

2011-11-07 13:46:58 -06:00
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
2011-11-07 16:52:18 -06:00
* pluma-languages-manager.c
* This file is part of pluma
2011-11-07 13:46:58 -06:00
*
* 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
2012-11-18 19:54:49 -06:00
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
2011-11-07 13:46:58 -06:00
*/
/*
2011-11-07 16:52:18 -06:00
* Modified by the pluma Team, 2003-2006. See the AUTHORS file for a
* list of people on the pluma Team.
2011-11-07 13:46:58 -06:00
* See the ChangeLog files for a list of changes.
*
* $Id$
*/
#include <string.h>
2013-10-29 18:56:56 -05:00
#include <gtk/gtk.h>
2013-10-30 11:06:27 -05:00
#if GTK_CHECK_VERSION (3, 0, 0)
2013-10-29 18:56:56 -05:00
#include <gtksourceview/gtksource.h>
2013-10-30 11:06:27 -05:00
#endif
2011-11-07 16:52:18 -06:00
#include "pluma-language-manager.h"
#include "pluma-prefs-manager.h"
#include "pluma-utils.h"
#include "pluma-debug.h"
2011-11-07 13:46:58 -06:00
static GtkSourceLanguageManager *language_manager = NULL;
GtkSourceLanguageManager *
2011-11-07 16:52:18 -06:00
pluma_get_language_manager (void)
2011-11-07 13:46:58 -06:00
{
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 *
2011-11-07 16:52:18 -06:00
pluma_language_manager_list_languages_sorted (GtkSourceLanguageManager *lm,
2011-11-07 13:46:58 -06:00
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);
2013-10-29 18:56:56 -05:00
#if GTK_CHECK_VERSION (3, 0, 0)
g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (lang), NULL);
#else
2011-11-07 13:46:58 -06:00
g_return_val_if_fail (GTK_IS_SOURCE_LANGUAGE (lang), NULL);
2013-10-29 18:56:56 -05:00
#endif
2011-11-07 13:46:58 -06:00
++ids;
if (include_hidden || !gtk_source_language_get_hidden (lang))
{
languages = g_slist_prepend (languages, lang);
}
}
return g_slist_sort (languages, (GCompareFunc)language_compare);
}