Skip to content

Commit

Permalink
- Fix hyperlink color is not themed (fix #347)
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Feb 14, 2025
1 parent 78f337f commit 8aa4ac2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Codist/Helpers/ThemeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static ThemeHelper() {
public static WpfBrush DocumentPageBrush { get; private set; }
public static GdiColor DocumentTextColor { get; private set; }
public static WpfBrush DocumentTextBrush { get; private set; }
public static WpfBrush HyperlinkBrush { get; private set; }
public static WpfBrush FileTabProvisionalSelectionBrush { get; private set; }
public static WpfColor ToolWindowBackgroundColor { get; private set; }
public static WpfColor TitleBackgroundColor { get; private set; }
Expand Down Expand Up @@ -152,6 +153,7 @@ static void RefreshThemeCache() {
DocumentPageBrush = new WpfBrush(DocumentPageColor.ToWpfColor());
DocumentTextColor = CommonDocumentColors.PageTextColorKey.GetGdiColor();
DocumentTextBrush = new WpfBrush(DocumentTextColor.ToWpfColor());
HyperlinkBrush = CommonDocumentColors.HyperlinkBrushKey.GetWpfBrush();
FileTabProvisionalSelectionBrush = EnvironmentColors.FileTabProvisionalSelectedActiveBrushKey.GetWpfBrush();
ToolWindowBackgroundColor = EnvironmentColors.ToolWindowBackgroundColorKey.GetWpfColor();
TitleBackgroundColor = EnvironmentColors.MainWindowActiveCaptionColorKey.GetWpfColor();
Expand Down
16 changes: 12 additions & 4 deletions Codist/Helpers/WpfHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,22 @@ public static TTextBlock Append<TTextBlock>(this TTextBlock block, string text,
}
return block;
}
public static TTextBlock AppendLink<TTextBlock>(this TTextBlock block, string text, string uri, string toolTip)
public static TTextBlock AppendLink<TTextBlock>(this TTextBlock block, string text, string uri, string toolTip, Brush foreground = null)
where TTextBlock : TextBlock {
block.Inlines.Add(new Hyperlink(new Run(text)) { NavigateUri = new Uri(uri), ToolTip = toolTip }.ClickToNavigate());
var link = new Hyperlink(new Run(text)) { NavigateUri = new Uri(uri), ToolTip = toolTip }.ClickToNavigate();
if (foreground != null) {
link.Foreground = foreground;
}
block.Inlines.Add(link);
return block;
}
public static TTextBlock AppendLink<TTextBlock>(this TTextBlock block, string text, Action<Hyperlink> clickHandler, string toolTip)
public static TTextBlock AppendLink<TTextBlock>(this TTextBlock block, string text, Action<Hyperlink> clickHandler, string toolTip, Brush foreground = null)
where TTextBlock : TextBlock {
block.Inlines.Add(new Hyperlink(new Run(text)) { ToolTip = toolTip }.ClickToNavigate(clickHandler));
var link = new Hyperlink(new Run(text)) { ToolTip = toolTip }.ClickToNavigate(clickHandler);
if (foreground != null) {
link.Foreground = foreground;
}
block.Inlines.Add(link);
return block;
}
public static TTextBlock AppendFileLink<TTextBlock>(this TTextBlock block, string file, string folder)
Expand Down
4 changes: 2 additions & 2 deletions Codist/Options/SyntaxHighlightCustomizationWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,8 @@ void LoadSyntaxStyles(SyntaxStyleSource source) {
catch (Exception ex) {
MessageWindow.Error(ex);
}
}, R.T_ClassificationTypesJsonTip));
l.Add(new TextBlock { Margin = WpfHelper.SmallMargin }.AppendLink(R.T_AboutCustomSyntaxRules, "https://github.com/wmjordan/Codist/wiki/ClassificationTypes.json-and-Codist.ct.json", R.T_AboutCustomSyntaxRulesTip));
}, R.T_ClassificationTypesJsonTip, ThemeHelper.HyperlinkBrush));
l.Add(new TextBlock { Margin = WpfHelper.SmallMargin }.AppendLink(R.T_AboutCustomSyntaxRules, "https://github.com/wmjordan/Codist/wiki/ClassificationTypes.json-and-Codist.ct.json", R.T_AboutCustomSyntaxRulesTip, ThemeHelper.HyperlinkBrush));
}
}

Expand Down
4 changes: 3 additions & 1 deletion Codist/Semantics/XmlDocRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ static string UnindentTextBlock(string text) {
void CreateLink(InlineCollection inlines, XElement e, string url) {
var link = new Hyperlink {
NavigateUri = new Uri(url),
ToolTip = e.Attribute("title") != null ? $"{e.Attribute("title").Value}{Environment.NewLine}{url}" : url
ToolTip = e.Attribute("title") != null ? $"{e.Attribute("title").Value}{Environment.NewLine}{url}" : url,
Foreground = ThemeHelper.HyperlinkBrush
}.ClickToNavigate();
if (e.IsEmpty) {
link.Inlines.Add(url);
Expand Down Expand Up @@ -689,6 +690,7 @@ static bool IsInlineElementName(string name) {
case "seealso":
case "paramref":
case "typeparamref":
case "a":
case "b":
case "i":
case "u":
Expand Down

0 comments on commit 8aa4ac2

Please sign in to comment.