]> git.lyx.org Git - lyx.git/blob - src/insets/InsetListingsParams.h
Account for old versions of Pygments
[lyx.git] / src / insets / InsetListingsParams.h
1 // -*- C++ -*-
2 /**
3  * \file InsetListingsParams.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Bo Peng
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INSETLISTINGSPARAMS_H
13 #define INSETLISTINGSPARAMS_H
14
15 #include "InsetCaptionable.h"
16
17 #include <map>
18
19 namespace lyx {
20
21 class InsetListingsParams {
22 public:
23         ///
24         InsetListingsParams();
25
26         ///
27         InsetListingsParams(std::string const &, bool in=false,
28                 InsetCollapsable::CollapseStatus s = InsetCollapsable::Open);
29
30         /// write parameters to an ostream
31         void write(std::ostream &) const;
32
33         /// read parameters from an ostream
34         void read(Lexer &);
35
36         /// valid parameter string
37         std::string params(std::string const & sep=",") const;
38
39         /// add key=value to params_. key_=value will be used if key=value already exists
40         /// unless replace=true.
41         void addParam(std::string const & key, std::string const & value, 
42                         bool replace = false);
43
44         /// add a few parameters
45         void addParams(std::string const & par);
46
47         /// set params_ with par, throw an exception if par is valid
48         void setParams(std::string const & par);
49
50         /// generate a parameter string that can be safely save and restored
51         /// by lyx' lexer
52         std::string encodedString() const;
53
54         /// newline (\n) separated parameters. comma can be removed.
55         /// One possible complication is that , may appear in option value.
56         std::string separatedParams(bool keepComma = false) const;
57
58         /// get parameter from encoded string
59         void fromEncodedString(std::string const & par);
60
61         ///
62         bool isInline() const { return inline_; }
63
64         ///
65         bool isFloat() const;
66
67         ///
68         InsetCollapsable::CollapseStatus status() const { return status_; }
69
70         ///
71         void setInline(bool i) { inline_ = i; }
72
73         ///
74         void setMinted(bool use_minted) { package_ = use_minted ? 1 : 0; }
75
76         ///
77         static int package() { return package_; }
78
79         ///
80         bool minted() { return package_ == 1; }
81
82         /// get value of option \c param
83         std::string getParamValue(std::string const & param) const;
84
85         ///
86         void clear() { params_.clear(); }
87         
88         /// validate parameter, return an error message
89         docstring validate() const;
90
91 private:
92         /// listings or minted package (0 or 1, respectively)
93         static int package_;
94
95         /// inline or normal listings
96         bool inline_;
97
98         /// Do we have a param with the given \c key?
99         bool hasParam(std::string const & key) const;
100         /// return the value for the given \c key, if avaible, else empty string
101         std::string getValue(std::string const & key) const;
102
103         /// key-value pairs of the parameters
104         // Use a vector of pairs in order to maintain the order of insertion.
105         typedef std::vector<std::pair<std::string, std::string> > keyValuePair;
106         keyValuePair params_;
107
108         /// collapsable status
109         InsetCollapsable::CollapseStatus status_;
110 };
111
112
113 } // namespace lyx
114
115 #endif