]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetInclude.cpp
Remove embedding stuff from InsetBibtex.
[lyx.git] / src / insets / InsetInclude.cpp
index c2b3aeb6ed46ea9656b2be3553e16a0cc86b8dd6..130c843e9a911ccfb8502b40e286e8b56eeab50e 100644 (file)
@@ -5,7 +5,6 @@
  *
  * \author Lars Gullik Bjønnes
  * \author Richard Heck (conversion to InsetCommand)
- * \author Bo Peng (embedding stuff)
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -45,9 +44,9 @@
 #include "insets/InsetListingsParams.h"
 #include "insets/RenderPreview.h"
 
+#include "support/assert.h"
 #include "support/debug.h"
 #include "support/docstream.h"
-#include "support/ExceptionMessage.h"
 #include "support/FileNameList.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
@@ -137,16 +136,11 @@ string const parentFilename(Buffer const & buffer)
 }
 
 
-EmbeddedFile const includedFilename(Buffer const & buffer,
+FileName const includedFilename(Buffer const & buffer,
                              InsetCommandParams const & params)
 {
-       // it is not a good idea to create this EmbeddedFile object
-       // each time, but there seems to be no easy way around.
-       EmbeddedFile file(to_utf8(params["filename"]),
-              onlyPath(parentFilename(buffer)));
-       file.setEmbed(!params["embed"].empty());
-       file.enable(buffer.embedded(), &buffer, false);
-       return file;
+       return makeAbsPath(to_utf8(params["filename"]),
+                          onlyPath(parentFilename(buffer)));
 }
 
 InsetLabel * createLabel(docstring const & label_str)
@@ -215,10 +209,9 @@ InsetInclude::~InsetInclude()
 
 void InsetInclude::setBuffer(Buffer & buffer)
 {
-       buffer_ = &buffer;
+       InsetCommand::setBuffer(buffer);
        if (label_)
                label_->setBuffer(buffer);
-
 }
 
 
@@ -231,7 +224,6 @@ ParamInfo const & InsetInclude::findInfo(string const & /* cmdName */)
        if (param_info_.empty()) {
                param_info_.add("filename", ParamInfo::LATEX_REQUIRED);
                param_info_.add("lstparams", ParamInfo::LATEX_OPTIONAL);
-               param_info_.add("embed", ParamInfo::LYX_INTERNAL);
        }
        return param_info_;
 }
@@ -245,14 +237,13 @@ bool InsetInclude::isCompatibleCommand(string const & s)
 
 void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       BOOST_ASSERT(&cur.buffer() == &buffer());
+       LASSERT(&cur.buffer() == &buffer(), /**/);
        switch (cmd.action) {
 
        case LFUN_INSET_MODIFY: {
                InsetCommandParams p(INCLUDE_CODE);
-               InsetCommandMailer::string2params("include", to_utf8(cmd.argument()), p);
+               InsetCommand::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"));
@@ -266,23 +257,7 @@ 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.
-                               if (p["embed"] == _("false"))
-                                       p["embed"].clear();
-                               else
-                                       p["embed"] = from_utf8(EmbeddedFile(to_utf8(p["filename"]),
-                                               onlyPath(parentFilename(buf))).inzipName());
-                               // test parameter
-                               includedFilename(cur.buffer(), p);
-                       } catch (ExceptionMessage const & message) {
-                               Alert::error(message.title_, message.details_);
-                               // do not set parameter if an error happens
-                               break;
-                       }
                        setParams(p);
-                       buffer().updateBibfilesCache();
                } else
                        cur.noUpdate();
                break;
@@ -306,6 +281,8 @@ void InsetInclude::setParams(InsetCommandParams const & p)
 
        if (type(params()) == INPUT)
                add_preview(*preview_, *this, buffer());
+
+       buffer().updateBibfilesCache();
 }
 
 
@@ -330,7 +307,7 @@ docstring InsetInclude::screenLabel() const
                        temp = listings_label_;
                        break;
                case NONE:
-                       BOOST_ASSERT(false);
+                       LASSERT(false, /**/);
        }
 
        temp += ": ";
@@ -340,8 +317,6 @@ docstring InsetInclude::screenLabel() const
        else
                temp += from_utf8(onlyFilename(to_utf8(params()["filename"])));
 
-       if (!params()["embed"].empty())
-               temp += _(" (embedded)");
        return temp;
 }
 
@@ -411,7 +386,7 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
                return 0;
 
        FileName const included_file =
