]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetinclude.C
prepare for 1.1.6pre2
[lyx.git] / src / insets / insetinclude.C
index 835e1fac42b72858796fcd4a9133ffaa9db4cb5d..60cc1b2269be721721a06f08f7e3095e7ddb35e0 100644 (file)
@@ -104,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
@@ -117,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());
@@ -137,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));
@@ -159,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))
@@ -173,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;
                
@@ -192,27 +193,18 @@ void include_cb(FL_OBJECT *, long arg)
 
 static inline
 string unique_id() {
-       static unsigned int seed=1000;
+       static unsigned int seed = 1000;
 
-//#ifdef HAVE_SSTREAM
        std::ostringstream ost;
        ost << "file" << ++seed;
 
        // Needed if we use lyxstring.
        return ost.str().c_str();
-//#else
-//     char ctmp[16];
-//     ostrstream ost(ctmp,16);
-//     ost << "file" << ++seed << '\0';
-//
-//     // Needed if we use lyxstring.
-//     return ost.str();
-//#endif
 }
 
 
-InsetInclude::InsetInclude(InsetCommandParams const & p, Buffer * bf)
-       : InsetCommand(p), master(bf)
+InsetInclude::InsetInclude(InsetCommandParams const & p, Buffer const & bf)
+       : InsetCommand(p), master(&bf)
 {
        flag = InsetInclude::INCLUDE;
        noload = false;
@@ -237,9 +229,9 @@ InsetInclude::~InsetInclude()
 }
 
 
-Inset * InsetInclude::Clone() const
+Inset * InsetInclude::Clone(Buffer const & buffer) const
 { 
-       InsetInclude * ii = new InsetInclude (params(), 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.
@@ -255,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;
     
@@ -280,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"));
        }
 }
@@ -356,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()) {
@@ -431,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 << ';';
        
@@ -468,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 << ';';
        
@@ -508,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;
@@ -538,17 +534,16 @@ void InsetInclude::Validate(LaTeXFeatures & features) 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;
 }
 
 
@@ -557,9 +552,9 @@ 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());
        }