Add utils_get_config_files().
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4396 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
01b408c09b
commit
dfd1ea1782
@ -6,6 +6,8 @@
|
||||
scheme files exist in a colorschemes config directory. Color scheme
|
||||
files must end in ".conf" and currently only the [named_styles]
|
||||
section is read.
|
||||
* src/templates.c, src/utils.c, src/highlighting.c, src/utils.h:
|
||||
Add utils_get_config_files().
|
||||
|
||||
|
||||
2009-10-30 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
||||
|
@ -527,7 +527,7 @@ static GKeyFile *utils_key_file_new(const gchar *filename)
|
||||
}
|
||||
|
||||
|
||||
static void read_named_styles(GKeyFile *config, GKeyFile *config_home)
|
||||
static void load_named_styles(GKeyFile *config, GKeyFile *config_home)
|
||||
{
|
||||
const gchar *scheme = editor_prefs.color_scheme;
|
||||
|
||||
@ -562,7 +562,7 @@ static void read_named_styles(GKeyFile *config, GKeyFile *config_home)
|
||||
|
||||
static void styleset_common_init(gint ft_id, GKeyFile *config, GKeyFile *config_home)
|
||||
{
|
||||
read_named_styles(config, config_home);
|
||||
load_named_styles(config, config_home);
|
||||
|
||||
get_keyfile_style(config, config_home, "default", &common_style_set.styling[GCS_DEFAULT]);
|
||||
get_keyfile_style(config, config_home, "selection", &common_style_set.styling[GCS_SELECTION]);
|
||||
@ -3420,44 +3420,11 @@ static void add_color_scheme_item(const gchar *fname, GtkWidget *menu)
|
||||
}
|
||||
|
||||
|
||||
/* TODO: move */
|
||||
static void utils_slist_remove_next(GSList *node)
|
||||
{
|
||||
GSList *old = node->next;
|
||||
|
||||
g_return_if_fail(old);
|
||||
|
||||
node->next = old->next;
|
||||
g_slist_free_1(old);
|
||||
}
|
||||
|
||||
|
||||
/* note: color scheme code adapted from custom file template code */
|
||||
static gboolean add_color_scheme_items(GtkWidget *menu)
|
||||
{
|
||||
gchar *path = g_build_path(G_DIR_SEPARATOR_S, app->configdir, GEANY_COLORSCHEMES_SUBDIR, NULL);
|
||||
GSList *list = utils_get_file_list_full(path, FALSE, FALSE, NULL);
|
||||
GSList *syslist, *node;
|
||||
GSList *list = utils_get_config_files(GEANY_COLORSCHEMES_SUBDIR);
|
||||
GSList *node;
|
||||
|
||||
if (!list)
|
||||
{
|
||||
utils_mkdir(path, FALSE);
|
||||
}
|
||||
setptr(path, g_build_path(G_DIR_SEPARATOR_S, app->datadir, GEANY_COLORSCHEMES_SUBDIR, NULL));
|
||||
syslist = utils_get_file_list_full(path, FALSE, FALSE, NULL);
|
||||
/* merge lists */
|
||||
list = g_slist_concat(list, syslist);
|
||||
|
||||
list = g_slist_sort(list, (GCompareFunc) utils_str_casecmp);
|
||||
/* remove duplicates (next to each other after sorting) */
|
||||
foreach_slist(node, list)
|
||||
{
|
||||
if (node->next && utils_str_equal(node->next->data, node->data))
|
||||
{
|
||||
g_free(node->next->data);
|
||||
utils_slist_remove_next(node);
|
||||
}
|
||||
}
|
||||
foreach_slist(node, list)
|
||||
{
|
||||
gchar *fname = node->data;
|
||||
@ -3467,7 +3434,6 @@ static gboolean add_color_scheme_items(GtkWidget *menu)
|
||||
g_free(fname);
|
||||
}
|
||||
g_slist_free(list);
|
||||
g_free(path);
|
||||
return list != NULL;
|
||||
}
|
||||
|
||||
|
@ -364,44 +364,11 @@ static void add_file_item(const gchar *fname, GtkWidget *menu)
|
||||
}
|
||||
|
||||
|
||||
static void utils_slist_remove_next(GSList *node)
|
||||
{
|
||||
GSList *old = node->next;
|
||||
|
||||
g_return_if_fail(old);
|
||||
|
||||
node->next = old->next;
|
||||
g_slist_free_1(old);
|
||||
}
|
||||
|
||||
|
||||
static gboolean add_custom_template_items(void)
|
||||
{
|
||||
gchar *path = g_build_path(G_DIR_SEPARATOR_S, app->configdir, GEANY_TEMPLATES_SUBDIR,
|
||||
"files", NULL);
|
||||
GSList *list = utils_get_file_list_full(path, FALSE, FALSE, NULL);
|
||||
GSList *syslist, *node;
|
||||
GSList *list = utils_get_config_files(GEANY_TEMPLATES_SUBDIR G_DIR_SEPARATOR_S "files");
|
||||
GSList *node;
|
||||
|
||||
if (!list)
|
||||
{
|
||||
utils_mkdir(path, FALSE);
|
||||
}
|
||||
setptr(path, g_build_path(G_DIR_SEPARATOR_S, app->datadir, GEANY_TEMPLATES_SUBDIR,
|
||||
"files", NULL));
|
||||
syslist = utils_get_file_list_full(path, FALSE, FALSE, NULL);
|
||||
/* merge lists */
|
||||
list = g_slist_concat(list, syslist);
|
||||
|
||||
list = g_slist_sort(list, (GCompareFunc) utils_str_casecmp);
|
||||
/* remove duplicates (next to each other after sorting) */
|
||||
foreach_slist(node, list)
|
||||
{
|
||||
if (node->next && utils_str_equal(node->next->data, node->data))
|
||||
{
|
||||
g_free(node->next->data);
|
||||
utils_slist_remove_next(node);
|
||||
}
|
||||
}
|
||||
foreach_slist(node, list)
|
||||
{
|
||||
gchar *fname = node->data;
|
||||
@ -410,7 +377,6 @@ static gboolean add_custom_template_items(void)
|
||||
g_free(fname);
|
||||
}
|
||||
g_slist_free(list);
|
||||
g_free(path);
|
||||
return list != NULL;
|
||||
}
|
||||
|
||||
|
42
src/utils.c
42
src/utils.c
@ -1822,3 +1822,45 @@ gchar *utils_str_remove_chars(gchar *string, const gchar *chars)
|
||||
}
|
||||
|
||||
|
||||
static void utils_slist_remove_next(GSList *node)
|
||||
{
|
||||
GSList *old = node->next;
|
||||
|
||||
g_return_if_fail(old);
|
||||
|
||||
node->next = old->next;
|
||||
g_slist_free_1(old);
|
||||
}
|
||||
|
||||
|
||||
/* Gets list of sorted filenames with no path and no duplicates from user and system config */
|
||||
GSList *utils_get_config_files(const gchar *subdir)
|
||||
{
|
||||
gchar *path = g_build_path(G_DIR_SEPARATOR_S, app->configdir, subdir, NULL);
|
||||
GSList *list = utils_get_file_list_full(path, FALSE, FALSE, NULL);
|
||||
GSList *syslist, *node;
|
||||
|
||||
if (!list)
|
||||
{
|
||||
utils_mkdir(path, FALSE);
|
||||
}
|
||||
setptr(path, g_build_path(G_DIR_SEPARATOR_S, app->datadir, subdir, NULL));
|
||||
syslist = utils_get_file_list_full(path, FALSE, FALSE, NULL);
|
||||
/* merge lists */
|
||||
list = g_slist_concat(list, syslist);
|
||||
|
||||
list = g_slist_sort(list, (GCompareFunc) utils_str_casecmp);
|
||||
/* remove duplicates (next to each other after sorting) */
|
||||
foreach_slist(node, list)
|
||||
{
|
||||
if (node->next && utils_str_equal(node->next->data, node->data))
|
||||
{
|
||||
g_free(node->next->data);
|
||||
utils_slist_remove_next(node);
|
||||
}
|
||||
}
|
||||
g_free(path);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
@ -196,6 +196,10 @@ gint utils_mkdir(const gchar *path, gboolean create_parent_dirs);
|
||||
|
||||
GSList *utils_get_file_list(const gchar *path, guint *length, GError **error);
|
||||
|
||||
GSList *utils_get_file_list_full(const gchar *path, gboolean full_path, gboolean sort, GError **error);
|
||||
|
||||
GSList *utils_get_config_files(const gchar *subdir);
|
||||
|
||||
gboolean utils_str_has_upper(const gchar *str);
|
||||
|
||||
gint utils_is_file_writeable(const gchar *locale_filename);
|
||||
@ -223,6 +227,4 @@ gchar *utils_str_middle_truncate(const gchar *string, guint truncate_length);
|
||||
|
||||
gchar *utils_str_remove_chars(gchar *string, const gchar *chars);
|
||||
|
||||
GSList *utils_get_file_list_full(const gchar *path, gboolean full_path, gboolean sort, GError **error);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user