[geany/geany] 8abf31: Improve project directory determination

Jiří Techet git-noreply at geany.org
Fri May 13 00:19:38 UTC 2022


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Sat, 19 Mar 2022 16:50:30 UTC
Commit:      8abf31d3c6f559df18505fd1c69ac771b23cd94c
             https://github.com/geany/geany/commit/8abf31d3c6f559df18505fd1c69ac771b23cd94c

Log Message:
-----------
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.


Modified Paths:
--------------
    src/project.c

Modified: src/project.c
30 lines changed, 27 insertions(+), 3 deletions(-)
===================================================================
@@ -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);
 }
 
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list