Bug 689403 - GIMP saves files in strange directories when started from an...

If one single directory is passed on the command line, use it
as default folder for the open/save dialogs.
This commit is contained in:
Michael Natterer
2012-12-15 00:34:15 +01:00
parent cc20c8d7f6
commit af7916b3e6
6 changed files with 69 additions and 26 deletions

View File

@ -519,6 +519,9 @@ file_open_dialog_show (Gimp *gimp,
if (uri) if (uri)
gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog), uri); gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog), uri);
else if (gimp->default_folder)
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog),
gimp->default_folder);
gimp_file_dialog_set_open_image (GIMP_FILE_DIALOG (dialog), gimp_file_dialog_set_open_image (GIMP_FILE_DIALOG (dialog),
image, open_as_layers); image, open_as_layers);

View File

@ -145,12 +145,34 @@ app_run (const gchar *full_prog_name,
GimpInitStatusFunc update_status_func = NULL; GimpInitStatusFunc update_status_func = NULL;
Gimp *gimp; Gimp *gimp;
GMainLoop *loop; GMainLoop *loop;
gchar *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);
}
else
{
gchar *absolute = g_build_path (G_DIR_SEPARATOR_S,
g_get_current_dir (),
filenames[0],
NULL);
default_folder = g_filename_to_uri (absolute, NULL, NULL);
g_free (absolute);
}
filenames = NULL;
}
/* Create an instance of the "Gimp" object which is the root of the /* Create an instance of the "Gimp" object which is the root of the
* core object system * core object system
*/ */
gimp = gimp_new (full_prog_name, gimp = gimp_new (full_prog_name,
session_name, session_name,
default_folder,
be_verbose, be_verbose,
no_data, no_data,
no_fonts, no_fonts,

View File

@ -191,6 +191,7 @@ gimp_init (Gimp *gimp)
{ {
gimp->config = NULL; gimp->config = NULL;
gimp->session_name = NULL; gimp->session_name = NULL;
gimp->default_folder = NULL;
gimp->be_verbose = FALSE; gimp->be_verbose = FALSE;
gimp->no_data = FALSE; gimp->no_data = FALSE;
@ -455,6 +456,12 @@ gimp_finalize (GObject *object)
gimp->edit_config = NULL; gimp->edit_config = NULL;
} }
if (gimp->default_folder)
{
g_free (gimp->default_folder);
gimp->default_folder = NULL;
}
if (gimp->session_name) if (gimp->session_name)
{ {
g_free (gimp->session_name); g_free (gimp->session_name);
@ -746,6 +753,7 @@ gimp_real_exit (Gimp *gimp,
Gimp * Gimp *
gimp_new (const gchar *name, gimp_new (const gchar *name,
const gchar *session_name, const gchar *session_name,
const gchar *default_folder,
gboolean be_verbose, gboolean be_verbose,
gboolean no_data, gboolean no_data,
gboolean no_fonts, gboolean no_fonts,
@ -764,6 +772,7 @@ gimp_new (const gchar *name,
NULL); NULL);
gimp->session_name = g_strdup (session_name); gimp->session_name = g_strdup (session_name);
gimp->default_folder = g_strdup (default_folder);
gimp->be_verbose = be_verbose ? TRUE : FALSE; gimp->be_verbose = be_verbose ? TRUE : FALSE;
gimp->no_data = no_data ? TRUE : FALSE; gimp->no_data = no_data ? TRUE : FALSE;
gimp->no_fonts = no_fonts ? TRUE : FALSE; gimp->no_fonts = no_fonts ? TRUE : FALSE;

View File

@ -41,6 +41,7 @@ struct _Gimp
* for the preferences dialog * for the preferences dialog
*/ */
gchar *session_name; gchar *session_name;
gchar *default_folder;
gboolean be_verbose; gboolean be_verbose;
gboolean no_data; gboolean no_data;
@ -144,6 +145,7 @@ GType gimp_get_type (void) G_GNUC_CONST;
Gimp * gimp_new (const gchar *name, Gimp * gimp_new (const gchar *name,
const gchar *session_name, const gchar *session_name,
const gchar *default_folder,
gboolean be_verbose, gboolean be_verbose,
gboolean no_data, gboolean no_data,
gboolean no_fonts, gboolean no_fonts,

View File

@ -66,7 +66,7 @@ gimp_init_for_testing (void)
gimp_log_init (); gimp_log_init ();
gegl_init (NULL, NULL); gegl_init (NULL, NULL);
gimp = gimp_new ("Unit Tested GIMP", NULL, FALSE, TRUE, TRUE, TRUE, gimp = gimp_new ("Unit Tested GIMP", NULL, NULL, FALSE, TRUE, TRUE, TRUE,
FALSE, TRUE, TRUE, FALSE); FALSE, TRUE, TRUE, FALSE);
units_init (gimp); units_init (gimp);
@ -100,7 +100,7 @@ gimp_init_for_gui_testing_internal (gboolean show_gui,
gimp_session_info_class_set_position_accuracy (klass, 5); gimp_session_info_class_set_position_accuracy (klass, 5);
/* from app_run() */ /* from app_run() */
gimp = gimp_new ("Unit Tested GIMP", NULL, FALSE, TRUE, TRUE, !show_gui, gimp = gimp_new ("Unit Tested GIMP", NULL, NULL, FALSE, TRUE, TRUE, !show_gui,
FALSE, TRUE, TRUE, FALSE); FALSE, TRUE, TRUE, FALSE);
gimp_set_show_gui (gimp, show_gui); gimp_set_show_gui (gimp, show_gui);
units_init (gimp); units_init (gimp);

View File

@ -123,7 +123,7 @@ static void gimp_file_dialog_help_clicked (GtkWidget *widge
gpointer dialog); gpointer dialog);
static gchar * gimp_file_dialog_pattern_from_extension (const gchar *extension); static gchar * gimp_file_dialog_pattern_from_extension (const gchar *extension);
static gchar * gimp_file_dialog_get_documents_uri (void); static gchar * gimp_file_dialog_get_default_uri (Gimp *gimp);
static gchar * gimp_file_dialog_get_dirname_from_uri (const gchar *uri); static gchar * gimp_file_dialog_get_dirname_from_uri (const gchar *uri);
@ -489,17 +489,17 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
gboolean close_after_saving, gboolean close_after_saving,
GimpObject *display) GimpObject *display)
{ {
const gchar *dir_uri = NULL; const gchar *dir_uri = NULL;
const gchar *name_uri = NULL; const gchar *name_uri = NULL;
const gchar *ext_uri = NULL; const gchar *ext_uri = NULL;
gchar *docs_uri = NULL; gchar *default_uri = NULL;
gchar *dirname = NULL; gchar *dirname = NULL;
gchar *basename = NULL; gchar *basename = NULL;
g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog)); g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
g_return_if_fail (GIMP_IS_IMAGE (image)); g_return_if_fail (GIMP_IS_IMAGE (image));
docs_uri = gimp_file_dialog_get_documents_uri (); default_uri = gimp_file_dialog_get_default_uri (gimp);
dialog->image = image; dialog->image = image;
dialog->save_a_copy = save_a_copy; dialog->save_a_copy = save_a_copy;
@ -519,7 +519,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
* 3. Path of source XCF * 3. Path of source XCF
* 4. Path of Import source * 4. Path of Import source
* 5. Last Save path of any GIMP document * 5. Last Save path of any GIMP document
* 6. The OS 'Documents' path * 6. The default path (usually the OS 'Documents' path)
*/ */
if (save_a_copy) if (save_a_copy)
@ -540,7 +540,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
GIMP_FILE_SAVE_LAST_URI_KEY); GIMP_FILE_SAVE_LAST_URI_KEY);
if (! dir_uri) if (! dir_uri)
dir_uri = docs_uri; dir_uri = default_uri;
/* Priority of default basenames for Save: /* Priority of default basenames for Save:
@ -588,7 +588,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
* 3. Path of XCF source * 3. Path of XCF source
* 4. Last path of any save to XCF * 4. Last path of any save to XCF
* 5. Last Export path of any document * 5. Last Export path of any document
* 6. The OS 'Documents' path * 6. The default path (usually the OS 'Documents' path)
*/ */
dir_uri = gimp_image_get_exported_uri (image); dir_uri = gimp_image_get_exported_uri (image);
@ -612,7 +612,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
GIMP_FILE_EXPORT_LAST_URI_KEY); GIMP_FILE_EXPORT_LAST_URI_KEY);
if (! dir_uri) if (! dir_uri)
dir_uri = docs_uri; dir_uri = default_uri;
/* Priority of default basenames for Export: /* Priority of default basenames for Export:
@ -672,7 +672,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), dirname); gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), dirname);
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), basename); gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), basename);
g_free (docs_uri); g_free (default_uri);
g_free (basename); g_free (basename);
g_free (dirname); g_free (dirname);
} }
@ -1143,20 +1143,27 @@ gimp_file_dialog_pattern_from_extension (const gchar *extension)
} }
static gchar * static gchar *
gimp_file_dialog_get_documents_uri (void) gimp_file_dialog_get_default_uri (Gimp *gimp)
{ {
gchar *path; if (gimp->default_folder)
gchar *uri; {
return g_strdup (gimp->default_folder);
}
else
{
gchar *path;
gchar *uri;
/* Make sure it ends in '/' */ /* Make sure it ends in '/' */
path = g_build_path ("/", path = g_build_path (G_DIR_SEPARATOR_S,
g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS), g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS),
"/", G_DIR_SEPARATOR_S,
NULL); NULL);
uri = g_filename_to_uri (path, NULL, NULL); uri = g_filename_to_uri (path, NULL, NULL);
g_free (path); g_free (path);
return uri; return uri;
}
} }
static gchar * static gchar *