]> git.lyx.org Git - lyx.git/blob - src/mathed/command_inset.C
f8a03c2e382e4f34962bbbb2434a3bbca9d1aa74
[lyx.git] / src / mathed / command_inset.C
1
2 #include "command_inset.h"
3 #include "math_mathmlstream.h"
4 #include "funcrequest.h"
5 #include "Lsstream.h"
6
7
8 CommandInset::CommandInset(string const & data)
9 {
10         lock_ = true;
11
12         string::size_type idx0 = data.find("|++|");
13         name_ = data.substr(0, idx0);
14         if (idx0 == string::npos)
15                 return;
16         idx0 += 4;
17         string::size_type idx1 = data.find("|++|", idx0);
18         cell(0) = asArray(data.substr(idx0, idx1 - idx0));
19         if (idx1 == string::npos)
20                 return;
21         cell(1) = asArray(data.substr(idx1 + 4));
22 }
23
24
25 MathInset * CommandInset::clone() const
26 {
27         return new CommandInset(*this);
28 }
29
30
31 dispatch_result
32 CommandInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
33 {
34         switch (cmd.action) {
35                 default:
36                         return ButtonInset::dispatch(cmd, idx, pos);
37         }
38         return UNDISPATCHED;
39 }
40
41
42 void CommandInset::write(WriteStream & os) const
43 {
44         os << '\\' << name_.c_str();
45         if (cell(1).size())
46                 os << '[' << cell(1) << ']';
47         os << '{' << cell(0) << '}';
48 }
49
50
51 string CommandInset::screenLabel() const
52 {
53         return name_;
54 }
55
56
57 string const CommandInset::createDialogStr(string const & name) const
58 {
59         ostringstream data;
60         data << name << " LatexCommand ";
61         WriteStream wsdata(data);
62         write(wsdata);
63         wsdata << "\n\\end_inset\n\n";
64
65         return data.str();
66 }
67
68