]> git.lyx.org Git - features.git/blob - src/insets/InsetListingsParams.h
Add support for listings package. Two listings command \lstinline, \lstinputlisting...
[features.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 <vector>
16 #include <exception>
17 #include "Lexer.h"
18 #include "InsetCollapsable.h"
19
20 namespace lyx {
21
22 class InsetListingsParams {
23 public:
24         ///
25         InsetListingsParams();
26
27         ///
28         InsetListingsParams(std::string const &, bool in=false,
29                 InsetCollapsable::CollapseStatus s = InsetCollapsable::Open);
30
31         /// write parameters to an ostream
32         void write(std::ostream &) const;
33
34         /// read parameters from an ostream
35         void read(Lexer &);
36
37         /// valid parameter string
38         std::string params() const { return params_; }
39         
40         /// add key=value to params_
41         void addParam(std::string const & key, std::string const & value);
42         
43         /// set params_ with par, throw an exception if par is valid
44         void setParams(std::string const & par);
45
46         /// generate a parameter string that can be safely save and restored
47         /// by lyx' lexer
48         std::string encodedString() const;
49
50         /// newline (\n) separated parameters. comma can be removed.
51         /// One possible complication is that , may appear in option value.
52         std::string separatedParams(bool keepComma = false) const;
53
54         /// get parameter from encoded string
55         void fromEncodedString(std::string const & par);
56
57         /// 
58         bool isInline() const { return inline_; }
59
60         ///
61         InsetCollapsable::CollapseStatus status() const { return status_; }
62
63         ///
64         void setInline(bool i) { inline_ = i; }
65
66         ///
67         void clear() { params_.clear(); }
68
69 private:
70         /// inline or normal listings
71         bool inline_;
72
73         /// listing parameters, this will always be a *valid* string
74         /// that can be passed to listing packages.
75         std::string params_;
76
77         /// collapsable status
78         InsetCollapsable::CollapseStatus status_;
79 };
80
81
82 class invalidParam : public std::exception {
83 public:
84         invalidParam(std::string const & details) :
85                 details_(details)
86         {}
87
88         virtual const char * what() const throw() {
89                 return details_.c_str();
90         }
91
92         virtual ~invalidParam() throw() {}
93 private:
94         std::string const details_;
95 };
96
97
98 } // namespace lyx
99
100 #endif