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
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-03-21 13:27:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2003-09-05 15:31:19 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
#include "helper_funcs.h"
|
|
|
|
|
2003-09-05 15:31:19 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
|
|
|
|
#include "frontends/Alert.h"
|
2001-03-30 09:51:46 +00:00
|
|
|
#include "frontends/FileDialog.h"
|
2003-09-05 15:31:19 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
#include "support/filetools.h" // OnlyPath, OnlyFilename
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::MakeAbsPath;
|
|
|
|
using lyx::support::MakeRelPath;
|
|
|
|
using lyx::support::OnlyFilename;
|
|
|
|
using lyx::support::OnlyPath;
|
|
|
|
using lyx::support::prefixIs;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
using std::pair;
|
2001-03-21 13:27:03 +00:00
|
|
|
using std::vector;
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2001-03-30 09:51:46 +00:00
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2003-02-21 12:22:25 +00:00
|
|
|
string const browseFile(string const & filename,
|
2001-03-30 09:51:46 +00:00
|
|
|
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
|
|
|
|
2003-02-21 12:22:25 +00:00
|
|
|
FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2003-03-29 10:55:48 +00:00
|
|
|
Alert::error(_("Invalid filename"),
|
|
|
|
_("Filename can't contain any "
|
|
|
|
"of these characters:\n"
|
|
|
|
"space, '#', '~', '$' or '%'."));
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-21 12:22:25 +00:00
|
|
|
string const browseRelFile(string const & filename,
|
2002-01-14 23:31:23 +00:00
|
|
|
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
|
|
|
|
2003-02-21 12:22:25 +00:00
|
|
|
string const outname = browseFile(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-21 12:22:25 +00:00
|
|
|
string const browseDir(string const & pathname,
|
2003-01-14 21:51:34 +00:00
|
|
|
string const & title,
|
|
|
|
pair<string,string> const & dir1,
|
|
|
|
pair<string,string> const & dir2)
|
|
|
|
{
|
|
|
|
string lastPath(".");
|
|
|
|
if (!pathname.empty())
|
|
|
|
lastPath = OnlyPath(pathname);
|
|
|
|
|
2003-02-21 12:22:25 +00:00
|
|
|
FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
|
2003-01-14 21:51:34 +00:00
|
|
|
|
|
|
|
FileDialog::Result result;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
result = fileDlg.opendir(lastPath,
|
|
|
|
OnlyFilename(pathname));
|
|
|
|
|
|
|
|
if (result.second.empty())
|
|
|
|
return result.second;
|
|
|
|
|
|
|
|
lastPath = OnlyPath(result.second);
|
|
|
|
|
|
|
|
if (result.second.find_first_of("#~$% ") == string::npos)
|
|
|
|
break;
|
|
|
|
|
2003-03-29 10:55:48 +00:00
|
|
|
Alert::error(_("Invalid filename"),
|
|
|
|
_("Filename can't contain any "
|
|
|
|
"of these characters:\n"
|
|
|
|
"space, '#', '~', '$' or '%'."));
|
2003-01-14 21:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|