2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2001 The LyX Team.
9 * ======================================================
11 * \file helper_funcs.C
12 * \author Angus Leeming <a.leeming@ic.ac.uk>
18 #pragma implementation
23 #include "helper_funcs.h"
25 #include "frontends/FileDialog.h"
26 #include "support/filetools.h" // OnlyPath, OnlyFilename
27 #include "gettext.h" // _()
28 #include "lyx_gui_misc.h" // WriteAlert
35 string const getStringFromVector(vector<string> const & vec,
40 for (vector<string>::const_iterator it = vec.begin();
41 it != vec.end(); ++it) {
42 if (it->empty()) continue;
44 if (i++ > 0) str += delim;
50 vector<string> const getVectorFromString(string const & str,
57 string::size_type const idx = keys.find(delim);
58 if (idx == string::npos) {
63 string const key = keys.substr(0, idx);
67 string::size_type const start = idx + delim.size();
68 keys = keys.substr(start);
74 string const browseFile(LyXView * lv, string const & filename,
76 string const & pattern,
77 pair<string,string> const & dir1,
78 pair<string,string> const & dir2)
80 string lastPath = ".";
81 if (!filename.empty()) lastPath = OnlyPath(filename);
83 FileDialog fileDlg(lv, title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
85 FileDialog::Result result;
88 result = fileDlg.Select(lastPath, pattern, OnlyFilename(filename));
90 if (result.second.empty())
93 lastPath = OnlyPath(result.second);
95 if (result.second.find_first_of("#~$% ") == string::npos)
98 WriteAlert(_("Filename can't contain any "
99 "of these characters:"),
100 _("space, '#', '~', '$' or '%'."));
103 return result.second;