]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
* InsetMathNest.C (handleFont): avoid crash on undo when
[lyx.git] / src / buffer.C
index 9dfff5ad844a692694130b0810bf9bb259f99428..f4e64964cae3d84022be6a811d6c7d58fee500cf 100644 (file)
@@ -102,7 +102,6 @@ using support::createBufferTmpDir;
 using support::destroyDir;
 using support::FileName;
 using support::getFormatFromContents;
-using support::isDirWriteable;
 using support::libFileSearch;
 using support::latex_path;
 using support::ltrim;
@@ -142,7 +141,7 @@ using std::string;
 
 namespace {
 
-int const LYX_FORMAT = 255;
+int const LYX_FORMAT = 256;
 
 } // namespace anon
 
@@ -389,9 +388,8 @@ void Buffer::setReadonly(bool const flag)
 
 void Buffer::setFileName(string const & newfile)
 {
-       string const filename = makeAbsPath(newfile);
-       pimpl_->filename = FileName(filename);
-       params().filepath = onlyPath(filename);
+       pimpl_->filename = makeAbsPath(newfile);
+       params().filepath = onlyPath(pimpl_->filename.absFilename());
        setReadonly(fs::is_readonly(pimpl_->filename.toFilesystemEncoding()));
        updateTitles();
 }
@@ -569,11 +567,10 @@ void Buffer::insertStringAsLines(ParagraphList & pars,
 }
 
 
-bool Buffer::readFile(string const & filename)
+bool Buffer::readFile(FileName const & filename)
 {
        // Check if the file is compressed.
-       FileName const name(makeAbsPath(filename));
-       string const format = getFormatFromContents(name);
+       string const format = getFormatFromContents(filename);
        if (format == "gzip" || format == "zip" || format == "compress") {
                params().compressed = true;
        }
@@ -581,7 +578,7 @@ bool Buffer::readFile(string const & filename)
        // remove dummy empty par
        paragraphs().clear();
        LyXLex lex(0, 0);
-       lex.setFile(name);
+       lex.setFile(filename);
        if (!readFile(lex, filename))
                return false;
 
@@ -606,13 +603,13 @@ void Buffer::fully_loaded(bool const value)
 }
 
 
-bool Buffer::readFile(LyXLex & lex, string const & filename)
+bool Buffer::readFile(LyXLex & lex, FileName const & filename)
 {
        BOOST_ASSERT(!filename.empty());
 
        if (!lex.isOK()) {
                Alert::error(_("Document could not be read"),
-                            bformat(_("%1$s could not be read."), from_utf8(filename)));
+                            bformat(_("%1$s could not be read."), from_utf8(filename.absFilename())));
                return false;
        }
 
@@ -621,7 +618,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
 
        if (!lex.isOK()) {
                Alert::error(_("Document could not be read"),
-                            bformat(_("%1$s could not be read."), from_utf8(filename)));
+                            bformat(_("%1$s could not be read."), from_utf8(filename.absFilename())));
                return false;
        }
 
@@ -631,7 +628,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
 
                Alert::error(_("Document format failure"),
                             bformat(_("%1$s is not a LyX document."),
-                                      from_utf8(filename)));
+                                      from_utf8(filename.absFilename())));
                return false;
        }
 
@@ -647,14 +644,14 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
        //lyxerr << "format: " << file_format << endl;
 
        if (file_format != LYX_FORMAT) {
-               string const tmpfile = tempName();
+               FileName const tmpfile(tempName());
                if (tmpfile.empty()) {
                        Alert::error(_("Conversion failed"),
                                     bformat(_("%1$s is from an earlier"
                                              " version of LyX, but a temporary"
                                              " file for converting it could"
                                                            " not be created."),
-                                             from_utf8(filename)));
+                                             from_utf8(filename.absFilename())));
                        return false;
                }
                FileName const lyx2lyx = libFileSearch("lyx2lyx", "lyx2lyx");
@@ -664,14 +661,15 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
                                               " version of LyX, but the"
                                               " conversion script lyx2lyx"
                                                            " could not be found."),
-                                              from_utf8(filename)));
+                                              from_utf8(filename.absFilename())));
                        return false;
                }
                ostringstream command;
-               command << os::python() << ' ' << quoteName(lyx2lyx.toFilesystemEncoding())
-                       << " -t " << convert<string>(LYX_FORMAT)
-                       << " -o " << quoteName(tmpfile) << ' '
-                       << quoteName(filename);
+               command << os::python()
+                       << ' ' << quoteName(lyx2lyx.toFilesystemEncoding())
+                       << " -t " << convert<string>(LYX_FORMAT)
+                       << " -o " << quoteName(tmpfile.toFilesystemEncoding())
+                       << ' ' << quoteName(filename.toFilesystemEncoding());
                string const command_str = command.str();
 
                lyxerr[Debug::INFO] << "Running '"
@@ -684,7 +682,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
                                     bformat(_("%1$s is from an earlier version"
                                              " of LyX, but the lyx2lyx script"
                                                            " failed to convert it."),
-                                             from_utf8(filename)));
+                                             from_utf8(filename.absFilename())));
                        return false;
                } else {
                        bool const ret = readFile(tmpfile);
@@ -698,7 +696,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
                Alert::error(_("Document format failure"),
                             bformat(_("%1$s ended unexpectedly, which means"
                                                    " that it is probably corrupted."),
-                                      from_utf8(filename)));
+                                      from_utf8(filename.absFilename())));
        }
 
        //lyxerr << "removing " << MacroTable::localMacros().size()
@@ -833,20 +831,7 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
                           OutputParams const & runparams,
                           bool output_preamble, bool output_body)
 {
-       string encoding;
-       if (params().inputenc == "auto")
-               encoding = params().language->encoding()->iconvName();
-       else {
-               Encoding const * enc = encodings.getFromLaTeXName(params().inputenc);
-               if (enc)
-                       encoding = enc->iconvName();
-               else {
-                       lyxerr << "Unknown inputenc value `"
-                              << params().inputenc
-                              << "'. Using `auto' instead." << endl;
-                       encoding = params().language->encoding()->iconvName();
-               }
-       }
+       string const encoding = params().encoding().iconvName();
        lyxerr[Debug::LATEX] << "makeLaTeXFile encoding: "
                << encoding << "..." << endl;
 
@@ -1223,7 +1208,7 @@ void Buffer::getLabelList(vector<docstring> & list) const
 
 
 // This is also a buffer property (ale)
-void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys)
+void Buffer::fillWithBibKeys(vector<pair<string, docstring> > & keys)
        const
 {
        /// if this is a child document and the parent is already loaded
@@ -1247,11 +1232,12 @@ void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys)
                } else if (it->lyxCode() == InsetBase::BIBITEM_CODE) {
                        InsetBibitem const & inset =
                                dynamic_cast<InsetBibitem const &>(*it);
-                       string const key = inset.getContents();
-                       string const opt = inset.getOptions();
-                       string const ref; // = pit->asString(this, false);
-                       string const info = opt + "TheBibliographyRef" + ref;
-                       keys.push_back(pair<string, string>(key, info));
+                       // FIXME UNICODE
+                       string const key = to_utf8(inset.getParam("key"));
+                       docstring const label = inset.getParam("label");
+                       docstring const ref; // = pit->asString(this, false);
+                       docstring const info = label + "TheBibliographyRef" + ref;
+                       keys.push_back(pair<string, docstring>(key, info));
                }
        }
 }
@@ -1630,10 +1616,10 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to,
        vector<docstring> labels;
 
        if (code == InsetBase::CITE_CODE) {
-               vector<pair<string, string> > keys;
+               vector<pair<string, docstring> > keys;
                fillWithBibKeys(keys);
-               vector<pair<string, string> >::const_iterator bit  = keys.begin();
-               vector<pair<string, string> >::const_iterator bend = keys.end();
+               vector<pair<string, docstring> >::const_iterator bit  = keys.begin();
+               vector<pair<string, docstring> >::const_iterator bend = keys.end();
 
                for (; bit != bend; ++bit)
                        // FIXME UNICODE
@@ -1694,7 +1680,7 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
 ErrorList const & Buffer::errorList(string const & type) const
 {
        static ErrorList const emptyErrorList;
-       std::map<std::string, ErrorList>::const_iterator I = errorLists_.find(type);
+       std::map<string, ErrorList>::const_iterator I = errorLists_.find(type);
        if (I == errorLists_.end())
                return emptyErrorList;