#include "buffer.h"
#include "author.h"
+#include "BranchList.h"
#include "buffer_funcs.h"
#include "bufferlist.h"
#include "bufferparams.h"
#include <boost/bind.hpp>
#include <boost/filesystem/operations.hpp>
-#include <utime.h>
+#if defined (HAVE_UTIME_H)
+# include <utime.h>
+#elif defined (HAVE_SYS_UTIME_H)
+# include <sys/utime.h>
+#endif
#include <iomanip>
#include <stack>
using lyx::support::getFormatFromContents;
using lyx::support::IsDirWriteable;
using lyx::support::LibFileSearch;
+using lyx::support::latex_path;
using lyx::support::ltrim;
using lyx::support::MakeAbsPath;
using lyx::support::MakeDisplayPath;
namespace {
-int const LYX_FORMAT = 240;
+int const LYX_FORMAT = 241;
} // namespace anon
filename(file), filepath(OnlyPath(file)), file_fully_loaded(false),
inset(params)
{
+ inset.setAutoBreakRows(true);
lyxvc.buffer(&parent);
temppath = createBufferTmpDir();
// FIXME: And now do something if temppath == string(), because we
int line = -1;
int begin_header_line = -1;
+ // Initialize parameters that may be/go lacking in header:
+ params().branchlist().clear();
+ params().options.erase();
+ params().float_placement.erase();
+ params().paperwidth.erase();
+ params().paperheight.erase();
+ params().leftmargin.erase();
+ params().rightmargin.erase();
+ params().topmargin.erase();
+ params().bottommargin.erase();
+ params().headheight.erase();
+ params().headsep.erase();
+ params().footskip.erase();
+
while (lex.isOK()) {
lex.next();
string const token = lex.getString();
// needed to insert the selection
void Buffer::insertStringAsLines(ParagraphList & pars,
- pit_type & par, pos_type & pos,
+ pit_type & pit, pos_type & pos,
LyXFont const & fn, string const & str, bool autobreakrows)
{
- LyXLayout_ptr const & layout = pars[par].layout();
-
LyXFont font = fn;
- pars[par].checkInsertChar(font);
+ pars[pit].checkInsertChar(font);
// insert the string, don't insert doublespace
bool space_inserted = true;
for (string::const_iterator cit = str.begin();
cit != str.end(); ++cit) {
+ Paragraph & par = pars[pit];
if (*cit == '\n') {
- if (autobreakrows && (!pars[par].empty() || pars[par].allowEmpty())) {
- breakParagraph(params(), paragraphs(), par, pos,
- layout->isEnvironment());
- ++par;
+ if (autobreakrows && (!par.empty() || par.allowEmpty())) {
+ breakParagraph(params(), pars, pit, pos,
+ par.layout()->isEnvironment());
+ ++pit;
pos = 0;
space_inserted = true;
} else {
}
// do not insert consecutive spaces if !free_spacing
} else if ((*cit == ' ' || *cit == '\t') &&
- space_inserted && !pars[par].isFreeSpacing()) {
+ space_inserted && !par.isFreeSpacing()) {
continue;
} else if (*cit == '\t') {
- if (!pars[par].isFreeSpacing()) {
+ if (!par.isFreeSpacing()) {
// tabs are like spaces here
- pars[par].insertChar(pos, ' ', font);
+ par.insertChar(pos, ' ', font);
++pos;
space_inserted = true;
} else {
const pos_type n = 8 - pos % 8;
for (pos_type i = 0; i < n; ++i) {
- pars[par].insertChar(pos, ' ', font);
+ par.insertChar(pos, ' ', font);
++pos;
}
space_inserted = true;
continue;
} else {
// just insert the character
- pars[par].insertChar(pos, *cit, font);
+ par.insertChar(pos, *cit, font);
++pos;
space_inserted = (*cit == ' ');
}
filename));
return false;
}
- string command =
- "python " + LibFileSearch("lyx2lyx", "lyx2lyx");
- if (command.empty()) {
+ string const lyx2lyx = LibFileSearch("lyx2lyx", "lyx2lyx");
+ if (lyx2lyx.empty()) {
Alert::error(_("Conversion script not found"),
bformat(_("%1$s is from an earlier"
" version of LyX, but the"
filename));
return false;
}
- command += " -t"
- + convert<string>(LYX_FORMAT)
- + " -o " + tmpfile + ' '
- + QuoteName(filename);
+ ostringstream command;
+ command << "python " << QuoteName(lyx2lyx)
+ << " -t " << convert<string>(LYX_FORMAT)
+ << " -o " << QuoteName(tmpfile) << ' '
+ << QuoteName(filename);
+ string const command_str = command.str();
+
lyxerr[Debug::INFO] << "Running '"
- << command << '\''
+ << command_str << '\''
<< endl;
- cmd_ret const ret = RunCommand(command);
+
+ cmd_ret const ret = RunCommand(command_str);
if (ret.first != 0) {
Alert::error(_("Conversion script failed"),
bformat(_("%1$s is from an earlier version"
// good enough. (Lgb)
// But to use this we need fs::copy_file to actually do a copy,
// even when the target file exists. (Lgb)
- if (fs::exists(fileName())) {
+ if (fs::exists(fileName()) && fs::is_writable(fs::path(fileName()).branch_path())) {
//try {
fs::copy_file(fileName(), s, false);
//}
texrow().newline();
}
if (!original_path.empty()) {
- string inputpath = os::external_path(original_path);
- subst(inputpath, "~", "\\string~");
+ string const inputpath = latex_path(original_path);
os << "\\makeatletter\n"
<< "\\def\\input@path{{"
<< inputpath << "/}}\n"