From 776235882a06eede8b2ce1e5bcc4fce438f237c7 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Wed, 5 Jun 2013 15:19:18 +0000 Subject: [PATCH] more tries to get the file chooser to behave --- Fltk/fileDialogs.cpp | 22 +++++++++++++++++----- Fltk/graphicWindow.cpp | 11 ++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Fltk/fileDialogs.cpp b/Fltk/fileDialogs.cpp index bf17b21b11..4b4643bf36 100644 --- a/Fltk/fileDialogs.cpp +++ b/Fltk/fileDialogs.cpp @@ -23,12 +23,14 @@ #include "GmshConfig.h" #include "GmshMessage.h" #include "GmshDefines.h" +#include "StringUtils.h" #include "FlGui.h" #include "optionWindow.h" #include "fileDialogs.h" #include "CreateFile.h" #include "Options.h" #include "Context.h" +#include "GModel.h" #include "PView.h" #include "PViewOptions.h" @@ -86,12 +88,22 @@ int fileChooser(FILE_CHOOSER_TYPE type, const char *message, static char thefilter[1024] = ""; static int thefilterindex = 0; + // reset the filter and the selection if the filter has changed if(strncmp(thefilter, filter, 1024)) { - // reset the filter and the selection if the filter has changed strncpy(thefilter, filter, 1024); thefilterindex = 0; } + // determine where to start + static std::string thepath; + + if(fname) + thepath = std::string(fname); + else + thepath = GModel::current()->getFileName(); + std::vector<std::string> split = SplitFileName(thepath); + if(split[0].empty()) thepath = std::string("./") + thepath; + #if defined(HAVE_NATIVE_FILE_CHOOSER) if(!fc) fc = new Fl_Native_File_Chooser(); switch(type){ @@ -109,10 +121,10 @@ int fileChooser(FILE_CHOOSER_TYPE type, const char *message, fc->filter_value(thefilterindex); static bool first = true; - if(fname && first){ + if(first){ // preset the path and the file only the first time in a given // session. Afterwards, always reuse the last directory - fc->preset_file(fname); + fc->preset_file(thepath.c_str()); first = false; } else{ @@ -153,10 +165,10 @@ int fileChooser(FILE_CHOOSER_TYPE type, const char *message, fc->filter(thefilter); fc->filter_value(thefilterindex); static bool first = true; - if(fname && first){ + if(first){ // preset the path and the file only the first time in a given // session. Afterwards, always reuse the last directory - fc->value(fname); + fc->value(thepath.c_str()); first = false; } else{ diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp index c75de33728..1b3bf57fb3 100644 --- a/Fltk/graphicWindow.cpp +++ b/Fltk/graphicWindow.cpp @@ -62,8 +62,7 @@ typedef unsigned long intptr_t; static void file_new_cb(Fl_Widget *w, void *data) { test: - if(fileChooser(FILE_CHOOSER_CREATE, "New", "", - GModel::current()->getFileName().c_str())) { + if(fileChooser(FILE_CHOOSER_CREATE, "New", "")) { std::string name = fileChooserGetName(1); if(!StatFile(name)){ if(fl_choice("File '%s' already exists.\n\nDo you want to erase it?", @@ -140,7 +139,7 @@ static void file_open_merge_cb(Fl_Widget *w, void *data) std::string mode((char*)data); int n = PView::list.size(); int f = fileChooser(FILE_CHOOSER_MULTI, (mode == "open") ? "Open" : "Merge", - input_formats, GModel::current()->getFileName().c_str()); + input_formats); if(f){ for(int i = 1; i <= f; i++){ if(mode == "open") @@ -421,8 +420,7 @@ static void file_save_as_cb(Fl_Widget *w, void *data) } test: - if(fileChooser(FILE_CHOOSER_CREATE, "Save As", pat, - GModel::current()->getFileName().c_str())) { + if(fileChooser(FILE_CHOOSER_CREATE, "Save As", pat)) { std::string name = fileChooserGetName(1); if(CTX::instance()->confirmOverwrite) { if(!StatFile(name)) @@ -461,8 +459,7 @@ static void file_options_save_cb(Fl_Widget *w, void *data) static void file_rename_cb(Fl_Widget *w, void *data) { test: - if(fileChooser(FILE_CHOOSER_CREATE, "Rename", "", - GModel::current()->getFileName().c_str())) { + if(fileChooser(FILE_CHOOSER_CREATE, "Rename", "")) { std::string name = fileChooserGetName(1); if(CTX::instance()->confirmOverwrite) { if(!StatFile(name)) -- GitLab