diff options
| author | Manolo Gouy <Manolo> | 2014-06-20 15:40:50 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2014-06-20 15:40:50 +0000 |
| commit | 0831d31b0359c4d7160e9cbfed7f5f3b1f7dd395 (patch) | |
| tree | 61ddf04fc82f99e230a21b963af2af9fc3fc71bc /src | |
| parent | 37f77a271c4bbccfa23a63bd786eff7b6749b320 (diff) | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Native_File_Chooser_GTK.cxx | 35 |
1 files changed, 23 insertions, 12 deletions
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; |
