]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
Second Locale patch.
[lyx.git] / src / buffer.C
index 9287b877badee5cd4171f149eb58dac8a5534a45..6200281c9dc7e6bec412e5ce96eeda065a6f4acd 100644 (file)
@@ -13,6 +13,7 @@
 #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>
@@ -97,6 +102,7 @@ using lyx::support::destroyDir;
 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;
@@ -137,7 +143,7 @@ extern BufferList bufferlist;
 
 namespace {
 
-int const LYX_FORMAT = 241;
+int const LYX_FORMAT = 243;
 
 } // namespace anon
 
@@ -207,8 +213,8 @@ Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
 }
 
 
-Buffer::Buffer(string const & file, bool ronly)
-       : pimpl_(new Impl(*this, file, ronly))
+Buffer::Buffer(string const & file, bool readonly)
+       : pimpl_(new Impl(*this, file, readonly))
 {
        lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
 }
@@ -395,6 +401,20 @@ int Buffer::readHeader(LyXLex & lex)
        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();
@@ -478,7 +498,6 @@ void Buffer::insertStringAsLines(ParagraphList & pars,
 {
        LyXFont font = fn;
 
-       pars[pit].checkInsertChar(font);
        // insert the string, don't insert doublespace
        bool space_inserted = true;
        for (string::const_iterator cit = str.begin();
@@ -618,9 +637,8 @@ bool Buffer::readFile(LyXLex & lex, string const & filename, pit_type const pit)
                                              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"
@@ -629,14 +647,18 @@ bool Buffer::readFile(LyXLex & lex, string const & filename, pit_type const pit)
                                               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"
@@ -662,7 +684,6 @@ bool Buffer::readFile(LyXLex & lex, string const & filename, pit_type const pit)
        //lyxerr << "removing " << MacroTable::localMacros().size()
        //      << " temporary macro entries" << endl;
        //MacroTable::localMacros().clear();
-       params().setPaperStuff();
 
        pimpl_->file_fully_loaded = true;
        return true;
@@ -687,7 +708,7 @@ bool Buffer::save() const
                // 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);
                    //}
@@ -855,8 +876,7 @@ void Buffer::makeLaTeXFile(ostream & os,
                        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"