Juergen Spitzmueller wrote: > Here's the patch. The labels can be switch on/off by means of > all-insets-toggle, furthermore the label setting is saved as a param. I'm > not sure the params solution is ideal, but it works (and I didn't have > another idea). > > All that's missing is the dile format change/lyx2lyx (removing the param > show_label).
Here's a complete patch including the lyx2lyx changes. Georg, could you have a look if they are correct? Jürgen
Index: development/FORMAT =================================================================== --- development/FORMAT (Revision 15206) +++ development/FORMAT (Arbeitskopie) @@ -1,6 +1,12 @@ LyX file-format changes ----------------------- +2006-10-03 Jürgen Spitzmüller <[EMAIL PROTECTED]> + + * format incremented to 250: save show_label param for charstyles. + + On revert, the show_label param is just removed. Nothing to convert. + 2006-08-14 Georg Baum <[EMAIL PROTECTED]> * format incremented to 249: Unicode Index: lib/lyx2lyx/LyX.py =================================================================== --- lib/lyx2lyx/LyX.py (Revision 15206) +++ lib/lyx2lyx/LyX.py (Arbeitskopie) @@ -73,7 +73,7 @@ format_relation = [("0_06", [200], ge ("1_2", [220], generate_minor_versions("1.2" , 4)), ("1_3", [221], generate_minor_versions("1.3" , 7)), ("1_4", range(222,246), generate_minor_versions("1.4" , 3)), - ("1_5", range(246,250), generate_minor_versions("1.5" , 0))] + ("1_5", range(246,251), generate_minor_versions("1.5" , 0))] def formats_list(): Index: lib/lyx2lyx/lyx_1_5.py =================================================================== --- lib/lyx2lyx/lyx_1_5.py (Revision 15206) +++ lib/lyx2lyx/lyx_1_5.py (Arbeitskopie) @@ -231,6 +231,28 @@ def revert_utf8(document): document.encoding = get_encoding(document.language, document.inputencoding, 248) +def revert_cs_label(document): + " Remove status flag of charstyle label. " + i = 0 + while 1: + i = find_token(document.body, "\\begin_inset CharStyle", i) + if i == -1: + return + # Seach for a line starting 'show_label' + # If it is not there, break with a warning message + i = i + 1 + while 1: + if (document.body[i][:10] == "show_label"): + del document.body[i] + break + elif (document.body[i][:13] == "\\begin_layout"): + document.warning("Malformed LyX document: Missing 'show_label'.") + break + i = i + 1 + + i = i + 1 + + ## # Conversion hub # @@ -239,9 +261,11 @@ supported_versions = ["1.5.0","1.5"] convert = [[246, []], [247, [convert_font_settings]], [248, []], - [249, [convert_utf8]]] + [249, [convert_utf8]], + [250, []]] -revert = [[248, [revert_utf8]], +revert = [[249, [revert_cs_label]], + [248, [revert_utf8]], [247, [revert_booktabs]], [246, [revert_font_settings]], [245, [revert_framed]]] Index: src/insets/insetcharstyle.h =================================================================== --- src/insets/insetcharstyle.h (Revision 15206) +++ src/insets/insetcharstyle.h (Arbeitskopie) @@ -35,6 +35,8 @@ public: LyXFont font; /// LyXFont labelfont; + /// + bool show_label; }; @@ -106,8 +108,6 @@ private: void init(); /// InsetCharStyleParams params_; - /// - bool has_label_; }; #endif Index: src/insets/insetcharstyle.C =================================================================== --- src/insets/insetcharstyle.C (Revision 15206) +++ src/insets/insetcharstyle.C (Arbeitskopie) @@ -34,6 +34,8 @@ #include "frontends/font_metrics.h" #include "frontends/Painter.h" +#include "support/convert.h" + #include <sstream> using lyx::docstring; @@ -51,7 +53,6 @@ void InsetCharStyle::init() setInsetName("CharStyle"); setInlined(); setDrawFrame(false); - has_label_ = true; } @@ -101,6 +102,7 @@ void InsetCharStyle::setUndefined() params_.font = LyXFont(LyXFont::ALL_INHERIT); params_.labelfont = LyXFont(LyXFont::ALL_INHERIT); params_.labelfont.setColor(LColor::error); + params_.show_label = true; } @@ -111,6 +113,7 @@ void InsetCharStyle::setDefined(CharStyl params_.latexparam = cs->latexparam; params_.font = cs->font; params_.labelfont = cs->labelfont; + params_.show_label = true; } @@ -129,6 +132,7 @@ void InsetCharStyle::write(Buffer const void InsetCharStyle::read(Buffer const & buf, LyXLex & lex) { + params_.read(lex); InsetCollapsable::read(buf, lex); setInlined(); } @@ -143,7 +147,7 @@ void InsetCharStyle::metrics(MetricsInfo mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET; InsetText::metrics(mi, dim); mi.base.font = tmpfont; - if (has_label_) { + if (params_.show_label) { // consider width of the inset label LyXFont font(params_.labelfont); font.realize(LyXFont(LyXFont::ALL_SANE)); @@ -165,7 +169,7 @@ void InsetCharStyle::metrics(MetricsInfo dim.wid += 2 * TEXT_TO_INSET_OFFSET; mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET; dim_ = dim; - if (has_label_) + if (params_.show_label) dim_.des += ascent(); } @@ -182,7 +186,7 @@ void InsetCharStyle::draw(PainterInfo & pi.base.font = tmpfont; int desc = InsetText::descent(); - if (has_label_) + if (params_.show_label) desc -= ascent(); pi.pain.line(x, y + desc - 4, x, y + desc, params_.labelfont.color()); @@ -192,7 +196,7 @@ void InsetCharStyle::draw(PainterInfo & params_.labelfont.color()); // the name of the charstyle. Can be toggled. - if (has_label_) { + if (params_.show_label) { LyXFont font(params_.labelfont); font.realize(LyXFont(LyXFont::ALL_SANE)); font.decSize(); @@ -237,11 +241,23 @@ void InsetCharStyle::doDispatch(LCursor case LFUN_MOUSE_PRESS: if (cmd.button() == mouse_button::button3) - has_label_ = !has_label_; + params_.show_label = !params_.show_label; else InsetText::doDispatch(cur, cmd); break; + case LFUN_INSET_TOGGLE: + if (cmd.argument() == "open") + params_.show_label = true; + else if (cmd.argument() == "close") + params_.show_label = false; + else if (cmd.argument() == "toggle" || cmd.argument().empty()) + params_.show_label = !params_.show_label; + else // if assign or anything else + cur.undispatched(); + cur.dispatched(); + break; + default: InsetCollapsable::doDispatch(cur, cmd); break; @@ -331,18 +347,29 @@ void InsetCharStyle::validate(LaTeXFeatu void InsetCharStyleParams::write(ostream & os) const { os << "CharStyle " << type << "\n"; + os << "show_label " << convert<string>(show_label) << "\n"; } void InsetCharStyleParams::read(LyXLex & lex) { - if (lex.isOK()) { + while (lex.isOK()) { lex.next(); string token = lex.getString(); - } - if (lex.isOK()) { - lex.next(); - type = lex.getString(); + if (token == "CharStyle") { + lex.next(); + type = lex.getString(); + } + + else if (token == "show_label") { + lex.next(); + show_label = lex.getBool(); + } + + else if (token == "status") { + lex.pushToken(token); + break; + } } } Index: src/buffer.C =================================================================== --- src/buffer.C (Revision 15206) +++ src/buffer.C (Arbeitskopie) @@ -144,7 +144,7 @@ using std::string; namespace { -int const LYX_FORMAT = 249; +int const LYX_FORMAT = 250; } // namespace anon