Skip to content

Commit

Permalink
changed marker tooltip to a popup
Browse files Browse the repository at this point in the history
  • Loading branch information
retailcoder committed Mar 29, 2024
1 parent d71c880 commit 8f3ef82
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 92 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Linq;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -52,29 +51,33 @@ protected async override Task OnExecuteAsync(object? parameter)
if (diff.Any())
{
Service.SettingsProvider.Write(newSettings);
ShowSettingsSavedMessage(diff);
}
}
}

var details = new StringBuilder();
foreach (var item in diff)
{
var itemTitle = SettingsUI.ResourceManager.GetString($"{item.Key}_Title");
if (item.SettingDataType == SettingDataType.ListSetting)
{
var nbReferenceValues = item.ReferenceValue is null ? 0 : ((object[])item.ReferenceValue.Value!).Length;
var nbComparableValues = item.ComparableValue is null ? 0 : ((object[])item.ComparableValue.Value!).Length;
details.AppendLine($"•{itemTitle}: {nbReferenceValues} items -> {nbComparableValues} items");
}
else
{
details.AppendLine($"•{itemTitle}: {item.ReferenceValue?.Value ?? "(added)"} -> {item.ComparableValue?.Value ?? "(removed)"}");
}
}

var msgKey = "SettingsSaved";
var message = SettingsUI.ResourceManager.GetString($"{msgKey}_Message") ?? $"[missing key:{msgKey}_Message]";
var title = SettingsUI.ResourceManager.GetString($"{msgKey}_Title") ?? $"[missing key:{msgKey}_Title]";
_message.ShowMessage(new() { Key = msgKey, Level = LogLevel.Information, Title = title, Message = message, Verbose = $"Modified settings:\n{details}" });
private void ShowSettingsSavedMessage(System.Collections.Generic.IEnumerable<RubberduckSettingDiff> diff)
{
var details = new StringBuilder();
foreach (var item in diff)
{
var itemTitle = SettingsUI.ResourceManager.GetString($"{item.Key}_Title");
if (item.SettingDataType == SettingDataType.ListSetting)
{
var nbReferenceValues = item.ReferenceValue is null ? 0 : ((object[])item.ReferenceValue.Value!).Length;
var nbComparableValues = item.ComparableValue is null ? 0 : ((object[])item.ComparableValue.Value!).Length;
details.AppendLine($"•{itemTitle}: {nbReferenceValues} items -> {nbComparableValues} items");
}
else
{
details.AppendLine($"•{itemTitle}: {item.ReferenceValue?.Value ?? "(added)"} -> {item.ComparableValue?.Value ?? "(removed)"}");
}
}

var msgKey = "SettingsSaved";
var message = SettingsUI.ResourceManager.GetString($"{msgKey}_Message") ?? $"[missing key:{msgKey}_Message]";
var title = SettingsUI.ResourceManager.GetString($"{msgKey}_Title") ?? $"[missing key:{msgKey}_Title]";
_message.ShowMessage(new() { Key = msgKey, Level = LogLevel.Information, Title = title, Message = message, Verbose = $"Modified settings:\n{details}" });
}
}
}
30 changes: 22 additions & 8 deletions Client/Rubberduck.UI/Services/TextMarkerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using Rubberduck.InternalApi.Model;
using Rubberduck.UI.Command.SharedHandlers;
using Rubberduck.UI.Services.Abstract;
using Rubberduck.UI.Shell;
using Rubberduck.UI.Shell.Document;
using System;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;

namespace Rubberduck.UI.Services;
Expand All @@ -20,7 +23,7 @@ public static class TextMarkerExtensions
public static readonly Color ErrorMarkerColor = Color.FromRgb(168, 18, 18);
public static readonly Color UndefinedMarkerColor = Color.FromRgb(0, 0, 0);

public static void WithTextMarker(this Diagnostic diagnostic, BindableTextEditor editor, TextMarkerService service)
public static void WithTextMarker(this Diagnostic diagnostic, BindableTextEditor editor, TextMarkerService service, ICommand showSettingsCommand)
{
var document = editor.Document;
var start = document.GetOffset(diagnostic.Range.Start.Line, diagnostic.Range.Start.Character + 1);
Expand All @@ -44,13 +47,13 @@ public static void WithTextMarker(this Diagnostic diagnostic, BindableTextEditor
_ => (TextMarkerTypes.NormalUnderline, UndefinedMarkerColor),
};

marker.ToolTip = CreateToolTip(editor, diagnostic);
marker.ToolTip = CreateToolTip(editor, diagnostic, showSettingsCommand);
}
}

