medit/moo/gtksourceview/gtksourceview-utils.c

108 lines
2.6 KiB
C
Raw Normal View History

2007-04-27 21:19:36 -05:00
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
* gtksourceviewutils.c
*
* Copyright (C) 2007 - Gustavo Giráldez and Paolo Maggi
*
2007-06-18 00:03:03 -05:00
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
2007-04-27 21:19:36 -05:00
*
2007-06-18 00:03:03 -05:00
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2007-04-27 21:19:36 -05:00
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "gtksourceview-utils.h"
#define SOURCEVIEW_DIR "gtksourceview-2.0"
gchar **
2010-08-30 22:19:58 -07:00
_gtk_source_view_get_default_dirs (const char *basename)
2007-04-27 21:19:36 -05:00
{
const gchar * const *xdg_dirs;
GPtrArray *dirs;
dirs = g_ptr_array_new ();
/* user dir */
g_ptr_array_add (dirs, g_build_filename (g_get_user_data_dir (),
SOURCEVIEW_DIR,
basename,
NULL));
/* system dir */
for (xdg_dirs = g_get_system_data_dirs (); xdg_dirs && *xdg_dirs; ++xdg_dirs)
g_ptr_array_add (dirs, g_build_filename (*xdg_dirs,
SOURCEVIEW_DIR,
basename,
NULL));
g_ptr_array_add (dirs, NULL);
return (gchar**) g_ptr_array_free (dirs, FALSE);
}
static GSList *
2007-07-17 11:19:25 -05:00
build_file_listing (const gchar *item,
2007-04-27 21:19:36 -05:00
GSList *filenames,
2007-07-17 11:19:25 -05:00
const gchar *suffix,
gboolean only_dirs)
2007-04-27 21:19:36 -05:00
{
GDir *dir;
const gchar *name;
2007-07-31 06:11:24 -05:00
if (!only_dirs && g_file_test (item, G_FILE_TEST_IS_REGULAR))
2007-07-17 11:19:25 -05:00
{
filenames = g_slist_prepend (filenames, g_strdup(item));
return filenames;
2007-07-31 06:11:24 -05:00
2007-07-17 11:19:25 -05:00
}
dir = g_dir_open (item, 0, NULL);
2007-04-27 21:19:36 -05:00
2007-07-31 06:11:24 -05:00
if (dir == NULL)
2007-04-27 21:19:36 -05:00
return filenames;
while ((name = g_dir_read_name (dir)) != NULL)
{
2007-07-17 11:19:25 -05:00
gchar *full_path = g_build_filename (item, name, NULL);
2007-04-27 21:19:36 -05:00
if (!g_file_test (full_path, G_FILE_TEST_IS_DIR) &&
g_str_has_suffix (name, suffix))
{
filenames = g_slist_prepend (filenames, full_path);
}
else
{
g_free (full_path);
}
}
g_dir_close (dir);
return filenames;
}
GSList *
2007-07-17 11:19:25 -05:00
_gtk_source_view_get_file_list (gchar **path,
const gchar *suffix,
gboolean only_dirs)
2007-04-27 21:19:36 -05:00
{
GSList *files = NULL;
2007-07-17 11:19:25 -05:00
for ( ; path && *path; ++path)
files = build_file_listing (*path, files, suffix, only_dirs);
2007-04-27 21:19:36 -05:00
return g_slist_reverse (files);
}