mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 02:14:50 +00:00
undefined charstyle fixes from Martin and me
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9903 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
026cce7c1e
commit
674038dc8c
@ -1,3 +1,13 @@
|
||||
2005-05-03 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||
|
||||
* CutAndPaste.[Ch] (SwitchLayoutsBetweenClasses): rename to
|
||||
SwitchBetweenClasses and remove the unused return value.
|
||||
Handle character styles, too
|
||||
|
||||
2005-05-03 Martin Vermeer <martin.vermeer@hut.fi>
|
||||
|
||||
* factory.C (createInset): handle undefined character styles
|
||||
|
||||
2005-05-02 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* buffer.C: protect the #include of utime.h with a preprocessor
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "errorlist.h"
|
||||
#include "funcrequest.h"
|
||||
#include "gettext.h"
|
||||
#include "insetiterator.h"
|
||||
#include "lfuns.h"
|
||||
#include "lyxrc.h"
|
||||
#include "lyxtext.h"
|
||||
@ -34,6 +35,7 @@
|
||||
#include "pariterator.h"
|
||||
#include "undo.h"
|
||||
|
||||
#include "insets/insetcharstyle.h"
|
||||
#include "insets/insettabular.h"
|
||||
|
||||
#include "mathed/math_data.h"
|
||||
@ -131,8 +133,7 @@ pasteSelectionHelper(Buffer const & buffer, ParagraphList & pars,
|
||||
}
|
||||
|
||||
// Make sure there is no class difference.
|
||||
lyx::cap::SwitchLayoutsBetweenClasses(textclass, tc, insertion,
|
||||
errorlist);
|
||||
lyx::cap::SwitchBetweenClasses(textclass, tc, insertion, errorlist);
|
||||
|
||||
ParagraphList::iterator tmpbuf = insertion.begin();
|
||||
int depth_delta = pars[pit].params().depth() - tmpbuf->params().depth();
|
||||
@ -372,13 +373,12 @@ string grabAndEraseSelection(LCursor & cur)
|
||||
}
|
||||
|
||||
|
||||
int SwitchLayoutsBetweenClasses(textclass_type c1, textclass_type c2,
|
||||
void SwitchBetweenClasses(textclass_type c1, textclass_type c2,
|
||||
ParagraphList & pars, ErrorList & errorlist)
|
||||
{
|
||||
BOOST_ASSERT(!pars.empty());
|
||||
int ret = 0;
|
||||
if (c1 == c2)
|
||||
return ret;
|
||||
return;
|
||||
|
||||
LyXTextClass const & tclass1 = textclasslist[c1];
|
||||
LyXTextClass const & tclass2 = textclasslist[c2];
|
||||
@ -386,6 +386,7 @@ int SwitchLayoutsBetweenClasses(textclass_type c1, textclass_type c2,
|
||||
InsetText in;
|
||||
std::swap(in.paragraphs(), pars);
|
||||
|
||||
// layouts
|
||||
ParIterator end = par_iterator_end(in);
|
||||
for (ParIterator it = par_iterator_begin(in); it != end; ++it) {
|
||||
string const name = it->layout()->name();
|
||||
@ -397,19 +398,48 @@ int SwitchLayoutsBetweenClasses(textclass_type c1, textclass_type c2,
|
||||
it->layout(tclass2.defaultLayout());
|
||||
|
||||
if (!hasLayout && name != tclass1.defaultLayoutName()) {
|
||||
++ret;
|
||||
string const s = bformat(
|
||||
_("Layout had to be changed from\n%1$s to %2$s\n"
|
||||
"because of class conversion from\n%3$s to %4$s"),
|
||||
name, it->layout()->name(), tclass1.name(), tclass2.name());
|
||||
// To warn the user that something had to be done.
|
||||
errorlist.push_back(ErrorItem("Changed Layout", s,
|
||||
errorlist.push_back(ErrorItem(_("Changed Layout"), s,
|
||||
it->id(), 0,
|
||||
it->size()));
|
||||
}
|
||||
}
|
||||
|
||||
// character styles
|
||||
InsetIterator const i_end = inset_iterator_end(in);
|
||||
for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) {
|
||||
if (it->lyxCode() == InsetBase::CHARSTYLE_CODE) {
|
||||
InsetCharStyle & inset =
|
||||
static_cast<InsetCharStyle &>(*it);
|
||||
string const name = inset.params().type;
|
||||
CharStyles::iterator const found_cs =
|
||||
tclass2.charstyle(name);
|
||||
if (found_cs == tclass2.charstyles().end()) {
|
||||
// The character style is undefined in tclass2
|
||||
inset.setUndefined();
|
||||
string const s = bformat(_(
|
||||
"Character style %1$s is "
|
||||
"undefined because of class "
|
||||
"conversion from\n%2$s to %3$s"),
|
||||
name, tclass1.name(), tclass2.name());
|
||||
// To warn the user that something had to be done.
|
||||
errorlist.push_back(ErrorItem(
|
||||
_("Undefined character style"),
|
||||
s, it.paragraph().id(),
|
||||
it.pos(), it.pos() + 1));
|
||||
} else if (inset.undefined()) {
|
||||
// The character style is undefined in
|
||||
// tclass1 and is defined in tclass2
|
||||
inset.setDefined(found_cs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::swap(in.paragraphs(), pars);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,10 +55,10 @@ void copySelection(LCursor & cur);
|
||||
void pasteSelection(LCursor & cur, size_t sel_index = 0);
|
||||
|
||||
/** Needed to switch between different classes. This works
|
||||
* for a list of paragraphs beginning with the specified par
|
||||
* return value is the number of wrong conversions.
|
||||
* for a list of paragraphs beginning with the specified par.
|
||||
* It changes layouts and character styles.
|
||||
*/
|
||||
int SwitchLayoutsBetweenClasses(lyx::textclass_type c1,
|
||||
void SwitchBetweenClasses(lyx::textclass_type c1,
|
||||
lyx::textclass_type c2,
|
||||
ParagraphList & par,
|
||||
ErrorList &);
|
||||
|
@ -88,8 +88,12 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd)
|
||||
|
||||
case LFUN_INSERT_CHARSTYLE: {
|
||||
string s = cmd.getArg(0);
|
||||
CharStyles::iterator found_cs = params.getLyXTextClass().charstyle(s);
|
||||
LyXTextClass tclass = params.getLyXTextClass();
|
||||
CharStyles::iterator found_cs = tclass.charstyle(s);
|
||||
if (found_cs != tclass.charstyles().end())
|
||||
return new InsetCharStyle(params, found_cs);
|
||||
else
|
||||
return new InsetCharStyle(params, s);
|
||||
}
|
||||
|
||||
case LFUN_INSERT_NOTE: {
|
||||
@ -417,7 +421,12 @@ InsetBase * readInset(LyXLex & lex, Buffer const & buf)
|
||||
lex.next();
|
||||
string s = lex.getString();
|
||||
CharStyles::iterator found_cs = tclass.charstyle(s);
|
||||
if (found_cs != tclass.charstyles().end())
|
||||
inset.reset(new InsetCharStyle(buf.params(), found_cs));
|
||||
else {
|
||||
// "Undefined" inset
|
||||
inset.reset(new InsetCharStyle(buf.params(), s));
|
||||
}
|
||||
} else if (tmptok == "Branch") {
|
||||
inset.reset(new InsetBranch(buf.params(),
|
||||
InsetBranchParams()));
|
||||
|
@ -1,3 +1,11 @@
|
||||
2005-05-03 Martin Vermeer <martin.vermeer@hut.fi>
|
||||
2005-05-03 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||
|
||||
* insetcharstyle.[Ch] (undefined, setUndefined, setDefined): new,
|
||||
handle undefined character styles
|
||||
* insetcharstyle.[Ch] (latex, linuxdoc, docbook, plaintext, validate):
|
||||
handle undefined character styles
|
||||
|
||||
2005-04-23 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
|
||||
|
||||
* insettabular.C: handle the LFUN_UNSET_* longtabular methods
|
||||
|
@ -51,16 +51,21 @@ void InsetCharStyle::init()
|
||||
}
|
||||
|
||||
|
||||
InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s)
|
||||
: InsetCollapsable(bp)
|
||||
{
|
||||
params_.type = s;
|
||||
setUndefined();
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
InsetCharStyle::InsetCharStyle(BufferParams const & bp,
|
||||
CharStyles::iterator cs)
|
||||
: InsetCollapsable(bp)
|
||||
{
|
||||
params_.type = cs->name;
|
||||
params_.latextype = cs->latextype;
|
||||
params_.latexname = cs->latexname;
|
||||
params_.latexparam = cs->latexparam;
|
||||
params_.font = cs->font;
|
||||
params_.labelfont = cs->labelfont;
|
||||
setDefined(cs);
|
||||
init();
|
||||
}
|
||||
|
||||
@ -78,6 +83,33 @@ auto_ptr<InsetBase> InsetCharStyle::doClone() const
|
||||
}
|
||||
|
||||
|
||||
bool InsetCharStyle::undefined() const
|
||||
{
|
||||
return params_.latexname.empty();
|
||||
}
|
||||
|
||||
|
||||
void InsetCharStyle::setUndefined()
|
||||
{
|
||||
params_.latextype.clear();
|
||||
params_.latexname.clear();
|
||||
params_.latexparam.clear();
|
||||
params_.font = LyXFont(LyXFont::ALL_INHERIT);
|
||||
params_.labelfont = LyXFont(LyXFont::ALL_INHERIT);
|
||||
params_.labelfont.setColor(LColor::red);
|
||||
}
|
||||
|
||||
|
||||
void InsetCharStyle::setDefined(CharStyles::iterator cs)
|
||||
{
|
||||
params_.latextype = cs->latextype;
|
||||
params_.latexname = cs->latexname;
|
||||
params_.latexparam = cs->latexparam;
|
||||
params_.font = cs->font;
|
||||
params_.labelfont = cs->labelfont;
|
||||
}
|
||||
|
||||
|
||||
string const InsetCharStyle::editMessage() const
|
||||
{
|
||||
return _("Opened CharStyle Inset");
|
||||
@ -147,9 +179,12 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
|
||||
int w = 0;
|
||||
int a = 0;
|
||||
int d = 0;
|
||||
string s(params_.type);
|
||||
if (undefined())
|
||||
s = _("Undef: ") + s;
|
||||
font_metrics::rectText(params_.type, font, w, a, d);
|
||||
pi.pain.rectText(x + (dim_.wid - w) / 2, y + desc + a,
|
||||
params_.type, font, LColor::none, LColor::none);
|
||||
s, font, LColor::none, LColor::none);
|
||||
}
|
||||
|
||||
// a visual clue when the cursor is inside the inset
|
||||
@ -210,11 +245,14 @@ bool InsetCharStyle::getStatus(LCursor & cur, FuncRequest const & cmd,
|
||||
int InsetCharStyle::latex(Buffer const & buf, ostream & os,
|
||||
OutputParams const & runparams) const
|
||||
{
|
||||
if (!undefined()) {
|
||||
os << "\\" << params_.latexname;
|
||||
if (!params_.latexparam.empty())
|
||||
os << params_.latexparam;
|
||||
os << "{";
|
||||
}
|
||||
int i = InsetText::latex(buf, os, runparams);
|
||||
if (!undefined())
|
||||
os << "}";
|
||||
return i;
|
||||
}
|
||||
@ -223,8 +261,10 @@ int InsetCharStyle::latex(Buffer const & buf, ostream & os,
|
||||
int InsetCharStyle::linuxdoc(Buffer const & buf, ostream & os,
|
||||
OutputParams const & runparams) const
|
||||
{
|
||||
if (!undefined())
|
||||
sgml::openTag(os, params_.latexname, params_.latexparam);
|
||||
int i = InsetText::linuxdoc(buf, os, runparams);
|
||||
if (!undefined())
|
||||
sgml::closeTag(os, params_.latexname);
|
||||
return i;
|
||||
}
|
||||
@ -236,7 +276,9 @@ int InsetCharStyle::docbook(Buffer const & buf, ostream & os,
|
||||
ParagraphList::const_iterator par = paragraphs().begin();
|
||||
ParagraphList::const_iterator end = paragraphs().end();
|
||||
|
||||
sgml::openTag(os, params_.latexname, par->getID(buf, runparams) + params_.latexparam);
|
||||
if (!undefined())
|
||||
sgml::openTag(os, params_.latexname,
|
||||
par->getID(buf, runparams) + params_.latexparam);
|
||||
|
||||
for (; par != end; ++par) {
|
||||
par->simpleDocBookOnePar(buf, os, runparams,
|
||||
@ -244,7 +286,9 @@ int InsetCharStyle::docbook(Buffer const & buf, ostream & os,
|
||||
paragraphs()));
|
||||
}
|
||||
|
||||
if (!undefined())
|
||||
sgml::closeTag(os, params_.latexname);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -258,6 +302,7 @@ int InsetCharStyle::plaintext(Buffer const & buf, ostream & os,
|
||||
|
||||
void InsetCharStyle::validate(LaTeXFeatures & features) const
|
||||
{
|
||||
// Force inclusion of preamble snippet in layout file
|
||||
features.require(params_.type);
|
||||
InsetText::validate(features);
|
||||
}
|
||||
|
@ -43,8 +43,17 @@ public:
|
||||
*/
|
||||
class InsetCharStyle : public InsetCollapsable {
|
||||
public:
|
||||
/// Construct an undefined character style
|
||||
InsetCharStyle::InsetCharStyle(BufferParams const &, std::string const);
|
||||
///
|
||||
InsetCharStyle(BufferParams const &, CharStyles::iterator);
|
||||
/// Is this character style defined in the document's textclass?
|
||||
/// May be wrong after textclass change or paste from another document
|
||||
bool undefined() const;
|
||||
/// Set the character style to "undefined"
|
||||
void setUndefined();
|
||||
/// (Re-)set the character style parameters from \p cs
|
||||
void setDefined(CharStyles::iterator cs);
|
||||
///
|
||||
std::string const editMessage() const;
|
||||
///
|
||||
|
@ -1468,7 +1468,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
||||
|
||||
owner->message(_("Converting document to new document class..."));
|
||||
ErrorList el;
|
||||
lyx::cap::SwitchLayoutsBetweenClasses(
|
||||
lyx::cap::SwitchBetweenClasses(
|
||||
old_class, new_class,
|
||||
buffer->paragraphs(), el);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user