inset.setAutoBreakRows(true);
lyxvc.setBuffer(&parent);
temppath = createBufferTmpDir();
- params.filepath = onlyPath(file.absFilename());
+
// FIXME: And now do something if temppath == string(), because we
// assume from now on that temppath points to a valid temp dir.
// See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg67406.html
void Buffer::setFileName(string const & newfile)
{
pimpl_->filename = makeAbsPath(newfile);
- params().filepath = onlyPath(pimpl_->filename.absFilename());
setReadonly(pimpl_->filename.isReadOnly());
updateTitles();
}
LYXERR(Debug::PARSER, "Handling document header token: `"
<< token << '\'');
- string unknown = params().readToken(lex, token);
+ string unknown = params().readToken(lex, token, pimpl_->filename.onlyPath());
if (!unknown.empty()) {
if (unknown[0] != '\\' && token == "\\textclass") {
Alert::warning(_("Unknown document class"),
backupName = FileName(absFileName() + '~');
if (!lyxrc.backupdir_path.empty()) {
string const mangledName =
- subst(subst(os::internal_path(
- backupName.absFilename()), '/', '!'), ':', '!');
+ subst(subst(backupName.absFilename(), '/', '!'), ':', '!');
backupName = FileName(addName(lyxrc.backupdir_path,
mangledName));
}
}
-string const & Buffer::filePath() const
+string Buffer::filePath() const
{
- return params().filepath;
+ return pimpl_->filename.onlyPath().absFilename();
}
/// Returns the the path where the buffer lives.
/// It is always an absolute path.
- std::string const & filePath() const;
+ std::string filePath() const;
/** A transformed version of the file name, adequate for LaTeX.
\param no_path optional if \c true then the path is stripped.
#include "support/convert.h"
#include "support/docstream.h"
+#include "support/FileName.h"
#include "support/filetools.h"
#include "support/Translator.h"
#include "support/lstrings.h"
}
-string const BufferParams::readToken(Lexer & lex, string const & token)
+string const BufferParams::readToken(Lexer & lex, string const & token,
+ FileName const & filepath)
{
if (token == "\\textclass") {
lex.next();
string const classname = lex.getString();
// if there exists a local layout file, ignore the system one
// NOTE: in this case, the textclass (.cls file) is assumed to be available.
- pair<bool, lyx::textclass_type> pp = textclasslist.addTextClass(classname, filepath);
+ pair<bool, lyx::textclass_type> pp = textclasslist.addTextClass(
+ classname, filepath.absFilename());
if (pp.first)
setBaseClass(pp.second);
else {
namespace lyx {
+namespace support {
+class FileName;
+}
+
class AuthorList;
class BranchList;
class Bullet;
docstring const B_(std::string const & l10n) const;
/// read a header token, if unrecognised, return it or an unknown class name
- std::string const readToken(Lexer & lex, std::string const & token);
+ std::string const readToken(Lexer & lex,
+ std::string const & token, ///< token to read.
+ support::FileName const & filepath); ///< where to look for local layout file.
///
void writeFile(std::ostream &) const;
std::string const & sf, std::string const & tt,
bool const & sc, bool const & osf,
int const & sfscale, int const & ttscale) const;
- /// path of the current buffer
- std::string filepath;
+
/// get the appropriate cite engine (natbib handling)
biblio::CiteEngine getEngine() const;
void GuiExternal::applyView()
{
- params_.filename.set(internal_path(fromqstr(fileED->text())),
- bufferFilepath());
+ params_.filename.set(fromqstr(fileED->text()), bufferFilepath());
params_.settemplate(getTemplate(externalCO->currentIndex()).lyxName);
{
InsetGraphicsParams & igp = params_;
- igp.filename.set(internal_path(fromqstr(filename->text())),
- bufferFilepath());
+ igp.filename.set(fromqstr(filename->text()), bufferFilepath());
igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
// the bb section
{
}
+
FileName::FileName(string const & abs_filename)
: d(abs_filename.empty() ? new Private : new Private(abs_filename))
{
-#if defined(_WIN32)
- BOOST_ASSERT(!contains(abs_filename, '\\'));
-#endif
}
{
d->fi.setFile(toqstr(name));
BOOST_ASSERT(d->fi.isAbsolute());
-#if defined(_WIN32)
- BOOST_ASSERT(!contains(name, '\\'));
-#endif
}
}
+void FileName::changeExtension(std::string const & extension)
+{
+ // FIXME: use Qt native methods...
+ string const oldname = absFilename();
+ string::size_type const last_slash = oldname.rfind('/');
+ string::size_type last_dot = oldname.rfind('.');
+ if (last_dot < last_slash && last_slash != string::npos)
+ last_dot = string::npos;
+
+ string ext;
+ // Make sure the extension starts with a dot
+ if (!extension.empty() && extension[0] != '.')
+ ext= '.' + extension;
+ else
+ ext = extension;
+
+ set(oldname.substr(0, last_dot) + ext);
+}
+
+
string FileName::guessFormatFromContents() const
{
// the different filetypes and what they contain in one of the first lines
// Now the real work
string mname = os::internal_path(name);
// Remove the extension.
- mname = changeExtension(name, string());
+ mname = support::changeExtension(name, string());
// The mangled name must be a valid LaTeX name.
// The list of characters to keep is probably over-restrictive,
// but it is not really a problem.
while ((pos = mname.find_first_not_of(keep, pos)) != string::npos)
mname[pos++] = '_';
// Add the extension back on
- mname = changeExtension(mname, getExtension(name));
+ mname = support::changeExtension(mname, getExtension(name));
// Prepend a counter to the filename. This is necessary to make
// the mangled name unique.
* \p name must have an absolute path.
*/
+ /// Change extension.
+ /**
+ * If oldname does not have an extension, it is appended.
+ * If the extension is empty, any extension is removed from the name.
+ */
+ void changeExtension(std::string const & extension);
+
/** Guess the file format name (as in Format::name()) from contents.
Normally you don't want to use this directly, but rather
Formats::getFormatFromFile().
// Typical example: C:/TEMP/.
char path[MAX_PATH];
GetTempPath(MAX_PATH, path);
- return FileName(os::internal_path(to_utf8(from_local8bit(path))));
+ return FileName(to_utf8(from_local8bit(path)));
#else // Posix-like.
return FileName("/tmp");
#endif
}
// returns absolute path
- return FileName(os::internal_path(tempBase));
+ return FileName(tempBase);
}
LYXERR(Debug::LATEX, "kpse status = " << c.first << '\n'
<< "kpse result = `" << rtrim(c.second, "\n\r") << '\'');
if (c.first != -1)
- return FileName(os::internal_path(rtrim(to_utf8(from_filesystem8bit(c.second)),
- "\n\r")));
+ return FileName(rtrim(to_utf8(from_filesystem8bit(c.second)), "\n\r"));
else
return FileName();
}