]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetinclude.C
hopefully fix tex2lyx linking.
[lyx.git] / src / insets / insetinclude.C
index 468f56f676f5986ba78681a0ec448b42dc1b9fcf..f0954516f42f251904a07ab4b6908e53d75c2a90 100644 (file)
@@ -30,6 +30,7 @@
 #include "lyxlex.h"
 #include "metricsinfo.h"
 #include "outputparams.h"
+#include "TocBackend.h"
 
 #include "frontends/Alert.h"
 #include "frontends/Painter.h"
 #include <boost/bind.hpp>
 #include <boost/filesystem/operations.hpp>
 
-#include "support/std_ostream.h"
-
-#include <sstream>
-
 
 namespace lyx {
 
@@ -62,7 +59,7 @@ using support::bformat;
 using support::changeExtension;
 using support::contains;
 using support::copy;
-using support::FileName;
+using support::DocFileName;
 using support::getFileContents;
 using support::isFileReadable;
 using support::isLyXFilename;
@@ -88,10 +85,10 @@ namespace fs = boost::filesystem;
 
 namespace {
 
-string const uniqueID()
+docstring const uniqueID()
 {
        static unsigned int seed = 1000;
-       return "file" + convert<string>(++seed);
+       return "file" + convert<docstring>(++seed);
 }
 
 } // namespace anon
@@ -273,7 +270,27 @@ void InsetInclude::read(Buffer const &, LyXLex & lex)
 
 void InsetInclude::read(LyXLex & lex)
 {
-       params_.read(lex);
+       if (lex.isOK()) {
+               lex.next();
+               string const command = lex.getString();
+               params_.scanCommand(command);
+       }
+       string token;
+       while (lex.isOK()) {
+               lex.next();
+               token = lex.getString();
+               if (token == "\\end_inset")
+                       break;
+               if (token == "preview") {
+                       lex.next();
+                       params_.preview(lex.getBool());
+               } else
+                       lex.printError("Unknown parameter name `$$Token' for command " + params_.getCmdName());
+       }
+       if (token != "\\end_inset") {
+               lex.printError("Missing \\end_inset at this point. "
+                              "Read: `$$Token'");
+       }
 }
 
 
@@ -373,7 +390,7 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
 
        // write it to a file (so far the complete file)
        string const exportfile = changeExtension(incfile, ".tex");
-       string const mangled = FileName(changeExtension(included_file,
+       string const mangled = DocFileName(changeExtension(included_file,
                                                        ".tex")).mangledFilename();
        string const writefile = makeAbsPath(mangled, m_buffer->temppath());
 
@@ -507,7 +524,7 @@ int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
        if (loadIfNeeded(buffer, params_)) {
                Buffer * tmp = theBufferList().getBuffer(included_file);
 
-               string const mangled = FileName(writefile).mangledFilename();
+               string const mangled = DocFileName(writefile).mangledFilename();
                writefile = makeAbsPath(mangled,
                                        buffer.getMasterBuffer()->temppath());
                if (!runparams.nice)
@@ -525,13 +542,12 @@ int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
        runparams.exportdata->addExternalFile("docbook-xml", writefile,
                                              exportfile);
 
-        // FIXME UNICODE
        if (isVerbatim(params_)) {
                os << "<inlinegraphic fileref=\""
-                  << '&' << from_ascii(include_label) << ';'
+                  << '&' << include_label << ';'
                   << "\" format=\"linespecific\">";
        } else
-                os << '&' << from_ascii(include_label) << ';';
+                os << '&' << include_label << ';';
 
        return 0;
 }
@@ -552,7 +568,7 @@ void InsetInclude::validate(LaTeXFeatures & features) const
                writefile = included_file;
 
        if (!features.runparams().nice && !isVerbatim(params_)) {
-               incfile = FileName(writefile).mangledFilename();
+               incfile = DocFileName(writefile).mangledFilename();
                writefile = makeAbsPath(incfile,
                                        buffer.getMasterBuffer()->temppath());
        }
@@ -752,6 +768,31 @@ void InsetInclude::addPreview(graphics::PreviewLoader & ploader) const
 }
 
 
+void InsetInclude::addToToc(TocList & toclist, Buffer const & buffer) const
+{
+       Buffer const * const childbuffer = getChildBuffer(buffer, params_);
+       if (!childbuffer)
+               return;
+
+       TocList const & childtoclist = childbuffer->tocBackend().tocs();
+       TocList::const_iterator it = childtoclist.begin();
+       TocList::const_iterator const end = childtoclist.end();
+       for(; it != end; ++it)
+               toclist[it->first].insert(toclist[it->first].end(),
+                               it->second.begin(), it->second.end());
+}
+
+
+void InsetInclude::updateLabels(Buffer const & buffer) const
+{
+       Buffer const * const childbuffer = getChildBuffer(buffer, params_);
+       if (!childbuffer)
+               return;
+
+       lyx::updateLabels(*childbuffer, true);
+}
+
+
 string const InsetIncludeMailer::name_("include");
 
 InsetIncludeMailer::InsetIncludeMailer(InsetInclude & inset)