2001-03-21 13:27:03 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 2001 The LyX Team.
|
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* \file helper_funcs.C
|
|
|
|
* \author Angus Leeming <a.leeming@ic.ac.uk>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
|
|
|
|
string const getStringFromVector(vector<string> const & vec,
|
|
|
|
string const & delim)
|
|
|
|
{
|
|
|
|
string str;
|
2001-04-09 10:47:20 +00:00
|
|
|
int i = 0;
|
|
|
|
for (vector<string>::const_iterator it = vec.begin();
|
|
|
|
it != vec.end(); ++it) {
|
2001-08-01 15:22:01 +00:00
|
|
|
string item = strip(frontStrip(*it));
|
|
|
|
if (item.empty()) continue;
|
2001-04-09 10:47:20 +00:00
|
|
|
|
|
|
|
if (i++ > 0) str += delim;
|
2001-08-01 15:22:01 +00:00
|
|
|
str += item;
|
2001-03-21 13:27:03 +00:00
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<string> const getVectorFromString(string const & str,
|
|
|
|
string const & delim)
|
|
|
|
{
|
|
|
|
vector<string> vec;
|
2001-07-19 14:12:37 +00:00
|
|
|
if (str.empty())
|
|
|
|
return vec;
|
|
|
|
|
2001-08-01 15:22:01 +00:00
|
|
|
string keys(strip(str));
|
2001-03-21 13:27:03 +00:00
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
string::size_type const idx = keys.find(delim);
|
2001-06-02 14:53:35 +00:00
|
|
|
if (idx == string::npos) {
|
2001-08-07 16:23:52 +00:00
|
|
|
vec.push_back(frontStrip(keys));
|
2001-06-02 14:53:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-04-09 10:47:20 +00:00
|
|
|
|
2001-08-01 15:22:01 +00:00
|
|
|
string const key = strip(frontStrip(keys.substr(0, idx)));
|
2001-04-09 10:47:20 +00:00
|
|
|
if (!key.empty())
|
|
|
|
vec.push_back(key);
|
2001-03-21 13:27:03 +00:00
|
|
|
|
|
|
|
string::size_type const start = idx + delim.size();
|
|
|
|
keys = keys.substr(start);
|
|
|
|
}
|
|
|
|
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
string const browseFile(LyXView * lv, string const & filename,
|
|
|
|
string const & title,
|
|
|
|
string const & pattern,
|
|
|
|
pair<string,string> const & dir1,
|
|
|
|
pair<string,string> const & dir2)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
result = fileDlg.Select(lastPath, pattern, OnlyFilename(filename));
|
|
|
|
|
|
|
|
if (result.second.empty())
|
|
|
|
return result.second;
|
|
|
|
|
|
|
|
lastPath = OnlyPath(result.second);
|
|
|
|
|
|
|
|
if (result.second.find_first_of("#~$% ") == string::npos)
|
|
|
|
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,
|
|
|
|
string const & pattern,
|
|
|
|
pair<string,string> const & dir1,
|
|
|
|
pair<string,string> const & dir2)
|
|
|
|
{
|
|
|
|
string const fname = MakeAbsPath(filename, refpath);
|
|
|
|
|
2002-01-19 17:05:24 +00:00
|
|
|
string const outname = browseFile(lv, fname, title, pattern,
|
|
|
|
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;
|
|
|
|
const char * str;
|
|
|
|
for(int i=0; (str = stringFromUnit(i)); ++i)
|
|
|
|
units.push_back(str);
|
|
|
|
|
|
|
|
return units;
|
|
|
|
}
|