]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetListingsParams.h
InsetInfo: enable inset dissolve
[lyx.git] / src / insets / InsetListingsParams.h
index 797cf44d74424363ccf308b211efa35e6e3c874a..ddcca62f23a2b9d32439fa05b2b68199950a7a80 100644 (file)
 #ifndef INSETLISTINGSPARAMS_H
 #define INSETLISTINGSPARAMS_H
 
-#include <vector>
-#include <exception>
-#include "Lexer.h"
-#include "InsetCollapsable.h"
+#include "InsetCaptionable.h"
+
+#include <map>
 
 namespace lyx {
 
@@ -26,7 +25,7 @@ public:
 
        ///
        InsetListingsParams(std::string const &, bool in=false,
-               InsetCollapsable::CollapseStatus s = InsetCollapsable::Open);
+               InsetCollapsible::CollapseStatus s = InsetCollapsible::Open);
 
        /// write parameters to an ostream
        void write(std::ostream &) const;
@@ -35,14 +34,16 @@ public:
        void read(Lexer &);
 
        /// valid parameter string
-       std::string params() const { return params_; }
-       
-       /// add key=value to params_
-       void addParam(std::string const & key, std::string const & value);
+       std::string params(std::string const & sep=",") const;
+
+       /// add key=value to params_. key_=value will be used if key=value already exists
+       /// unless replace=true.
+       void addParam(std::string const & key, std::string const & value,
+                       bool replace = false);
 
        /// add a few parameters
        void addParams(std::string const & par);
-       
+
        /// set params_ with par, throw an exception if par is valid
        void setParams(std::string const & par);
 
@@ -57,53 +58,55 @@ public:
        /// get parameter from encoded string
        void fromEncodedString(std::string const & par);
 
-       /// 
+       ///
        bool isInline() const { return inline_; }
 
        ///
        bool isFloat() const;
 
        ///
-       InsetCollapsable::CollapseStatus status() const { return status_; }
+       InsetCollapsible::CollapseStatus status() const { return status_; }
 
        ///
        void setInline(bool i) { inline_ = i; }
 
+       ///
+       void setMinted(bool use_minted) { package_ = use_minted ? 1 : 0; }
+
+       ///
+       static int package() { return package_; }
+
+       ///
+       bool minted() { return package_ == 1; }
+
        /// get value of option \c param
        std::string getParamValue(std::string const & param) const;
 
        ///
        void clear() { params_.clear(); }
 
+       /// validate parameter, return an error message
+       docstring validate() const;
+
 private:
+       /// listings or minted package (0 or 1, respectively)
+       static int package_;
+
        /// inline or normal listings
        bool inline_;
 
-       /// listing parameters, this will always be a *valid* string
-       /// that can be passed to listing packages.
-       std::string params_;
-
-       /// keys defined in params_ 
-       std::vector<std::string> keys_;
-
-       /// collapsable status
-       InsetCollapsable::CollapseStatus status_;
-};
+       /// Do we have a param with the given \c key?
+       bool hasParam(std::string const & key) const;
+       /// return the value for the given \c key, if avaible, else empty string
+       std::string getValue(std::string const & key) const;
 
+       /// key-value pairs of the parameters
+       // Use a vector of pairs in order to maintain the order of insertion.
+       typedef std::vector<std::pair<std::string, std::string> > keyValuePair;
+       keyValuePair params_;
 
-class invalidParam : public std::exception {
-public:
-       invalidParam(docstring const & details)
-                                       : details_(to_utf8(details))
-       {}
-
-       virtual const char * what() const throw() {
-               return details_.c_str();
-       }
-
-       virtual ~invalidParam() throw() {}
-private:
-       std::string const details_;
+       /// collapsible status
+       InsetCollapsible::CollapseStatus status_;
 };