]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/helper_funcs.C
Really dull and boring header shit
[lyx.git] / src / frontends / controllers / helper_funcs.C
1 /**
2  * \file helper_funcs.C
3  * See the file COPYING.
4  *
5  * \author Angus Leeming
6  *
7  * Full author contact details are available in file CREDITS
8  */
9
10 #include <vector>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include <config.h>
17 #include "LString.h"
18 #include "helper_funcs.h"
19
20 #include "frontends/FileDialog.h"
21 #include "support/filetools.h" // OnlyPath, OnlyFilename
22 #include "support/lstrings.h"
23 #include "gettext.h" // _()
24 #include "frontends/Alert.h"
25
26 using std::pair;
27 using std::vector;
28 using std::make_pair;
29
30 string const browseFile(LyXView * lv, string const & filename,
31                         string const & title,
32                         string const & pattern,
33                         pair<string,string> const & dir1,
34                         pair<string,string> const & dir2)
35 {
36         string lastPath = ".";
37         if (!filename.empty())
38                 lastPath = OnlyPath(filename);
39
40         FileDialog fileDlg(lv, title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
41
42         FileDialog::Result result;
43
44         while (1) {
45                 result = fileDlg.Select(lastPath, pattern, OnlyFilename(filename));
46
47                 if (result.second.empty())
48                         return result.second;
49
50                 lastPath = OnlyPath(result.second);
51
52                 if (result.second.find_first_of("#~$% ") == string::npos)
53                         break;
54
55                 Alert::alert(_("Filename can't contain any "
56                         "of these characters:"),
57                         _("space, '#', '~', '$' or '%'."));
58         }
59
60         return result.second;
61 }
62
63
64 string const browseRelFile(LyXView * lv, string const & filename,
65                         string const & refpath,
66                         string const & title,
67                         string const & pattern,
68                         pair<string,string> const & dir1,
69                         pair<string,string> const & dir2)
70 {
71         string const fname = MakeAbsPath(filename, refpath);
72
73         string const outname = browseFile(lv, fname, title, pattern,
74                                           dir1, dir2);
75         string const reloutname = MakeRelPath(outname, refpath);
76         if (prefixIs(reloutname, "../"))
77                 return outname;
78         else
79                 return reloutname;
80 }
81
82
83 // sorry this is just a temporary hack we should include vspace.h! (Jug)
84 extern const char * stringFromUnit(int);
85
86 vector<string> const getLatexUnits()
87 {
88         vector<string> units;
89         const char * str;
90         for(int i=0; (str = stringFromUnit(i)); ++i)
91             units.push_back(str);
92
93         return units;
94 }