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