]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetinclude.C
reformatting and remove using delc
[lyx.git] / src / insets / insetinclude.C
index e5bff61a18190f2c473a2f373bf1ff8e099e5059..52fbee7f33023aeb574638bcfeff5fc60bc81561 100644 (file)
@@ -29,9 +29,10 @@ using std::pair;
 
 extern BufferList bufferlist;
 
+namespace {
 
-static inline
-string unique_id() {
+string const unique_id()
+{
        static unsigned int seed = 1000;
 
        std::ostringstream ost;
@@ -41,20 +42,19 @@ string unique_id() {
        return ost.str().c_str();
 }
 
+} // namespace anon
 
-InsetInclude::InsetInclude(InsetIncludeParams const & p)
-{
-       include_label = unique_id();
-       setFromParams(p);
-       params_.buffer = p.buffer;
-}
+
+InsetInclude::InsetInclude(Params const & p)
+       : params_(p), include_label(unique_id())
+{}
 
 
 InsetInclude::InsetInclude(InsetCommandParams const & p, Buffer const & b)
 {
+       params_.cparams = p;
+       params_.masterFilename_ = b.fileName();
        include_label = unique_id();
-       params_.buffer = &b;
-       setFromParams(p);
 }
 
 
@@ -64,48 +64,60 @@ InsetInclude::~InsetInclude()
 }
 
 
-InsetInclude::InsetIncludeParams const & InsetInclude::params() const
+InsetInclude::Params const & InsetInclude::params() const
 {
        return params_;
 }
 
 
-void InsetInclude::setFromParams(InsetIncludeParams const & p)
+bool InsetInclude::Params::operator==(Params const & o) const
 {
-       params_.cparams.setContents(p.cparams.getContents());
-       params_.noload = p.noload;
-       if (params_.flag == p.flag)
-               return;
+       if (cparams == o.cparams && flag == o.flag &&
+           noload == o.noload && masterFilename_ == o.masterFilename_)
+               return true;
+       
+       return false;
+}
 
-       params_.flag = p.flag;
 
-       string command;
+bool InsetInclude::Params::operator!=(Params const & o) const
+{
+       return !(*this == o);
+}
+
 
+void InsetInclude::set(Params const & p)
+{
+       params_ = p;
+
+       // Just to be safe...
+       string command;
        switch (params_.flag) {
-               case INCLUDE:
-                       command="include";
-                       break;
-               case VERB:
-                       command="verbatiminput";
-                       break;
-               case INPUT:
-                       command="input";
-                       break;
-               case VERBAST:
-                       command="verbatiminput*";
-                       break;
+               case INCLUDE:
+                       command="include";
+                       break;
+               case VERB:
+                       command="verbatiminput";
+                       break;
+               case INPUT:
+                       command="input";
+                       break;
+               case VERBAST:
+                       command="verbatiminput*";
+                       break;
        }
-
        params_.cparams.setCmdName(command);
 }
 
 
 Inset * InsetInclude::Clone(Buffer const & buffer) const
 {
-       InsetIncludeParams p(params_);
-       p.buffer = &buffer;
+       Params p(params_);
+       p.masterFilename_ = buffer.fileName();
 
-       return new InsetInclude (p);
+       return new InsetInclude(p);
 }
 
 
@@ -181,7 +193,7 @@ string const InsetInclude::getFileName() const
 
 string const InsetInclude::getMasterFilename() const
 {
-       return params_.buffer->fileName();
+       return params_.masterFilename_;
 }
 
 
@@ -364,11 +376,11 @@ void InsetInclude::Validate(LaTeXFeatures & features) const
        string incfile(params_.cparams.getContents());
        string writefile;
 
-       Buffer const & b = *params_.buffer;
+       Buffer const * const b = bufferlist.getBuffer(getMasterFilename());
 
-       if (!b.tmppath.empty() && b.niceFile) {
+       if (b && !b->tmppath.empty() && b->niceFile) {
                incfile = subst(incfile, '/','@');
-               writefile = AddName(b.tmppath, incfile);
+               writefile = AddName(b->tmppath, incfile);
        } else
                writefile = getFileName();
 
@@ -385,8 +397,9 @@ void InsetInclude::Validate(LaTeXFeatures & features) const
        // to be loaded:
        if (loadIfNeeded()) {
                // a file got loaded
-               Buffer * tmp = bufferlist.getBuffer(getFileName());
-               tmp->validate(features);
+               Buffer const * const tmp = bufferlist.getBuffer(getFileName());
+               if (tmp)
+                       tmp->validate(features);
        }
 }