]> git.lyx.org Git - features.git/commitdiff
Add empty InsetLayout for undefined cases. Should avoid possible bugs caused by empty...
authorRichard Heck <rgheck@comcast.net>
Thu, 21 Feb 2008 16:31:59 +0000 (16:31 +0000)
committerRichard Heck <rgheck@comcast.net>
Thu, 21 Feb 2008 16:31:59 +0000 (16:31 +0000)
NOTE: Some cleanup is needed here, and I'll do it shortly. Doing it properly, though, requires making InsetLayout a proper class. (At the moment, it's just a C-style struct.) That should be committed separately.

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

src/CutAndPaste.cpp
src/TextClass.cpp
src/TextClass.h
src/insets/InsetCollapsable.cpp
src/insets/InsetCollapsable.h
src/insets/InsetFlex.cpp
src/insets/InsetFlex.h
src/insets/InsetLayout.h

index 1dfd91e6afde8c6978a9e52579d7146e8bd44827..f06e7cd32a70afa2bf9075a22bca07fcff464555 100644 (file)
@@ -449,7 +449,7 @@ void switchBetweenClasses(TextClassPtr const & oldone,
                        // FIXME: Should we verify all InsetCollapsable?
                        continue;
                inset->setLayout(newone);
-               if (inset->getLayout().labelstring != from_utf8("UNDEFINED"))
+               if (!inset->undefined())
                        continue;
                // The flex inset is undefined in newtc
                docstring const s = bformat(_(
index aad36787237920b567cc893aa9bfc317caf13208..7f640b85be0f4a65d28d74a596dd867282e5a5c6 100644 (file)
@@ -133,6 +133,9 @@ TextClass::TextClass(string const & fn, string const & cln,
 docstring const TextClass::emptylayout_ = from_ascii("PlainLayout");
 
 
+InsetLayout TextClass::empty_insetlayout_;
+
+
 bool TextClass::isTeXClassAvailable() const
 {
        return texClassAvail_;
@@ -1168,12 +1171,7 @@ InsetLayout const & TextClass::insetlayout(docstring const & name) const
                        break;
                n = n.substr(0,i);
        }
-       static InsetLayout empty;
-       empty.labelstring = from_utf8("UNDEFINED");
-       empty.labelfont = sane_font;
-       empty.labelfont.setColor(Color_error);
-       empty.bgcolor = Color_error;
-       return empty;
+       return empty_insetlayout_;
 }
 
 
index 4b9c1d3cea5e63bbff291e5c2445b8d7741f81ef..818ce6a56dfb4ec69c40058f6b99980e32fadeb3 100644 (file)
@@ -182,6 +182,8 @@ public:
        int max_toclevel() const;
        /// returns true if the class has a ToC structure
        bool hasTocLevels() const;
+       ///
+       static InsetLayout const & emptyInsetLayout() { return empty_insetlayout_; }
 private:
        ///
        bool deleteLayout(docstring const &);
@@ -265,6 +267,8 @@ private:
        int min_toclevel_;
        /// The maximal TocLevel of sectioning layouts
        int max_toclevel_;
+       ///
+       static InsetLayout empty_insetlayout_;
 };
 
 
index 107553fd30fd2e2afdb1f3ae4193978fa73d35b4..0780999c2e7bbe4b15961731428a8705b04c5278 100644 (file)
@@ -132,7 +132,7 @@ void InsetCollapsable::setLayout(TextClassPtr tc)
                layout_ = &tc->insetlayout(name());
                labelstring_ = layout_->labelstring;
        } else {
-               layout_ = 0;
+               layout_ = &TextClass::emptyInsetLayout();
                labelstring_ = _("UNDEFINED");
        }
 
@@ -885,4 +885,11 @@ void InsetCollapsable::validate(LaTeXFeatures & features) const
 }
 
 
+bool InsetCollapsable::undefined() const
+{
+       std::string const & n = getLayout().name;
+       return n.empty() || n == TextClass::emptyInsetLayout().name;
+}
+
+
 } // namespace lyx
index 71dba1731524fd9987c0143da0bafa7750a5a3d1..432e52c8cdc026665c6023fc4999fd311d45a466 100644 (file)
@@ -161,7 +161,9 @@ public:
        virtual bool forceLTR() const { return layout_->forceltr; }
        ///
        virtual bool useEmptyLayout() const { return true; }
-
+       /// Is this inset's layout defined in the document's textclass?
+       /// May be wrong after textclass change or paste from another document
+       bool undefined() const;
 protected:
        ///
        virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
index 2b2664c66fe07fefb45dc08ea16207d525c7eb1f..7a83014013031bb876e50c0b4ffc00b79c9b41f0 100644 (file)
@@ -61,12 +61,6 @@ Inset * InsetFlex::clone() const
 }
 
 
-bool InsetFlex::undefined() const
-{
-       return getLayout().labelstring == from_utf8("UNDEFINED");
-}
-
-
 docstring const InsetFlex::editMessage() const
 {
        return _("Opened Flex Inset");
index 75c52bc02de53fa31c8b3adbca0e05d00674ece9..3bb10abe493a6b2918d784cb1296cc529e1fdd28 100644 (file)
@@ -31,9 +31,6 @@ public:
        ///
        docstring name() const { return from_utf8(name_); }
 
-       /// Is this character style defined in the document's textclass?
-       /// May be wrong after textclass change or paste from another document
-       bool undefined() const;
        ///
        virtual docstring const editMessage() const;
        ///
index 37ccb9d28f197c060178fcad4607db317fbc12c7..c5f64c6a9eb807b1b1af1326965d6ecf497fbf48 100644 (file)
@@ -23,6 +23,12 @@ namespace lyx {
 ///
 class InsetLayout {
 public:
+       InsetLayout() : 
+               name("undefined"),
+               labelstring(from_utf8("UNDEFINED")),
+               font(sane_font), labelfont(sane_font),
+               bgcolor(Color_error)
+               { labelfont.setColor(Color_error); };
        std::string name;
        std::string lyxtype;
        docstring labelstring;