1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
10 * \file helper_funcs.C
11 * \author Angus Leeming <a.leeming@ic.ac.uk>
17 #pragma implementation
22 #include "helper_funcs.h"
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"
34 string const browseFile(LyXView * lv, string const & filename,
36 string const & pattern,
37 pair<string,string> const & dir1,
38 pair<string,string> const & dir2)
40 string lastPath = ".";
41 if (!filename.empty())
42 lastPath = OnlyPath(filename);
44 FileDialog fileDlg(lv, title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
46 FileDialog::Result result;
49 result = fileDlg.Select(lastPath, pattern, OnlyFilename(filename));
51 if (result.second.empty())
54 lastPath = OnlyPath(result.second);
56 if (result.second.find_first_of("#~$% ") == string::npos)
59 Alert::alert(_("Filename can't contain any "
60 "of these characters:"),
61 _("space, '#', '~', '$' or '%'."));
68 string const browseRelFile(LyXView * lv, string const & filename,
69 string const & refpath,
71 string const & pattern,
72 pair<string,string> const & dir1,
73 pair<string,string> const & dir2)
75 string const fname = MakeAbsPath(filename, refpath);
77 string const outname = browseFile(lv, fname, title, pattern,
79 string const reloutname = MakeRelPath(outname, refpath);
80 if (prefixIs(reloutname, "../"))
87 // sorry this is just a temporary hack we should include vspace.h! (Jug)
88 extern const char * stringFromUnit(int);
90 vector<string> const getLatexUnits()
94 for(int i=0; (str = stringFromUnit(i)); ++i)