]> git.lyx.org Git - lyx.git/commitdiff
Remove redundant code and introduce InsetCollapsable::setLabelColor().
authorAbdelrazak Younes <younes@lyx.org>
Fri, 2 Nov 2007 16:46:48 +0000 (16:46 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Fri, 2 Nov 2007 16:46:48 +0000 (16:46 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21380 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetBox.cpp
src/insets/InsetCollapsable.h
src/insets/InsetERT.cpp
src/insets/InsetFloat.cpp
src/insets/InsetHyperlink.cpp
src/insets/InsetListings.cpp
src/insets/InsetOptArg.cpp
src/insets/InsetTheorem.cpp
src/insets/InsetWrap.cpp

index 727ca92aab2f02f1a6236502cd3be9b6573aef17..7def781ac28dfa21bca8b8f9ac4af6478226e3c7 100644 (file)
@@ -142,10 +142,6 @@ void InsetBox::read(Buffer const & buf, Lexer & lex)
 
 void InsetBox::setButtonLabel()
 {
-       FontInfo font = sane_font;
-       font.decSize();
-       font.decSize();
-
        BoxType btype = boxtranslator().find(params_.type);
 
        docstring label;
@@ -162,8 +158,7 @@ void InsetBox::setButtonLabel()
 
        setLabel(label);
 
-       font.setColor(Color_foreground);
-       setLabelFont(font);
+       setLabelColor(Color_foreground);
 }
 
 
index 6ac7ca4bcf60afc70b9174a98495871bca5c5236..df406e26ef0a1527639cad917e369da0477b28a3 100644 (file)
@@ -72,6 +72,8 @@ public:
        ///
        void setLabelFont(FontInfo const & f);
        ///
+       void setLabelColor(ColorCode code);
+       ///
        bool isOpen() const { return geometry() != ButtonOnly; }
        ///
        CollapseStatus status() const;
index a94d3729c044118c0275c489893671bb6ba4c4c2..0a9a3e9f86201fb87eb052dfae1cc54978cb5584 100644 (file)
@@ -52,7 +52,6 @@ using std::string;
 void InsetERT::init()
 {
        setButtonLabel();
-
        // FIXME: what to do with those?
        //text_.current_font.setLanguage(latex_language);
        //text_.real_current_font.setLanguage(latex_language);
index 437a95010b6c73da5ee3e654633cfbffa1e5ddcd..b710d9ae8c9e5a3e8135a33cb8f7f0cee61b2a64 100644 (file)
@@ -115,11 +115,6 @@ InsetFloat::InsetFloat(BufferParams const & bp, string const & type)
        : InsetCollapsable(bp), name_(from_utf8(type))
 {
        setLabel(_("float: ") + floatName(type, bp));
-       FontInfo font = sane_font;
-       font.decSize();
-       font.decSize();
-       font.setColor(Color_collapsable);
-       setLabelFont(font);
        params_.type = type;
 }
 
index d38509b60e7943527ed7b3a3cfb0df960d8337c1..a799488864cd12398b93e95a97bf254f615c89bf 100644 (file)
@@ -65,28 +65,36 @@ docstring const InsetHyperlink::getScreenLabel(Buffer const &) const
 }
 
 
+static void replaceAny(docstring & s, docstring const & items,
+               docstring const & replacement)
+{
+       if (s.empty())
+               return;
+
+       size_t i = 0;
+       while (i < s.size()) {
+               if ((i = s.find_first_of(items, i)) == string::npos)
+                       break;
+               s.insert(i, replacement);
+               i += 2;
+       }
+}
+
+
 int InsetHyperlink::latex(Buffer const &, odocstream & os,
                    OutputParams const & runparams) const
 {
        docstring url = getParam("target");
        static docstring const backslash = from_ascii("\\");
        static docstring const braces = from_ascii("{}");
-       static char_type const chars_url[2] = {'%', '#'};
        static char_type const chars_name[6] = {
                '&', '_', '$', '%', '#', '^'};
 
        // The characters in chars_url[] need to be changed to a command when
        // they are in the url field.
-       if (!url.empty()) {
-               // the chars_url[] characters must be handled for both, url and href
-               for (int k = 0; k < 2; k++) {
-                       for (size_t i = 0, pos;
-                               (pos = url.find(chars_url[k], i)) != string::npos;
-                               i = pos + 2) {
-                               url.replace(pos, 1, backslash + chars_url[k]);
-                       }
-               }
-       } // end if (!url.empty())
+       // the chars_url[] characters must be handled for both, url and href
+       static docstring const chars_url = from_ascii("%#");
+       replaceAny(url, chars_url, backslash);
 
        docstring name = getParam("name");
 
index fb41bd0fe19d8fa3d52fc0580319fbe255c85d09..fd8810a867603f233643cb9ceb93d9c5d2f949c9 100644 (file)
@@ -48,11 +48,8 @@ char const lstinline_delimiters[] =
 void InsetListings::init()
 {
        setButtonLabel();
-       FontInfo font = sane_font;
-       font.decSize();
-       font.decSize();
-       font.setColor(Color_none);
-       setLabelFont(font);
+       layout_.labelfont.setColor(Color_none);
+
        // FIXME: what to do with those?
        //text_.current_font.setLanguage(latex_language);
        //text_.real_current_font.setLanguage(latex_language);
index 89e0e33f268fd7ef3a9ae8da6ec450d0b1e621f4..964c04e578384c539f11877893d818cff857a1f8 100644 (file)
@@ -24,9 +24,6 @@ namespace lyx {
 InsetOptArg::InsetOptArg(BufferParams const & ins)
        : InsetCollapsable(ins)
 {
-       FontInfo font = sane_font;
-       font.setColor(Color_collapsable);
-       setLabelFont(font);
        setLabel(_("opt"));
 }
 
@@ -34,9 +31,6 @@ InsetOptArg::InsetOptArg(BufferParams const & ins)
 InsetOptArg::InsetOptArg(InsetOptArg const & in)
        : InsetCollapsable(in)
 {
-       FontInfo font = sane_font;
-       font.setColor(Color_collapsable);
-       setLabelFont(font);
        setLabel(_("opt"));
 }
 
index 02d592295afe39d73d16cdc68ecca88b5e59c94b..676248caff71773f850d691500fb3ab2125f94fa 100644 (file)
@@ -40,11 +40,6 @@ Inset.heorem::InsetTheorem()
        : InsetCollapsable()
 {
        setLabel(_("theorem"));
-       FontInfo font = sane_font;
-       font.decSize();
-       font.decSize();
-       font.setColor(Color_collapsable);
-       setLabelFont(font);
 #if 0
        setAutoCollapse(false);
 #endif
index 008c3250b9d3979765587e816446e2461adc259b..35271bbf1e10a5c97e35f2304288b4d746e2b098 100644 (file)
@@ -47,11 +47,6 @@ InsetWrap::InsetWrap(BufferParams const & bp, string const & type)
        : InsetCollapsable(bp), name_(from_utf8(type))
 {
        setLabel(_("wrap: ") + floatName(type, bp));
-       FontInfo font = sane_font;
-       font.decSize();
-       font.decSize();
-       font.setColor(Color_collapsable);
-       setLabelFont(font);
        params_.type = type;
        params_.lines = 0;
        params_.placement = "o";