Skip to content

Commit

Permalink
Merge pull request #879 from LarsGit223/wb-git-projects
Browse files Browse the repository at this point in the history
workbench: added option to let git decide which files to display
  • Loading branch information
LarsGit223 authored Jul 18, 2019
2 parents 1fa76e8 + 6dfe1b6 commit 3f4011e
Show file tree
Hide file tree
Showing 13 changed files with 617 additions and 99 deletions.
3 changes: 3 additions & 0 deletions build/workbench.m4
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ AC_DEFUN([GP_CHECK_WORKBENCH],
GP_ARG_DISABLE([Workbench], [auto])
GP_CHECK_UTILSLIB([Workbench])
GP_CHECK_PLUGIN_DEPS([Workbench], [WORKBENCH],
[libgit2 >= 0.21])
GP_COMMIT_PLUGIN_STATUS([Workbench])
AC_CONFIG_FILES([
workbench/Makefile
Expand Down
109 changes: 107 additions & 2 deletions utils/src/filelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ typedef struct
ScanDirParams;


typedef struct
{
GSList *filelist;
GHashTable *visited_paths;
void (*callback)(const gchar *path, gboolean *add, gboolean *enter, void *userdata);
void *userdata;
}
ScanDirParamsCallback;


/** Get precompiled patterns.
*
* The function builds the precompiled patterns for @a patterns and returns them
Expand All @@ -48,7 +58,7 @@ ScanDirParams;
* @return Pointer to GSList of patterns or NULL if patterns == NULL
*
**/
static GSList *filelist_get_precompiled_patterns(gchar **patterns)
GSList *filelist_get_precompiled_patterns(gchar **patterns)
{
guint i;
GSList *pattern_list = NULL;
Expand All @@ -74,7 +84,7 @@ static GSList *filelist_get_precompiled_patterns(gchar **patterns)
* @return TRUE if str matches the pattern, FALSE otherwise
*
**/
static gboolean filelist_patterns_match(GSList *patterns, const gchar *str)
gboolean filelist_patterns_match(GSList *patterns, const gchar *str)
{
GSList *elem = NULL;
foreach_slist (elem, patterns)
Expand Down Expand Up @@ -360,3 +370,98 @@ gboolean gp_filelist_filepath_matches_patterns(const gchar *filepath, gchar **fi

return match;
}


/* Scan directory searchdir. Let a callback-function decide which files
to add and which directories to enter/crawl. */
static void filelist_scan_directory_callback_int(const gchar *searchdir, ScanDirParamsCallback *params)
{
GDir *dir;
gchar *locale_path = utils_get_locale_from_utf8(searchdir);
gchar *real_path = utils_get_real_path(locale_path);

dir = g_dir_open(locale_path, 0, NULL);
if (!dir || !real_path || g_hash_table_lookup(params->visited_paths, real_path))
{
if (dir != NULL)
{
g_dir_close(dir);
}
g_free(locale_path);
g_free(real_path);
return;
}

g_hash_table_insert(params->visited_paths, real_path, GINT_TO_POINTER(1));

while (TRUE)
{
const gchar *locale_name;
gchar *locale_filename, *utf8_filename, *utf8_name;
gboolean add, enter;

locale_name = g_dir_read_name(dir);
if (!locale_name)
{
break;
}

utf8_name = utils_get_utf8_from_locale(locale_name);
locale_filename = g_build_filename(locale_path, locale_name, NULL);
utf8_filename = utils_get_utf8_from_locale(locale_filename);

/* Call user callback. */
params->callback(locale_filename, &add, &enter, params->userdata);

/* Should the file/path be added to the list? */
if (add)
{
params->filelist = g_slist_prepend(params->filelist, g_strdup(utf8_filename));
}

/* If the path is a directory, should it be entered? */
if (enter && g_file_test(locale_filename, G_FILE_TEST_IS_DIR))
{
filelist_scan_directory_callback_int(utf8_filename, params);
}

g_free(utf8_filename);
g_free(locale_filename);
g_free(utf8_name);
}

g_dir_close(dir);
g_free(locale_path);
}


/** Scan a directory and return a list of files and directories.
*
* The function scans directory searchdir and returns a list of files.
* The list will only include files for which the callback function returned
* 'add == TRUE'. Sub-directories will only be scanned if the callback function
* returned 'enter == TRUE'.
*
* @param searchdir Directory which shall be scanned
* @param callback Function to be called to decide which files to add to
* the list and to decide which sub-directories to enter
* or to ignore.
* @param userdata A pointer which is transparently passed through
* to the callback function.
* @return GSList of matched files
*
**/
GSList *gp_filelist_scan_directory_callback(const gchar *searchdir,
void (*callback)(const gchar *path, gboolean *add, gboolean *enter, void *userdata),
void *userdata)
{
ScanDirParamsCallback params = { 0 };

params.callback = callback;
params.userdata = userdata;
params.visited_paths = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
filelist_scan_directory_callback_int(searchdir, &params);
g_hash_table_destroy(params.visited_paths);

return params.filelist;
}
5 changes: 5 additions & 0 deletions utils/src/filelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ typedef enum
FILELIST_FLAG_ADD_DIRS = 1,
}FILELIST_FLAG;

GSList *filelist_get_precompiled_patterns(gchar **patterns);
gboolean filelist_patterns_match(GSList *patterns, const gchar *str);
GSList *gp_filelist_scan_directory(guint *files, guint *folders, const gchar *searchdir, gchar **file_patterns,
gchar **ignored_dirs_patterns, gchar **ignored_file_patterns);
GSList *gp_filelist_scan_directory_full(guint *files, guint *folders, const gchar *searchdir, gchar **file_patterns,
gchar **ignored_dirs_patterns, gchar **ignored_file_patterns, guint flags);
gboolean gp_filelist_filepath_matches_patterns(const gchar *filepath, gchar **file_patterns,
gchar **ignored_dirs_patterns, gchar **ignored_file_patterns);
GSList *gp_filelist_scan_directory_callback(const gchar *searchdir,
void (*callback)(const gchar *path, gboolean *add, gboolean *enter, void *userdata),
void *userdata);

G_END_DECLS

Expand Down
8 changes: 6 additions & 2 deletions workbench/README
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ These are the available items:
**Directory settings**
Select this item to change the directory settings. It is only available
if you right clicked inside of a project directory. In the directory
settings you can set a filter which controls the files and sub-directories
that will be displayed or not.
settings you can set filters which control the files and sub-directories
that will be displayed or not. You can choose between a filter mechanism
controlled by the workbench plugin or controlled by git. In the later case
the .gitignore settings decide which files are displayed and which not.
This option is only available if the directory is/contains a git
repository.

**Fold/unfold directory**
Fold or unfold the items belonging to the directory. It is only available
Expand Down
3 changes: 2 additions & 1 deletion workbench/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ workbench_la_SOURCES = \

workbench_la_CPPFLAGS = $(AM_CPPFLAGS) \
-DG_LOG_DOMAIN=\"Workbench\"
workbench_la_CFLAGS = $(AM_CFLAGS) \
workbench_la_CFLAGS = $(AM_CFLAGS) $(WORKBENCH_CFLAGS) \
-I$(top_srcdir)/utils/src
workbench_la_LIBADD = $(COMMONLIBS) \
$(WORKBENCH_LIBS) \
$(top_builddir)/utils/src/libgeanypluginutils.la
include $(top_srcdir)/build/cppcheck.mk

Loading

0 comments on commit 3f4011e

Please sign in to comment.