Feature Request: Allow use of a separate color for linked usernames.

The setting is HTMLAgentColor, I will not add this to preferences for now.

Note that usernames before the colon in the chat are cached,
set before login to change it for everyone or relog.
Also hook up getStyle() for the registered urls,
cleans up some code in lltexteditor.
This commit is contained in:
Lirusaito
2019-02-01 08:12:12 -05:00
parent a7886443c5
commit d20dbaa7d2
8 changed files with 65 additions and 45 deletions

View File

@@ -4268,7 +4268,7 @@ void LLTextEditor::appendTextImpl(const std::string &new_text, const LLStyleSP s
{ {
std::string text = new_text; std::string text = new_text;
static LLUICachedControl<bool> replace_links("SinguReplaceLinks"); static LLUICachedControl<bool> replace_links("SinguReplaceLinks");
bool is_link = style && !style->getLinkHREF().empty(); // Don't search for URLs inside a link segment (STORM-358). bool is_link = style && !style->isLink(); // Don't search for URLs inside a link segment (STORM-358).
S32 part = (S32)LLTextParser::WHOLE; S32 part = (S32)LLTextParser::WHOLE;
if (mReadOnly && mParseHTML && !is_link) // Singu Note: Do not replace html if the user is going to edit it. (Like in profiles) if (mReadOnly && mParseHTML && !is_link) // Singu Note: Do not replace html if the user is going to edit it. (Like in profiles)
@@ -4276,16 +4276,21 @@ void LLTextEditor::appendTextImpl(const std::string &new_text, const LLStyleSP s
LL_RECORD_BLOCK_TIME(FTM_PARSE_HTML); LL_RECORD_BLOCK_TIME(FTM_PARSE_HTML);
S32 start=0,end=0; S32 start=0,end=0;
LLUrlMatch match; LLUrlMatch match;
const auto& link_color = mLinkColor ? *mLinkColor : LLUI::sConfigGroup->getColor4("HTMLLinkColor");
auto append_substr = [&](const size_t& pos, const size_t& count) auto append_substr = [&](const size_t& pos, const size_t& count)
{ {
appendAndHighlightText(text.substr(pos, count), part, style); appendAndHighlightText(text.substr(pos, count), part, style);
}; };
auto append_link = [&](const std::string& link) auto append_link = [&](const std::string& link, LLStyleSP link_style)
{ {
LLStyleSP link_style(style ? new LLStyle(*style) : new LLStyle); if (style) // Respect styling
link_style->setColor(link_color); {
link_style->setLinkHREF(match.getUrl()); const auto& text_style = *style;
link_style->mItalic = text_style.mItalic;
link_style->mBold = text_style.mBold;
link_style->mUnderline = text_style.mUnderline;
}
// Hack around colors looking bad on some backgrounds by allowing setting link color for this editor
if (mLinkColor) link_style->setColor(*mLinkColor);
appendAndHighlightText(link, part, link_style, true/*match.underlineOnHoverOnly()*/); appendAndHighlightText(link, part, link_style, true/*match.underlineOnHoverOnly()*/);
}; };
while (!text.empty() && LLUrlRegistry::instance().findUrl(text, match, while (!text.empty() && LLUrlRegistry::instance().findUrl(text, match,
@@ -4323,7 +4328,7 @@ void LLTextEditor::appendTextImpl(const std::string &new_text, const LLStyleSP s
}*/ }*/
// output the styled url // output the styled url
append_link(label + match.getQuery()); append_link(label + match.getQuery(), match.getStyle());
bool tooltip_required = !match.getTooltip().empty(); bool tooltip_required = !match.getTooltip().empty();
// set the tooltip for the Url label // set the tooltip for the Url label
@@ -4359,7 +4364,7 @@ void LLTextEditor::appendTextImpl(const std::string &new_text, const LLStyleSP s
append_substr(start, brackets ? 1 : pos-start); append_substr(start, brackets ? 1 : pos-start);
// In the special cases, only link exactly the url, this might not have a protocol so calculate the exact string // In the special cases, only link exactly the url, this might not have a protocol so calculate the exact string
if (fallback) url = brackets ? text.substr(start+1, text.find(' ', start+2)-start) : text.substr(start, end-start); if (fallback) url = brackets ? text.substr(start+1, text.find(' ', start+2)-start) : text.substr(start, end-start);
append_link(url); // Append the link append_link(url, match.getStyle()); // Append the link
const auto url_end = pos + url.size(); const auto url_end = pos + url.size();
if (fallback == brackets && end > url_end) // Ending text, only in special case if brackets present if (fallback == brackets && end > url_end) // Ending text, only in special case if brackets present
append_substr(url_end, end-url_end); append_substr(url_end, end-url_end);

View File

@@ -69,14 +69,13 @@ std::string LLUrlEntryBase::getIcon(const std::string &url)
return mIcon; return mIcon;
} }
/*LLStyle::Params LLUrlEntryBase::getStyle() const LLStyleSP LLUrlEntryBase::getStyle() const
{ {
LLStyle::Params style_params; static LLUICachedControl<LLColor4> color("HTMLLinkColor");
style_params.color = LLUIColorTable::instance().getColor("HTMLLinkColor"); LLStyleSP style_params(new LLStyle(true, color, LLStringUtil::null));
style_params.readonly_color = LLUIColorTable::instance().getColor("HTMLLinkColor"); //style_params->mUnderline = true; // Singu Note: We're not gonna bother here, underlining on hover
style_params.font.style = "UNDERLINE";
return style_params; return style_params;
}*/ }
std::string LLUrlEntryBase::getIDStringFromUrl(const std::string &url) const std::string LLUrlEntryBase::getIDStringFromUrl(const std::string &url) const
@@ -677,13 +676,12 @@ std::string LLUrlEntryAgent::getLabel(const std::string &url, const LLUrlLabelCa
} }
} }
/*LLStyle::Params LLUrlEntryAgent::getStyle() const LLStyleSP LLUrlEntryAgent::getStyle() const
{ {
LLStyle::Params style_params = LLUrlEntryBase::getStyle(); static LLUICachedControl<LLColor4> color("HTMLAgentColor");
style_params.color = LLUIColorTable::instance().getColor("HTMLLinkColor"); LLStyleSP style_params(new LLStyle(true, color, LLStringUtil::null));
style_params.readonly_color = LLUIColorTable::instance().getColor("HTMLLinkColor");
return style_params; return style_params;
}*/ }
std::string localize_slapp_label(const std::string& url, const std::string& full_name) std::string localize_slapp_label(const std::string& url, const std::string& full_name)
{ {
@@ -788,11 +786,12 @@ std::string LLUrlEntryAgentName::getLabel(const std::string &url, const LLUrlLab
} }
} }
/*LLStyle::Params LLUrlEntryAgentName::getStyle() const LLStyleSP LLUrlEntryAgentName::getStyle() const
{ {
// don't override default colors static LLUICachedControl<LLColor4> color("HTMLAgentColor");
return LLStyle::Params().is_link(false); LLStyleSP style_params(new LLStyle(true, color, LLStringUtil::null));
}*/ return style_params;
}
// //
// LLUrlEntryAgentCompleteName describes a Second Life agent complete name Url, e.g., // LLUrlEntryAgentCompleteName describes a Second Life agent complete name Url, e.g.,
@@ -924,13 +923,12 @@ std::string LLUrlEntryGroup::getLabel(const std::string &url, const LLUrlLabelCa
} }
} }
/*LLStyle::Params LLUrlEntryGroup::getStyle() const LLStyleSP LLUrlEntryGroup::getStyle() const
{ {
LLStyle::Params style_params = LLUrlEntryBase::getStyle(); LLStyleSP style_params = LLUrlEntryBase::getStyle();
style_params.color = LLUIColorTable::instance().getColor("HTMLLinkColor"); //style_params->mUnderline = false; // Singu Note: We're not gonna bother here, underlining on hover
style_params.readonly_color = LLUIColorTable::instance().getColor("HTMLLinkColor");
return style_params; return style_params;
}*/ }
// //
@@ -1392,11 +1390,12 @@ std::string LLUrlEntryNoLink::getLabel(const std::string &url, const LLUrlLabelC
return getUrl(url); return getUrl(url);
} }
/*LLStyle::Params LLUrlEntryNoLink::getStyle() const LLStyleSP LLUrlEntryNoLink::getStyle() const
{ {
// Don't render as URL (i.e. no context menu or hand cursor). // Don't render as URL (i.e. no context menu or hand cursor).
return LLStyle::Params().is_link(false); // Singu Note: What the heck? No, that's misleading!!
}*/ return LLUrlEntryBase::getStyle();
}
// //

