medit/moo/gtksourceview/gtksourcestyleschememanager.c

578 lines
15 KiB
C
Raw Normal View History

2006-11-02 00:43:53 -06:00
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
2007-09-09 14:21:19 -05:00
* gtksourcestyleschememanager.c
2006-11-02 00:43:53 -06:00
*
2007-07-17 11:19:25 -05:00
* Copyright (C) 2003-2007 - Paolo Maggi <paolo@gnome.org>
2006-11-02 00:43:53 -06:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library 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 Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
2007-09-09 14:21:19 -05:00
#include "gtksourcestyleschememanager.h"
2006-11-02 00:43:53 -06:00
#include "gtksourceview-marshal.h"
2007-04-27 21:19:36 -05:00
#include "gtksourceview-i18n.h"
#include "gtksourceview-utils.h"
2006-11-02 00:43:53 -06:00
#include <string.h>
2007-06-18 00:03:03 -05:00
#define SCHEME_FILE_SUFFIX ".xml"
2006-11-02 00:43:53 -06:00
#define STYLES_DIR "styles"
2007-09-09 14:21:19 -05:00
struct _GtkSourceStyleSchemeManagerPrivate
2006-11-02 00:43:53 -06:00
{
2007-07-17 11:19:25 -05:00
GHashTable *schemes_hash;
gchar **search_path;
2006-11-02 00:43:53 -06:00
gboolean need_reload;
2007-07-17 11:19:25 -05:00
gchar **ids; /* Cache the IDs of the available schemes */
2006-11-02 00:43:53 -06:00
};
2007-07-17 11:19:25 -05:00
2007-04-27 21:19:36 -05:00
enum {
PROP_0,
2007-07-17 11:19:25 -05:00
PROP_SEARCH_PATH,
PROP_SCHEME_IDS
2007-04-27 21:19:36 -05:00
};
2006-11-02 00:43:53 -06:00
2007-09-09 14:21:19 -05:00
G_DEFINE_TYPE (GtkSourceStyleSchemeManager, gtk_source_style_scheme_manager, G_TYPE_OBJECT)
2006-11-02 00:43:53 -06:00
static void
2007-09-09 14:21:19 -05:00
gtk_source_style_scheme_manager_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
2006-11-02 00:43:53 -06:00
{
2007-09-09 14:21:19 -05:00
GtkSourceStyleSchemeManager *sm;
2006-11-02 00:43:53 -06:00
2007-09-09 14:21:19 -05:00
sm = GTK_SOURCE_STYLE_SCHEME_MANAGER (object);
2006-11-02 00:43:53 -06:00
2007-04-27 21:19:36 -05:00
switch (prop_id)
{
case PROP_SEARCH_PATH:
2007-09-09 14:21:19 -05:00
gtk_source_style_scheme_manager_set_search_path
(sm, g_value_get_boxed (value));
2007-04-27 21:19:36 -05:00
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
prop_id,
pspec);
break;
}
2006-11-02 00:43:53 -06:00
}
static void
2007-09-09 14:21:19 -05:00
gtk_source_style_scheme_manager_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
2006-11-02 00:43:53 -06:00
{
2007-09-09 14:21:19 -05:00
GtkSourceStyleSchemeManager *sm;
2007-04-27 21:19:36 -05:00
2007-09-09 14:21:19 -05:00
sm = GTK_SOURCE_STYLE_SCHEME_MANAGER (object);
2007-04-27 21:19:36 -05:00
switch (prop_id)
{
case PROP_SEARCH_PATH:
2007-09-09 14:21:19 -05:00
g_value_set_boxed (value,
gtk_source_style_scheme_manager_get_search_path (sm));
2007-04-27 21:19:36 -05:00
break;
2007-07-17 11:19:25 -05:00
case PROP_SCHEME_IDS:
2007-09-09 14:21:19 -05:00
g_value_set_boxed (value,
gtk_source_style_scheme_manager_get_scheme_ids (sm));
2007-07-17 11:19:25 -05:00
break;
2007-04-27 21:19:36 -05:00
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
prop_id,
pspec);
break;
}
2006-11-02 00:43:53 -06:00
}
2007-07-17 11:19:25 -05:00
static void
2007-09-09 14:21:19 -05:00
free_schemes (GtkSourceStyleSchemeManager *mgr)
2007-07-17 11:19:25 -05:00
{
if (mgr->priv->schemes_hash != NULL)
{
g_hash_table_destroy (mgr->priv->schemes_hash);
mgr->priv->schemes_hash = NULL;
}
g_strfreev (mgr->priv->ids);
mgr->priv->ids = NULL;
}
2006-11-02 00:43:53 -06:00
static void
2007-09-09 14:21:19 -05:00
gtk_source_style_scheme_manager_finalize (GObject *object)
2006-11-02 00:43:53 -06:00
{
2007-09-09 14:21:19 -05:00
GtkSourceStyleSchemeManager *mgr;
2006-11-02 00:43:53 -06:00
2007-09-09 14:21:19 -05:00
mgr = GTK_SOURCE_STYLE_SCHEME_MANAGER (object);
2006-11-02 00:43:53 -06:00
2007-07-17 11:19:25 -05:00
free_schemes (mgr);
g_strfreev (mgr->priv->search_path);
2006-11-02 00:43:53 -06:00
2007-09-09 14:21:19 -05:00
G_OBJECT_CLASS (gtk_source_style_scheme_manager_parent_class)->finalize (object);
2006-11-02 00:43:53 -06:00
}
2007-04-27 21:19:36 -05:00
static void
2007-09-09 14:21:19 -05:00
gtk_source_style_scheme_manager_class_init (GtkSourceStyleSchemeManagerClass *klass)
2006-11-02 00:43:53 -06:00
{
2007-04-27 21:19:36 -05:00
GObjectClass *object_class = G_OBJECT_CLASS (klass);
2006-11-02 00:43:53 -06:00
2007-09-09 14:21:19 -05:00
object_class->finalize = gtk_source_style_scheme_manager_finalize;
object_class->set_property = gtk_source_style_scheme_manager_set_property;
object_class->get_property = gtk_source_style_scheme_manager_get_property;
2007-04-27 21:19:36 -05:00
g_object_class_install_property (object_class,
PROP_SEARCH_PATH,
g_param_spec_boxed ("search-path",
2007-07-17 11:19:25 -05:00
_("Style scheme search path"),
_("List of directories and files where the "
"style schemes are located"),
2007-04-27 21:19:36 -05:00
G_TYPE_STRV,
G_PARAM_READWRITE));
2006-11-02 00:43:53 -06:00
2007-07-17 11:19:25 -05:00
g_object_class_install_property (object_class,
PROP_SCHEME_IDS,
g_param_spec_boxed ("scheme-ids",
_("Scheme ids"),
_("List of the ids of the available "
"style schemes"),
G_TYPE_STRV,
G_PARAM_READABLE));
2006-11-02 00:43:53 -06:00
2007-09-09 14:21:19 -05:00
g_type_class_add_private (object_class, sizeof(GtkSourceStyleSchemeManagerPrivate));
2006-11-02 00:43:53 -06:00
}
2007-04-27 21:19:36 -05:00
static void
2007-09-09 14:21:19 -05:00
gtk_source_style_scheme_manager_init (GtkSourceStyleSchemeManager *mgr)
2006-11-02 00:43:53 -06:00
{
2007-09-09 14:21:19 -05:00
mgr->priv = G_TYPE_INSTANCE_GET_PRIVATE (mgr,
GTK_TYPE_SOURCE_STYLE_SCHEME_MANAGER,
GtkSourceStyleSchemeManagerPrivate);
2007-07-17 11:19:25 -05:00
mgr->priv->schemes_hash = NULL;
mgr->priv->ids = NULL;
mgr->priv->search_path = NULL;
2007-04-27 21:19:36 -05:00
mgr->priv->need_reload = TRUE;
}
2006-11-02 00:43:53 -06:00
2007-06-12 00:43:25 -05:00
/**
2007-09-09 14:21:19 -05:00
* gtk_source_style_scheme_manager_new:
2007-06-12 00:43:25 -05:00
*
* Creates a new style manager. If you do not need more than one style
2007-09-09 14:21:19 -05:00
* manager then use gtk_source_style_scheme_manager_get_default() instead.
2007-06-12 00:43:25 -05:00
*
2007-09-09 14:21:19 -05:00
* Returns: a #GtkSourceStyleSchemeManager.
2007-07-31 06:11:24 -05:00
*/
2007-09-09 14:21:19 -05:00
GtkSourceStyleSchemeManager *
gtk_source_style_scheme_manager_new (void)
2007-04-27 21:19:36 -05:00
{
2007-09-09 14:21:19 -05:00
return g_object_new (GTK_TYPE_SOURCE_STYLE_SCHEME_MANAGER, NULL);
2006-11-02 00:43:53 -06:00
}
2007-06-12 00:43:25 -05:00
/**
2007-09-09 14:21:19 -05:00
* gtk_source_style_scheme_manager_get_default:
2007-06-12 00:43:25 -05:00
*
2007-09-09 14:21:19 -05:00
* Returns the default #GtkSourceStyleSchemeManager instance.
2007-06-12 00:43:25 -05:00
*
2007-09-09 14:21:19 -05:00
* Returns: a #GtkSourceStyleSchemeManager. Return value is owned
2007-06-12 00:43:25 -05:00
* by GtkSourceView library and must not be unref'ed.
2007-07-31 06:11:24 -05:00
*/
2007-09-09 14:21:19 -05:00
GtkSourceStyleSchemeManager *
gtk_source_style_scheme_manager_get_default (void)
2007-06-12 00:43:25 -05:00
{
2007-09-09 14:21:19 -05:00
static GtkSourceStyleSchemeManager *instance;
2007-06-12 00:43:25 -05:00
if (instance == NULL)
{
2007-09-09 14:21:19 -05:00
instance = gtk_source_style_scheme_manager_new ();
2007-06-12 00:43:25 -05:00
g_object_add_weak_pointer (G_OBJECT (instance),
2007-07-17 11:19:25 -05:00
(gpointer) &instance);
2007-06-12 00:43:25 -05:00
}
return instance;
}
2007-07-17 11:19:25 -05:00
static GSList *
ids_list_remove (GSList *ids, const gchar *id, gboolean free_data)
{
GSList *o = g_slist_find_custom (ids, id, (GCompareFunc) strcmp);
2007-09-09 14:21:19 -05:00
2007-07-17 11:19:25 -05:00
if (o != NULL)
{
if (free_data)
g_free (o->data);
ids = g_slist_delete_link (ids, o);
}
return ids;
}
2006-11-02 00:43:53 -06:00
static gboolean
build_reference_chain (GtkSourceStyleScheme *scheme,
GHashTable *hash,
GSList **ret)
{
GSList *chain;
gboolean retval = TRUE;
chain = g_slist_prepend (NULL, scheme);
while (TRUE)
{
GtkSourceStyleScheme *parent_scheme;
const gchar *parent_id;
parent_id = _gtk_source_style_scheme_get_parent_id (scheme);
if (parent_id == NULL)
break;
parent_scheme = g_hash_table_lookup (hash, parent_id);
if (parent_scheme == NULL)
{
2007-07-17 11:19:25 -05:00
g_warning ("Unknown parent scheme '%s' in scheme '%s'",
2006-11-02 00:43:53 -06:00
parent_id, gtk_source_style_scheme_get_id (scheme));
retval = FALSE;
break;
}
else if (g_slist_find (chain, parent_scheme) != NULL)
{
2007-07-17 11:19:25 -05:00
g_warning ("Reference cycle in scheme '%s'", parent_id);
2006-11-02 00:43:53 -06:00
retval = FALSE;
break;
}
else
{
_gtk_source_style_scheme_set_parent (scheme, parent_scheme);
}
chain = g_slist_prepend (chain, parent_scheme);
scheme = parent_scheme;
}
*ret = chain;
return retval;
}
static GSList *
2007-07-17 11:19:25 -05:00
check_parents (GSList *ids,
2006-11-02 00:43:53 -06:00
GHashTable *hash)
{
GSList *to_check;
2007-07-17 11:19:25 -05:00
to_check = g_slist_copy (ids);
2006-11-02 00:43:53 -06:00
while (to_check != NULL)
{
GSList *chain;
gboolean valid;
2007-07-17 11:19:25 -05:00
GtkSourceStyleScheme *scheme_to_check;
2006-11-02 00:43:53 -06:00
2007-07-17 11:19:25 -05:00
scheme_to_check = g_hash_table_lookup (hash, to_check->data);
g_return_val_if_fail (scheme_to_check != NULL, NULL);
valid = build_reference_chain (scheme_to_check, hash, &chain);
2006-11-02 00:43:53 -06:00
while (chain != NULL)
{
2007-07-17 11:19:25 -05:00
const gchar *id;
2006-11-02 00:43:53 -06:00
GtkSourceStyleScheme *scheme = chain->data;
2007-07-17 11:19:25 -05:00
id = gtk_source_style_scheme_get_id (scheme);
to_check = ids_list_remove (to_check, id, FALSE);
2006-11-02 00:43:53 -06:00
if (!valid)
{
2007-07-17 11:19:25 -05:00
ids = ids_list_remove (ids, id, TRUE);
g_hash_table_remove (hash, id);
2006-11-02 00:43:53 -06:00
}
chain = g_slist_delete_link (chain, chain);
}
}
2007-07-17 11:19:25 -05:00
return ids;
2006-11-02 00:43:53 -06:00
}
2007-07-17 11:19:25 -05:00
static gchar **
slist_to_strv (GSList *list)
2006-11-09 04:59:08 -06:00
{
2007-07-17 11:19:25 -05:00
gchar **res;
guint i = 0;
res = g_new (gchar *, g_slist_length (list) + 1);
for ( ; list != NULL; list = list->next)
2006-11-09 04:59:08 -06:00
{
2007-07-17 11:19:25 -05:00
res[i] = list->data;
++i;
2006-11-09 04:59:08 -06:00
}
2007-07-17 11:19:25 -05:00
res[i] = NULL;
return res;
2006-11-09 04:59:08 -06:00
}
static void
2007-09-09 14:21:19 -05:00
reload_if_needed (GtkSourceStyleSchemeManager *mgr)
2006-11-02 00:43:53 -06:00
{
2007-07-17 11:19:25 -05:00
GSList *ids = NULL;
2006-11-02 00:43:53 -06:00
GSList *files;
2007-04-27 21:19:36 -05:00
GSList *l;
2007-07-17 11:19:25 -05:00
GHashTable *schemes_hash;
2006-11-02 00:43:53 -06:00
2007-07-17 11:19:25 -05:00
if (!mgr->priv->need_reload)
return;
2006-11-02 00:43:53 -06:00
schemes_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
2007-07-17 11:19:25 -05:00
2007-09-09 14:21:19 -05:00
files = _gtk_source_view_get_file_list ((gchar **)gtk_source_style_scheme_manager_get_search_path (mgr),
2007-07-17 11:19:25 -05:00
SCHEME_FILE_SUFFIX,
FALSE);
2007-04-27 21:19:36 -05:00
for (l = files; l != NULL; l = l->next)
2006-11-02 00:43:53 -06:00
{
GtkSourceStyleScheme *scheme;
2007-04-27 21:19:36 -05:00
gchar *filename;
2006-11-02 00:43:53 -06:00
2007-04-27 21:19:36 -05:00
filename = l->data;
2006-11-02 00:43:53 -06:00
scheme = _gtk_source_style_scheme_new_from_file (filename);
if (scheme != NULL)
{
const gchar *id = gtk_source_style_scheme_get_id (scheme);
GtkSourceStyleScheme *old;
old = g_hash_table_lookup (schemes_hash, id);
if (old != NULL)
2007-07-17 11:19:25 -05:00
ids = ids_list_remove (ids, id, TRUE);
2006-11-02 00:43:53 -06:00
2007-07-17 11:19:25 -05:00
ids = g_slist_prepend (ids, g_strdup (id));
g_hash_table_insert (schemes_hash, g_strdup (id), scheme);
2006-11-02 00:43:53 -06:00
}
}
2007-07-17 11:19:25 -05:00
ids = check_parents (ids, schemes_hash);
2006-11-02 00:43:53 -06:00
2007-04-27 21:19:36 -05:00
g_slist_foreach (files, (GFunc) g_free, NULL);
g_slist_free (files);
2007-07-17 11:19:25 -05:00
free_schemes (mgr);
2006-11-02 00:43:53 -06:00
mgr->priv->need_reload = FALSE;
2007-07-17 11:19:25 -05:00
mgr->priv->schemes_hash = schemes_hash;
mgr->priv->ids = slist_to_strv (ids);
g_slist_free (ids); /* slist_to_strv trasfer the onwnership of the strings
to the string array */
}
static void
2007-09-09 14:21:19 -05:00
notify_search_path (GtkSourceStyleSchemeManager *mgr)
2007-07-17 11:19:25 -05:00
{
mgr->priv->need_reload = TRUE;
g_object_notify (G_OBJECT (mgr), "search-path");
g_object_notify (G_OBJECT (mgr), "scheme-ids");
2006-11-02 00:43:53 -06:00
}
2007-07-31 06:11:24 -05:00
/**
2007-09-09 14:21:19 -05:00
* gtk_source_style_scheme_manager_set_search_path:
* @manager: a #GtkSourceStyleSchemeManager.
2007-07-31 06:11:24 -05:00
* @path: a %NULL-terminated array of strings or %NULL.
*
* Sets the list of directories where the @manager looks for
* style scheme files.
* If @dirs is %NULL, the search path is reset to default.
*/
2006-11-02 00:43:53 -06:00
void
2007-09-09 14:21:19 -05:00
gtk_source_style_scheme_manager_set_search_path (GtkSourceStyleSchemeManager *manager,
gchar **path)
2006-11-02 00:43:53 -06:00
{
2007-07-17 11:19:25 -05:00
gchar **tmp;
2007-09-09 14:21:19 -05:00
g_return_if_fail (GTK_IS_SOURCE_STYLE_SCHEME_MANAGER (manager));
2007-07-17 11:19:25 -05:00
tmp = manager->priv->search_path;
2006-11-02 00:43:53 -06:00
2007-07-17 11:19:25 -05:00
if (path == NULL)
2010-08-30 22:19:58 -07:00
manager->priv->search_path = _gtk_source_view_get_default_dirs (STYLES_DIR);
2007-07-17 11:19:25 -05:00
else
manager->priv->search_path = g_strdupv (path);
2006-11-02 00:43:53 -06:00
2007-04-27 21:19:36 -05:00
g_strfreev (tmp);
2006-11-09 04:59:08 -06:00
2007-07-17 11:19:25 -05:00
notify_search_path (manager);
2006-11-02 00:43:53 -06:00
}
2007-07-31 06:11:24 -05:00
/**
2007-09-09 14:21:19 -05:00
* gtk_source_style_scheme_manager_append_search_path:
* @manager: a #GtkSourceStyleSchemeManager.
2007-07-31 06:11:24 -05:00
* @path: a directory or a filename.
*
* Appends @path to the list of directories where the @manager looks for
* style scheme files.
2007-09-09 14:21:19 -05:00
* See gtk_source_style_scheme_manager_set_search_path() for details.
2007-07-31 06:11:24 -05:00
*/
2007-07-17 11:19:25 -05:00
void
2007-09-09 14:21:19 -05:00
gtk_source_style_scheme_manager_append_search_path (GtkSourceStyleSchemeManager *manager,
const gchar *path)
2006-11-02 00:43:53 -06:00
{
2007-07-17 11:19:25 -05:00
guint len = 0;
2007-09-09 14:21:19 -05:00
g_return_if_fail (GTK_IS_SOURCE_STYLE_SCHEME_MANAGER (manager));
2007-07-17 11:19:25 -05:00
g_return_if_fail (path != NULL);
2006-11-02 00:43:53 -06:00
2007-07-17 11:19:25 -05:00
if (manager->priv->search_path == NULL)
2010-08-30 22:19:58 -07:00
manager->priv->search_path = _gtk_source_view_get_default_dirs (STYLES_DIR);
2006-11-02 00:43:53 -06:00
2007-07-17 11:19:25 -05:00
g_return_if_fail (manager->priv->search_path != NULL);
len = g_strv_length (manager->priv->search_path);
manager->priv->search_path = g_renew (gchar *,
manager->priv->search_path,
len + 2); /* old path + new entry + NULL */
manager->priv->search_path[len] = g_strdup (path);
manager->priv->search_path[len + 1] = NULL;
notify_search_path (manager);
2006-11-02 00:43:53 -06:00
}
2007-07-31 06:11:24 -05:00
/**
2007-09-09 14:21:19 -05:00
* gtk_source_style_scheme_manager_prepend_search_path:
* @manager: a #GtkSourceStyleSchemeManager.
2007-07-31 06:11:24 -05:00
* @path: a directory or a filename.
*
* Prepends @path to the list of directories where the @manager looks
* for style scheme files.
2007-09-09 14:21:19 -05:00
* See gtk_source_style_scheme_manager_set_search_path() for details.
2007-07-31 06:11:24 -05:00
*/
2007-07-17 11:19:25 -05:00
void
2007-09-09 14:21:19 -05:00
gtk_source_style_scheme_manager_prepend_search_path (GtkSourceStyleSchemeManager *manager,
const gchar *path)
2007-07-17 11:19:25 -05:00
{
guint len = 0;
gchar **new_search_path;
2007-09-09 14:21:19 -05:00
g_return_if_fail (GTK_IS_SOURCE_STYLE_SCHEME_MANAGER (manager));
2007-07-17 11:19:25 -05:00
g_return_if_fail (path != NULL);
if (manager->priv->search_path == NULL)
2010-08-30 22:19:58 -07:00
manager->priv->search_path = _gtk_source_view_get_default_dirs (STYLES_DIR);
2007-07-17 11:19:25 -05:00
g_return_if_fail (manager->priv->search_path != NULL);
len = g_strv_length (manager->priv->search_path);
new_search_path = g_new (gchar *, len + 2);
new_search_path[0] = g_strdup (path);
memcpy (new_search_path + 1, manager->priv->search_path, (len + 1) * sizeof (gchar*));
g_free (manager->priv->search_path);
manager->priv->search_path = new_search_path;
notify_search_path (manager);
}
/**
2007-09-09 14:21:19 -05:00
* gtk_source_style_scheme_manager_get_search_path:
* @manager: a #GtkSourceStyleSchemeManager.
2007-07-17 11:19:25 -05:00
*
* Returns the current search path for the @manager.
2007-09-09 14:21:19 -05:00
* See gtk_source_style_scheme_manager_set_search_path() for details.
2007-07-17 11:19:25 -05:00
*
* Returns: a NULL-terminated array of string containing the search path.
* The array is owned by the @manager and must not be modified.
2007-07-31 06:11:24 -05:00
*/
const gchar* const *
2007-09-09 14:21:19 -05:00
gtk_source_style_scheme_manager_get_search_path (GtkSourceStyleSchemeManager *manager)
2006-11-02 00:43:53 -06:00
{
2007-09-09 14:21:19 -05:00
g_return_val_if_fail (GTK_IS_SOURCE_STYLE_SCHEME_MANAGER (manager), NULL);
2007-07-17 11:19:25 -05:00
if (manager->priv->search_path == NULL)
2010-08-30 22:19:58 -07:00
manager->priv->search_path = _gtk_source_view_get_default_dirs (STYLES_DIR);
2007-07-17 11:19:25 -05:00
return (const gchar * const *)manager->priv->search_path;
2006-11-02 00:43:53 -06:00
}
2007-06-27 04:33:56 -05:00
/**
2007-09-09 14:21:19 -05:00
* gtk_source_style_scheme_manager_force_rescan:
* @manager: a #GtkSourceStyleSchemeManager
2007-06-27 04:33:56 -05:00
*
2007-07-17 11:19:25 -05:00
* Mark any currently cached information about the available style scehems
* as invalid. All the available style schemes will be reloaded next time
* the @manager is accessed.
*/
void
2007-09-09 14:21:19 -05:00
gtk_source_style_scheme_manager_force_rescan (GtkSourceStyleSchemeManager *manager)
2007-07-17 11:19:25 -05:00
{
manager->priv->need_reload = TRUE;
g_object_notify (G_OBJECT (manager), "scheme-ids");
}
/**
2007-09-09 14:21:19 -05:00
* gtk_source_style_scheme_manager_get_scheme_ids:
* @manager: a #GtkSourceStyleSchemeManager
2007-07-17 11:19:25 -05:00
*
* Returns the ids of the available style schemes.
2007-06-27 04:33:56 -05:00
*
2007-07-17 11:19:25 -05:00
* Returns: a %NULL-terminated array of string containing the ids of the
* available style schemes or %NULL if no style scheme is available. The array
* is owned by the @manager and must not be modified.
2007-07-31 06:11:24 -05:00
*/
const gchar* const *
2007-09-09 14:21:19 -05:00
gtk_source_style_scheme_manager_get_scheme_ids (GtkSourceStyleSchemeManager *manager)
2006-11-02 00:43:53 -06:00
{
2007-09-09 14:21:19 -05:00
g_return_val_if_fail (GTK_IS_SOURCE_STYLE_SCHEME_MANAGER (manager), NULL);
2006-11-02 00:43:53 -06:00
2007-06-27 04:33:56 -05:00
reload_if_needed (manager);
2006-11-02 00:43:53 -06:00
2007-07-17 11:19:25 -05:00
return (const gchar * const *)manager->priv->ids;
2006-11-02 00:43:53 -06:00
}
2007-06-27 04:33:56 -05:00
/**
2007-09-09 14:21:19 -05:00
* gtk_source_style_scheme_manager_get_scheme:
* @manager: a #GtkSourceStyleSchemeManager
2007-06-27 04:33:56 -05:00
* @scheme_id: style scheme id to find
*
* Looks up style scheme by id.
*
* Returns: a #GtkSourceStyleScheme object. Returned value is owned by
* @manager and must not be unref'ed.
2007-07-31 06:11:24 -05:00
*/
2006-11-02 00:43:53 -06:00
GtkSourceStyleScheme *
2007-09-09 14:21:19 -05:00
gtk_source_style_scheme_manager_get_scheme (GtkSourceStyleSchemeManager *manager,
const gchar *scheme_id)
2006-11-02 00:43:53 -06:00
{
2007-09-09 14:21:19 -05:00
g_return_val_if_fail (GTK_IS_SOURCE_STYLE_SCHEME_MANAGER (manager), NULL);
2006-11-02 00:43:53 -06:00
g_return_val_if_fail (scheme_id != NULL, NULL);
2007-06-27 04:33:56 -05:00
reload_if_needed (manager);
2006-11-02 00:43:53 -06:00
2007-07-17 11:19:25 -05:00
return g_hash_table_lookup (manager->priv->schemes_hash, scheme_id);
2006-11-02 00:43:53 -06:00
}