]> git.lyx.org Git - features.git/commitdiff
Fix for another part of 5403, and related bugs, anyway. The InsetLayout
authorRichard Heck <rgheck@comcast.net>
Sat, 25 Oct 2008 13:32:54 +0000 (13:32 +0000)
committerRichard Heck <rgheck@comcast.net>
Sat, 25 Oct 2008 13:32:54 +0000 (13:32 +0000)
tags should not be so case-dependent, and we ought to use an Enum instead.
of relying upon string comparisons.

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

src/Text3.cpp
src/frontends/qt4/Menus.cpp
src/insets/InsetLayout.cpp
src/insets/InsetLayout.h

index 2d7b15659c361cfd78ae45b82a29883c6b95a287..11f5e4e9012b77683bd2a9680dc6fdd27f2b592b 100644 (file)
@@ -1992,10 +1992,10 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                string s = cmd.getArg(0);
                InsetLayout il =
                        cur.buffer().params().documentClass().insetLayout(from_utf8(s));
-               if (il.lyxtype() != "charstyle" &&
-                   il.lyxtype() != "custom" &&
-                   il.lyxtype() != "element" &&
-                   il.lyxtype ()!= "standard")
+               if (il.lyxtype() != InsetLayout::CHARSTYLE &&
+                   il.lyxtype() != InsetLayout::CUSTOM &&
+                   il.lyxtype() != InsetLayout::ELEMENT &&
+                   il.lyxtype ()!= InsetLayout::STANDARD)
                        enable = false;
                break;
                }
@@ -2145,9 +2145,11 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
 
        case LFUN_INSET_DISSOLVE:
                if (!cmd.argument().empty()) {
-                       InsetLayout il = cur.inset().getLayout(cur.buffer().params());
+                       InsetLayout const & il = cur.inset().getLayout(cur.buffer().params());
+                       InsetLayout::InsetLyXType const type = 
+                                       translateLyXType(to_utf8(cmd.argument()));
                        enable = cur.inset().lyxCode() == FLEX_CODE
-                                && il.lyxtype() == to_utf8(cmd.argument());
+                                && il.lyxtype() == type;
                } else {
                        enable = !isMainText(cur.bv().buffer())
                                 && cur.inset().nargs() == 1;
index f40c54fa964bf946abc0b53ae1bd10b397302fea..f8fcc963824758f1b80067922cdde32e44483508 100644 (file)
@@ -288,7 +288,7 @@ public:
        void expandFormats(MenuItem::Kind kind, Buffer const * buf);
        void expandFloatListInsert(Buffer const * buf);
        void expandFloatInsert(Buffer const * buf);
-       void expandFlexInsert(Buffer const * buf, std::string s);
+       void expandFlexInsert(Buffer const * buf, InsetLayout::InsetLyXType type);
        void expandToc2(Toc const & toc_list, size_t from, size_t to, int depth);
        void expandToc(Buffer const * buf);
        void expandPasteRecent(Buffer const * buf);
@@ -834,7 +834,8 @@ void MenuDefinition::expandFloatInsert(Buffer const * buf)
 }
 
 
