]> 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 1d28e3347b4e8ab3b3389c3a5a03c663182e5127..440190bb5449d104c2d06d1b9b9d69c7a666eb76 100644 (file)
@@ -25,6 +25,8 @@
 
 using std::ostream;
 using std::endl;
+using std::vector;
+using std::pair;
 
 extern BufferView * current_view;
 
@@ -186,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") 
 {
@@ -193,6 +211,7 @@ InsetInclude::InsetInclude(string const & fname, Buffer * bf)
        setContents(fname);
        flag = InsetInclude::INCLUDE;
        noload = false;
+       include_label = unique_id();
 }
 
 
@@ -215,7 +234,7 @@ InsetInclude::~InsetInclude()
 
 Inset * InsetInclude::Clone() const
 { 
-       InsetInclude * ii = new InsetInclude (contents, master); 
+       InsetInclude * ii = new InsetInclude (getContents(), master); 
        ii->setNoLoad(isNoLoad());
        // By default, the newly created inset is of `include' type,
        // so we do not test this case.
@@ -240,7 +259,7 @@ void InsetInclude::Edit(BufferView * bv, int, int, unsigned int)
        }
         form->include->u_vdata = this;
     
-        fl_set_input(form->input, contents.c_str());
+        fl_set_input(form->input, getContents().c_str());
        fl_set_button(form->flag1, int(isNoLoad()));
        fl_set_button(form->flag2, int(isInput()));
        fl_set_button(form->flag3, int(isInclude()));
@@ -262,15 +281,15 @@ void InsetInclude::Edit(BufferView * bv, int, int, unsigned int)
 }
 
 
-void InsetInclude::Write(ostream & os) const
+void InsetInclude::Write(Buffer const *, ostream & os) const
 {
        os << "Include " << getCommand() << "\n";
 }
 
 
-void InsetInclude::Read(LyXLex & lex)
+void InsetInclude::Read(Buffer const * buf, LyXLex & lex)
 {
-       InsetCommand::Read(lex);
+       InsetCommand::Read(buf, lex);
     
        if (getCmdName() == "include")
                setInclude();
@@ -301,10 +320,10 @@ string InsetInclude::getScreenLabel() const
        } else temp += _("Include");
        temp += ": ";
        
-       if (contents.empty()) {
+       if (getContents().empty()) {
                temp+= "???";
        } else {
-               temp+= contents;
+               temp+= getContents();
        }
        return temp;
 }
@@ -313,7 +332,7 @@ string InsetInclude::getScreenLabel() const
 void InsetInclude::setContents(string const & c)
 {
        InsetCommand::setContents(c);
-       filename = MakeAbsPath(contents
+       filename = MakeAbsPath(getContents()
                               OnlyPath(getMasterFilename())); 
 }
 
@@ -332,16 +351,16 @@ bool InsetInclude::loadIfNeeded() const
 }
 
 
-int InsetInclude::Latex(ostream & os,
+int InsetInclude::Latex(Buffer const *, ostream & os,
                        bool /*fragile*/, bool /*fs*/) const
 {
        // Do nothing if no file name has been specified
-       if (contents.empty())
+       if (getContents().empty())
                return 0;
     
        // Use += to force a copy of contents (JMarc)
        // How does that force anything? (Lgb)
-       string incfile(contents);
+       string incfile(getContents());
 
        if (loadIfNeeded()) {
                Buffer * tmp = bufferlist.getBuffer(getFileName());
@@ -358,7 +377,7 @@ int InsetInclude::Latex(ostream & os,
                }
                
                // write it to a file (so far the complete file)
-               string writefile = ChangeExtension(getFileName(), ".tex", false);
+               string writefile = ChangeExtension(getFileName(), ".tex");
                if (!master->tmppath.empty()
                    && !master->niceFile) {
                        incfile = subst(incfile, '/','@');
@@ -368,7 +387,7 @@ int InsetInclude::Latex(ostream & os,
                        writefile = AddName(master->tmppath, incfile);
                } else
                        writefile = getFileName();
-               writefile = ChangeExtension(writefile, ".tex", false);
+               writefile = ChangeExtension(writefile, ".tex");
                lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
                lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
                
@@ -380,22 +399,21 @@ int InsetInclude::Latex(ostream & os,
        } 
 
        if (isVerb()) {
-               os << '\\' << command << '{' << incfile << '}';
-       } 
-       else if (isInput()) {
+               os << '\\' << getCmdName() << '{' << incfile << '}';
+       } else if (isInput()) {
                // \input wants file with extension (default is .tex)
                if (!IsLyXFilename(getFileName())) {
-                       os << '\\' << command << '{' << incfile << '}';
+                       os << '\\' << getCmdName() << '{' << incfile << '}';
                } else {
-                       os << '\\' << command << '{'
-                          << ChangeExtension(incfile, ".tex", false)
+                       os << '\\' << getCmdName() << '{'
+                          << ChangeExtension(incfile, ".tex")
                           <<  '}';
                }
        } else {
                // \include don't want extension and demands that the
                // file really have .tex
-               os << '\\' << command << '{'
-                  << ChangeExtension(incfile, string(), false)
+               os << '\\' << getCmdName() << '{'
+                  << ChangeExtension(incfile, string())
                   << '}';
        }
 
@@ -403,8 +421,97 @@ int InsetInclude::Latex(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;
 
@@ -419,49 +526,32 @@ void InsetInclude::Validate(LaTeXFeatures & features) const
 }
 
 
-string InsetInclude::getLabel(int) const
+vector<string> InsetInclude::getLabelList() const
 {
-    string label;
+    vector<string> l;
     string parentname;
-       
-       
+
     if (loadIfNeeded()) {
        Buffer * tmp = bufferlist.getBuffer(getFileName());
        tmp->setParentName(""); 
-       label =  tmp->getReferenceList('\n');
+       l = tmp->getLabelList();
        tmp->setParentName(getMasterFilename());
     }
 
-    return label;
-}
-
-
-int InsetInclude::GetNumberOfLabels() const
-{
-    string label;
-
-    if (loadIfNeeded()) {
-       Buffer * tmp = bufferlist.getBuffer(getFileName());
-       tmp->setParentName("");    
-       label = tmp->getReferenceList('\n');
-       tmp->setParentName(getMasterFilename());
-    }
-    int nl = (label.empty())? 0: 1;
-       
-    return nl;
+    return l;
 }
 
 
-string InsetInclude::getKeys(char delim) const
+vector<pair<string,string> > InsetInclude::getKeys() const
 {
-       string lst;
+       vector<pair<string,string> > keys;
        
        if (loadIfNeeded()) {
                Buffer *tmp = bufferlist.getBuffer(getFileName());
                tmp->setParentName(""); 
-               lst =  tmp->getBibkeyList(delim);
+               keys =  tmp->getBibkeyList();
                tmp->setParentName(getMasterFilename());
        }
        
-       return lst;
+       return keys;
 }