View File

@@ -82,7 +82,7 @@ public:
virtual std::string getIcon(const std::string &url); virtual std::string getIcon(const std::string &url);
/// Return the style to render the displayed text /// Return the style to render the displayed text
//virtual LLStyle::Params getStyle() const; virtual LLStyleSP getStyle() const;
/// Given a matched Url, return a tooltip string for the hyperlink /// Given a matched Url, return a tooltip string for the hyperlink
virtual std::string getTooltip(const std::string &string) const { return mTooltip; } virtual std::string getTooltip(const std::string &string) const { return mTooltip; }
@@ -232,7 +232,7 @@ public:
/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb) override; /*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb) override;
/*virtual*/ std::string getIcon(const std::string &url) override; /*virtual*/ std::string getIcon(const std::string &url) override;
/*virtual*/ std::string getTooltip(const std::string &string) const override; /*virtual*/ std::string getTooltip(const std::string &string) const override;
///*virtual*/ LLStyle::Params getStyle() const override; /*virtual*/ LLStyleSP getStyle() const override;
/*virtual*/ LLUUID getID(const std::string &string) const override; /*virtual*/ LLUUID getID(const std::string &string) const override;
/*virtual*/ bool underlineOnHoverOnly(const std::string &string) const override; /*virtual*/ bool underlineOnHoverOnly(const std::string &string) const override;
protected: protected:
@@ -265,7 +265,7 @@ public:
} }
/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb) override; /*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb) override;
///*virtual*/ LLStyle::Params getStyle() const override; /*virtual*/ LLStyleSP getStyle() const override;
protected: protected:
// override this to pull out relevant name fields // override this to pull out relevant name fields
virtual std::string getName(const LLAvatarName& avatar_name) = 0; virtual std::string getName(const LLAvatarName& avatar_name) = 0;
@@ -332,7 +332,7 @@ class LLUrlEntryGroup : public LLUrlEntryBase
public: public:
LLUrlEntryGroup(); LLUrlEntryGroup();
/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb) override; /*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb) override;
///*virtual*/ LLStyle::Params getStyle() const override; /*virtual*/ LLStyleSP getStyle() const override;
/*virtual*/ LLUUID getID(const std::string &string) const override; /*virtual*/ LLUUID getID(const std::string &string) const override;
private: private:
void onGroupNameReceived(const LLUUID& id, const std::string& name, bool is_group); void onGroupNameReceived(const LLUUID& id, const std::string& name, bool is_group);
@@ -492,7 +492,7 @@ public:
LLUrlEntryNoLink(); LLUrlEntryNoLink();
/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb) override; /*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb) override;
/*virtual*/ std::string getUrl(const std::string &string) const override; /*virtual*/ std::string getUrl(const std::string &string) const override;
///*virtual*/ LLStyle::Params getStyle() const override; /*virtual*/ LLStyleSP getStyle() const override;
}; };
/// ///

