]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetInclude.cpp
Cosmetics.
[lyx.git] / src / insets / InsetInclude.cpp
index 140fe76cc2efb1aef9e9655244bd853ac52167f5..37ffc6fe9a097b29b03a0f376be8c38ebf38a3b8 100644 (file)
@@ -216,6 +216,19 @@ InsetInclude::~InsetInclude()
 
 void InsetInclude::setBuffer(Buffer & buffer)
 {
+       if (buffer_) {
+               try {
+                       EmbeddedFile file_from = includedFilename(*buffer_, params());
+                       EmbeddedFile file_to = file_from.copyTo(&buffer);
+                       if (file_to.embedded())
+                               setParam("embed", from_utf8(file_to.inzipName()));
+               } catch (ExceptionMessage const & message) {
+                       Alert::error(message.title_, message.details_);
+                       // failed to embed
+                       setParam("embed", docstring());
+               }
+
+       }
        buffer_ = &buffer;
        if (label_)
                label_->setBuffer(buffer);
@@ -253,7 +266,6 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
                InsetCommandParams p(INCLUDE_CODE);
                InsetCommandMailer::string2params("include", to_utf8(cmd.argument()), p);
                if (!p.getCmdName().empty()) {
-                       Buffer const & buf = cur.buffer();
                        if (isListings(p)){
                                InsetListingsParams new_params(to_utf8(p["lstparams"]));
                                docstring const label_str = from_utf8(new_params.getParamValue("label"));
@@ -267,24 +279,6 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
                                        label_->initView();
                                }
                        }
-                       try {
-                               // the embed parameter passed back from the dialog
-                               // is "true" or "false", we need to change it.
-                               EmbeddedFile file = EmbeddedFile(to_utf8(p["filename"]),
-                                       onlyPath(parentFilename(buf)));
-                               file.setEmbed(p["embed"] == _("true"));
-                               // move file around if needed, an exception may be raised.
-                               file.enable(buf.embedded(), &buf, true);
-                               // if things are OK..., set p["embed"]
-                               if (file.embedded())
-                                       p["embed"] = from_utf8(file.inzipName());
-                               else
-                                       p["embed"].clear();
-                       } catch (ExceptionMessage const & message) {
-                               Alert::error(message.title_, message.details_);
-                               // do not set parameter if an error happens
-                               break;
-                       }
                        setParams(p);
                        buffer().updateBibfilesCache();
                } else
@@ -493,7 +487,7 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
                        string const module = *it;
                        vector<string>::const_iterator found =
                                find(masterModules.begin(), masterModules.end(), module);
-                       if (found != masterModules.end()) {
+                       if (found == masterModules.end()) {
                                docstring text = bformat(_("Included file `%1$s'\n"
                                        "uses module `%2$s'\n"
                                        "which is not used in parent file."),