]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/xforms_helpers.C
Applied John's FileDialog patch.
[lyx.git] / src / frontends / xforms / xforms_helpers.C
index 72d346f4ac09604ddce881bba030efeb20922fdd..02d3a69e365cb5de410ccfcddc1fe6c2cd967491 100644 (file)
 #ifdef __GNUG_
 #pragma implementation
 #endif
-
 #include "xforms_helpers.h"
 #include "lyxlex.h"
-#include "filedlg.h" // LyXFileDlg
+#include "frontends/FileDialog.h"
 #include "support/FileInfo.h"
 #include "support/filetools.h"
 #include "lyx_gui_misc.h" // WriteAlert
@@ -83,7 +83,7 @@ string formatted(string const & sin, int w, int size, int style)
 }
 
 
-string const browseFile(string const & filename,
+string const browseFile(LyXView * lv, string const & filename,
                        string const & title,
                        string const & pattern, 
                        pair<string,string> const & dir1,
@@ -92,43 +92,27 @@ string const browseFile(string const & filename,
        string lastPath = ".";
        if (!filename.empty()) lastPath = OnlyPath(filename);
 
-       LyXFileDlg fileDlg;
-
-       if (!dir1.second.empty()) {
-               FileInfo fileInfo(dir1.second);
-               if (fileInfo.isOK() && fileInfo.isDir())
-                       fileDlg.SetButton(0, _(dir1.first), dir1.second);
-       }
-
-       if (!dir2.second.empty()) {
-               FileInfo fileInfo(dir2.second);
-               if (fileInfo.isOK() && fileInfo.isDir())
-                   fileDlg.SetButton(1, _(dir2.first), dir2.second);
-       }
+       FileDialog fileDlg(lv, title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
 
-       bool error = false;
-       string buf;
-       do {
-               string p = fileDlg.Select(_(title),
-                                         lastPath,
-                                         pattern, OnlyFilename(filename));
+       FileDialog::Result result;
+       while (1) {
+               result = fileDlg.Select(lastPath, pattern, OnlyFilename(filename));
 
-               if (p.empty()) return p;
+               if (result.second.empty()) 
+                       return result.second;
 
-               lastPath = OnlyPath(p);
+               lastPath = OnlyPath(result.second);
 
-               if (p.find_first_of("#~$% ") != string::npos) {
-                       WriteAlert(_("Filename can't contain any "
-                                    "of these characters:"),
-                                  _("space, '#', '~', '$' or '%'."));
-                       error = true;
-               } else {
-                       error = false;
-                       buf = p;
-               }
-       } while (error);
+               if (result.second.find_first_of("#~$% ") == string::npos)
+                       break; 
+               WriteAlert(_("Filename can't contain any "
+                       "of these characters:"),
+                       _("space, '#', '~', '$' or '%'."));
+       }
 
-       return buf;
+       return result.second;
 }