3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
7 * \author Martin Vermeer
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
15 #include "InsetFlex.h"
18 #include "BufferParams.h"
20 #include "FuncRequest.h"
21 #include "FuncStatus.h"
23 #include "TextClass.h"
25 #include "support/gettext.h"
34 InsetFlex::InsetFlex(Buffer * buf, string const & layoutName)
35 : InsetCollapsable(buf), name_(layoutName)
41 InsetFlex::InsetFlex(InsetFlex const & in)
42 : InsetCollapsable(in), name_(in.name_)
46 InsetLayout const & InsetFlex::getLayout() const
49 return DocumentClass::plainInsetLayout();
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_));
59 InsetLayout::InsetDecoration InsetFlex::decoration() const
61 InsetLayout::InsetDecoration const dec = getLayout().decoration();
62 return dec == InsetLayout::DEFAULT ? InsetLayout::CONGLOMERATE : dec;
66 void InsetFlex::write(ostream & os) const
69 (name_.empty() ? "undefined" : name_) << "\n";
70 InsetCollapsable::write(os);
74 bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
75 FuncStatus & flag) const
77 switch (cmd.action()) {
78 case LFUN_INSET_DISSOLVE:
79 if (!cmd.argument().empty()) {
80 InsetLayout const & il = getLayout();
81 InsetLayout::InsetLyXType const type =
82 translateLyXType(to_utf8(cmd.argument()));
83 if (il.lyxtype() == type) {
84 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
85 return InsetCollapsable::getStatus(cur, temp_cmd, flag);
91 return InsetCollapsable::getStatus(cur, cmd, flag);
96 void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
98 switch (cmd.action()) {
99 case LFUN_INSET_DISSOLVE:
100 if (!cmd.argument().empty()) {
101 InsetLayout const & il = getLayout();
102 InsetLayout::InsetLyXType const type =
103 translateLyXType(to_utf8(cmd.argument()));
105 if (il.lyxtype() == type) {
106 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
107 InsetCollapsable::doDispatch(cur, temp_cmd);
114 InsetCollapsable::doDispatch(cur, cmd);