From 12a3c703d16d64c5897c228dadc3cb179eafdf87 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 2 Nov 2007 16:46:48 +0000 Subject: [PATCH] Remove redundant code and introduce InsetCollapsable::setLabelColor(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21380 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/InsetBox.cpp | 7 +------ src/insets/InsetCollapsable.h | 2 ++ src/insets/InsetERT.cpp | 1 - src/insets/InsetFloat.cpp | 5 ----- src/insets/InsetHyperlink.cpp | 30 +++++++++++++++++++----------- src/insets/InsetListings.cpp | 7 ++----- src/insets/InsetOptArg.cpp | 6 ------ src/insets/InsetTheorem.cpp | 5 ----- src/insets/InsetWrap.cpp | 5 ----- 9 files changed, 24 insertions(+), 44 deletions(-) diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp index 727ca92aab..7def781ac2 100644 --- a/src/insets/InsetBox.cpp +++ b/src/insets/InsetBox.cpp @@ -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); } diff --git a/src/insets/InsetCollapsable.h b/src/insets/InsetCollapsable.h index 6ac7ca4bcf..df406e26ef 100644 --- a/src/insets/InsetCollapsable.h +++ b/src/insets/InsetCollapsable.h @@ -72,6 +72,8 @@ public: /// void setLabelFont(FontInfo const & f); /// + void setLabelColor(ColorCode code); + /// bool isOpen() const { return geometry() != ButtonOnly; } /// CollapseStatus status() const; diff --git a/src/insets/InsetERT.cpp b/src/insets/InsetERT.cpp index a94d3729c0..0a9a3e9f86 100644 --- a/src/insets/InsetERT.cpp +++ b/src/insets/InsetERT.cpp @@ -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); diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 437a95010b..b710d9ae8c 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -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; } diff --git a/src/insets/InsetHyperlink.cpp b/src/insets/InsetHyperlink.cpp index d38509b60e..a799488864 100644 --- a/src/insets/InsetHyperlink.cpp +++ b/src/insets/InsetHyperlink.cpp @@ -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"); diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index fb41bd0fe1..fd8810a867 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -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); diff --git a/src/insets/InsetOptArg.cpp b/src/insets/InsetOptArg.cpp index 89e0e33f26..964c04e578 100644 --- a/src/insets/InsetOptArg.cpp +++ b/src/insets/InsetOptArg.cpp @@ -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")); } diff --git a/src/insets/InsetTheorem.cpp b/src/insets/InsetTheorem.cpp index 02d592295a..676248caff 100644 --- a/src/insets/InsetTheorem.cpp +++ b/src/insets/InsetTheorem.cpp @@ -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 diff --git a/src/insets/InsetWrap.cpp b/src/insets/InsetWrap.cpp index 008c3250b9..35271bbf1e 100644 --- a/src/insets/InsetWrap.cpp +++ b/src/insets/InsetWrap.cpp @@ -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"; -- 2.39.2