1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
10 * \file helper_funcs.C
11 * \author Angus Leeming <a.leeming@ic.ac.uk>
17 #pragma implementation
22 #include "helper_funcs.h"
24 #include "frontends/FileDialog.h"
25 #include "support/filetools.h" // OnlyPath, OnlyFilename
26 #include "gettext.h" // _()
27 #include "lyx_gui_misc.h" // WriteAlert
34 string const getStringFromVector(vector<string> const & vec,
38 for (vector<string>::size_type i=0; i<vec.size(); ++i) {
39 if (i > 0) str += delim;
45 vector<string> const getVectorFromString(string const & str,
52 string::size_type const idx = keys.find(delim);
53 if (idx == string::npos) break;
55 vec.push_back(keys.substr(0, idx));
57 string::size_type const start = idx + delim.size();
58 keys = keys.substr(start);
61 if (vec.empty()) // unable to separate
67 string const browseFile(LyXView * lv, string const & filename,
69 string const & pattern,
70 pair<string,string> const & dir1,
71 pair<string,string> const & dir2)
73 string lastPath = ".";
74 if (!filename.empty()) lastPath = OnlyPath(filename);
76 FileDialog fileDlg(lv, title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
78 FileDialog::Result result;
81 result = fileDlg.Select(lastPath, pattern, OnlyFilename(filename));
83 if (result.second.empty())
86 lastPath = OnlyPath(result.second);
88 if (result.second.find_first_of("#~$% ") == string::npos)
91 WriteAlert(_("Filename can't contain any "
92 "of these characters:"),
93 _("space, '#', '~', '$' or '%'."));