2003-11-12 14:38:26 +00:00
|
|
|
/**
|
2007-09-05 15:29:04 +00:00
|
|
|
* \file InsetFlex.cpp
|
2003-11-12 14:38:26 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
* \author Martin Vermeer
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
2003-11-12 14:38:26 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-09-05 15:29:04 +00:00
|
|
|
#include "InsetFlex.h"
|
2003-11-12 14:38:26 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
2009-10-26 23:49:43 +00:00
|
|
|
#include "Cursor.h"
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "FuncStatus.h"
|
2013-05-23 20:36:59 +00:00
|
|
|
#include "Language.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2013-05-23 20:36:59 +00:00
|
|
|
#include "ParIterator.h"
|
2010-10-31 01:04:03 +00:00
|
|
|
#include "TextClass.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
|
|
|
|
#include "support/gettext.h"
|
2014-12-08 08:06:41 +00:00
|
|
|
#include "support/lstrings.h"
|
2003-11-12 14:38:26 +00:00
|
|
|
|
2008-04-09 09:36:08 +00:00
|
|
|
#include <ostream>
|
2003-11-12 14:38:26 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetFlex::InsetFlex(Buffer * buf, string const & layoutName)
|
2017-10-16 08:12:21 +00:00
|
|
|
: InsetCollapsible(buf), name_(layoutName)
|
2012-12-08 08:35:52 +00:00
|
|
|
{}
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
|
|
|
2007-09-05 15:29:04 +00:00
|
|
|
InsetFlex::InsetFlex(InsetFlex const & in)
|
2017-10-16 08:12:21 +00:00
|
|
|
: InsetCollapsible(in), name_(in.name_)
|
2007-11-03 00:56:48 +00:00
|
|
|
{}
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
|
|
|
2012-04-22 10:32:41 +00:00
|
|
|
// special code for InsetFlex when there is not the explicit Flex:: prefix
|
2010-10-12 15:37:02 +00:00
|
|
|
InsetLayout const & InsetFlex::getLayout() const
|
|
|
|
{
|
2010-11-26 16:45:58 +00:00
|
|
|
if (!buffer_)
|
|
|
|
return DocumentClass::plainInsetLayout();
|
|
|
|
|
2010-10-12 15:37:02 +00:00
|
|
|
DocumentClass const & dc = buffer().params().documentClass();
|
2017-07-03 17:53:14 +00:00
|
|
|
docstring const dname = from_utf8(name_);
|
2010-10-12 15:37:02 +00:00
|
|
|
if (dc.hasInsetLayout(dname))
|
|
|
|
return dc.insetLayout(dname);
|
|
|
|
return dc.insetLayout(from_utf8("Flex:" + name_));
|
2010-10-12 14:46:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-13 14:06:05 +00:00
|
|
|
InsetLayout::InsetDecoration InsetFlex::decoration() const
|
|
|
|
{
|
|
|
|
InsetLayout::InsetDecoration const dec = getLayout().decoration();
|
|
|
|
return dec == InsetLayout::DEFAULT ? InsetLayout::CONGLOMERATE : dec;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetFlex::write(ostream & os) const
|
2003-11-12 14:38:26 +00:00
|
|
|
{
|
2014-12-08 08:06:41 +00:00
|
|
|
os << "Flex ";
|
2016-04-11 16:33:14 +00:00
|
|
|
string name;
|
2014-12-08 08:06:41 +00:00
|
|
|
if (name_.empty())
|
2016-04-11 16:33:14 +00:00
|
|
|
name = "undefined";
|
2014-12-08 08:06:41 +00:00
|
|
|
else {
|
2016-04-11 16:33:14 +00:00
|
|
|
InsetLayout const & il = getLayout();
|
|
|
|
// use il.name(), since this resolves obsoleted InsetLayout names
|
|
|
|
if (il.name() == "undefined")
|
|
|
|
// This is the name of the plain_insetlayout_. We assume that the
|
|
|
|
// name resolution has failed.
|
|
|
|
name = name_;
|
|
|
|
else {
|
|
|
|
name = to_utf8(il.name());
|
|
|
|
// Remove the "Flex:" prefix, if it is present
|
|
|
|
if (support::prefixIs(name, "Flex:"))
|
|
|
|
name = support::split(name, ':');
|
|
|
|
}
|
2014-12-08 08:06:41 +00:00
|
|
|
}
|
2016-04-11 16:33:14 +00:00
|
|
|
os << name << "\n";
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::write(os);
|
2003-11-12 14:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-26 23:49:43 +00:00
|
|
|
bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2009-10-26 23:49:43 +00:00
|
|
|
case LFUN_INSET_DISSOLVE:
|
|
|
|
if (!cmd.argument().empty()) {
|
|
|
|
InsetLayout const & il = getLayout();
|
2017-07-03 17:53:14 +00:00
|
|
|
InsetLayout::InsetLyXType const type =
|
2009-10-26 23:49:43 +00:00
|
|
|
translateLyXType(to_utf8(cmd.argument()));
|
2019-09-11 13:49:50 +00:00
|
|
|
if (il.lyxtype() == type
|
|
|
|
|| (il.name() == DocumentClass::plainInsetLayout().name()
|
|
|
|
&& type == InsetLayout::CHARSTYLE)) {
|
2009-10-26 23:49:43 +00:00
|
|
|
FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
|
2017-10-16 08:12:21 +00:00
|
|
|
return InsetCollapsible::getStatus(cur, temp_cmd, flag);
|
2009-10-26 23:49:43 +00:00
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// fall-through
|
|
|
|
default:
|
2017-10-16 08:12:21 +00:00
|
|
|
return InsetCollapsible::getStatus(cur, cmd, flag);
|
2009-10-26 23:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2009-10-26 23:49:43 +00:00
|
|
|
case LFUN_INSET_DISSOLVE:
|
|
|
|
if (!cmd.argument().empty()) {
|
|
|
|
InsetLayout const & il = getLayout();
|
2017-07-03 17:53:14 +00:00
|
|
|
InsetLayout::InsetLyXType const type =
|
2009-10-26 23:49:43 +00:00
|
|
|
translateLyXType(to_utf8(cmd.argument()));
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2019-09-11 13:49:50 +00:00
|
|
|
if (il.lyxtype() == type
|
|
|
|
|| (il.name() == DocumentClass::plainInsetLayout().name()
|
|
|
|
&& type == InsetLayout::CHARSTYLE)) {
|
2009-10-26 23:49:43 +00:00
|
|
|
FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::doDispatch(cur, temp_cmd);
|
2009-10-26 23:49:43 +00:00
|
|
|
} else
|
|
|
|
cur.undispatched();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fall-through
|
|
|
|
default:
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::doDispatch(cur, cmd);
|
2009-10-26 23:49:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-06 12:23:01 +00:00
|
|
|
void InsetFlex::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted)
|
2013-05-23 20:36:59 +00:00
|
|
|
{
|
|
|
|
BufferParams const & bp = buffer().masterBuffer()->params();
|
|
|
|
InsetLayout const & il = getLayout();
|
|
|
|
docstring custom_label = translateIfPossible(il.labelstring());
|
2013-05-28 13:41:44 +00:00
|
|
|
|
|
|
|
Counters & cnts = bp.documentClass().counters();
|
|
|
|
docstring const & count = il.counter();
|
|
|
|
bool const have_counter = cnts.hasCounter(count);
|
|
|
|
if (have_counter) {
|
2018-05-03 03:56:41 +00:00
|
|
|
Paragraph const & par = it.paragraph();
|
|
|
|
if (!par.isDeleted(it.pos())) {
|
|
|
|
cnts.step(count, utype);
|
|
|
|
custom_label += ' ' +
|
|
|
|
cnts.theCounter(count, it.paragraph().getParLanguage(bp)->code());
|
|
|
|
} else
|
|
|
|
custom_label += ' ' + from_ascii("#");
|
2013-05-28 13:41:44 +00:00
|
|
|
}
|
2013-05-23 20:36:59 +00:00
|
|
|
setLabel(custom_label);
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2013-05-28 13:41:44 +00:00
|
|
|
bool const save_counter = have_counter && utype == OutputUpdate;
|
|
|
|
if (save_counter) {
|
|
|
|
// we assume the counter is local to this inset
|
|
|
|
// if this turns out to be wrong in some case, we will
|
|
|
|
// need a layout flag
|
|
|
|
cnts.saveLastCounter();
|
|
|
|
}
|
2020-03-06 12:23:01 +00:00
|
|
|
InsetCollapsible::updateBuffer(it, utype, deleted);
|
2013-05-28 13:41:44 +00:00
|
|
|
if (save_counter)
|
2013-05-23 20:36:59 +00:00
|
|
|
cnts.restoreLastCounter();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|