]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFlex.cpp
Fix wrongly copy-pasted entries in SpellcheckerUi.ui
[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         status_= Collapsed;
38 }
39
40
41 InsetFlex::InsetFlex(InsetFlex const & in)
42         : InsetCollapsable(in), name_(in.name_)
43 {}
44
45
46 InsetLayout const & InsetFlex::getLayout() const
47 {
48         if (!buffer_)
49                 return DocumentClass::plainInsetLayout();
50
51         DocumentClass const & dc = buffer().params().documentClass();
52         docstring const dname = from_utf8(name_); 
53         if (dc.hasInsetLayout(dname))
54                 return dc.insetLayout(dname);
55         return dc.insetLayout(from_utf8("Flex:" + name_));
56 }
57
58
59 bool InsetFlex::resetFontEdit() const
60 {
61         if (getLayout().resetsFont())
62                 return true;
63         return InsetCollapsable::resetFontEdit();
64 }
65
66
67 InsetLayout::InsetDecoration InsetFlex::decoration() const
68 {
69         InsetLayout::InsetDecoration const dec = getLayout().decoration();
70         return dec == InsetLayout::DEFAULT ? InsetLayout::CONGLOMERATE : dec;
71 }
72
73
74 void InsetFlex::write(ostream & os) const
75 {
76         os << "Flex " <<
77                 (name_.empty() ? "undefined" : name_) << "\n";
78         InsetCollapsable::write(os);
79 }
80
81
82 bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
83                 FuncStatus & flag) const
84 {
85         switch (cmd.action()) {
86         case LFUN_INSET_DISSOLVE:
87                 if (!cmd.argument().empty()) {
88                         InsetLayout const & il = getLayout();
89                         InsetLayout::InsetLyXType const type = 
90                                 translateLyXType(to_utf8(cmd.argument()));
91                         if (il.lyxtype() == type) {
92                                 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
93                                 return InsetCollapsable::getStatus(cur, temp_cmd, flag);
94                         } else
95                                 return false;
96                 }
97                 // fall-through
98         default:
99                 return InsetCollapsable::getStatus(cur, cmd, flag);
100         }
101 }
102
103
104 void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
105 {
106         switch (cmd.action()) {
107         case LFUN_INSET_DISSOLVE:
108                 if (!cmd.argument().empty()) {
109                         InsetLayout const & il = getLayout();
110                         InsetLayout::InsetLyXType const type = 
111                                 translateLyXType(to_utf8(cmd.argument()));
112                         
113                         if (il.lyxtype() == type) {
114                                 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
115                                 InsetCollapsable::doDispatch(cur, temp_cmd);
116                         } else
117                                 cur.undispatched();
118                         break;
119                 }
120                 // fall-through
121         default:
122                 InsetCollapsable::doDispatch(cur, cmd);
123                 break;
124         }
125 }
126
127
128 } // namespace lyx