]> git.lyx.org Git - features.git/commitdiff
Clean-up in CharStyles, externalize detection of undefined styles to
authorMartin Vermeer <martin.vermeer@hut.fi>
Sat, 25 Aug 2007 14:43:59 +0000 (14:43 +0000)
committerMartin Vermeer <martin.vermeer@hut.fi>
Sat, 25 Aug 2007 14:43:59 +0000 (14:43 +0000)
layout files

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19790 a592a061-630c-0410-9148-cb99ea01b6c8

lib/layouts/stdcharstyles.inc
src/CutAndPaste.cpp
src/TextClass.cpp
src/TextClass.h
src/factory.cpp
src/insets/InsetCharStyle.cpp
src/insets/InsetCharStyle.h
src/insets/InsetCollapsable.cpp

index 5e3f687bfe2fa7c2b684df515b81c3df08971f41..52b494144a136194fc916c73fbb9754503ed6f6f 100644 (file)
@@ -27,3 +27,13 @@ InsetLayout CharStyle:Emph
        EndFont
 End
 
+
+# Error fallback:
+InsetLayout CharStyle
+       LyxType               end
+       LabelString           "UNDEFINED"
+       Font
+         Color               error
+       EndFont
+End
+
index d3623c3f47627e9846056fa5667910152d6a444c..ca34f48f70f3c4b4ef89986062d17e991584c86f 100644 (file)
@@ -455,11 +455,11 @@ void switchBetweenClasses(TextClass_ptr const & c1,
                        InsetCharStyle & inset =
                                static_cast<InsetCharStyle &>(*it);
                        string const name = inset.params().name;
-                       CharStyles::iterator const found_cs =
-                               tclass2.charstyle(name);
-                       if (found_cs == tclass2.charstyles().end()) {
+                       InsetLayout const il = 
+                               tclass2.insetlayout(from_utf8(name));
+                       inset.setLayout(il);
+                       if (il.labelstring == from_utf8("UNDEFINED")) {
                                // The character style is undefined in tclass2
-                               inset.setUndefined();
                                docstring const s = bformat(_(
                                        "Character style %1$s is "
                                        "undefined because of class "
@@ -470,11 +470,7 @@ void switchBetweenClasses(TextClass_ptr const & c1,
                                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);
-                       }
+                       } 
                }
        }
 }
index 5cb12193b1bc5e1d490745e79d968b9c14b1e208..54f5ef36ac0f8abcd7373feb495e0b0b3d2d5739 100644 (file)
@@ -1014,6 +1014,14 @@ Counters & TextClass::counters() const
        return *counters_.get();
 }
 
+
+// Return the layout object of an inset given by name. If the name
+// is not found as such, the part after the ':' is stripped off, and
+// searched again. In this way, an error fallback can be provided:
+// An erroneous 'CharStyle:badname' (e.g., after a documentclass switch)
+// will invoke the layout object defined by name = 'CharStyle'.
+// If that doesn't work either, an empty object returns (shouldn't
+// happen).  -- Idea JMarc, comment MV
 InsetLayout const & TextClass::insetlayout(docstring const & name) const 
 {
        docstring n = name;
@@ -1025,23 +1033,12 @@ InsetLayout const & TextClass::insetlayout(docstring const & name) const
                        break;
                n = n.substr(0,i);
        }
-       static const InsetLayout empty;
+       static InsetLayout empty;
+       empty.labelstring = from_utf8("UNDEFINED");
        return empty;
 }
 
 
-CharStyles::iterator TextClass::charstyle(string const & s) const
-{
-       CharStyles::iterator cs = charstyles().begin();
-       CharStyles::iterator csend = charstyles().end();
-       for (; cs != csend; ++cs) {
-               if (cs->name == s)
-                       return cs;
-       }
-       return csend;
-}
-
-
 docstring const & TextClass::defaultLayoutName() const
 {
        // This really should come from the actual layout... (Lgb)
index ad2d28f7ac5c3dc8263d6e9509ba6dd4d3a57a38..93afe4c63a18b9b4eb98762145783796bd767784 100644 (file)
@@ -113,8 +113,6 @@ public:
        InsetLayouts & insetlayouts() const { return insetlayoutlist_; };
        ///
        InsetLayout const & insetlayout(docstring const & name) const;
-       /// Retrieve element of name s:
-       CharStyles::iterator charstyle(std::string const & s) const;
        ///
        docstring const & defaultLayoutName() const;
        ///
index c790a377037479a1c6cc2a138a036d0158318351..30c822603e6f1dc74122e38da2706b5999813823 100644 (file)
@@ -105,11 +105,8 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                case LFUN_CHARSTYLE_INSERT: {
                        string s = cmd.getArg(0);
                        TextClass tclass = params.getTextClass();
-                       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);
+                       InsetLayout il = tclass.insetlayout(from_utf8(s));
+                       return new InsetCharStyle(params, il);
                }
 
                case LFUN_NOTE_INSERT: {
@@ -476,13 +473,8 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
                } else if (tmptok == "CharStyle") {
                        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));
