]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCommandParams.cpp
Fix mis-nomer
[lyx.git] / src / insets / InsetCommandParams.cpp
index af04f83f0ced77eb559aba760543790f1a9f8bc0..931e1bb09376111ee656618b3956beffb678d170 100644 (file)
@@ -12,6 +12,8 @@
 
 #include <config.h>
 #include <algorithm>
+#include <functional>
+
 
 #include "InsetCommandParams.h"
 
@@ -28,6 +30,7 @@
 #include "InsetRef.h"
 #include "InsetTOC.h"
 
+#include "Buffer.h"
 #include "Encoding.h"
 #include "Lexer.h"
 #include "OutputParams.h"
@@ -275,6 +278,12 @@ void InsetCommandParams::setCmdName(string const & name)
 
 
 void InsetCommandParams::read(Lexer & lex)
+{
+       Read(lex, 0);
+}
+
+
+void InsetCommandParams::Read(Lexer & lex, Buffer const * buffer)
 {
        lex.setContext("InsetCommandParams::read");
        lex >> insetName(insetCode_).c_str();
@@ -301,7 +310,25 @@ void InsetCommandParams::read(Lexer & lex)
                }
                if (info_.hasParam(token)) {
                        lex.next(true);
-                       params_[token] = lex.getDocString();
+                       docstring data = lex.getDocString();
+                       if (buffer && token == "filename") {
+                               data = from_utf8(buffer->includedFilePath(to_utf8(data)));
+                       } else if (buffer && token == "bibfiles") {
+                               int i = 0;
+                               docstring newdata;
+                               docstring bib = support::token(data, ',', i);
+                               while (!bib.empty()) {
+                                       bib = from_utf8(buffer->includedFilePath(to_utf8(bib), "bib"));
+                                       if (!newdata.empty())
+                                               newdata.append(1, ',');
+                                       newdata.append(bib);
+                                       bib = support::token(data, ',', ++i);
+                               }
+                               data = newdata;
+                       } else if (buffer && token == "options") {
+                               data = from_utf8(buffer->includedFilePath(to_utf8(data), "bst"));
+                       }
+                       params_[token] = data;
                } else {
                        lex.printError("Unknown parameter name `$$Token' for command " + cmdName_);
                        throw ExceptionMessage(WarningException,
@@ -320,6 +347,12 @@ void InsetCommandParams::read(Lexer & lex)
 
 
 void InsetCommandParams::write(ostream & os) const
+{
+       Write(os, 0);
+}
+
+
+void InsetCommandParams::Write(ostream & os, Buffer const * buffer) const
 {
        os << "CommandInset " << insetType() << '\n';
        os << "LatexCommand " << cmdName_ << '\n';
@@ -328,12 +361,29 @@ void InsetCommandParams::write(ostream & os) const
        ParamInfo::const_iterator it  = info_.begin();
        ParamInfo::const_iterator end = info_.end();
        for (; it != end; ++it) {
-               std::string const & name = it->name();
-               docstring const & data = (*this)[name];
+               string const & name = it->name();
+               string data = to_utf8((*this)[name]);
                if (!data.empty()) {
-                       // FIXME UNICODE
+                       // Adjust path of files if document was moved
+                       if (buffer && name == "filename") {
+                               data = buffer->includedFilePath(data);
+                       } else if (buffer && name == "bibfiles") {
+                               int i = 0;
+                               string newdata;
+                               string bib = token(data, ',', i);
+                               while (!bib.empty()) {
+                                       bib = buffer->includedFilePath(bib, "bib");
+                                       if (!newdata.empty())
+                                               newdata.append(1, ',');
+                                       newdata.append(bib);
+                                       bib = token(data, ',', ++i);
+                               }
+                               data = newdata;
+                       } else if (buffer && name == "options") {
+                               data = buffer->includedFilePath(data, "bst");
+                       }
                        os << name << ' '
-                          << Lexer::quoteString(to_utf8(data))
+                          << Lexer::quoteString(data)
                           << '\n';
                }
        }