View File

@@ -46,7 +46,7 @@ LLUrlMatch::LLUrlMatch() :
void LLUrlMatch::setValues(U32 start, U32 end, const std::string &url, const std::string &label, void LLUrlMatch::setValues(U32 start, U32 end, const std::string &url, const std::string &label,
const std::string& query, const std::string &tooltip, const std::string& query, const std::string &tooltip,
const std::string &icon, /*const LLStyle::Params& style,*/ const std::string &icon, const LLStyleSP& style,
const std::string &menu, const std::string &location, const std::string &menu, const std::string &location,
const LLUUID& id, bool underline_on_hover_only, bool trusted) const LLUUID& id, bool underline_on_hover_only, bool trusted)
{ {
@@ -57,8 +57,8 @@ void LLUrlMatch::setValues(U32 start, U32 end, const std::string &url, const std
mQuery = query; mQuery = query;
mTooltip = tooltip; mTooltip = tooltip;
mIcon = icon; mIcon = icon;
//mStyle = style; mStyle = style;
//mStyle.link_href = url; mStyle->setLinkHREF(url);
mMenuName = menu; mMenuName = menu;
mLocation = location; mLocation = location;
mID = id; mID = id;

View File

@@ -70,7 +70,7 @@ public:
std::string getIcon() const { return mIcon; } std::string getIcon() const { return mIcon; }
/// Return the color to render the displayed text /// Return the color to render the displayed text
//LLStyle::Params getStyle() const { return mStyle; } LLStyleSP getStyle() const { return mStyle; }
/// Return the name of a XUI file containing the context menu items /// Return the name of a XUI file containing the context menu items
std::string getMenuName() const { return mMenuName; } std::string getMenuName() const { return mMenuName; }
@@ -87,7 +87,7 @@ public:
/// Change the contents of this match object (used by LLUrlRegistry) /// Change the contents of this match object (used by LLUrlRegistry)
void setValues(U32 start, U32 end, const std::string &url, const std::string &label, void setValues(U32 start, U32 end, const std::string &url, const std::string &label,
const std::string& query, const std::string &tooltip, const std::string &icon, const std::string& query, const std::string &tooltip, const std::string &icon,
/*const LLStyle::Params& style,*/ const std::string &menu, const LLStyleSP& style, const std::string &menu,
const std::string &location, const LLUUID& id, const std::string &location, const LLUUID& id,
bool underline_on_hover_only = false, bool trusted = false); bool underline_on_hover_only = false, bool trusted = false);
@@ -103,7 +103,7 @@ private:
std::string mMenuName; std::string mMenuName;
std::string mLocation; std::string mLocation;
LLUUID mID; LLUUID mID;
//LLStyle::Params mStyle; LLStyleSP mStyle;
bool mUnderlineOnHoverOnly; bool mUnderlineOnHoverOnly;
bool mTrusted; bool mTrusted;
}; };

View File

@@ -265,7 +265,7 @@ bool LLUrlRegistry::findUrl(const std::string &text, LLUrlMatch &match, const LL
match_entry->getQuery(url), match_entry->getQuery(url),
match_entry->getTooltip(url), match_entry->getTooltip(url),
match_entry->getIcon(url), match_entry->getIcon(url),
//match_entry->getStyle(), match_entry->getStyle(),
match_entry->getMenuName(), match_entry->getMenuName(),
match_entry->getLocation(url), match_entry->getLocation(url),
match_entry->getID(url), match_entry->getID(url),
@@ -302,7 +302,7 @@ bool LLUrlRegistry::findUrl(const LLWString &text, LLUrlMatch &match, const LLUr
match.getQuery(), match.getQuery(),
match.getTooltip(), match.getTooltip(),
match.getIcon(), match.getIcon(),
//match.getStyle(), match.getStyle(),
match.getMenuName(), match.getMenuName(),
match.getLocation(), match.getLocation(),
match.getID(), match.getID(),

View File

@@ -9072,6 +9072,22 @@ This should be as low as possible, but too low may break functionality</string>
<key>Value</key> <key>Value</key>
<integer>400</integer> <integer>400</integer>
</map> </map>
<key>HTMLAgentColor</key>
<map>
<key>Comment</key>
<string>Color of hyperlinked usernames</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Color4</string>
<key>Value</key>
<array>
<real>0.600000023842</real>
<real>0.600000023842</real>
<real>1.0</real>
<real>1.0</real>
</array>
</map>
<key>HTMLLinkColor</key> <key>HTMLLinkColor</key>
<map> <map>
<key>Comment</key> <key>Comment</key>

View File

@@ -58,7 +58,7 @@ const LLStyleSP &LLStyleMap::lookupAgent(const LLUUID &source)
LLStyleSP style(new LLStyle); LLStyleSP style(new LLStyle);
if (source.notNull()) if (source.notNull())
{ {
style->setColor(gSavedSettings.getColor4("HTMLLinkColor")); style->setColor(gSavedSettings.getColor4("HTMLAgentColor"));
std::string link = llformat("secondlife:///app/agent/%s/about",source.asString().c_str()); std::string link = llformat("secondlife:///app/agent/%s/about",source.asString().c_str());
style->setLinkHREF(link); style->setLinkHREF(link);
} }