]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/helper_funcs.C
This file is part of LyX, the document processor.
[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 string const browseFile(LyXView * lv, string const & filename,
32                         string const & title,
33                         string const & pattern,
34                         pair<string,string> const & dir1,
35                         pair<string,string> const & dir2)
36 {
37         string lastPath = ".";
38         if (!filename.empty())
39                 lastPath = OnlyPath(filename);
40
41         FileDialog fileDlg(lv, title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
42
43         FileDialog::Result result;
44
45         while (1) {
46                 result = fileDlg.Select(lastPath, pattern, OnlyFilename(filename));
47
48                 if (result.second.empty())
49                         return result.second;
50
51                 lastPath = OnlyPath(result.second);
52
53                 if (result.second.find_first_of("#~$% ") == string::npos)
54                         break;
55
56                 Alert::alert(_("Filename can't contain any "
57                         "of these characters:"),
58                         _("space, '#', '~', '$' or '%'."));
59         }
60
61         return result.second;
62 }
63
64
65 string const browseRelFile(LyXView * lv, string const & filename,
66                         string const & refpath,
67                         string const & title,
68                         string const & pattern,
69                         pair<string,string> const & dir1,
70                         pair<string,string> const & dir2)
71 {
72         string const fname = MakeAbsPath(filename, refpath);
73
74         string const outname = browseFile(lv, fname, title, pattern,
75                                           dir1, dir2);
76         string const reloutname = MakeRelPath(outname, refpath);
77         if (prefixIs(reloutname, "../"))
78                 return outname;
79         else
80                 return reloutname;
81 }
82
83
84 // sorry this is just a temporary hack we should include vspace.h! (Jug)
85 extern const char * stringFromUnit(int);
86
87 vector<string> const getLatexUnits()
88 {
89         vector<string> units;
90         const char * str;
91         for(int i=0; (str = stringFromUnit(i)); ++i)
92             units.push_back(str);
93
94         return units;
95 }