SF.net SVN: geany: [1382] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Sat Mar 10 17:26:04 UTC 2007
Revision: 1382
http://svn.sourceforge.net/geany/?rev=1382&view=rev
Author: ntrel
Date: 2007-03-10 09:26:03 -0800 (Sat, 10 Mar 2007)
Log Message:
-----------
Make New Project dialog create parent directories of the chosen base
path if necessary.
Prevent warnings when setting open dialog directory to a path whose
parent directory doesn't exist.
Add create_parent_dirs argument for utils_mkdir().
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/project.c
trunk/src/utils.c
trunk/src/utils.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-03-10 12:27:55 UTC (rev 1381)
+++ trunk/ChangeLog 2007-03-10 17:26:03 UTC (rev 1382)
@@ -4,6 +4,12 @@
Separate New Project dialog from Project Properties dialog.
Make Properties Filename field read-only, below Name field.
Capitalize dialog titles.
+ * src/utils.c, src/utils.h, src/project.c:
+ Make New Project dialog create parent directories of the chosen base
+ path if necessary.
+ Prevent warnings when setting open dialog directory to a path whose
+ parent directory doesn't exist.
+ Add create_parent_dirs argument for utils_mkdir().
2007-03-09 Enrico Tröger <enrico.troeger at uvena.de>
Modified: trunk/src/project.c
===================================================================
--- trunk/src/project.c 2007-03-10 12:27:55 UTC (rev 1381)
+++ trunk/src/project.c 2007-03-10 17:26:03 UTC (rev 1382)
@@ -500,7 +500,7 @@
if (dialogs_show_question(
_("The specified project base path does not exist. Should it be created?")))
{
- utils_mkdir(locale_path);
+ utils_mkdir(locale_path, TRUE);
}
else
{
@@ -581,10 +581,15 @@
gchar *locale_filename = utils_get_locale_from_utf8(utf8_filename);
if (g_path_is_absolute(locale_filename))
- gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8_filename);
+ {
+ if (g_file_test(locale_filename, G_FILE_TEST_EXISTS))
+ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8_filename);
+ }
else
if (gtk_file_chooser_get_action(GTK_FILE_CHOOSER(dialog)) != GTK_FILE_CHOOSER_ACTION_OPEN)
+ {
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), utf8_filename);
+ }
g_free(locale_filename);
// run it
Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c 2007-03-10 12:27:55 UTC (rev 1381)
+++ trunk/src/utils.c 2007-03-10 17:26:03 UTC (rev 1382)
@@ -43,6 +43,8 @@
# include <sys/types.h>
#endif
+#include <glib/gstdio.h>
+
#include "support.h"
#include "document.h"
#include "sciwrappers.h"
@@ -782,7 +784,7 @@
if (! g_file_test(dir, G_FILE_TEST_EXISTS))
{
geany_debug("creating config directory %s", dir);
- error_nr = utils_mkdir(dir);
+ error_nr = utils_mkdir(dir, FALSE);
}
if (error_nr == 0 && ! g_file_test(conf_file, G_FILE_TEST_EXISTS))
@@ -804,7 +806,7 @@
if (! g_file_test(filedefs_dir, G_FILE_TEST_EXISTS))
{
- error_nr = utils_mkdir(filedefs_dir);
+ error_nr = utils_mkdir(filedefs_dir, FALSE);
}
if (error_nr == 0 && ! g_file_test(filedefs_readme, G_FILE_TEST_EXISTS))
{
@@ -826,7 +828,7 @@
if (! g_file_test(templates_dir, G_FILE_TEST_EXISTS))
{
- error_nr = utils_mkdir(templates_dir);
+ error_nr = utils_mkdir(templates_dir, FALSE);
}
if (error_nr == 0 && ! g_file_test(templates_readme, G_FILE_TEST_EXISTS))
{
@@ -1512,15 +1514,94 @@
}
-gint utils_mkdir(const gchar *path)
+#if ! GLIB_CHECK_VERSION(2, 8, 0)
+// Taken from GLib SVN, 2007-03-10
+/**
+ * g_mkdir_with_parents:
+ * @pathname: a pathname in the GLib file name encoding
+ * @mode: permissions to use for newly created directories
+ *
+ * Create a directory if it doesn't already exist. Create intermediate
+ * parent directories as needed, too.
+ *
+ * Returns: 0 if the directory already exists, or was successfully
+ * created. Returns -1 if an error occurred, with errno set.
+ *
+ * Since: 2.8
+ */
+int
+g_mkdir_with_parents (const gchar *pathname,
+ int mode)
{
+ gchar *fn, *p;
+
+ if (pathname == NULL || *pathname == '\0')
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ fn = g_strdup (pathname);
+
+ if (g_path_is_absolute (fn))
+ p = (gchar *) g_path_skip_root (fn);
+ else
+ p = fn;
+
+ do
+ {
+ while (*p && !G_IS_DIR_SEPARATOR (*p))
+ p++;
+
+ if (!*p)
+ p = NULL;
+ else
+ *p = '\0';
+
+ if (!g_file_test (fn, G_FILE_TEST_EXISTS))
+ {
+ if (g_mkdir (fn, mode) == -1)
+ {
+ int errno_save = errno;
+ g_free (fn);
+ errno = errno_save;
+ return -1;
+ }
+ }
+ else if (!g_file_test (fn, G_FILE_TEST_IS_DIR))
+ {
+ g_free (fn);
+ errno = ENOTDIR;
+ return -1;
+ }
+ if (p)
+ {
+ *p++ = G_DIR_SEPARATOR;
+ while (*p && G_IS_DIR_SEPARATOR (*p))
+ p++;
+ }
+ }
+ while (p);
+
+ g_free (fn);
+
+ return 0;
+}
+#endif
+
+
+gint utils_mkdir(const gchar *path, gboolean create_parent_dirs)
+{
+ gint mode = 0700;
+ gint result;
+
if (path == NULL || strlen(path) == 0)
return EFAULT;
-#ifdef G_OS_WIN32
- if (mkdir(path) != 0) return errno;
-#else
- if (mkdir(path, 0700) != 0) return errno;
-#endif
+ result = (create_parent_dirs) ? g_mkdir_with_parents(path, mode) : g_mkdir(path, mode);
+ if (result != 0)
+ return errno;
return 0;
}
+
+
Modified: trunk/src/utils.h
===================================================================
--- trunk/src/utils.h 2007-03-10 12:27:55 UTC (rev 1381)
+++ trunk/src/utils.h 2007-03-10 17:26:03 UTC (rev 1382)
@@ -161,6 +161,6 @@
* if first is NULL, NULL is returned. */
gchar **utils_strv_new(gchar *first, ...);
-gint utils_mkdir(const gchar *path);
+gint utils_mkdir(const gchar *path, gboolean create_parent_dirs);
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list