+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
#include "errorlist.h"
#include "funcrequest.h"
#include "gettext.h"
+#include "insetiterator.h"
#include "lfuns.h"
#include "lyxrc.h"
#include "lyxtext.h"
#include "pariterator.h"
#include "undo.h"
+#include "insets/insetcharstyle.h"
#include "insets/insettabular.h"
#include "mathed/math_data.h"
}
// 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();
}
-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];
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();
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;
}
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 &);
case LFUN_INSERT_CHARSTYLE: {
string s = cmd.getArg(0);
- CharStyles::iterator found_cs = params.getLyXTextClass().charstyle(s);
- return new InsetCharStyle(params, found_cs);
+ 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: {
lex.next();
string s = lex.getString();
CharStyles::iterator found_cs = tclass.charstyle(s);
- inset.reset(new InsetCharStyle(buf.params(), found_cs));
+ 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()));
+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
}
+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();
}
}
+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");
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
int InsetCharStyle::latex(Buffer const & buf, ostream & os,
OutputParams const & runparams) const
{
- os << "\\" << params_.latexname;
- if (!params_.latexparam.empty())
- os << params_.latexparam;
- os << "{";
+ if (!undefined()) {
+ os << "\\" << params_.latexname;
+ if (!params_.latexparam.empty())
+ os << params_.latexparam;
+ os << "{";
+ }
int i = InsetText::latex(buf, os, runparams);
- os << "}";
+ if (!undefined())
+ os << "}";
return i;
}
int InsetCharStyle::linuxdoc(Buffer const & buf, ostream & os,
OutputParams const & runparams) const
{
- sgml::openTag(os, params_.latexname, params_.latexparam);
+ if (!undefined())
+ sgml::openTag(os, params_.latexname, params_.latexparam);
int i = InsetText::linuxdoc(buf, os, runparams);
- sgml::closeTag(os, params_.latexname);
+ if (!undefined())
+ sgml::closeTag(os, params_.latexname);
return i;
}
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,
- outerFont(par - paragraphs().begin(),
+ outerFont(par - paragraphs().begin(),
paragraphs()));
}
- sgml::closeTag(os, params_.latexname);
+ if (!undefined())
+ sgml::closeTag(os, params_.latexname);
+
return 0;
}
void InsetCharStyle::validate(LaTeXFeatures & features) const
{
+ // Force inclusion of preamble snippet in layout file
features.require(params_.type);
InsetText::validate(features);
}
*/
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;
///
owner->message(_("Converting document to new document class..."));
ErrorList el;
- lyx::cap::SwitchLayoutsBetweenClasses(
+ lyx::cap::SwitchBetweenClasses(
old_class, new_class,
buffer->paragraphs(), el);