2002-09-05 14:10:50 +00:00
|
|
|
/**
|
|
|
|
* \file helper_funcs.C
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-03-21 13:27:03 +00:00
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author Angus Leeming
|
2001-03-21 13:27:03 +00:00
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
* Full author contact details are available in file CREDITS
|
2001-03-21 13:27:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include "LString.h"
|
|
|
|
#include "helper_funcs.h"
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
#include "frontends/FileDialog.h"
|
|
|
|
#include "support/filetools.h" // OnlyPath, OnlyFilename
|
2001-08-01 15:22:01 +00:00
|
|
|
#include "support/lstrings.h"
|
2001-03-30 09:51:46 +00:00
|
|
|
#include "gettext.h" // _()
|
2001-11-26 10:19:58 +00:00
|
|
|
#include "frontends/Alert.h"
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
using std::pair;
|
2001-03-21 13:27:03 +00:00
|
|
|
using std::vector;
|
2001-03-30 09:51:46 +00:00
|
|
|
using std::make_pair;
|
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
string const browseFile(LyXView * lv, string const & filename,
|
|
|
|
string const & title,
|
2002-03-21 21:21:28 +00:00
|
|
|
string const & pattern,
|
2002-11-17 08:32:09 +00:00
|
|
|
bool save,
|
2001-03-30 09:51:46 +00:00
|
|
|
pair<string,string> const & dir1,
|
|
|
|
pair<string,string> const & dir2)
|
|
|
|
{
|
2002-10-21 17:38:09 +00:00
|
|
|
string lastPath(".");
|
2002-01-16 22:17:38 +00:00
|
|
|
if (!filename.empty())
|
|
|
|
lastPath = OnlyPath(filename);
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
FileDialog fileDlg(lv, title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
|
|
|
|
|
|
|
|
FileDialog::Result result;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
while (true) {
|
2002-12-01 22:59:25 +00:00
|
|
|
if (save)
|
2002-11-17 08:32:09 +00:00
|
|
|
result = fileDlg.save(lastPath, pattern,
|
|
|
|
OnlyFilename(filename));
|
|
|
|
else
|
|
|
|
result = fileDlg.open(lastPath, pattern,
|
|
|
|
OnlyFilename(filename));
|
2001-03-30 09:51:46 +00:00
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
if (result.second.empty())
|
2001-03-30 09:51:46 +00:00
|
|
|
return result.second;
|
|
|
|
|
|
|
|
lastPath = OnlyPath(result.second);
|
|
|
|
|
|
|
|
if (result.second.find_first_of("#~$% ") == string::npos)
|
2002-03-21 21:21:28 +00:00
|
|
|
break;
|
|
|
|
|
2001-11-26 10:19:58 +00:00
|
|
|
Alert::alert(_("Filename can't contain any "
|
2001-03-30 09:51:46 +00:00
|
|
|
"of these characters:"),
|
|
|
|
_("space, '#', '~', '$' or '%'."));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-14 23:31:23 +00:00
|
|
|
string const browseRelFile(LyXView * lv, string const & filename,
|
|
|
|
string const & refpath,
|
|
|
|
string const & title,
|
2002-03-21 21:21:28 +00:00
|
|
|
string const & pattern,
|
2002-12-01 22:59:25 +00:00
|
|
|
bool save,
|
2002-01-14 23:31:23 +00:00
|
|
|
pair<string,string> const & dir1,
|
|
|
|
pair<string,string> const & dir2)
|
|
|
|
{
|
|
|
|
string const fname = MakeAbsPath(filename, refpath);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-11-17 08:32:09 +00:00
|
|
|
string const outname = browseFile(lv, fname, title, pattern, save,
|
2002-01-19 17:05:24 +00:00
|
|
|
dir1, dir2);
|
2002-01-14 23:31:23 +00:00
|
|
|
string const reloutname = MakeRelPath(outname, refpath);
|
2002-02-16 15:59:55 +00:00
|
|
|
if (prefixIs(reloutname, "../"))
|
2002-01-14 23:31:23 +00:00
|
|
|
return outname;
|
|
|
|
else
|
|
|
|
return reloutname;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-15 10:28:31 +00:00
|
|
|
// sorry this is just a temporary hack we should include vspace.h! (Jug)
|
|
|
|
extern const char * stringFromUnit(int);
|
|
|
|
|
|
|
|
vector<string> const getLatexUnits()
|
|
|
|
{
|
|
|
|
vector<string> units;
|
2002-10-21 17:38:09 +00:00
|
|
|
char const * str;
|
|
|
|
for (int i = 0; (str = stringFromUnit(i)); ++i)
|
2001-10-15 10:28:31 +00:00
|
|
|
units.push_back(str);
|
|
|
|
|
|
|
|
return units;
|
|
|
|
}
|