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 "support/lstrings.h"
27 #include "gettext.h" // _()
28 #include "frontends/Alert.h"
35 string const getStringFromVector(vector<string> const & vec,
40 for (vector<string>::const_iterator it = vec.begin();
41 it != vec.end(); ++it) {
42 string item = strip(frontStrip(*it));
43 if (item.empty()) continue;
45 if (i++ > 0) str += delim;
51 vector<string> const getVectorFromString(string const & str,
58 string keys(strip(str));
61 string::size_type const idx = keys.find(delim);
62 if (idx == string::npos) {
63 vec.push_back(frontStrip(keys));
67 string const key = strip(frontStrip(keys.substr(0, idx)));
71 string::size_type const start = idx + delim.size();
72 keys = keys.substr(start);
78 string const browseFile(LyXView * lv, string const & filename,
80 string const & pattern,
81 pair<string,string> const & dir1,
82 pair<string,string> const & dir2)
84 string lastPath = ".";
85 if (!filename.empty()) lastPath = OnlyPath(filename);
87 FileDialog fileDlg(lv, title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
89 FileDialog::Result result;
92 result = fileDlg.Select(lastPath, pattern, OnlyFilename(filename));
94 if (result.second.empty())
97 lastPath = OnlyPath(result.second);
99 if (result.second.find_first_of("#~$% ") == string::npos)
102 Alert::alert(_("Filename can't contain any "
103 "of these characters:"),
104 _("space, '#', '~', '$' or '%'."));
107 return result.second;
111 string const browseRelFile(LyXView * lv, string const & filename,
112 string const & refpath,
113 string const & title,
114 string const & pattern,
115 pair<string,string> const & dir1,
116 pair<string,string> const & dir2)
118 string const fname = MakeAbsPath(filename, refpath);
120 string const outname = browseFile(lv, fname, title, pattern, dir1);
121 string const reloutname = MakeRelPath(outname, refpath);
122 if(prefixIs(reloutname, "../"))
129 // sorry this is just a temporary hack we should include vspace.h! (Jug)
130 extern const char * stringFromUnit(int);
132 vector<string> const getLatexUnits()
134 vector<string> units;
136 for(int i=0; (str = stringFromUnit(i)); ++i)
137 units.push_back(str);