private static ToolTip CreateToolTip(BindableTextEditor editor, Diagnostic diagnostic)
private static Popup CreateToolTip(BindableTextEditor editor, Diagnostic diagnostic, ICommand showSettingsCommand)
{
var vm = GetToolTipViewModel(diagnostic);
var vm = GetToolTipViewModel(diagnostic, showSettingsCommand);
var tooltip = new TextMarkerToolTip
{
DataContext = vm,
Expand All @@ -59,19 +62,30 @@ private static ToolTip CreateToolTip(BindableTextEditor editor, Diagnostic diagn
return tooltip;
}

private static ITextMarkerToolTip GetToolTipViewModel(Diagnostic diagnostic)
private static ITextMarkerToolTip GetToolTipViewModel(Diagnostic diagnostic, ICommand showSettingsCommand)
{
var code = diagnostic.Code!.Value.String!;
var id = (RubberduckDiagnosticId)Convert.ToInt32(new string(code.SkipWhile(e => !char.IsAsciiDigit(e)).ToArray()));
var id = (RubberduckDiagnosticId)Convert.ToInt32(code.Substring(3));

var title = id.ToString(); // TODO get from resources
var tla = code.Substring(0, 3);
var type = tla switch
{
"VBC" => "VB Compile Error",
"VBR" => "VB Runtime Error",
"RD3" => "Rubberduck Diagnostic",
_ => null,
};
return new TextMarkerToolTipViewModel
{
Code = code,
Title = $"{code}",
Title = title is null ? code : $"[{code}] {title}",
Text = diagnostic.Message,
Type = type ?? "unknown",
Severity = diagnostic.Severity ?? 0,
SettingKey = code,
HelpUri = diagnostic.CodeDescription?.Href
HelpUri = diagnostic.CodeDescription?.Href,
ShowSettingsCommand = showSettingsCommand,
};
}
}
2 changes: 2 additions & 0 deletions Client/Rubberduck.UI/Shell/Document/IDocumentTabViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Rubberduck.UI.Shell.StatusBar;
using Rubberduck.UI.Windows;
using System;
using System.Windows.Input;

namespace Rubberduck.UI.Shell.Document
{
Expand Down Expand Up @@ -35,6 +36,7 @@ public interface IDocumentTabViewModel : ITabViewModel

SupportedDocumentType DocumentType { get; }
IDocumentStatusViewModel Status { get; }
ICommand? ShowSettingsCommand { get; }
}

public interface ICodeDocumentTabViewModel : IDocumentTabViewModel
Expand Down
9 changes: 8 additions & 1 deletion Client/Rubberduck.UI/Shell/Document/ITextMarkerToolTip.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using System;
using System.Windows.Input;

namespace Rubberduck.UI.Shell.Document;

Expand All @@ -8,18 +9,24 @@ public interface ITextMarkerToolTip
string Code { get; }
string Text { get; }
string Title { get; }
string Type { get; }
Uri? HelpUri { get; }

string? SettingKey { get; }
DiagnosticSeverity Severity { get; }

ICommand ShowSettingsCommand { get; }
}

