#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
}
-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,
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;
}