]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetinclude.C
prepare for 1.1.6pre2
[lyx.git] / src / insets / insetinclude.C
index 1e08cce899af0bc8678296ac18b67c900ad36dee..60cc1b2269be721721a06f08f7e3095e7ddb35e0 100644 (file)
@@ -1,3 +1,4 @@
+
 #include <config.h>
 
 #include <cstdlib>
@@ -103,7 +104,7 @@ void include_cb(FL_OBJECT *, long arg)
        {
                // Should browsing too be disabled in RO-mode?
                LyXFileDlg fileDlg;
-               string mpath = OnlyPath(inset->getMasterFilename());
+               string const mpath = OnlyPath(inset->getMasterFilename());
                 string ext;
     
                if (fl_get_button(form->flag2)) // Use Input Button
@@ -116,15 +117,16 @@ void include_cb(FL_OBJECT *, long arg)
                fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
     
                // Use by default the master's path
-               string filename = fileDlg.Select(_("Select Child Document"),
-                                                 mpath, ext, 
-                                                 inset->getContents());
+               string const filename =
+                       fileDlg.Select(_("Select Child Document"),
+                                      mpath, ext, 
+                                      inset->getContents());
                XFlush(fl_get_display());
  
                // check selected filename
                if (!filename.empty()) {
-                       string filename2 = MakeRelPath(filename,
-                                                       mpath);
+                       string const filename2 = MakeRelPath(filename,
+                                                            mpath);
                        if (prefixIs(filename2, ".."))
                                fl_set_input(form->input,
                                             filename.c_str());
@@ -136,7 +138,7 @@ void include_cb(FL_OBJECT *, long arg)
        }
 
        case 1:
-               if(!current_view->buffer()->isReadonly()) {
+               if (!current_view->buffer()->isReadonly()) {
                        inset->setContents(fl_get_input(form->input));
                        // don't typeset
                        inset->setNoLoad(fl_get_button(form->flag1));
@@ -158,7 +160,7 @@ void include_cb(FL_OBJECT *, long arg)
                fl_hide_form(form->include);
                break;
        case 5:
-               if(!current_view->buffer()->isReadonly()) {
+               if (!current_view->buffer()->isReadonly()) {
                        inset->setContents(fl_get_input(form->input));
                        inset->setNoLoad(fl_get_button(form->flag1));
                        if (fl_get_button(form->flag2))
@@ -172,7 +174,7 @@ void include_cb(FL_OBJECT *, long arg)
                        
                        fl_hide_form(form->include);
                        current_view->updateInset(inset, true);
-                       current_view->owner()->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, inset->getContents().c_str());
+                       current_view->owner()->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, inset->getContents());
                 }
                 break;
                
@@ -189,27 +191,21 @@ void include_cb(FL_OBJECT *, long arg)
 }
 
 
-static string unique_id() {
-       static unsigned int seed=1000;
+static inline
+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();
+       // Needed if we use lyxstring.
+       return ost.str().c_str();
 }
 
 
-InsetInclude::InsetInclude(string const & fname, Buffer * bf)
-       : InsetCommand("include") 
+InsetInclude::InsetInclude(InsetCommandParams const & p, Buffer const & bf)
+       : InsetCommand(p), master(&bf)
 {
-       master = bf;
-       setContents(fname);
        flag = InsetInclude::INCLUDE;
        noload = false;
        include_label = unique_id();
@@ -233,9 +229,9 @@ InsetInclude::~InsetInclude()
 }
 
 
-Inset * InsetInclude::Clone() const
+Inset * InsetInclude::Clone(Buffer const & buffer) const
 { 
-       InsetInclude * ii = new InsetInclude (getContents(), master); 
+       InsetInclude * ii = new InsetInclude (params(), buffer); 
        ii->setNoLoad(isNoLoad());
        // By default, the newly created inset is of `include' type,
        // so we do not test this case.
@@ -251,12 +247,12 @@ Inset * InsetInclude::Clone() const
 
 void InsetInclude::Edit(BufferView * bv, int, int, unsigned int)
 {
-       if(bv->buffer()->isReadonly())
+       if (bv->buffer()->isReadonly())
                WarnReadonly(bv->buffer()->fileName());
 
        if (!form) {
                 form = create_form_include();
-               fl_set_form_atclose(form->include, IgnoreCloseBoxCB, 0);
+               fl_set_form_atclose(form->include, CancelCloseBoxCB, 0);
        }
         form->include->u_vdata = this;
     
@@ -276,7 +272,8 @@ void InsetInclude::Edit(BufferView * bv, int, int, unsigned int)
         if (form->include->visible) {
                fl_raise_form(form->include);
        } else {
-               fl_show_form(form->include, FL_PLACE_MOUSE, FL_FULLBORDER,
+               fl_show_form(form->include,
+                            FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
                             _("Include"));
        }
 }
@@ -310,7 +307,7 @@ bool InsetInclude::display() const
 }
 
 
-string InsetInclude::getScreenLabel() const
+string const InsetInclude::getScreenLabel() const
 {
        string temp;
        if (isInput())
@@ -330,11 +327,16 @@ string InsetInclude::getScreenLabel() const
 }
 
 
-void InsetInclude::setContents(string const & c)
+string const InsetInclude::getFileName() const
 {
-       InsetCommand::setContents(c);
-       filename = MakeAbsPath(getContents(), 
-                              OnlyPath(getMasterFilename())); 
+       return MakeAbsPath(getContents(), 
+                          OnlyPath(getMasterFilename()));
+}
+
+
+string const InsetInclude::getMasterFilename() const
+{
+       return master->fileName();
 }
 
 
@@ -347,56 +349,54 @@ bool InsetInclude::loadIfNeeded() const
        
        // the readonly flag can/will be wrong, not anymore I think.
        FileInfo finfo(getFileName());
-       bool ro = !finfo.writable();
-       return ( bufferlist.readFile(getFileName(), ro) != 0 );
+       bool const ro = !finfo.writable();
+       return bufferlist.readFile(getFileName(), ro) != 0;
 }
 
 
-int InsetInclude::Latex(Buffer const *, ostream & os,
+int InsetInclude::Latex(Buffer const * buffer, ostream & os,
                        bool /*fragile*/, bool /*fs*/) const
 {
+       string incfile(getContents());
+       
        // Do nothing if no file name has been specified
-       if (getContents().empty())
+       if (incfile.empty())
                return 0;
     
-       // Use += to force a copy of contents (JMarc)
-       // How does that force anything? (Lgb)
-       string incfile(getContents());
-
        if (loadIfNeeded()) {
                Buffer * tmp = bufferlist.getBuffer(getFileName());
 
-               if (tmp->params.textclass != master->params.textclass) {
+               if (tmp->params.textclass != buffer->params.textclass) {
                        lyxerr << "ERROR: Cannot handle include file `"
                               << MakeDisplayPath(getFileName())
                               << "' which has textclass `"
                               << textclasslist.NameOfClass(tmp->params.textclass)
                               << "' instead of `"
-                              << textclasslist.NameOfClass(master->params.textclass)
+                              << textclasslist.NameOfClass(buffer->params.textclass)
                               << "'." << endl;
                        return 0;
                }
                
                // write it to a file (so far the complete file)
                string writefile = ChangeExtension(getFileName(), ".tex");
-               if (!master->tmppath.empty()
-                   && !master->niceFile) {
+               if (!buffer->tmppath.empty()
+                   && !buffer->niceFile) {
                        incfile = subst(incfile, '/','@');
 #ifdef __EMX__
                        incfile = subst(incfile, ':', '$');
 #endif
-                       writefile = AddName(master->tmppath, incfile);
+                       writefile = AddName(buffer->tmppath, incfile);
                } else
                        writefile = getFileName();
                writefile = ChangeExtension(writefile, ".tex");
                lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
                lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
                
-               tmp->markDepClean(master->tmppath);
+               tmp->markDepClean(buffer->tmppath);
                
                tmp->makeLaTeXFile(writefile,
                                   OnlyPath(getMasterFilename()), 
-                                  master->niceFile, true);
+                                  buffer->niceFile, true);
        } 
 
        if (isVerb()) {
@@ -422,36 +422,38 @@ int InsetInclude::Latex(Buffer const *, ostream & os,
 }
 
 
-int InsetInclude::Linuxdoc(Buffer const *, ostream & os) const
+int InsetInclude::Linuxdoc(Buffer const * buffer, ostream & os) const
 {
+       string incfile(getContents());
+       
        // Do nothing if no file name has been specified
-       if (getContents().empty())
+       if (incfile.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) {
+               if (!buffer->tmppath.empty() && !buffer->niceFile) {
                        incfile = subst(incfile, '/','@');
-                       writefile = AddName(master->tmppath, incfile);
+                       writefile = AddName(buffer->tmppath, incfile);
                } else
                        writefile = getFileName();
 
-               if(IsLyXFilename(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);
+               tmp->makeLinuxDocFile(writefile, buffer->niceFile, true);
        } 
 
        if (isVerb()) {
-               os << "<!-- includefile verbatim=\"" << incfile << "\" -->";
+               os << "<inlinegraphic fileref=\"" << '&' << include_label << ';'
+                  << "\" format=\"linespecific\">"
+                  << "</inlinegraphic>";
        } else 
                os << '&' << include_label << ';';
        
@@ -459,35 +461,37 @@ int InsetInclude::Linuxdoc(Buffer const *, ostream & os) const
 }
 
 
-int InsetInclude::DocBook(Buffer const *, ostream & os) const
+int InsetInclude::DocBook(Buffer const * buffer, ostream & os) const
 {
+       string incfile(getContents());
+
        // Do nothing if no file name has been specified
-       if (getContents().empty())
+       if (incfile.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) {
+               if (!buffer->tmppath.empty() && !buffer->niceFile) {
                        incfile = subst(incfile, '/','@');
-                       writefile = AddName(master->tmppath, incfile);
+                       writefile = AddName(buffer->tmppath, incfile);
                } else
                        writefile = getFileName();
-               if(IsLyXFilename(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);
+               tmp->makeDocBookFile(writefile, buffer->niceFile, true);
        } 
 
        if (isVerb()) {
-               os << "<!-- includefile verbatim=\"" << incfile << "\" -->";
+               os << "<inlinegraphic fileref=\"" << '&' << include_label << ';'
+                  << "\" format=\"linespecific\">"
+                  << "</inlinegraphic>";
        } else 
                os << '&' << include_label << ';';
        
@@ -499,16 +503,17 @@ void InsetInclude::Validate(LaTeXFeatures & features) const
 {
 
        string incfile(getContents());
-       string writefile = ChangeExtension(getFileName(), ".sgml");
+       string writefile; // = ChangeExtension(getFileName(), ".sgml");
+
        if (!master->tmppath.empty() && !master->niceFile) {
                incfile = subst(incfile, '/','@');
                writefile = AddName(master->tmppath, incfile);
        } else
-               // writefile = getFileName();
+               writefile = getFileName();
                // Use the relative path.
-               writefile = incfile;
+               //writefile = incfile;
 
-       if(IsLyXFilename(getFileName()))
+       if (IsLyXFilename(getFileName()))
                writefile = ChangeExtension(writefile, ".sgml");
 
        features.IncludedFiles[include_label] = writefile;
@@ -527,30 +532,29 @@ void InsetInclude::Validate(LaTeXFeatures & features) const
 }
 
 
-vector<string> InsetInclude::getLabelList() const
+vector<string> const InsetInclude::getLabelList() const
 {
-    vector<string> l;
-    string parentname;
+       vector<string> l;
 
-    if (loadIfNeeded()) {
-       Buffer * tmp = bufferlist.getBuffer(getFileName());
-       tmp->setParentName(""); 
-       l = tmp->getLabelList();
-       tmp->setParentName(getMasterFilename());
-    }
+       if (loadIfNeeded()) {
+               Buffer * tmp = bufferlist.getBuffer(getFileName());
+               tmp->setParentName(""); 
+               l = tmp->getLabelList();
+               tmp->setParentName(getMasterFilename());
+       }
 
-    return l;
+       return l;
 }
 
 
-vector<pair<string,string> > InsetInclude::getKeys() const
+vector<pair<string,string> > const InsetInclude::getKeys() const
 {
        vector<pair<string,string> > keys;
        
        if (loadIfNeeded()) {
-               Buffer *tmp = bufferlist.getBuffer(getFileName());
+               Buffer * tmp = bufferlist.getBuffer(getFileName());
                tmp->setParentName(""); 
-               keys =  tmp->getBibkeyList();
+               keys = tmp->getBibkeyList();
                tmp->setParentName(getMasterFilename());
        }