Skip to content

Commit

Permalink
Merge pull request #681 from LarsGit223/wb-fileops2
Browse files Browse the repository at this point in the history
workbench: added "Create file here..."/"Create directory here..."
  • Loading branch information
frlan authored Feb 3, 2018
2 parents 0ca2154 + 839819f commit 5677bf1
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 12 deletions.
83 changes: 80 additions & 3 deletions utils/src/filelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static gboolean filelist_patterns_match(GSList *patterns, const gchar *str)


/* Scan directory searchdir. Input and output parameters come from/go to params. */
static void filelist_scan_directory_int(const gchar *searchdir, ScanDirParams *params)
static void filelist_scan_directory_int(const gchar *searchdir, ScanDirParams *params, guint flags)
{
GDir *dir;
gchar *locale_path = utils_get_locale_from_utf8(searchdir);
Expand All @@ -115,7 +115,9 @@ static void filelist_scan_directory_int(const gchar *searchdir, ScanDirParams *p

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);
Expand All @@ -125,8 +127,12 @@ static void filelist_scan_directory_int(const gchar *searchdir, ScanDirParams *p
{
if (!filelist_patterns_match(params->ignored_dirs_list, utf8_name))
{
filelist_scan_directory_int(utf8_filename, params);
filelist_scan_directory_int(utf8_filename, params, flags);
params->folder_count++;
if (flags & FILELIST_FLAG_ADD_DIRS)
{
params->filelist = g_slist_prepend(params->filelist, g_strdup(utf8_filename));
}
}
}
else if (g_file_test(locale_filename, G_FILE_TEST_IS_REGULAR))
Expand Down Expand Up @@ -190,7 +196,78 @@ GSList *gp_filelist_scan_directory(guint *files, guint *folders, const gchar *se
params.ignored_file_list = filelist_get_precompiled_patterns(ignored_file_patterns);

params.visited_paths = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
filelist_scan_directory_int(searchdir, &params);
filelist_scan_directory_int(searchdir, &params, 0);
g_hash_table_destroy(params.visited_paths);

g_slist_foreach(params.file_patterns, (GFunc) g_pattern_spec_free, NULL);
g_slist_free(params.file_patterns);

g_slist_foreach(params.ignored_dirs_list, (GFunc) g_pattern_spec_free, NULL);
g_slist_free(params.ignored_dirs_list);

g_slist_foreach(params.ignored_file_list, (GFunc) g_pattern_spec_free, NULL);
g_slist_free(params.ignored_file_list);

if (files != NULL)
{
*files = params.file_count;
}
if (folders != NULL)
{
*folders = params.folder_count;
}

return params.filelist;
}


/** 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 which match the patterns in file_patterns.
* Directories or files matched by ignored_dirs_patterns or ignored_file_patterns
* will not be scanned or added to the list.
*
* If flags is 0 then the result will be the same as for gp_filelist_scan_directory().
*
* @param files Can be optionally specified to return the number of matched/found
* files in *files.
* @param folders Can be optionally specified to return the number of matched/found
* folders/sub-directories in *folders.
* @param searchdir Directory which shall be scanned
* @param file_patterns
* File patterns for matching files (e.g. "*.c") or NULL
* for all files.
* @param ignored_dirs_patterns
* Patterns for ignored directories
* @param ignored_file_patterns
* Patterns for ignored files
* @param flags Flags which influence the returned list:
* - FILELIST_FLAG_ADD_DIRS: if set, directories will be added
* as own list entries. This also includes empty dirs.
* @return GSList of matched files
*
**/
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)
{
ScanDirParams params = { 0 };

if (!file_patterns || !file_patterns[0])
{
const gchar *all_pattern[] = { "*", NULL };
params.file_patterns = filelist_get_precompiled_patterns((gchar **)all_pattern);
}
else
{
params.file_patterns = filelist_get_precompiled_patterns(file_patterns);
}

params.ignored_dirs_list = filelist_get_precompiled_patterns(ignored_dirs_patterns);
params.ignored_file_list = filelist_get_precompiled_patterns(ignored_file_patterns);

params.visited_paths = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
filelist_scan_directory_int(searchdir, &params, flags);
g_hash_table_destroy(params.visited_paths);

g_slist_foreach(params.file_patterns, (GFunc) g_pattern_spec_free, NULL);
Expand Down
7 changes: 7 additions & 0 deletions utils/src/filelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@

G_BEGIN_DECLS

typedef enum
{
FILELIST_FLAG_ADD_DIRS = 1,
}FILELIST_FLAG;

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);

G_END_DECLS

Expand Down
8 changes: 8 additions & 0 deletions workbench/README
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ These are the available items:
Remove file from the Workbench or project bookmarks. It is only available
if you right clicked on a bookmark.

**Create file here...**
Select this item to create a new file at the current selected position
in the file tree. Available since version 1.02 of the workbench plugin.

**Create directory here...**
Select this item to create a new directory at the current selected position
in the file tree. Available since version 1.02 of the workbench plugin.

Known issues
============

Expand Down
71 changes: 71 additions & 0 deletions workbench/src/dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,77 @@

extern GeanyPlugin *geany_plugin;


/** Shows the dialog "Create new file".
*
* The dialog lets the user create a new file (filter *).
*
* @param path The current folder
* @return The filename
*
**/
gchar *dialogs_create_new_file(const gchar *path)
{
gchar *filename = NULL;
GtkWidget *dialog;

dialog = gtk_file_chooser_dialog_new(_("Create new file"),
GTK_WINDOW(wb_globals.geany_plugin->geany_data->main_widgets->window), GTK_FILE_CHOOSER_ACTION_SAVE,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("C_reate"), GTK_RESPONSE_ACCEPT, NULL);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);

if (path != NULL)
{
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);
}

if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
}

gtk_widget_destroy(dialog);

return filename;
}


/** Shows the dialog "Create new directory".
*
* The dialog lets the user create a new directory.
*
* @param path The current folder
* @return The filename
*
**/
gchar *dialogs_create_new_directory(const gchar *path)
{
gchar *filename = NULL;
GtkWidget *dialog;

dialog = gtk_file_chooser_dialog_new(_("Create new directory"),
GTK_WINDOW(wb_globals.geany_plugin->geany_data->main_widgets->window), GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("C_reate"), GTK_RESPONSE_ACCEPT, NULL);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);

if (path != NULL)
{
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);
}

if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
}

gtk_widget_destroy(dialog);

return filename;
}


/** Shows the dialog "Create new workbench".
*
* The dialog lets the user create a new workbench file (filter *.geanywb).
Expand Down
2 changes: 2 additions & 0 deletions workbench/src/dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef __WB_DIALOGS_H__
#define __WB_DIALOGS_H__

gchar *dialogs_create_new_file(const gchar *path);
gchar *dialogs_create_new_directory(const gchar *path);
gchar *dialogs_create_new_workbench(void);
gchar *dialogs_open_workbench(void);
gchar *dialogs_add_project(void);
Expand Down
2 changes: 1 addition & 1 deletion workbench/src/plugin_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void geany_load_module(GeanyPlugin *plugin)
/* Set metadata */
plugin->info->name = _("Workbench");
plugin->info->description = _("Manage and customize multiple projects.");
plugin->info->version = "1.01";
plugin->info->version = "1.02";
plugin->info->author = "LarsGit223";

/* Set functions */
Expand Down
Loading

0 comments on commit 5677bf1

Please sign in to comment.