internal class TextMarkerToolTipViewModel : ITextMarkerToolTip
{
public string Code { get; init; }
public string Text { get; init; }
public string Title { get; init; }
public string Type { get; init; }
public string Text { get; init; }
public string? SettingKey { get; init; }
public DiagnosticSeverity Severity { get; init; }
public Uri? HelpUri { get; init; }

public ICommand ShowSettingsCommand { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;

namespace Rubberduck.UI.Shell.Document;
Expand Down Expand Up @@ -95,7 +96,7 @@ private bool ShowMarkerToolTip(int offset)
.OfType<TextMarker>()
.FirstOrDefault();

if (marker?.ToolTip is ToolTip tooltip)
if (marker?.ToolTip is Popup tooltip)
{
var markerRect = BackgroundGeometryBuilder.GetRectsForSegment(Editor.TextArea.TextView, marker).First();
markerRect.Offset(2d, 1d);
Expand All @@ -113,7 +114,7 @@ private bool ShowMarkerToolTip(int offset)

private void HideMarkerToolTip()
{
if (Editor.ToolTip is ToolTip toolTip)
if (Editor.ToolTip is Popup toolTip)
{
toolTip.IsOpen = false;
Editor.ToolTip = null;
Expand Down Expand Up @@ -204,7 +205,7 @@ private void UpdateDiagnostics()
_markers.RemoveAll(e => true);
foreach (var diagnostic in ViewModel.CodeDocumentState.Diagnostics)
{
diagnostic.WithTextMarker(Editor, _markers);
diagnostic.WithTextMarker(Editor, _markers, ViewModel.ShowSettingsCommand);
}
_margin.InvalidateVisual();
});
Expand Down
61 changes: 38 additions & 23 deletions Client/Rubberduck.UI/Shell/Document/TextMarkerToolTip.xaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
<ToolTip x:Class="Rubberduck.UI.Shell.Document.TextMarkerToolTip"
<Popup x:Class="Rubberduck.UI.Shell.Document.TextMarkerToolTip"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Rubberduck.UI.Shell.Document" xmlns:shell="clr-namespace:Rubberduck.UI.Shell"
mc:Ignorable="d"
Padding="0"
MaxWidth="500"
d:DataContext="{d:DesignInstance Type=local:TextMarkerToolTipViewModel, IsDesignTimeCreatable=True}"
d:DesignHeight="24" d:DesignWidth="800">
<ToolTip.Resources>
d:DesignHeight="80" d:DesignWidth="200">
<Popup.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Rubberduck.UI;component/Styles/DefaultStyle.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Rubberduck.UI;component/Styles/Templates.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</ToolTip.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Grid.Row="0" Background="{DynamicResource ThemeBackgroundColorBrush}" />
<StackPanel Orientation="Horizontal" Margin="5,2">
<Image Height="16" Width="16" Source="{Binding Severity, Converter={StaticResource DiagnosticSeverityIconConverter}}" />
<TextBlock Margin="5,2" Padding="1,1,1,0" FontSize="12" FontWeight="Bold" Text="{Binding Title}" />
</StackPanel>
</Popup.Resources>
<Border BorderThickness="1"
BorderBrush="{DynamicResource ThemeAccent1DarkColorBrush}"
Background="{DynamicResource ThemeBackgroundColorBrush}">
<StackPanel>
<DockPanel Background="{DynamicResource ThemeBackgroundDarkColorBrush}">

<shell:FlatButton DockPanel.Dock="Right" VerticalAlignment="Top" HorizontalAlignment="Right"
Icon="{StaticResource GearIcon}"
Margin="4,6"
Command="{Binding ShowSettingsCommand}"
CommandParameter="{Binding SettingKey}" />

<shell:FlatButton Icon="{StaticResource GearIcon}" HorizontalAlignment="Right" />
<DockPanel DockPanel.Dock="Top" VerticalAlignment="Top" Margin="5,0">
<Image DockPanel.Dock="Left" Height="16" Width="16" VerticalAlignment="Center" Source="{Binding Severity, Converter={StaticResource DiagnosticSeverityIconConverter}}" />
<Label DockPanel.Dock="Left" VerticalAlignment="Center" Margin="0,2" Style="{DynamicResource TextMarkerToolTipTitleStyle}">
<TextBlock VerticalAlignment="Center" Text="{Binding Title}" />
</Label>
</DockPanel>

<TextBlock Grid.Row="1" Margin="5" Padding="1,0,1,1" FontSize="11" FontWeight="SemiBold" Text="{Binding Text}" TextWrapping="Wrap" />
</DockPanel>
<DockPanel>
<Label DockPanel.Dock="Top" Margin="0" Style="{DynamicResource TextMarkerToolTipSubtitleStyle}">
<TextBlock Margin="5,0" Text="{Binding Type}" TextWrapping="Wrap" />
</Label>
<Label DockPanel.Dock="Top" Margin="0" Style="{DynamicResource TextMarkerToolTipTextStyle}">
<TextBlock Margin="5,0" Text="{Binding Text}" TextWrapping="Wrap" />
</Label>

<TextBlock Grid.Row="2" Margin="5" Padding="1,0,1,1" FontSize="11" FontWeight="SemiBold" Text="{Binding HelpUri}"
TextWrapping="NoWrap" Visibility="{Binding HelpUri, Converter={StaticResource HasItemsVisibilityConverter}}" />

</Grid>
</ToolTip>
<Label DockPanel.Dock="Top" Style="{DynamicResource HyperlinkLabelStyle}" Margin="5,0"
Visibility="{Binding HelpUri, Converter={StaticResource HasItemsVisibilityConverter}}">
<TextBlock Text="{Binding HelpUri}" TextWrapping="NoWrap"/>
</Label>
</DockPanel>
</StackPanel>
</Border>
</Popup>
4 changes: 2 additions & 2 deletions Client/Rubberduck.UI/Shell/Document/TextMarkerToolTip.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace Rubberduck.UI.Shell.Document
{
/// <summary>
/// Interaction logic for TextMarkerToolTip.xaml
/// </summary>
public partial class TextMarkerToolTip : ToolTip
public partial class TextMarkerToolTip : Popup
{
public TextMarkerToolTip()
{
Expand Down
Loading

0 comments on commit 8f3ef82

Please sign in to comment.