From 8abf31d3c6f559df18505fd1c69ac771b23cd94c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Techet?= Date: Sat, 19 Mar 2022 17:32:13 +0100 Subject: [PATCH] Improve project directory determination When using "New from Folder", open the directory selection dialog at current document's directory to simplify new project creation for opened files. Fall back to "project files" directory if no file opened and if this directory isn't set in preferences, fall back to user's home directory. In addition take into account that the "project files" directory may not be set when filling in entries in the "New Project" dialog and fall back to currently opened document's directory or to home directory when no document is opened. --- src/project.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/project.c b/src/project.c index a23798344..5b66bcaee 100644 --- a/src/project.c +++ b/src/project.c @@ -157,7 +157,19 @@ void project_new(gboolean from_folder) if (from_folder) { - base_path = ui_get_project_directory(local_prefs.project_file_path); + GeanyDocument *doc = document_get_current(); + gchar *start_path; + + if (doc && doc->file_name) + start_path = g_path_get_dirname(doc->file_name); + else if (!EMPTY(local_prefs.project_file_path)) + start_path = g_strdup(local_prefs.project_file_path); + else + start_path = utils_get_utf8_from_locale(g_get_home_dir()); + + base_path = ui_get_project_directory(start_path); + g_free(start_path); + if (!base_path) return; } @@ -973,12 +985,23 @@ static void update_new_project_dlg(GtkEditable *editable, PropertyDialogElements { gchar *base_path; gchar *file_name; - gchar *name; - const gchar *project_dir = local_prefs.project_file_path; + gchar *project_dir = NULL; if (e->entries_modified) return; + if (!EMPTY(local_prefs.project_file_path)) + project_dir = g_strdup(local_prefs.project_file_path); + else + { + GeanyDocument *doc = document_get_current(); + + if (doc && doc->file_name) + project_dir = g_path_get_dirname(doc->file_name); + else + project_dir = utils_get_utf8_from_locale(g_get_home_dir()); + } + if (!EMPTY(base_p)) { gchar *name = g_path_get_basename(base_p); @@ -1022,6 +1045,7 @@ static void update_new_project_dlg(GtkEditable *editable, PropertyDialogElements g_free(base_path); g_free(file_name); + g_free(project_dir); } -- 2.11.4.GIT