From 0831d31b0359c4d7160e9cbfed7f5f3b1f7dd395 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Fri, 20 Jun 2014 15:40:50 +0000 Subject: GTK file chooser: set correct current directory when selecting for a folder. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10203 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Native_File_Chooser_GTK.cxx | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Fl_Native_File_Chooser_GTK.cxx b/src/Fl_Native_File_Chooser_GTK.cxx index 11516aec3..7b7fbe155 100644 --- a/src/Fl_Native_File_Chooser_GTK.cxx +++ b/src/Fl_Native_File_Chooser_GTK.cxx @@ -393,6 +393,23 @@ int Fl_GTK_File_Chooser::show() return retval; } +static char *extract_dir_from_path(const char *path) +{ + static char *dir = NULL; + if (fl_filename_isdir(path)) { + return (char*)path; + } + if (*path != '/') return NULL; + if (dir) free(dir); + dir = strdup(path); + do { + char *p = strrchr(dir, '/'); + if (p == dir) p++; + *p = 0; + } + while (!fl_filename_isdir(dir)); + return dir; +} static void run_response_handler(GtkDialog *dialog, gint response_id, gpointer data) { @@ -476,19 +493,13 @@ int Fl_GTK_File_Chooser::fl_gtk_chooser_wrapper() break; } - if (_directory && _directory[0]) fl_gtk_file_chooser_set_current_folder((GtkFileChooser *)gtkw_ptr, _directory); + if (_directory && _directory[0]) { + p = extract_dir_from_path(_directory); + if (p) fl_gtk_file_chooser_set_current_folder((GtkFileChooser *)gtkw_ptr, p); + } else if (_preset_file) { - if (fl_filename_isdir(_preset_file)) { - fl_gtk_file_chooser_set_current_folder((GtkFileChooser *)gtkw_ptr, _preset_file); - } - else if (strrchr(_preset_file, '/')) { - char *dir = strdup(_preset_file); - p = strrchr(dir, '/'); - if (p == dir) p++; - *p = 0; - fl_gtk_file_chooser_set_current_folder((GtkFileChooser *)gtkw_ptr, dir); - free(dir); - } + p = extract_dir_from_path(_preset_file); + if (p) fl_gtk_file_chooser_set_current_folder((GtkFileChooser *)gtkw_ptr, p); } GtkFileFilter **filter_tab = NULL; -- cgit v1.2.3