Remember the char style label state and make it globally switchable.

* src/buffer: 
	file format incrementation to 251
* src/insets/insetcharstyle.[Ch]:
	- make show_label a param and save its state
	- let all-insets-toggle togle the label in charstyles
* development/FORMAT: 
	document file format change
* lib/lyx2lyx/LyX.py:
	add new file format
* lib/lyx2lyx/lyx_1_5.py:
	remove char style label param on reversion to 250.
	

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15345 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2006-10-16 07:06:41 +00:00
parent 90cbd48fd3
commit 77e145a406
6 changed files with 75 additions and 17 deletions

View File

@ -1,5 +1,12 @@
LyX file-format changes
-----------------------§
2006-10-03 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* 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 <martin.vermeer@hut.fi>
* Format incremented to 250: allow optional arg to environments

View File

@ -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():

View File

@ -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]],

View File

@ -144,7 +144,7 @@ using std::string;
namespace {
int const LYX_FORMAT = 250;
int const LYX_FORMAT = 251;
} // namespace anon

View File

@ -34,6 +34,8 @@
#include "frontends/FontMetrics.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(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<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;
}
}
}

View File

@ -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