[gimp] app: change Gimp->default_folder from being a path to a GFile
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: change Gimp->default_folder from being a path to a GFile
- Date: Wed, 9 Jul 2014 18:16:04 +0000 (UTC)
commit 39f7401703f5ceeec3241181f12c3e9cac2351e2
Author: Michael Natterer <mitch gimp org>
Date: Wed Jul 9 20:12:05 2014 +0200
app: change Gimp->default_folder from being a path to a GFile
Also fix GimpFileDialog to actually start with that folder, and not in
its parent folder.
app/actions/file-commands.c | 4 +-
app/app.c | 9 +++--
app/core/gimp.c | 8 +++--
app/core/gimp.h | 4 +-
app/widgets/gimpfiledialog.c | 75 ++++++++++++++++++++++++-----------------
5 files changed, 59 insertions(+), 41 deletions(-)
---
diff --git a/app/actions/file-commands.c b/app/actions/file-commands.c
index daba322..fead957 100644
--- a/app/actions/file-commands.c
+++ b/app/actions/file-commands.c
@@ -523,8 +523,8 @@ file_open_dialog_show (Gimp *gimp,
if (file)
gtk_file_chooser_set_file (GTK_FILE_CHOOSER (dialog), file, NULL);
else if (gimp->default_folder)
- gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog),
- gimp->default_folder);
+ gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog),
+ gimp->default_folder, NULL);
gimp_file_dialog_set_open_image (GIMP_FILE_DIALOG (dialog),
image, open_as_layers);
diff --git a/app/app.c b/app/app.c
index a6b7973..783d99d 100644
--- a/app/app.c
+++ b/app/app.c
@@ -162,14 +162,14 @@ app_run (const gchar *full_prog_name,
Gimp *gimp;
GMainLoop *loop;
GMainLoop *run_loop;
- gchar *default_folder = NULL;
+ GFile *default_folder = NULL;
if (filenames && filenames[0] && ! filenames[1] &&
g_file_test (filenames[0], G_FILE_TEST_IS_DIR))
{
if (g_path_is_absolute (filenames[0]))
{
- default_folder = g_filename_to_uri (filenames[0], NULL, NULL);
+ default_folder = g_file_new_for_path (filenames[0]);
}
else
{
@@ -177,7 +177,7 @@ app_run (const gchar *full_prog_name,
g_get_current_dir (),
filenames[0],
NULL);
- default_folder = g_filename_to_uri (absolute, NULL, NULL);
+ default_folder = g_file_new_for_path (absolute);
g_free (absolute);
}
@@ -200,6 +200,9 @@ app_run (const gchar *full_prog_name,
stack_trace_mode,
pdb_compat_mode);
+ if (default_folder)
+ g_object_unref (default_folder);
+
gimp_cpu_accel_set_use (use_cpu_accel);
errors_init (gimp, full_prog_name, use_debug_handler, stack_trace_mode);
diff --git a/app/core/gimp.c b/app/core/gimp.c
index ff6c618..581ab62 100644
--- a/app/core/gimp.c
+++ b/app/core/gimp.c
@@ -460,7 +460,7 @@ gimp_finalize (GObject *object)
if (gimp->default_folder)
{
- g_free (gimp->default_folder);
+ g_object_unref (gimp->default_folder);
gimp->default_folder = NULL;
}
@@ -755,7 +755,7 @@ gimp_real_exit (Gimp *gimp,
Gimp *
gimp_new (const gchar *name,
const gchar *session_name,
- const gchar *default_folder,
+ GFile *default_folder,
gboolean be_verbose,
gboolean no_data,
gboolean no_fonts,
@@ -774,8 +774,10 @@ gimp_new (const gchar *name,
"name", name,
NULL);
+ if (default_folder)
+ gimp->default_folder = g_object_ref (default_folder);
+
gimp->session_name = g_strdup (session_name);
- gimp->default_folder = g_strdup (default_folder);
gimp->be_verbose = be_verbose ? TRUE : FALSE;
gimp->no_data = no_data ? TRUE : FALSE;
gimp->no_fonts = no_fonts ? TRUE : FALSE;
diff --git a/app/core/gimp.h b/app/core/gimp.h
index 4040a07..ed81206 100644
--- a/app/core/gimp.h
+++ b/app/core/gimp.h
@@ -41,7 +41,7 @@ struct _Gimp
* for the preferences dialog
*/
gchar *session_name;
- gchar *default_folder;
+ GFile *default_folder;
gboolean be_verbose;
gboolean no_data;
@@ -146,7 +146,7 @@ GType gimp_get_type (void) G_GNUC_CONST;
Gimp * gimp_new (const gchar *name,
const gchar *session_name,
- const gchar *default_folder,
+ GFile *default_folder,
gboolean be_verbose,
gboolean no_data,
gboolean no_fonts,
diff --git a/app/widgets/gimpfiledialog.c b/app/widgets/gimpfiledialog.c
index dd80b63..44d7eb6 100644
--- a/app/widgets/gimpfiledialog.c
+++ b/app/widgets/gimpfiledialog.c
@@ -122,8 +122,8 @@ static void gimp_file_dialog_help_func (const gchar *help_
static void gimp_file_dialog_help_clicked (GtkWidget *widget,
gpointer dialog);
-static gchar * gimp_file_dialog_pattern_from_extension (const gchar *extension);
-static GFile * gimp_file_dialog_get_default_file (Gimp *gimp);
+static gchar * gimp_file_dialog_pattern_from_extension (const gchar *extension);
+static GFile * gimp_file_dialog_get_default_folder (Gimp *gimp);
G_DEFINE_TYPE_WITH_CODE (GimpFileDialog, gimp_file_dialog,
@@ -490,15 +490,11 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
GFile *dir_file = NULL;
GFile *name_file = NULL;
GFile *ext_file = NULL;
- GFile *default_file;
- GFile *parent_file;
gchar *basename;
g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
g_return_if_fail (GIMP_IS_IMAGE (image));
- default_file = gimp_file_dialog_get_default_file (gimp);
-
dialog->image = image;
dialog->save_a_copy = save_a_copy;
dialog->export = export;
@@ -538,7 +534,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
GIMP_FILE_SAVE_LAST_FILE_KEY);
if (! dir_file)
- dir_file = default_file;
+ dir_file = gimp_file_dialog_get_default_folder (gimp);
/* Priority of default basenames for Save:
@@ -610,7 +606,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
GIMP_FILE_EXPORT_LAST_FILE_KEY);
if (! dir_file)
- dir_file = default_file;
+ dir_file = gimp_file_dialog_get_default_folder (gimp);
/* Priority of default basenames for Export:
@@ -664,10 +660,19 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
basename = g_path_get_basename (gimp_file_get_utf8_name (name_file));
}
- parent_file = g_file_get_parent (dir_file);
- gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog),
- parent_file, NULL);
- g_object_unref (parent_file);
+ if (g_file_query_file_type (dir_file, G_FILE_QUERY_INFO_NONE, NULL) ==
+ G_FILE_TYPE_DIRECTORY)
+ {
+ gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog),
+ dir_file, NULL);
+ }
+ else
+ {
+ GFile *parent_file = g_file_get_parent (dir_file);
+ gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog),
+ parent_file, NULL);
+ g_object_unref (parent_file);
+ }
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), basename);
}
@@ -1140,32 +1145,40 @@ gimp_file_dialog_pattern_from_extension (const gchar *extension)
}
static GFile *
-gimp_file_dialog_get_default_file (Gimp *gimp)
+gimp_file_dialog_get_default_folder (Gimp *gimp)
{
if (gimp->default_folder)
{
- return g_file_new_for_path (gimp->default_folder);
+ return gimp->default_folder;
}
else
{
- GFile *file;
- gchar *path;
+ GFile *file = g_object_get_data (G_OBJECT (gimp),
+ "gimp-documents-folder");
- /* Make sure it ends in '/' */
- path = g_build_path (G_DIR_SEPARATOR_S,
- g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS),
- G_DIR_SEPARATOR_S,
- NULL);
-
- /* Paranoia fallback, see bug #722400 */
- if (! path)
- path = g_build_path (G_DIR_SEPARATOR_S,
- g_get_home_dir (),
- G_DIR_SEPARATOR_S,
- NULL);
-
- file = g_file_new_for_path (path);
- g_free (path);
+ if (! file)
+ {
+ gchar *path;
+
+ /* Make sure it ends in '/' */
+ path = g_build_path (G_DIR_SEPARATOR_S,
+ g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS),
+ G_DIR_SEPARATOR_S,
+ NULL);
+
+ /* Paranoia fallback, see bug #722400 */
+ if (! path)
+ path = g_build_path (G_DIR_SEPARATOR_S,
+ g_get_home_dir (),
+ G_DIR_SEPARATOR_S,
+ NULL);
+
+ file = g_file_new_for_path (path);
+ g_free (path);
+
+ g_object_set_data_full (G_OBJECT (gimp), "gimp-documents-folder",
+ file, (GDestroyNotify) g_object_unref);
+ }
return file;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]