]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetInclude.cpp
pimpl not needed here
[lyx.git] / src / insets / InsetInclude.cpp
index b7708c14fa048e9df0bcd5001f26fac252571ed6..e236ad70367405cc2122adee361712b635720dfd 100644 (file)
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Lars Gullik Bjønnes
+ * \author Richard Heck (conversion to InsetCommand)
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -41,6 +42,7 @@
 #include "insets/RenderPreview.h"
 #include "insets/InsetListingsParams.h"
 
+#include "support/docstream.h"
 #include "support/filetools.h"
 #include "support/lstrings.h" // contains
 #include "support/lyxalgo.h"
@@ -95,27 +97,29 @@ docstring const uniqueID()
 
 /// the type of inclusion
 enum Types {
-       INCLUDE = 0,
- VERB = 1,
- INPUT = 2,
- VERBAST = 3,
- LISTINGS = 4,
+       INCLUDE, VERB, INPUT, VERBAST, LISTINGS, NONE
 };
 
 
-Types type(InsetCommandParams const & params)
-{
-       string const command_name = params.getCmdName();
-
-       if (command_name == "input")
+Types type(std::string const & s) {
+       if (s == "input")
                return INPUT;
-       if  (command_name == "verbatiminput")
+       if (s == "verbatiminput")
                return VERB;
-       if  (command_name == "verbatiminput*")
+       if (s == "verbatiminput*")
                return VERBAST;
-       if  (command_name == "lstinputlisting")
+       if (s == "lstinputlisting")
                return LISTINGS;
-       return INCLUDE;
+       if (s == "include")
+               return INCLUDE;
+       return NONE;
+}
+
+
+Types type(InsetCommandParams const & params)
+{
+       string const command_name = params.getCmdName();
+       return type(command_name);
 }
 
 
@@ -128,14 +132,14 @@ bool isListings(InsetCommandParams const & params)
 bool isVerbatim(InsetCommandParams const & params)
 {
        Types const t = type(params);
-       return (t == VERB) || (t == VERBAST);
+       return t == VERB || t == VERBAST;
 }
 
 
 bool isInputOrInclude(InsetCommandParams const & params)
 {
        Types const t = type(params);
-       return (t == INPUT) || (t == INCLUDE);
+       return t == INPUT || t == INCLUDE;
 }
 
 } // namespace anon
@@ -157,6 +161,22 @@ InsetInclude::InsetInclude(InsetInclude const & other)
 }
 
 
+CommandInfo const * InsetInclude::findInfo(std::string const & /* cmdName */)
+{
+       //This is only correct for the case of listings, but it'll do for now.
+       //In the other cases, this second parameter should just be empty.
+       static const char * const paramnames[] = {"filename", "lstparams", ""};
+       static const bool isoptional[] = {false, true};
+       static const CommandInfo info = {2, paramnames, isoptional};
+       return &info;
+}
+
+
+bool InsetInclude::isCompatibleCommand(std::string const & s) {
+       return type(s) != NONE;
+}
+
+
 void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
@@ -166,8 +186,8 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
                InsetCommandMailer::string2params("include", to_utf8(cmd.argument()), p);
                if (!p.getCmdName().empty()) {
                        if (isListings(p)){
-                               InsetListingsParams par_old(params().getOptions());
-                               InsetListingsParams par_new(p.getOptions());
+                               InsetListingsParams par_old(to_utf8(params()["lstparams"]));
+                               InsetListingsParams par_new(to_utf8(p["lstparams"]));
                                if (par_old.getParamValue("label") !=
                                    par_new.getParamValue("label")
                                    && !par_new.getParamValue("label").empty())
@@ -254,9 +274,10 @@ docstring const InsetInclude::getScreenLabel(Buffer const & buf) const
                case INCLUDE:
                        temp = buf.B_("Include");
                        break;
-               case LISTINGS: {
+               case LISTINGS:
                        temp = listings_label_;
-               }
+               case NONE:
+                       BOOST_ASSERT(false);
        }
 
        temp += ": ";
@@ -483,7 +504,7 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
                }
        } else if (type(params()) == LISTINGS) {
                os << '\\' << from_ascii(params().getCmdName());
-               string opt = params().getOptions();
+               string const opt = to_utf8(params()["lstparams"]);
                // opt is set in QInclude dialog and should have passed validation.
                InsetListingsParams params(opt);
                if (!params.params().empty())
@@ -585,7 +606,7 @@ int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
 
 void InsetInclude::validate(LaTeXFeatures & features) const
 {
-       string incfile(to_utf8(params()["filename"]));
+       string incfile = to_utf8(params()["filename"]);
        string writefile;
 
        Buffer const & buffer = features.buffer();
@@ -636,7 +657,7 @@ void InsetInclude::getLabelList(Buffer const & buffer,
                                std::vector<docstring> & list) const
 {
        if (isListings(params())) {
-               InsetListingsParams p(params().getOptions());
+               InsetListingsParams p(to_utf8(params()["lstparams"]));
                string label = p.getParamValue("label");
                if (!label.empty())
                        list.push_back(from_utf8(label));
@@ -814,7 +835,7 @@ void InsetInclude::addToToc(TocList & toclist, Buffer const & buffer,
        ParConstIterator const & pit) const
 {
        if (isListings(params())) {
-               InsetListingsParams p(params().getOptions());
+               InsetListingsParams p(to_utf8(params()["lstparams"]));
                string caption = p.getParamValue("caption");
                if (caption.empty())
                        return;
@@ -845,7 +866,7 @@ void InsetInclude::updateLabels(Buffer const & buffer, ParIterator const &)
        if (childbuffer)
                lyx::updateLabels(*childbuffer, true);
        else if (isListings(params())) {
-               InsetListingsParams const par = params().getOptions();
+               InsetListingsParams const par(to_utf8(params()["lstparams"]));
                if (par.getParamValue("caption").empty())
                        listings_label_.clear();
                else {