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