Commit 7ff53218 authored by Paolo Borelli's avatar Paolo Borelli Committed by Paolo Borelli

gedit/gedit-file-chooser-dialog.c

2007-06-28  Paolo Borelli  <pborelli@katamail.com>

	* gedit/gedit-file-chooser-dialog.c
	* gedit/gedit-language-manager.c:
	* gedit/gedit-window.c:

	Adapt to gtksourceview changes.


svn path=/trunk/; revision=5659
parent 7807163c
2007-06-28 Paolo Borelli <pborelli@katamail.com>
* gedit/gedit-file-chooser-dialog.c
* gedit/gedit-language-manager.c:
* gedit/gedit-window.c:
Adapt to gtksourceview changes.
2007-06-27 Paolo Borelli <pborelli@katamail.com>
* gedit/gedit-source-style-manager.c: do not unref style
......
......@@ -162,11 +162,11 @@ all_text_files_filter (const GtkFileFilterInfo *filter_info,
if (known_mime_types == NULL)
{
GtkSourceLanguageManager *lm;
const GSList *languages;
const GSList *l;
GSList *languages;
GSList *l;
lm = gedit_get_language_manager ();
languages = gtk_source_language_manager_get_available_languages (lm);
languages = gtk_source_language_manager_list_languages (lm);
for (l = languages; l != NULL; l = l->next)
{
......@@ -201,6 +201,8 @@ all_text_files_filter (const GtkFileFilterInfo *filter_info,
g_strfreev (mime_types);
}
g_slist_free (languages);
/* known_mime_types always has "text/plain" as first item" */
known_mime_types = g_slist_prepend (known_mime_types, g_strdup ("text/plain"));
}
......
......@@ -37,9 +37,6 @@
#include "gedit-debug.h"
static GtkSourceLanguageManager *language_manager = NULL;
static const GSList *languages_list = NULL;
static GSList *languages_list_sorted = NULL;
GtkSourceLanguageManager *
gedit_get_language_manager (void)
......@@ -55,39 +52,22 @@ gedit_get_language_manager (void)
static gint
language_compare (gconstpointer a, gconstpointer b)
{
GtkSourceLanguage *lang_a = a;
GtkSourceLanguage *lang_b = 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);
gint res;
res = g_utf8_collate (name_a, name_b);
return res;
return g_utf8_collate (name_a, name_b);
}
/* Move the sorting in sourceview as a flag to get_available_langs? */
const GSList *
gedit_language_manager_get_available_languages_sorted (GtkSourceLanguageManager *lm)
GSList *
gedit_language_manager_list_languages_sorted (GtkSourceLanguageManager *lm)
{
const GSList *languages;
// FIXME This is totally broken also in the old code: checking if
// languages != languages_list is not a good way to see if no new lang
// were loaded: elements could have been appended to the list without
// changing the list head! Should be easy to fix if we make gsv return
// an array and the array len... or even better if gsv is able to sort
GSList *languages;
languages = gtk_source_language_manager_get_available_languages (lm);
languages = gtk_source_language_manager_list_languages (lm);
if ((languages_list_sorted == NULL) || (languages != languages_list))
{
languages_list = languages;
languages_list_sorted = g_slist_copy ((GSList *)languages);
languages_list_sorted = g_slist_sort (languages_list_sorted, (GCompareFunc)language_compare);
}
return languages_list_sorted;
return g_slist_sort (languages, (GCompareFunc)language_compare);
}
/* Returns a hash table that is used as a cache of already matched mime-types */
......@@ -143,8 +123,8 @@ GtkSourceLanguage *
gedit_language_manager_get_language_from_mime_type (GtkSourceLanguageManager *lm,
const gchar *mime_type)
{
const GSList *languages;
const GSList *l;
GSList *languages;
GSList *l;
GtkSourceLanguage *lang;
GtkSourceLanguage *parent = NULL;
......@@ -160,7 +140,7 @@ gedit_language_manager_get_language_from_mime_type (GtkSourceLanguageManager *lm
gedit_debug_message (DEBUG_DOCUMENT,
"Cache miss for %s", mime_type);
languages = gtk_source_language_manager_get_available_languages (lm);
languages = gtk_source_language_manager_list_languages (lm);
for (l = languages; l != NULL; l = l->next)
{
......@@ -221,6 +201,8 @@ gedit_language_manager_get_language_from_mime_type (GtkSourceLanguageManager *lm
g_strfreev (mime_types);
}
g_slist_free (languages);
if (parent != NULL)
add_language_to_cache (lm, mime_type, parent);
......
......@@ -38,7 +38,7 @@ G_BEGIN_DECLS
GtkSourceLanguageManager *gedit_get_language_manager (void);
const GSList *gedit_language_manager_get_available_languages_sorted
GSList *gedit_language_manager_list_languages_sorted
(GtkSourceLanguageManager *lm);
GtkSourceLanguage *gedit_language_manager_get_language_from_mime_type
......
......@@ -799,14 +799,15 @@ set_sensitivity_according_to_tab (GeditWindow *window,
gedit_plugins_engine_update_plugins_ui (window, FALSE);
}
#define GEDIT_SOURCE_LANGUAGE_KEY "sourcelanguage"
static void
language_toggled (GtkToggleAction *action,
GeditWindow *window)
{
GeditDocument *doc;
const GSList *languages;
const GtkSourceLanguage *lang;
gint n;
GtkSourceLanguage *lang;
const gchar *lang_id;
if (gtk_toggle_action_get_active (action) == FALSE)
return;
......@@ -815,22 +816,25 @@ language_toggled (GtkToggleAction *action,
if (doc == NULL)
return;
n = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
if (n < 0)
lang_id = g_object_get_data (G_OBJECT (action),
GEDIT_SOURCE_LANGUAGE_KEY);
if (lang_id == NULL)
{
/* Normal (no highlighting) */
lang = NULL;
}
else
{
languages = gedit_language_manager_get_available_languages_sorted (
gedit_get_language_manager ());
lang = g_slist_nth_data ((GSList *) languages, n);
lang = gtk_source_language_manager_get_language_by_id (
gedit_get_language_manager (),
lang_id);
if (lang == NULL)
{
g_warning ("Could not get language %s\n", lang_id);
}
}
gedit_document_set_language (doc, (GtkSourceLanguage *) lang);
gedit_document_set_language (doc, lang);
}
static gchar *
......@@ -863,6 +867,7 @@ create_language_menu_item (GtkSourceLanguage *lang,
GSList *group;
const gchar *section;
gchar *escaped_section;
const gchar *lang_id;
const gchar *lang_name;
gchar *escaped_lang_name;
gchar *tip;
......@@ -908,6 +913,13 @@ create_language_menu_item (GtkSourceLanguage *lang,
NULL,
index);
/* store lang id */
lang_id = gtk_source_language_get_id (lang);
g_object_set_data_full (G_OBJECT (action),
GEDIT_SOURCE_LANGUAGE_KEY,
g_strdup (lang_id),
(GDestroyNotify) g_free);
/* 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),
......@@ -942,8 +954,8 @@ static void
create_languages_menu (GeditWindow *window)
{
GtkRadioAction *action_none;
const GSList *languages;
const GSList *l;
GSList *languages;
GSList *l;
guint id;
gint i;
......@@ -979,14 +991,18 @@ create_languages_menu (GeditWindow *window)
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action_none), TRUE);
/* now add all the known languages */
languages = gedit_language_manager_get_available_languages_sorted (
languages = gedit_language_manager_list_languages_sorted (
gedit_get_language_manager ());
for (l = languages, i = 0; l != NULL; l = l->next, ++i)
{
create_language_menu_item (l->data,
i,
id,
window);
i,
id,
window);
}
g_slist_free (languages);
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment