mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-09-20 06:49:56 +00:00
Convert makeRelPath to docstring (from Michael Gerz)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17586 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
64767ea78d
commit
0f83c2563b
@ -537,14 +537,16 @@ docstring const LaTeXFeatures::getLyXSGMLEntities() const
|
||||
docstring const LaTeXFeatures::getIncludedFiles(string const & fname) const
|
||||
{
|
||||
odocstringstream sgmlpreamble;
|
||||
string const basename = onlyPath(fname);
|
||||
// FIXME UNICODE
|
||||
docstring const basename(from_utf8(onlyPath(fname)));
|
||||
|
||||
FileMap::const_iterator end = IncludedFiles_.end();
|
||||
for (FileMap::const_iterator fi = IncludedFiles_.begin();
|
||||
fi != end; ++fi)
|
||||
// FIXME UNICODE
|
||||
sgmlpreamble << "\n<!ENTITY " << fi->first
|
||||
<< (isSGMLFilename(fi->second) ? " SYSTEM \"" : " \"")
|
||||
<< from_ascii(makeRelPath(fi->second, basename)) << "\">";
|
||||
<< makeRelPath(from_utf8(fi->second), basename) << "\">";
|
||||
|
||||
return sgmlpreamble.str();
|
||||
}
|
||||
|
@ -397,10 +397,13 @@ bool Converters::convert(Buffer const * buffer,
|
||||
runLaTeX(*buffer, latex_command_, runparams, errorList);
|
||||
}
|
||||
|
||||
// FIXME UNICODE
|
||||
string const infile2 = (conv.original_dir)
|
||||
? infile.absFilename() : makeRelPath(infile.absFilename(), path);
|
||||
? infile.absFilename() : to_utf8(makeRelPath(from_utf8(infile.absFilename()),
|
||||
from_utf8(path)));
|
||||
string const outfile2 = (conv.original_dir)
|
||||
? outfile.absFilename() : makeRelPath(outfile.absFilename(), path);
|
||||
? outfile.absFilename() : to_utf8(makeRelPath(from_utf8(outfile.absFilename()),
|
||||
from_utf8(path)));
|
||||
|
||||
string command = conv.command;
|
||||
command = subst(command, token_from, quoteName(infile2));
|
||||
|
@ -23,8 +23,6 @@
|
||||
#include "support/lstrings.h"
|
||||
#include "support/package.h"
|
||||
|
||||
using lyx::docstring;
|
||||
|
||||
using std::pair;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@ -32,7 +30,6 @@ using std::vector;
|
||||
namespace lyx {
|
||||
|
||||
using support::addName;
|
||||
using support::changeExtension;
|
||||
using support::FileFilterList;
|
||||
using support::getExtension;
|
||||
using support::libFileSearch;
|
||||
@ -42,6 +39,7 @@ using support::onlyFilename;
|
||||
using support::onlyPath;
|
||||
using support::package;
|
||||
using support::prefixIs;
|
||||
using support::removeExtension;
|
||||
|
||||
namespace frontend {
|
||||
|
||||
@ -55,7 +53,7 @@ docstring const browseFile(docstring const & filename,
|
||||
{
|
||||
docstring lastPath = from_ascii(".");
|
||||
if (!filename.empty())
|
||||
lastPath = lyx::from_utf8(onlyPath(lyx::to_utf8(filename)));
|
||||
lastPath = from_utf8(onlyPath(to_utf8(filename)));
|
||||
|
||||
FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
|
||||
|
||||
@ -63,10 +61,10 @@ docstring const browseFile(docstring const & filename,
|
||||
|
||||
if (save)
|
||||
result = fileDlg.save(lastPath, filters,
|
||||
lyx::from_utf8(onlyFilename(lyx::to_utf8(filename))));
|
||||
from_utf8(onlyFilename(to_utf8(filename))));
|
||||
else
|
||||
result = fileDlg.open(lastPath, filters,
|
||||
lyx::from_utf8(onlyFilename(lyx::to_utf8(filename))));
|
||||
from_utf8(onlyFilename(to_utf8(filename))));
|
||||
|
||||
return result.second;
|
||||
}
|
||||
@ -85,9 +83,8 @@ docstring const browseRelFile(docstring const & filename,
|
||||
|
||||
docstring const outname = browseFile(fname, title, filters, save,
|
||||
dir1, dir2);
|
||||
docstring const reloutname = lyx::from_utf8(
|
||||
makeRelPath(lyx::to_utf8(outname), lyx::to_utf8(refpath)));
|
||||
if (prefixIs(lyx::to_utf8(reloutname), "../"))
|
||||
docstring const reloutname = makeRelPath(outname, refpath);
|
||||
if (prefixIs(reloutname, from_ascii("../")))
|
||||
return outname;
|
||||
else
|
||||
return reloutname;
|
||||
@ -103,24 +100,24 @@ docstring const browseLibFile(docstring const & dir,
|
||||
{
|
||||
// FIXME UNICODE
|
||||
pair<docstring, docstring> const dir1(_("System files|#S#s"),
|
||||
lyx::from_utf8(addName(package().system_support(), lyx::to_utf8(dir))));
|
||||
from_utf8(addName(package().system_support(), to_utf8(dir))));
|
||||
|
||||
pair<docstring, docstring> const dir2(_("User files|#U#u"),
|
||||
lyx::from_utf8(addName(package().user_support(), lyx::to_utf8(dir))));
|
||||
from_utf8(addName(package().user_support(), to_utf8(dir))));
|
||||
|
||||
docstring const result = browseFile(lyx::from_utf8(
|
||||
docstring const result = browseFile(from_utf8(
|
||||
libFileSearch(to_utf8(dir), to_utf8(name), to_utf8(ext)).absFilename()),
|
||||
title, filters, false, dir1, dir2);
|
||||
|
||||
// remove the extension if it is the default one
|
||||
docstring noextresult;
|
||||
if (lyx::from_utf8(getExtension(lyx::to_utf8(result))) == ext)
|
||||
noextresult = lyx::from_utf8(changeExtension(lyx::to_utf8(result), string()));
|
||||
if (from_utf8(getExtension(to_utf8(result))) == ext)
|
||||
noextresult = from_utf8(removeExtension(to_utf8(result)));
|
||||
else
|
||||
noextresult = result;
|
||||
|
||||
// remove the directory, if it is the default one
|
||||
docstring const file = lyx::from_utf8(onlyFilename(lyx::to_utf8(noextresult)));
|
||||
docstring const file = from_utf8(onlyFilename(to_utf8(noextresult)));
|
||||
if (from_utf8(libFileSearch(to_utf8(dir), to_utf8(file), to_utf8(ext)).absFilename()) == result)
|
||||
return file;
|
||||
else
|
||||
@ -133,14 +130,14 @@ docstring const browseDir(docstring const & pathname,
|
||||
pair<docstring,docstring> const & dir1,
|
||||
pair<docstring,docstring> const & dir2)
|
||||
{
|
||||
docstring lastPath = lyx::from_ascii(".");
|
||||
docstring lastPath = from_ascii(".");
|
||||
if (!pathname.empty())
|
||||
lastPath = lyx::from_utf8(onlyPath(lyx::to_utf8(pathname)));
|
||||
lastPath = from_utf8(onlyPath(to_utf8(pathname)));
|
||||
|
||||
FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
|
||||
|
||||
FileDialog::Result const result =
|
||||
fileDlg.opendir(lastPath, lyx::from_utf8(onlyFilename(lyx::to_utf8(pathname))));
|
||||
fileDlg.opendir(lastPath, from_utf8(onlyFilename(to_utf8(pathname))));
|
||||
|
||||
return result.second;
|
||||
}
|
||||
@ -152,7 +149,7 @@ vector<docstring> const getLatexUnits()
|
||||
int i = 0;
|
||||
char const * str = stringFromUnit(i);
|
||||
for (; str != 0; ++i, str = stringFromUnit(i))
|
||||
units.push_back(lyx::from_ascii(str));
|
||||
units.push_back(from_ascii(str));
|
||||
|
||||
return units;
|
||||
}
|
||||
|
@ -106,12 +106,16 @@ string const doSubstitution(InsetExternalParams const & params,
|
||||
string const masterpath = external_in_tmpdir ?
|
||||
m_buffer->temppath() :
|
||||
m_buffer->filePath();
|
||||
// FIXME UNICODE
|
||||
string relToMasterPath = support::onlyPath(
|
||||
support::makeRelPath(absname, masterpath));
|
||||
to_utf8(support::makeRelPath(from_utf8(absname),
|
||||
from_utf8(masterpath))));
|
||||
if (relToMasterPath == "./")
|
||||
relToMasterPath.clear();
|
||||
// FIXME UNICODE
|
||||
string relToParentPath = support::onlyPath(
|
||||
support::makeRelPath(absname, parentpath));
|
||||
to_utf8(support::makeRelPath(from_utf8(absname),
|
||||
from_utf8(parentpath))));
|
||||
if (relToParentPath == "./")
|
||||
relToParentPath.clear();
|
||||
|
||||
|
@ -119,7 +119,9 @@ string normalize_name(Buffer const & buffer, OutputParams const & runparams,
|
||||
else if (!runparams.nice)
|
||||
return fname;
|
||||
else
|
||||
return makeRelPath(fname, buffer.getMasterBuffer()->filePath());
|
||||
// FIXME UNICODE
|
||||
return to_utf8(makeRelPath(from_utf8(fname),
|
||||
from_utf8(buffer.getMasterBuffer()->filePath())));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -383,8 +383,9 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
|
||||
// if incfile is relative, make it relative to the master
|
||||
// buffer directory.
|
||||
if (!absolutePath(incfile)) {
|
||||
incfile = makeRelPath(included_file.absFilename(),
|
||||
m_buffer->filePath());
|
||||
// FIXME UNICODE
|
||||
incfile = to_utf8(makeRelPath(from_utf8(included_file.absFilename()),
|
||||
from_utf8(m_buffer->filePath())));
|
||||
}
|
||||
|
||||
// write it to a file (so far the complete file)
|
||||
|
@ -143,13 +143,15 @@ void DocFileName::erase()
|
||||
|
||||
string const DocFileName::relFilename(string const & path) const
|
||||
{
|
||||
return makeRelPath(name_, path);
|
||||
// FIXME UNICODE
|
||||
return to_utf8(makeRelPath(from_utf8(name_), from_utf8(path)));
|
||||
}
|
||||
|
||||
|
||||
string const DocFileName::outputFilename(string const & path) const
|
||||
{
|
||||
return save_abs_path_ ? name_ : makeRelPath(name_, path);
|
||||
// FIXME UNICODE
|
||||
return save_abs_path_ ? name_ : to_utf8(makeRelPath(from_utf8(name_), from_utf8(path)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -669,18 +669,16 @@ string const replaceEnvironmentPath(string const & path)
|
||||
|
||||
|
||||
// Make relative path out of two absolute paths
|
||||
string const makeRelPath(string const & abspath, string const & basepath)
|
||||
docstring const makeRelPath(docstring const & abspath, docstring const & basepath)
|
||||
// Makes relative path out of absolute path. If it is deeper than basepath,
|
||||
// it's easy. If basepath and abspath share something (they are all deeper
|
||||
// than some directory), it'll be rendered using ..'s. If they are completely
|
||||
// different, then the absolute path will be used as relative path.
|
||||
{
|
||||
string::size_type const abslen = abspath.length();
|
||||
string::size_type const baselen = basepath.length();
|
||||
docstring::size_type const abslen = abspath.length();
|
||||
docstring::size_type const baselen = basepath.length();
|
||||
|
||||
// FIXME UNICODE
|
||||
docstring::size_type i =
|
||||
os::common_path(from_utf8(abspath), from_utf8(basepath));
|
||||
docstring::size_type i = os::common_path(abspath, basepath);
|
||||
|
||||
if (i == 0) {
|
||||
// actually no match - cannot make it relative
|
||||
@ -689,8 +687,8 @@ string const makeRelPath(string const & abspath, string const & basepath)
|
||||
|
||||
// Count how many dirs there are in basepath above match
|
||||
// and append as many '..''s into relpath
|
||||
string buf;
|
||||
string::size_type j = i;
|
||||
docstring buf;
|
||||
docstring::size_type j = i;
|
||||
while (j < baselen) {
|
||||
if (basepath[j] == '/') {
|
||||
if (j + 1 == baselen)
|
||||
|
@ -252,8 +252,8 @@ makeDisplayPath(std::string const & path, unsigned int threshold = 1000);
|
||||
different, then the absolute path will be used as relative path
|
||||
WARNING: the absolute path and base path must really be absolute paths!!!
|
||||
*/
|
||||
std::string const
|
||||
makeRelPath(std::string const & abspath, std::string const & basepath);
|
||||
docstring const
|
||||
makeRelPath(docstring const & abspath, docstring const & basepath);
|
||||
|
||||
/// Strip filename from path name
|
||||
std::string const onlyPath(std::string const & fname);
|
||||
|
@ -1024,8 +1024,8 @@ void fix_relative_filename(string & name)
|
||||
return;
|
||||
// FIXME UNICODE encoding of name may be wrong (makeAbsPath expects
|
||||
// utf8)
|
||||
name = makeRelPath(makeAbsPath(name, getMasterFilePath()).absFilename(),
|
||||
getParentFilePath());
|
||||
name = to_utf8(makeRelPath(from_utf8(makeAbsPath(name, getMasterFilePath()).absFilename()),
|
||||
from_utf8(getParentFilePath())));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user