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