]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFlex.cpp
Add Nomenclature to the TOC.
[lyx.git] / src / insets / InsetFlex.cpp
1 /**
2  * \file InsetFlex.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Martin Vermeer
8  * \author Jürgen Spitzmüller
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "InsetFlex.h"
16
17 #include "Buffer.h"
18 #include "BufferParams.h"
19 #include "Cursor.h"
20 #include "FuncRequest.h"
21 #include "FuncStatus.h"
22 #include "Lexer.h"
23 #include "TextClass.h"
24
25 #include "support/gettext.h"
26
27 #include <ostream>
28
29 using namespace std;
30
31 namespace lyx {
32
33
34 InsetFlex::InsetFlex(Buffer * buf, string const & layoutName)
35         : InsetCollapsable(buf), name_(layoutName)
36 {}
37
38
39 InsetFlex::InsetFlex(InsetFlex const & in)
40         : InsetCollapsable(in), name_(in.name_)
41 {}
42
43
44 // special code for InsetFlex when there is not the explicit Flex:: prefix
45 InsetLayout const & InsetFlex::getLayout() const
46 {
47         if (!buffer_)
48                 return DocumentClass::plainInsetLayout();
49
50         DocumentClass const & dc = buffer().params().documentClass();
51         docstring const dname = from_utf8(name_); 
52         if (dc.hasInsetLayout(dname))
53                 return dc.insetLayout(dname);
54         return dc.insetLayout(from_utf8("Flex:" + name_));
55 }
56
57
58 bool InsetFlex::resetFontEdit() const
59 {
60         if (getLayout().resetsFont())
61                 return true;
62         return InsetCollapsable::resetFontEdit();
63 }
64
65
66 InsetLayout::InsetDecoration InsetFlex::decoration() const
67 {
68         InsetLayout::InsetDecoration const dec = getLayout().decoration();
69         return dec == InsetLayout::DEFAULT ? InsetLayout::CONGLOMERATE : dec;
70 }
71
72
73 void InsetFlex::write(ostream & os) const
74 {
75         os << "Flex " <<
76                 (name_.empty() ? "undefined" : name_) << "\n";
77         InsetCollapsable::write(os);
78 }
79
80
81 bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
82                 FuncStatus & flag) const
83 {
84         switch (cmd.action()) {
85         case LFUN_INSET_DISSOLVE:
86                 if (!cmd.argument().empty()) {
87                         InsetLayout const & il = getLayout();
88                         InsetLayout::InsetLyXType const type = 
89                                 translateLyXType(to_utf8(cmd.argument()));
90                         if (il.lyxtype() == type) {
91                                 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
92                                 return InsetCollapsable::getStatus(cur, temp_cmd, flag);
93                         } else
94                                 return false;
95                 }
96                 // fall-through
97         default:
98                 return InsetCollapsable::getStatus(cur, cmd, flag);
99         }
100 }
101
102
103 void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
104 {
105         switch (cmd.action()) {
106         case LFUN_INSET_DISSOLVE:
107                 if (!cmd.argument().empty()) {
108                         InsetLayout const & il = getLayout();
109                         InsetLayout::InsetLyXType const type = 
110                                 translateLyXType(to_utf8(cmd.argument()));
111                         
112                         if (il.lyxtype() == type) {
113                                 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
114                                 InsetCollapsable::doDispatch(cur, temp_cmd);
115                         } else
116                                 cur.undispatched();
117                         break;
118                 }
119                 // fall-through
120         default:
121                 InsetCollapsable::doDispatch(cur, cmd);
122                 break;
123         }
124 }
125
126
127 } // namespace lyx