-                       }
+                       InsetLayout il = tclass.insetlayout(from_utf8(s));
+                       inset.reset(new InsetCharStyle(buf.params(), il));
                } else if (tmptok == "Branch") {
                        inset.reset(new InsetBranch(buf.params(),
                                                    InsetBranchParams()));
index d967957e7a9f3a0e1284cc82d124463f8e801ef2..4c454947544d2cb91861d17f404791060e58fe1b 100644 (file)
@@ -48,34 +48,26 @@ using std::ostream;
 using std::ostringstream;
 
 
-void InsetCharStyle::init()
-{}
-
 
 InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s)
        : InsetCollapsable(bp, Collapsed)
 {
        params_.name = s;
-       setUndefined();
-       init();
 }
 
 
 InsetCharStyle::InsetCharStyle(BufferParams const & bp,
-                               CharStyles::iterator cs)
+                               InsetLayout il)
        : InsetCollapsable(bp, Collapsed)
 {
-       params_.name = cs->name;
-       setDefined(cs);
-       init();
+       params_.name = il.name;
+       setLayout(il);
 }
 
 
 InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
        : InsetCollapsable(in), params_(in.params_)
-{
-       init();
-}
+{}
 
 
 auto_ptr<Inset> InsetCharStyle::doClone() const
@@ -86,24 +78,13 @@ auto_ptr<Inset> InsetCharStyle::doClone() const
 
 bool InsetCharStyle::undefined() const
 {
-       return layout_.latexname.empty();
-}
-
-
-void InsetCharStyle::setUndefined()
-{
-       layout_.latextype.clear();
-       layout_.latexname.clear();
-       layout_.latexparam.clear();
-       layout_.font = Font(Font::ALL_INHERIT);
-       layout_.labelfont = Font(Font::ALL_INHERIT);
-       layout_.labelfont.setColor(Color::error);
+       return layout_.labelstring == from_utf8("UNDEFINED");
 }
 
 
-void InsetCharStyle::setDefined(CharStyles::iterator cs)
+void InsetCharStyle::setLayout(InsetLayout il)
 {
-       layout_ = *cs;
+       layout_ = il;
 }
 
 
@@ -135,16 +116,6 @@ bool InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
        mi.base.font.realize(tmpfont);
        bool changed = InsetCollapsable::metrics(mi, dim);
        mi.base.font = tmpfont;
-       if (status() == Open) {
-               // FIXME UNICODE
-               docstring s(from_utf8(params_.name));
-               // Chop off prefix:
-               if (s.find(':') != string::npos)
-                       s = s.substr(s.find(':'));
-               if (undefined())
-                       s = _("Undef: ") + s;
-               layout_.labelstring = s;
-       }
        return changed;
 }
 
@@ -159,18 +130,6 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
        //needed, or even wanted, here. It just works. -- MV 10.04.2005
        InsetCollapsable::draw(pi, x, y);
        pi.base.font = tmpfont;
-
-       // the name of the charstyle. Can be toggled.
-       if (status() == Open) {
-               // FIXME UNICODE
-               docstring s(from_utf8(params_.name));
-               // Chop off prefix:
-               if (s.find(':') != string::npos)
-                       s = s.substr(s.find(':'));
-               if (undefined())
-                       s = _("Undef: ") + s;
-               layout_.labelstring = s;
-       }
 }
 
 
index b63dfda8f69eaa3385a4a35418200284a8641200..b06f4d7ae000a2457dca6b0f0a20bbf87e19f374 100644 (file)
@@ -39,16 +39,14 @@ public:
        /// Construct an undefined character style
        InsetCharStyle(BufferParams const &, std::string const);
        ///
-       InsetCharStyle(BufferParams const &, CharStyles::iterator);
+       InsetCharStyle(BufferParams const &, InsetLayout);
        ///
        docstring name() const { return from_ascii("CharStyle"); }
        /// 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);
+       /// (Re-)set the character style parameters from \p il
+       void setLayout(InsetLayout il);
        ///
        virtual docstring const editMessage() const;
        ///
@@ -94,8 +92,6 @@ private:
 
        virtual std::auto_ptr<Inset> doClone() const;
 
-       /// used by the constructors
-       void init();
        ///
        InsetCharStyleParams params_;
 };
index 16027b444d8b9abdfc886db658cb777fe3cef5e3..2b9a336311a1cecc99df6d2000fd55537b369787 100644 (file)
@@ -246,6 +246,8 @@ bool InsetCollapsable::setMouseHover(bool mouse_hover)
 
 void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
 {
+       autoOpen_ = pi.base.bv->cursor().isInside(this);
+
        const int xx = x + TEXT_TO_INSET_OFFSET;
 
        // Draw button first -- top, left or only
@@ -497,7 +499,6 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MOUSE_RELEASE:
                if (cmd.button() == mouse_button::button3) {
                        if (decoration() == Conglomerate) {
-
                                if (internalStatus() == Open)
                                        setStatus(cur, Collapsed);
                                else