LyX file-format changes
-----------------------
+2007-08-17 Martin Vermeer
+
+ * format incremented to 280: the show_label parameter
+ is depreciated in favour of (Collapsable) status.
+
2007-08-17 Martin Vermeer
* format incremented to 279: CharStyle names are now
("1_3", [221], generate_minor_versions("1.3" , 7)),
("1_4", range(222,246), generate_minor_versions("1.4" , 5)),
("1_5", range(246,277), generate_minor_versions("1.5" , 1)),
- ("1_6", range(277,280), generate_minor_versions("1.6" , 0))]
+ ("1_6", range(277,281), generate_minor_versions("1.6" , 0))]
def formats_list():
i += 1
+def axe_show_label(document):
+ i = 0
+ while True:
+ i = find_token(document.body, "\\begin_inset CharStyle", i)
+ if i == -1:
+ return
+ if document.body[i + 1].find("show_label") != -1:
+ if document.body[i + 1].find("true") != -1:
+ document.body[i + 1] = "status open"
+ del document.body[ i + 2]
+ else:
+ if document.body[i + 1].find("false") != -1:
+ document.body[i + 1] = "status collapsed"
+ del document.body[ i + 2]
+ else:
+ document.warning("Malformed LyX document: show_label neither false nor true.")
+ else:
+ document.warning("Malformed LyX document: show_label missing in CharStyle.")
+
+ i += 1
+
+
+def revert_show_label(document):
+ i = 0
+ while True:
+ i = find_token(document.body, "\\begin_inset CharStyle", i)
+ if i == -1:
+ return
+ if document.body[i + 1].find("status open") != -1:
+ document.body.insert(i + 1, "show_label true")
+ else:
+ if document.body[i + 1].find("status collapsed") != -1:
+ document.body.insert(i + 1, "show_label false")
+ else:
+ document.warning("Malformed LyX document: no legal status line in CharStyle.")
+ i += 1
+
+
+
##
# Conversion hub
#
convert = [
[277, [fix_wrong_tables]],
[278, [close_begin_deeper]],
- [279, [long_charstyle_names]]
+ [279, [long_charstyle_names]],
+ [280, [axe_show_label]]
]
revert = [
+ [279, [revert_show_label]],
[278, [revert_long_charstyle_names]],
[277, []],
[276, []]
namespace {
-int const LYX_FORMAT = 279;
+int const LYX_FORMAT = 280;
} // namespace anon
void InsetCharStyle::init()
-{
- setDrawFrame(false);
-}
+{}
InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s)
- : InsetCollapsable(bp)
+ : InsetCollapsable(bp, Collapsed)
{
params_.type = s;
setUndefined();
InsetCharStyle::InsetCharStyle(BufferParams const & bp,
CharStyles::iterator cs)
- : InsetCollapsable(bp)
+ : InsetCollapsable(bp, Collapsed)
{
params_.type = cs->name;
setDefined(cs);
params_.font = Font(Font::ALL_INHERIT);
params_.labelfont = Font(Font::ALL_INHERIT);
params_.labelfont.setColor(Color::error);
- params_.show_label = true;
}
params_.latexparam = cs->latexparam;
params_.font = cs->font;
params_.labelfont = cs->labelfont;
- params_.show_label = true;
}
mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
InsetText::metrics(mi, dim);
mi.base.font = tmpfont;
- if (params_.show_label) {
+ if (status() == Open) {
// consider width of the inset label
Font font(params_.labelfont);
font.realize(Font(Font::ALL_SANE));
dim.des += TEXT_TO_INSET_OFFSET;
dim.wid += 2 * TEXT_TO_INSET_OFFSET;
mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
- if (params_.show_label)
+ if (status() == Open)
dim.des += ascent();
- bool const changed = dim_ != dim;
+ else {
+ dim.des -= 3;
+ dim.asc -= 3;
+ }
+ bool const changed = dim_ != dim;
dim_ = dim;
return changed;
}
getDrawFont(pi.base.font);
// I don't understand why the above .reduce and .realize aren't
//needed, or even wanted, here. It just works. -- MV 10.04.2005
- InsetText::draw(pi, x + TEXT_TO_INSET_OFFSET, y);
+ InsetCollapsable::draw(pi, x, y);
pi.base.font = tmpfont;
int desc = InsetText::descent();
- if (params_.show_label)
+ if (status() == Open)
desc -= ascent();
+ else
+ desc -= 3;
pi.pain.line(x, y + desc - 4, x, y + desc, params_.labelfont.color());
pi.pain.line(x, y + desc, x + dim_.wid - 3, y + desc,
params_.labelfont.color());
// the name of the charstyle. Can be toggled.
- if (params_.show_label) {
+ if (status() == Open) {
Font font(params_.labelfont);
font.realize(Font(Font::ALL_SANE));
font.decSize();
s, font, Color::none, Color::none);
}
- // a visual clue when the cursor is inside the inset
+ // a visual cue when the cursor is inside the inset
Cursor & cur = pi.base.bv->cursor();
if (cur.isInside(this)) {
y -= ascent();
+ y += 3;
pi.pain.line(x, y + 4, x, y, params_.labelfont.color());
pi.pain.line(x + 4, y, x, y, params_.labelfont.color());
pi.pain.line(x + dim_.wid - 3, y + 4, x + dim_.wid - 3, y,
case LFUN_MOUSE_RELEASE:
if (cmd.button() == mouse_button::button3)
- params_.show_label = !params_.show_label;
+ if (status() == Open)
+ setStatus(cur, Collapsed);
+ else
+ setStatus(cur, Open);
else
InsetCollapsable::doDispatch(cur, cmd);
break;
case LFUN_INSET_TOGGLE:
if (cmd.argument() == "open")
- params_.show_label = true;
+ setStatus(cur, Open);
else if (cmd.argument() == "close")
- params_.show_label = false;
+ setStatus(cur, Collapsed);
else if (cmd.argument() == "toggle" || cmd.argument().empty())
- params_.show_label = !params_.show_label;
+ if (status() == Open)
+ setStatus(cur, Collapsed);
+ else
+ setStatus(cur, Open);
else // if assign or anything else
cur.undispatched();
cur.dispatched();
void InsetCharStyleParams::write(ostream & os) const
{
os << "CharStyle " << type << "\n";
- os << "show_label " << convert<string>(show_label) << "\n";
}
type = lex.getString();
}
- else if (token == "show_label") {
- lex.next();
- show_label = lex.getBool();
- }
-
+ // This is handled in Collapsable
else if (token == "status") {
lex.pushToken(token);
break;
Font font;
///
Font labelfont;
- ///
- bool show_label;
};
{
const int xx = x + TEXT_TO_INSET_OFFSET;
- if (decoration() == Minimalistic) {
- InsetText::draw(pi, xx, y);
- } else {
- Dimension dimc = dimensionCollapsed();
- int const top = y - ascent() + TEXT_TO_INSET_OFFSET;
+ // Draw button first -- top, left or only
+ Dimension dimc = dimensionCollapsed();
+ int const top = y - ascent() + TEXT_TO_INSET_OFFSET;
+ if (decoration() == Classic) {
button_dim.x1 = xx + 0;
button_dim.x2 = xx + dimc.width();
button_dim.y1 = top;
button_dim.y2 = top + dimc.height();
pi.pain.buttonText(xx, top + dimc.asc, label, layout_.labelfont, mouse_hover_);
+ }
- int textx, texty;
- switch (geometry()) {
- case LeftButton:
- textx = xx + dimc.width();
- texty = top + textdim_.asc;
- InsetText::draw(pi, textx, texty);
- break;
- case TopButton:
- textx = xx;
- texty = top + dimc.height() + textdim_.asc;
- InsetText::draw(pi, textx, texty);
- break;
- case ButtonOnly:
- break;
- case NoButton:
- textx = xx;
- texty = top + textdim_.asc;
- InsetText::draw(pi, textx, texty);
- break;
- case SubLabel:
- case Corners:
- // FIXME add handling of SubLabel, Corners
- // still in CharStyle
- break;
- }
+ int textx, texty;
+ switch (geometry()) {
+ case LeftButton:
+ textx = xx + dimc.width();
+ texty = top + textdim_.asc;
+ InsetText::draw(pi, textx, texty);
+ break;
+ case TopButton:
+ textx = xx;
+ texty = top + dimc.height() + textdim_.asc;
+ InsetText::draw(pi, textx, texty);
+ break;
+ case ButtonOnly:
+ break;
+ case NoButton:
+ textx = xx;
+ texty = y + textdim_.asc;
+ InsetText::draw(pi, textx, texty);
+ break;
+ case SubLabel:
+ case Corners:
+ // FIXME add handling of SubLabel, Corners
+ // still in CharStyle
+ textx = xx;
+ texty = y + textdim_.asc;
+ const_cast<InsetCollapsable *>(this)->setDrawFrame(false);
+ InsetText::draw(pi, textx, texty);
+ const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
+ break;
}
setPosCache(pi, x, y);
}
{
docstring const label = notetranslator_loc().find(params_.type);
setLabel(label);
+ // isn't this an identity? - MV
setLabelFont(layout_.labelfont);
}