mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Transfer some code from InsetFlex to InsetCollapsable. Add some safeguards and FIXMEs.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21400 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
074dee47c3
commit
dc2a6f95ff
@ -444,27 +444,28 @@ void switchBetweenClasses(TextClassPtr const & c1,
|
||||
// character styles
|
||||
InsetIterator const i_end = inset_iterator_end(in);
|
||||
for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) {
|
||||
if (it->lyxCode() == FLEX_CODE) {
|
||||
InsetFlex & inset =
|
||||
static_cast<InsetFlex &>(*it);
|
||||
string const name = inset.params().name;
|
||||
InsetLayout const & il =
|
||||
tclass2.insetlayout(from_utf8(name));
|
||||
inset.setLayout(il);
|
||||
if (il.labelstring == from_utf8("UNDEFINED")) {
|
||||
// The flex inset is undefined in tclass2
|
||||
docstring const s = bformat(_(
|
||||
"Flex inset %1$s is "
|
||||
"undefined because of class "
|
||||
"conversion from\n%2$s to %3$s"),
|
||||
from_utf8(name), from_utf8(tclass1.name()),
|
||||
from_utf8(tclass2.name()));
|
||||
// To warn the user that something had to be done.
|
||||
errorlist.push_back(ErrorItem(
|
||||
_("Undefined flex inset"),
|
||||
s, it.paragraph().id(), it.pos(), it.pos() + 1));
|
||||
}
|
||||
}
|
||||
InsetCollapsable * inset = it->asInsetCollapsable();
|
||||
if (!inset)
|
||||
continue;
|
||||
if (inset->lyxCode() != FLEX_CODE)
|
||||
// FIXME: Should we verify all InsetCollapsable?
|
||||
continue;
|
||||
docstring const name = inset->name();
|
||||
InsetLayout const & il = tclass2.insetlayout(name);
|
||||
inset->setLayout(il);
|
||||
if (il.labelstring != from_utf8("UNDEFINED"))
|
||||
continue;
|
||||
// The flex inset is undefined in tclass2
|
||||
docstring const s = bformat(_(
|
||||
"Flex inset %1$s is "
|
||||
"undefined because of class "
|
||||
"conversion from\n%2$s to %3$s"),
|
||||
name, from_utf8(tclass1.name()),
|
||||
from_utf8(tclass2.name()));
|
||||
// To warn the user that something had to be done.
|
||||
errorlist.push_back(ErrorItem(
|
||||
_("Undefined flex inset"),
|
||||
s, it.paragraph().id(), it.pos(), it.pos() + 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,9 +73,9 @@ InsetCollapsable::Geometry InsetCollapsable::geometry() const
|
||||
}
|
||||
|
||||
|
||||
InsetCollapsable::InsetCollapsable
|
||||
(BufferParams const & bp, CollapseStatus status)
|
||||
: InsetText(bp), status_(status),
|
||||
InsetCollapsable::InsetCollapsable(BufferParams const & bp,
|
||||
CollapseStatus status, InsetLayout const * il)
|
||||
: InsetText(bp), layout_(il), status_(status),
|
||||
openinlined_(false), autoOpen_(false), mouse_hover_(false)
|
||||
{
|
||||
setAutoBreakRows(true);
|
||||
@ -102,7 +102,13 @@ InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
|
||||
|
||||
void InsetCollapsable::setLayout(BufferParams const & bp)
|
||||
{
|
||||
layout_ = &getLayout(bp);
|
||||
setLayout(bp.getTextClass().insetlayout(name()));
|
||||
}
|
||||
|
||||
|
||||
void InsetCollapsable::setLayout(InsetLayout const & il)
|
||||
{
|
||||
layout_ = &il;
|
||||
labelstring_ = layout_->labelstring;
|
||||
|
||||
setButtonLabel();
|
||||
@ -156,11 +162,11 @@ void InsetCollapsable::read(Buffer const & buf, Lexer & lex)
|
||||
}
|
||||
InsetText::read(buf, lex);
|
||||
|
||||
setLayout(buf.params());
|
||||
|
||||
if (!token_found)
|
||||
status_ = isOpen() ? Open : Collapsed;
|
||||
|
||||
setLayout(buf.params());
|
||||
|
||||
// Force default font, if so requested
|
||||
// This avoids paragraphs in buffer language that would have a
|
||||
// foreign language after a document language change, and it ensures
|
||||
@ -174,6 +180,7 @@ void InsetCollapsable::read(Buffer const & buf, Lexer & lex)
|
||||
|
||||
Dimension InsetCollapsable::dimensionCollapsed() const
|
||||
{
|
||||
BOOST_ASSERT(layout_);
|
||||
Dimension dim;
|
||||
theFontMetrics(layout_->labelfont).buttonText(
|
||||
labelstring_, dim.wid, dim.asc, dim.des);
|
||||
@ -183,6 +190,8 @@ Dimension InsetCollapsable::dimensionCollapsed() const
|
||||
|
||||
void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
{
|
||||
BOOST_ASSERT(layout_);
|
||||
|
||||
autoOpen_ = mi.base.bv->cursor().isInside(this);
|
||||
|
||||
FontInfo tmpfont = mi.base.font;
|
||||
@ -247,6 +256,8 @@ bool InsetCollapsable::setMouseHover(bool mouse_hover)
|
||||
|
||||
void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
BOOST_ASSERT(layout_);
|
||||
|
||||
autoOpen_ = pi.base.bv->cursor().isInside(this);
|
||||
ColorCode const old_color = pi.background_color;
|
||||
pi.background_color = backgroundColor();
|
||||
@ -574,7 +585,7 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
}
|
||||
|
||||
default:
|
||||
if (layout_->forceltr) {
|
||||
if (layout_ && layout_->forceltr) {
|
||||
// Force any new text to latex_language
|
||||
// FIXME: This should only be necessary in constructor, but
|
||||
// new paragraphs that are created by pressing enter at the
|
||||
@ -764,13 +775,14 @@ docstring InsetCollapsable::floatName(string const & type, BufferParams const &
|
||||
|
||||
InsetCollapsable::Decoration InsetCollapsable::decoration() const
|
||||
{
|
||||
if (layout_->decoration == "classic")
|
||||
if (!layout_ || layout_->decoration == "classic")
|
||||
return Classic;
|
||||
if (layout_->decoration == "minimalistic")
|
||||
return Minimalistic;
|
||||
if (layout_->decoration == "conglomerate")
|
||||
return Conglomerate;
|
||||
if (name() == from_ascii("Flex"))
|
||||
if (lyxCode() == FLEX_CODE)
|
||||
// FIXME: Is this really necessary?
|
||||
return Conglomerate;
|
||||
return Classic;
|
||||
}
|
||||
@ -779,6 +791,12 @@ InsetCollapsable::Decoration InsetCollapsable::decoration() const
|
||||
int InsetCollapsable::latex(Buffer const & buf, odocstream & os,
|
||||
OutputParams const & runparams) const
|
||||
{
|
||||
// FIXME: What should we do layout_ is 0?
|
||||
// 1) assert
|
||||
// 2) through an error
|
||||
if (!layout_)
|
||||
return 0;
|
||||
|
||||
// This implements the standard way of handling the LaTeX output of
|
||||
// a collapsable inset, either a command or an environment. Standard
|
||||
// collapsable insets should not redefine this, non-standard ones may
|
||||
@ -818,6 +836,9 @@ int InsetCollapsable::latex(Buffer const & buf, odocstream & os,
|
||||
|
||||
void InsetCollapsable::validate(LaTeXFeatures & features) const
|
||||
{
|
||||
if (!layout_)
|
||||
return;
|
||||
|
||||
// Force inclusion of preamble snippet in layout file
|
||||
features.require(layout_->name);
|
||||
InsetText::validate(features);
|
||||
|
@ -38,15 +38,23 @@ namespace frontend { class Painter; }
|
||||
class InsetCollapsable : public InsetText {
|
||||
public:
|
||||
///
|
||||
InsetCollapsable(BufferParams const &, CollapseStatus status = Inset::Open);
|
||||
InsetCollapsable(
|
||||
BufferParams const &,
|
||||
CollapseStatus status = Inset::Open,
|
||||
InsetLayout const * il = 0
|
||||
);
|
||||
///
|
||||
InsetCollapsable(InsetCollapsable const & rhs);
|
||||
|
||||
InsetCollapsable * asInsetCollapsable() { return this; }
|
||||
InsetCollapsable const * asInsetCollapsable() const { return this; }
|
||||
docstring name() const { return from_ascii("Collapsable"); }
|
||||
InsetLayout const & getLayout(BufferParams const &) const
|
||||
{ return *layout_; }
|
||||
///
|
||||
void setLayout(BufferParams const &);
|
||||
/// (Re-)set the character style parameters from \p il
|
||||
void setLayout(InsetLayout const & il);
|
||||
///
|
||||
void read(Buffer const &, Lexer &);
|
||||
///
|
||||
|
@ -45,10 +45,9 @@ using std::ostream;
|
||||
|
||||
InsetFlex::InsetFlex(BufferParams const & bp,
|
||||
InsetLayout const & il)
|
||||
: InsetCollapsable(bp, Collapsed)
|
||||
: InsetCollapsable(bp, Collapsed, &il)
|
||||
{
|
||||
params_.name = il.name;
|
||||
setLayout(il);
|
||||
}
|
||||
|
||||
|
||||
@ -69,12 +68,6 @@ bool InsetFlex::undefined() const
|
||||
}
|
||||
|
||||
|
||||
void InsetFlex::setLayout(InsetLayout const & il)
|
||||
{
|
||||
layout_ = &il;
|
||||
}
|
||||
|
||||
|
||||
docstring const InsetFlex::editMessage() const
|
||||
{
|
||||
return _("Opened Flex Inset");
|
||||
|
@ -39,15 +39,11 @@ public:
|
||||
///
|
||||
InsetFlex(BufferParams const &, InsetLayout const &);
|
||||
///
|
||||
docstring name() const { return from_ascii("Flex"); }
|
||||
///
|
||||
InsetLayout const & getLayout(BufferParams const &) const
|
||||
{ return *layout_; }
|
||||
docstring name() const { return from_utf8(params_.name); }
|
||||
|
||||
/// Is this character style defined in the document's textclass?
|
||||
/// May be wrong after textclass change or paste from another document
|
||||
bool undefined() const;
|
||||
/// (Re-)set the character style parameters from \p il
|
||||
void setLayout(InsetLayout const & il);
|
||||
///
|
||||
virtual docstring const editMessage() const;
|
||||
///
|
||||
|
@ -28,6 +28,7 @@ class FontInfo
|
||||
public:
|
||||
FontInfo() {}
|
||||
FontInfo & realize(FontInfo const &) { return *this; }
|
||||
void setColor(int) {}
|
||||
bool resolved() const { return true; }
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user