-               includedFilename(buffer(), params()).availableFile();
+               includedFilename(buffer(), params());
 
        // Check we're not trying to include ourselves.
        // FIXME RECURSIVE INCLUDE
@@ -489,7 +464,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."),
@@ -659,10 +634,10 @@ void InsetInclude::validate(LaTeXFeatures & features) const
        string incfile = to_utf8(params()["filename"]);
        string writefile;
 
-       BOOST_ASSERT(&buffer() == &features.buffer());
+       LASSERT(&buffer() == &features.buffer(), /**/);
 
        string const included_file =
-               includedFilename(buffer(), params()).availableFile().absFilename();
+               includedFilename(buffer(), params()).absFilename();
 
        if (isLyXFilename(included_file))
                writefile = changeExtension(included_file, ".sgml");
@@ -729,24 +704,24 @@ void InsetInclude::updateBibfilesCache()
 }
 
 
-EmbeddedFileList const &
-InsetInclude::getBibfilesCache(Buffer const & buffer) const
+support::FileNameList const &
+       InsetInclude::getBibfilesCache(Buffer const & buffer) const
 {
        Buffer * const tmp = getChildBuffer(buffer, params());
        if (tmp) {
                tmp->setParent(0);
-               EmbeddedFileList const & cache = tmp->getBibfilesCache();
+               support::FileNameList const & cache = tmp->getBibfilesCache();
                tmp->setParent(&buffer);
                return cache;
        }
-       static EmbeddedFileList const empty;
+       static support::FileNameList const empty;
        return empty;
 }
 
 
 void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       BOOST_ASSERT(mi.base.bv);
+       LASSERT(mi.base.bv, /**/);
 
        bool use_preview = false;
        if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
@@ -772,7 +747,7 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetInclude::draw(PainterInfo & pi, int x, int y) const
 {
-       BOOST_ASSERT(pi.base.bv);
+       LASSERT(pi.base.bv, /**/);
 
        bool use_preview = false;
        if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
@@ -863,7 +838,6 @@ void InsetInclude::addPreview(graphics::PreviewLoader & ploader) const
 
 void InsetInclude::addToToc(ParConstIterator const & cpit) const
 {
-       bool const embedded_status = !params()["embed"].empty();
        TocBackend & backend = buffer().tocBackend();
 
        if (isListings(params())) {
@@ -875,31 +849,20 @@ void InsetInclude::addToToc(ParConstIterator const & cpit) const
                if (caption.empty())
                        return;
                Toc & toc = backend.toc("listing");
-               docstring const str = convert<docstring>(toc.size() + 1)
+               docstring str = convert<docstring>(toc.size() + 1)
                        + ". " +  from_utf8(caption);
                ParConstIterator pit = cpit;
                pit.push_back(*this);
                toc.push_back(TocItem(pit, 0, str));
-               if (embedded_status)
-                       backend.toc("embedded").push_back(TocItem(cpit, 0, str));
                return;
        }
        Buffer const * const childbuffer = getChildBuffer(buffer(), params());
-       if (!childbuffer) {
-               if (embedded_status) 
-                       // Add it to the embedded list nonetheless.
-                       backend.toc("embedded").push_back(TocItem(cpit, 0,
-                               params()["filename"]));
+       if (!childbuffer)
                return;
-       }
 
        Toc & toc = backend.toc("child");
        docstring str = childbuffer->fileName().displayName();
-       if (embedded_status)
-               str += _(" (embedded)");
        toc.push_back(TocItem(cpit, 0, str));
-       if (embedded_status)
-               backend.toc("embedded").push_back(TocItem(cpit, 0, str));
 
        TocList & toclist = backend.tocs();
        TocList const & childtoclist = childbuffer->tocBackend().tocs();
@@ -939,19 +902,4 @@ void InsetInclude::updateLabels(ParIterator const & it)
 }
 
 
-void InsetInclude::registerEmbeddedFiles(EmbeddedFileList & files) const
-{
-       files.registerFile(includedFilename(buffer(), params()), this, buffer());
-}
-
-
-void InsetInclude::updateEmbeddedFile(EmbeddedFile const & file)
-{
-       InsetCommandParams p = params();
-       p["filename"] = from_utf8(file.outputFilename());
-       p["embed"] = file.embedded() ? from_utf8(file.inzipName()) : docstring();
-       setParams(p);
-}
-
-
 } // namespace lyx