Skip to content

Commit

Permalink
GTK file chooser: set correct current directory when selecting for a …
Browse files Browse the repository at this point in the history
…folder.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10203 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Manolo Gouy authored and Manolo Gouy committed Jun 20, 2014
1 parent 37f77a2 commit 0831d31
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/Fl_Native_File_Chooser_GTK.cxx
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0831d31

Please sign in to comment.