]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetinclude.C
Some more changes for updating text-insets.
[lyx.git] / src / insets / insetinclude.C
index 3f511181550d4d5e6de77c8c551f98e7f97ed2a0..440190bb5449d104c2d06d1b9b9d69c7a666eb76 100644 (file)
@@ -188,6 +188,22 @@ extern "C" void include_cb(FL_OBJECT *, long arg)
 }
 
 
+static string unique_id() {
+       static unsigned int seed=1000;
+
+#ifdef HAVE_SSTREAM
+       std::ostringstream ost;
+       ost << "file" << ++seed;
+#else
+       char ctmp[16];
+       ostrstream ost(ctmp,16);
+       ost << "file" << ++seed << '\0';
+#endif
+
+       return ost.str();
+}
+
+
 InsetInclude::InsetInclude(string const & fname, Buffer * bf)
        : InsetCommand("include") 
 {
@@ -195,6 +211,7 @@ InsetInclude::InsetInclude(string const & fname, Buffer * bf)
        setContents(fname);
        flag = InsetInclude::INCLUDE;
        noload = false;
+       include_label = unique_id();
 }
 
 
@@ -404,8 +421,97 @@ int InsetInclude::Latex(Buffer const *, ostream & os,
 }
 
 
+int InsetInclude::Linuxdoc(Buffer const *, ostream & os) const
+{
+       // Do nothing if no file name has been specified
+       if (getContents().empty())
+               return 0;
+    
+       string incfile(getContents());
+
+       if (loadIfNeeded()) {
+               Buffer * tmp = bufferlist.getBuffer(getFileName());
+
+               // write it to a file (so far the complete file)
+               string writefile = ChangeExtension(getFileName(), ".sgml");
+               if (!master->tmppath.empty() && !master->niceFile) {
+                       incfile = subst(incfile, '/','@');
+                       writefile = AddName(master->tmppath, incfile);
+               } else
+                       writefile = getFileName();
+
+               if(IsLyXFilename(getFileName()))
+                       writefile = ChangeExtension(writefile, ".sgml");
+
+               lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
+               lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
+               
+               tmp->makeLinuxDocFile(writefile, master->niceFile, true);
+       } 
+
+       if (isVerb()) {
+               os << "<!-- includefile verbatim=\"" << incfile << "\" -->";
+       } else 
+               os << '&' << include_label << ';';
+       
+       return 0;
+}
+
+
+int InsetInclude::DocBook(Buffer const *, ostream & os) const
+{
+       // Do nothing if no file name has been specified
+       if (getContents().empty())
+               return 0;
+    
+       string incfile(getContents());
+
+       if (loadIfNeeded()) {
+               Buffer * tmp = bufferlist.getBuffer(getFileName());
+
+               // write it to a file (so far the complete file)
+               string writefile = ChangeExtension(getFileName(), ".sgml");
+               if (!master->tmppath.empty() && !master->niceFile) {
+                       incfile = subst(incfile, '/','@');
+                       writefile = AddName(master->tmppath, incfile);
+               } else
+                       writefile = getFileName();
+               if(IsLyXFilename(getFileName()))
+                       writefile = ChangeExtension(writefile, ".sgml");
+
+               lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
+               lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
+               
+               tmp->makeDocBookFile(writefile, master->niceFile, true);
+       } 
+
+       if (isVerb()) {
+               os << "<!-- includefile verbatim=\"" << incfile << "\" -->";
+       } else 
+               os << '&' << include_label << ';';
+       
+       return 0;
+}
+
+
 void InsetInclude::Validate(LaTeXFeatures & features) const
 {
+
+       string incfile(getContents());
+       string writefile = ChangeExtension(getFileName(), ".sgml");
+       if (!master->tmppath.empty() && !master->niceFile) {
+               incfile = subst(incfile, '/','@');
+               writefile = AddName(master->tmppath, incfile);
+       } else
+               // writefile = getFileName();
+               // Use the relative path.
+               writefile = incfile;
+
+       if(IsLyXFilename(getFileName()))
+               writefile = ChangeExtension(writefile, ".sgml");
+
+       features.IncludedFiles[include_label] = writefile;
+
        if (isVerb())
                features.verbatim = true;