-void MenuDefinition::expandFlexInsert(Buffer const * buf, string s)
+void MenuDefinition::expandFlexInsert(
+               Buffer const * buf, InsetLayout::InsetLyXType type)
 {
        if (!buf) {
                add(MenuItem(MenuItem::Command, qt_("No Document Open!"),
@@ -847,13 +848,13 @@ void MenuDefinition::expandFlexInsert(Buffer const * buf, string s)
        TextClass::InsetLayouts::const_iterator end = insetLayouts.end();
        for (; cit != end; ++cit) {
                docstring const label = cit->first;
-               if (cit->second.lyxtype() == s)
+               if (cit->second.lyxtype() == type)
                        addWithStatusCheck(MenuItem(MenuItem::Command, 
                                toqstr(translateIfPossible(label)),
                                FuncRequest(LFUN_FLEX_INSERT, label)));
        }
        // FIXME This is a little clunky.
-       if (items_.empty() && s == "custom")
+       if (items_.empty() && type == InsetLayout::CUSTOM)
                add(MenuItem(MenuItem::Command,
                                    qt_("No custom insets defined!"),
                                    FuncRequest(LFUN_NOACTION)));
@@ -1358,15 +1359,15 @@ void Menus::Impl::expand(MenuDefinition const & frommenu,
                        break;
 
                case MenuItem::CharStyles:
-                       tomenu.expandFlexInsert(buf, "charstyle");
+                       tomenu.expandFlexInsert(buf, InsetLayout::CHARSTYLE);
                        break;
 
                case MenuItem::Custom:
-                       tomenu.expandFlexInsert(buf, "custom");
+                       tomenu.expandFlexInsert(buf, InsetLayout::CUSTOM);
                        break;
 
                case MenuItem::Elements:
-                       tomenu.expandFlexInsert(buf, "element");
+                       tomenu.expandFlexInsert(buf, InsetLayout::ELEMENT);
                        break;
 
                case MenuItem::FloatListInsert:
index 823e61b085defd6ef62d99aebf247ec08b995d4e..a46cdb4d1ef7316ff146bc8b21ca95eabe7c58ec 100644 (file)
@@ -31,8 +31,8 @@ using std::vector;
 namespace lyx {
 
 InsetLayout::InsetLayout() :
-       name_(from_ascii("undefined")), labelstring_(from_ascii("UNDEFINED")),
-       decoration_(InsetLayout::Default),
+       name_(from_ascii("undefined")), lyxtype_(STANDARD),
+       labelstring_(from_ascii("UNDEFINED")), decoration_(InsetLayout::Default),
        font_(sane_font), labelfont_(sane_font), bgcolor_(Color_error), 
        multipar_(false), custompars_(false), forceplain_(true), 
        passthru_(false), needprotect_(false), freespacing_(false), 
@@ -136,9 +136,14 @@ bool InsetLayout::read(Lexer & lex, TextClass & tclass)
                        break;
                }
                switch (le) {
-               case IL_LYXTYPE:
-                       lex >> lyxtype_;
+               case IL_LYXTYPE: {
+                       string lt;
+                       lex >> lt;
+                       lyxtype_ = translateLyXType(lt);
+                       if (lyxtype_  == NOLYXTYPE)
+                               LYXERR0("Unknown LyXType `" << lt << "'.");
                        break;
+               }
                case IL_LATEXTYPE:
                        lex >> latextype_;
                        break;
@@ -258,4 +263,21 @@ bool InsetLayout::read(Lexer & lex, TextClass & tclass)
        return true;
 }
 
+
+InsetLayout::InsetLyXType translateLyXType(std::string const & str) 
+{
+       
+       if (support::compare_ascii_no_case(str, "charstyle") == 0)
+               return InsetLayout::CHARSTYLE;
+       if (support::compare_ascii_no_case(str, "custom") == 0)
+               return InsetLayout::CUSTOM;
+       if (support::compare_ascii_no_case(str, "element") == 0)
+               return InsetLayout::ELEMENT;
+       if (support::compare_ascii_no_case(str, "end") == 0)
+               return InsetLayout::END;
+       if (support::compare_ascii_no_case(str, "standard") == 0)
+               return InsetLayout::STANDARD;
+       return InsetLayout::NOLYXTYPE;
+}
+
 } //namespace lyx
index 8d7193021b25f12c82e230fbad6bba6cbe1a3ad5..7cab643560b6dc97ac0586b9cca914ddd03ab07d 100644 (file)
@@ -38,12 +38,20 @@ public:
                Conglomerate,
                Default
        };
+       enum InsetLyXType {
+               NOLYXTYPE,
+               CHARSTYLE,
+               CUSTOM,
+               ELEMENT,
+               END,
+               STANDARD
+       };
        ///
        bool read(Lexer & lexrc, TextClass & tclass);
        ///
        docstring name() const { return name_; };
        ///
-       std::string lyxtype() const { return lyxtype_; };
+       InsetLyXType lyxtype() const { return lyxtype_; };
        ///
        docstring labelstring() const { return labelstring_; };
        ///
@@ -88,7 +96,7 @@ private:
                * Values are 'charstyle', 'custom' (things that by default look like a
                * footnote), 'element' (docbook), 'standard'.
                */
-       std::string lyxtype_;
+       InsetLyXType lyxtype_;
        ///
        docstring labelstring_;
        ///
@@ -127,6 +135,9 @@ private:
        bool forceltr_;
 };
 
+///
+InsetLayout::InsetLyXType translateLyXType(std::string const & str);
+
 } // namespace lyx
 
 #endif