Commit af7916b3 authored by Michael Natterer's avatar Michael Natterer 😴

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.
parent cc20c8d7
......@@ -519,6 +519,9 @@ file_open_dialog_show (Gimp *gimp,
if (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),
image, open_as_layers);
......
......@@ -145,12 +145,34 @@ app_run (const gchar *full_prog_name,
GimpInitStatusFunc update_status_func = NULL;
Gimp *gimp;
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
* core object system
*/
gimp = gimp_new (full_prog_name,
session_name,
default_folder,
be_verbose,
no_data,
no_fonts,
......
......@@ -191,6 +191,7 @@ gimp_init (Gimp *gimp)
{
gimp->config = NULL;
gimp->session_name = NULL;
gimp->default_folder = NULL;
gimp->be_verbose = FALSE;
gimp->no_data = FALSE;
......@@ -455,6 +456,12 @@ gimp_finalize (GObject *object)
gimp->edit_config = NULL;
}
if (gimp->default_folder)
{
g_free (gimp->default_folder);
gimp->default_folder = NULL;
}
if (gimp->session_name)
{
g_free (gimp->session_name);
......@@ -746,6 +753,7 @@ gimp_real_exit (Gimp *gimp,
Gimp *
gimp_new (const gchar *name,
const gchar *session_name,
const gchar *default_folder,
gboolean be_verbose,
gboolean no_data,
gboolean no_fonts,
......@@ -764,6 +772,7 @@ gimp_new (const gchar *name,
NULL);
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;
......
......@@ -41,6 +41,7 @@ struct _Gimp
* for the preferences dialog
*/
gchar *session_name;
gchar *default_folder;
gboolean be_verbose;
gboolean no_data;
......@@ -144,6 +145,7 @@ GType gimp_get_type (void) G_GNUC_CONST;
Gimp * gimp_new (const gchar *name,
const gchar *session_name,
const gchar *default_folder,
gboolean be_verbose,
gboolean no_data,
gboolean no_fonts,
......
......@@ -66,7 +66,7 @@ gimp_init_for_testing (void)
gimp_log_init ();
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);
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);
/* 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);
gimp_set_show_gui (gimp, show_gui);
units_init (gimp);
......
......@@ -123,7 +123,7 @@ static void gimp_file_dialog_help_clicked (GtkWidget *widge
gpointer dialog);
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);
......@@ -489,17 +489,17 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
gboolean close_after_saving,
GimpObject *display)
{
const gchar *dir_uri = NULL;
const gchar *name_uri = NULL;
const gchar *ext_uri = NULL;
gchar *docs_uri = NULL;
gchar *dirname = NULL;
gchar *basename = NULL;
const gchar *dir_uri = NULL;
const gchar *name_uri = NULL;
const gchar *ext_uri = NULL;
gchar *default_uri = NULL;
gchar *dirname = NULL;
gchar *basename = NULL;
g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
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->save_a_copy = save_a_copy;
......@@ -519,7 +519,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
* 3. Path of source XCF
* 4. Path of Import source
* 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)
......@@ -540,7 +540,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
GIMP_FILE_SAVE_LAST_URI_KEY);
if (! dir_uri)
dir_uri = docs_uri;
dir_uri = default_uri;
/* Priority of default basenames for Save:
......@@ -588,7 +588,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
* 3. Path of XCF source
* 4. Last path of any save to XCF
* 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);
......@@ -612,7 +612,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
GIMP_FILE_EXPORT_LAST_URI_KEY);
if (! dir_uri)
dir_uri = docs_uri;
dir_uri = default_uri;
/* 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_name (GTK_FILE_CHOOSER (dialog), basename);
g_free (docs_uri);
g_free (default_uri);
g_free (basename);
g_free (dirname);
}
......@@ -1143,20 +1143,27 @@ gimp_file_dialog_pattern_from_extension (const gchar *extension)
}
static gchar *
gimp_file_dialog_get_documents_uri (void)
gimp_file_dialog_get_default_uri (Gimp *gimp)
{
gchar *path;
gchar *uri;
/* Make sure it ends in '/' */
path = g_build_path ("/",
g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS),
"/",
NULL);
uri = g_filename_to_uri (path, NULL, NULL);
g_free (path);
return uri;
if (gimp->default_folder)
{
return g_strdup (gimp->default_folder);
}
else
{
gchar *path;
gchar *uri;
/* 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);
uri = g_filename_to_uri (path, NULL, NULL);
g_free (path);
return uri;
}
}
static gchar *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment