diff --git a/development/FORMAT b/development/FORMAT index 1ec15c454e..281fecc89b 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,5 +1,12 @@ LyX file-format changes -----------------------§ + +2006-10-03 Jürgen Spitzmüller + + * format incremented to 251: save show_label param for charstyles. + + On revert, the show_label param is just removed. Nothing to convert. + 2006-10-12 Martin Vermeer * Format incremented to 250: allow optional arg to environments diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index f04ee1c121..d137b95f90 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -73,7 +73,7 @@ format_relation = [("0_06", [200], generate_minor_versions("0.6" , 4)), ("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,251), generate_minor_versions("1.5" , 0))] + ("1_5", range(246,252), generate_minor_versions("1.5" , 0))] def formats_list(): diff --git a/lib/lyx2lyx/lyx_1_5.py b/lib/lyx2lyx/lyx_1_5.py index f1e50f0f74..365f6a17dc 100644 --- a/lib/lyx2lyx/lyx_1_5.py +++ b/lib/lyx2lyx/lyx_1_5.py @@ -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 # @@ -240,9 +262,11 @@ convert = [[246, []], [247, [convert_font_settings]], [248, []], [249, [convert_utf8]], - [250, []]] + [250, []], + [251, []]] -revert = [[249, []], +revert = [[250, [revert_cs_label]], + [249, []], [248, [revert_utf8]], [247, [revert_booktabs]], [246, [revert_font_settings]], diff --git a/src/buffer.C b/src/buffer.C index 5f90ee078d..bdc4b6fbad 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -144,7 +144,7 @@ using std::string; namespace { -int const LYX_FORMAT = 250; +int const LYX_FORMAT = 251; } // namespace anon diff --git a/src/insets/insetcharstyle.C b/src/insets/insetcharstyle.C index 88039d9898..c187b4f4e9 100644 --- a/src/insets/insetcharstyle.C +++ b/src/insets/insetcharstyle.C @@ -34,6 +34,8 @@ #include "frontends/FontMetrics.h" #include "frontends/Painter.h" +#include "support/convert.h" + #include 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(CharStyles::iterator cs) 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 & buf, ostream & os) 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, Dimension & dim) const 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 & mi, Dimension & dim) const 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, int x, int y) const 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 & pi, int x, int y) const 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 & cur, FuncRequest & cmd) 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(LaTeXFeatures & features) const void InsetCharStyleParams::write(ostream & os) const { os << "CharStyle " << type << "\n"; + os << "show_label " << convert(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; + } } } diff --git a/src/insets/insetcharstyle.h b/src/insets/insetcharstyle.h index 92583eea9f..a497a81dbb 100644 --- a/src/insets/insetcharstyle.h +++ b/src/insets/insetcharstyle.h @@ -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