]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlParagraph.C
Add a buffer_path arg to InsetGraphicsMailer's params2string, string2params.
[lyx.git] / src / frontends / controllers / ControlParagraph.C
1 // -*- C++ -*-
2 /**
3  * \file ControlParagraph.C
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Edwin Leuven
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS
11  */
12
13 #include <config.h>
14
15 #include "ControlParagraph.h"
16 #include "ButtonController.h"
17 #include "funcrequest.h"
18 #include "lyxlex.h"
19 #include "ParagraphParameters.h"
20 #include "support/LAssert.h"
21 #include "Lsstream.h"
22
23 using namespace lyx::support;
24
25 ControlParagraph::ControlParagraph(Dialog & parent)
26         : Dialog::Controller(parent), ininset_(false)
27 {}
28
29
30 bool ControlParagraph::initialiseParams(string const & data)
31 {
32         istringstream is(STRCONV(data));
33         LyXLex lex(0,0);
34         lex.setStream(is);
35
36         // Set tri-state flag:
37         // action == 0: show dialog
38         // action == 1: update dialog, accept changes
39         // action == 2: update dialog, do not accept changes
40         int action = 0;
41
42         if (lex.isOK()) {
43                 lex.next();
44                 string const token = lex.getString();
45
46                 if (token == "show") {
47                         action = 0;
48                 } else if (token == "update") {
49                         lex.next();
50                         bool const accept = lex.getBool();
51                         action = accept ? 1 : 2;
52                 } else if (!token.empty()) {
53                         // Unrecognised token
54                         return false;
55                 }
56         }
57
58         ParagraphParameters * tmp = new ParagraphParameters;
59         tmp->read(lex);
60
61         // For now, only reset the params on "show".
62         // Don't bother checking if the params are different on "update"
63         if (action == 0) {
64                 params_.reset(tmp);
65         } else {
66                 delete tmp;
67         }
68
69         // Read the rest of the data irrespective of "show" or "update"
70         int nset = 0;
71         while (lex.isOK()) {
72                 lex.next();
73                 string const token = lex.getString();
74
75                 if (token.empty())
76                         continue;
77
78                 int Int = 0;
79                 if (token == "\\alignpossible" ||
80                     token == "\\aligndefault" ||
81                     token == "\\ininset") {
82                         lex.next();
83                         Int = lex.getInteger();
84                 } else {
85                         // Unrecognised token
86                         return false;
87                 }
88
89                 ++nset;
90
91                 if (token == "\\alignpossible") {
92                         alignpossible_ = static_cast<LyXAlignment>(Int);
93                 } else if (token == "\\aligndefault") {
94                         aligndefault_ = static_cast<LyXAlignment>(Int);
95                 } else {
96                         ininset_ = Int;
97                 }
98         }
99         if (nset != 3) {
100                 return false;
101         }
102
103         // If "update", then set the activation status of the button controller
104         if (action > 0) {
105                 bool const accept = action == 1;
106                 dialog().bc().valid(accept);
107         }
108         return true;
109 }
110
111
112 void ControlParagraph::clearParams()
113 {
114         params_.reset();
115 }
116
117
118 void ControlParagraph::dispatchParams()
119 {
120         ostringstream data;
121         params().write(data);
122         FuncRequest const fr(LFUN_PARAGRAPH_APPLY, STRCONV(data.str()));
123         kernel().dispatch(fr);
124 }
125
126
127 ParagraphParameters & ControlParagraph::params()
128 {
129         Assert(params_.get());
130         return *params_;
131 }
132
133
134 ParagraphParameters const & ControlParagraph::params() const
135 {
136         Assert(params_.get());
137         return *params_;
138 }
139
140
141 bool ControlParagraph::inInset() const
142 {
143         return ininset_;
144 }
145
146
147 LyXAlignment ControlParagraph::alignPossible() const
148 {
149         return alignpossible_;
150 }
151
152
153 LyXAlignment ControlParagraph::alignDefault() const
154 {
155         return aligndefault_;
156 }