Skip to content

Commit bafe018

Browse files
committed
Add about window
1 parent 66c5732 commit bafe018

File tree

5 files changed

+255
-2
lines changed

5 files changed

+255
-2
lines changed

src/CodeSnip/MainWindow.xaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
</DataTemplate>
5151
</mah:MetroWindow.Resources>
5252
<mah:MetroWindow.InputBindings>
53+
<!-- F1 : Open About dialog -->
54+
<KeyBinding Key="F1" Command="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=OpenAboutCommand}" />
5355
<!-- Ctrl+Shift + S : Save snippet code -->
5456
<KeyBinding Key="S" Modifiers="Ctrl+Shift" Command="{Binding SaveCodeCommand}"/>
5557
<!-- Ctrl+Shift + A : Add new snippet -->
@@ -81,7 +83,13 @@
8183
<mah:WindowCommands/>
8284
</mah:MetroWindow.LeftWindowCommands>
8385
<mah:MetroWindow.RightWindowCommands>
84-
<mah:WindowCommands/>
86+
<mah:WindowCommands>
87+
<Button Click="About_Click" ToolTip="About" Margin="0,0,10,0">
88+
<Path Data="{StaticResource InfoCircle}" Fill="{DynamicResource MahApps.Brushes.Text}"
89+
Width="16" Height="16" Stretch="Uniform">
90+
</Path>
91+
</Button>
92+
</mah:WindowCommands>
8593
</mah:MetroWindow.RightWindowCommands>
8694

8795
<mah:MetroWindow.Flyouts>

src/CodeSnip/MainWindow.xaml.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public partial class MainWindow : MetroWindow, IFlyoutService
3232
public ICommand ToggleMultiLineCommentCommand { get; }
3333
public ICommand ToggleCommentSelectionCommand { get; }
3434

35+
public ICommand OpenAboutCommand { get; }
36+
3537
public MainWindow()
3638
{
3739
InitializeComponent();
@@ -43,7 +45,7 @@ public MainWindow()
4345
ToggleSingleLineCommentCommand = new RelayCommand(_ => ToggleSingleLineComment_Click(this, new RoutedEventArgs()));
4446
ToggleMultiLineCommentCommand = new RelayCommand(_ => ToggleMultiLineLineComment_Click(this, new RoutedEventArgs()));
4547
ToggleCommentSelectionCommand = new RelayCommand(_ => ToggleCommentSelection_Click(this, new RoutedEventArgs()));
46-
48+
OpenAboutCommand = new RelayCommand(_ => About_Click(this, new RoutedEventArgs()));
4749
}
4850

4951
#region IFlyoutService Implementation
@@ -576,6 +578,11 @@ private void ExportToFile_Click(object sender, RoutedEventArgs e)
576578
}
577579
}
578580

581+
private void About_Click(object sender, RoutedEventArgs e)
582+
{
583+
var aboutWindow = new Views.AboutView.AboutWindow(this);
584+
aboutWindow.ShowDialog();
585+
}
579586

580587
private void SetupFolding(Snippet snippet)
581588
{
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<mah:MetroWindow x:Class="CodeSnip.Views.AboutView.AboutWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
7+
xmlns:local="clr-namespace:CodeSnip.Views.AboutView"
8+
d:DataContext="{d:DesignInstance Type=local:AboutWindowModel}"
9+
mc:Ignorable="d"
10+
Title="About" Height="400" Width="600"
11+
ShowInTaskbar="False" ResizeMode="NoResize" WindowStartupLocation="CenterOwner" >
12+
<mah:MetroWindow.Resources>
13+
14+
</mah:MetroWindow.Resources>
15+
<Grid>
16+
<mah:MetroTabControl TabStripPlacement="Left" Style="{StaticResource MahApps.Styles.TabControl.Animated}" mah:HeaderedControlHelper.HeaderFontSize="18">
17+
18+
<mah:MetroTabItem Header="About">
19+
<StackPanel Margin="20" HorizontalAlignment="Center">
20+
21+
<TextBlock Text="{Binding Title}"
22+
FontWeight="Bold"
23+
FontSize="22"
24+
Foreground="{DynamicResource MahApps.Brushes.Accent}"
25+
HorizontalAlignment="Center" />
26+
27+
<TextBlock Text="Version:" FontWeight="SemiBold" Margin="0,20,0,0" />
28+
<TextBlock Text="{Binding Version}" FontSize="14" />
29+
30+
<TextBlock Text="Description:" FontWeight="SemiBold" Margin="0,15,0,0" />
31+
<TextBlock Text="{Binding Description}"
32+
TextWrapping="Wrap"
33+
FontSize="13"
34+
Foreground="{DynamicResource MahApps.Brushes.Gray}" />
35+
36+
<TextBlock Text="Company:" FontWeight="SemiBold" Margin="0,15,0,0" />
37+
<TextBlock Text="{Binding Company}" FontSize="14" />
38+
<!--<TextBlock Text="Copyright:" FontWeight="SemiBold" Margin="0,15,0,0" />-->
39+
<TextBlock Text="{Binding Copyright}" FontSize="14" Margin="0,15,0,0" />
40+
41+
<TextBlock Margin="15,30,0,0" HorizontalAlignment="Center" FontSize="14" ToolTip="{Binding Url}">
42+
<Run Text="Repository: " />
43+
<Hyperlink NavigateUri="https://github.com/mx7b7/codesnip-wpf/"
44+
RequestNavigate="Hyperlink_RequestNavigate">
45+
<Run Text="GitHub" />
46+
</Hyperlink>
47+
</TextBlock>
48+
</StackPanel>
49+
</mah:MetroTabItem>
50+
51+
<mah:MetroTabItem Header="Dependencies &amp; Tools">
52+
<ScrollViewer Margin="10" VerticalScrollBarVisibility="Auto">
53+
<StackPanel>
54+
55+
<mah:MetroHeader Content="Libraries"
56+
FontWeight="Bold"
57+
FontSize="16"
58+
Foreground="{DynamicResource MahApps.Brushes.Accent}"
59+
Margin="0,0,0,10"/>
60+
61+
<ItemsControl ItemsSource="{Binding Libraries}">
62+
<ItemsControl.ItemTemplate>
63+
<DataTemplate>
64+
<StackPanel Orientation="Horizontal" Margin="0,5" VerticalAlignment="Center">
65+
<TextBlock Text="" FontSize="16" Margin="0,0,5,0" VerticalAlignment="Center" />
66+
<TextBlock ToolTip="{Binding Url}">
67+
<Hyperlink NavigateUri="{Binding Url}" RequestNavigate="Hyperlink_RequestNavigate">
68+
<Run Text="{Binding Name}" />
69+
</Hyperlink>
70+
</TextBlock>
71+
</StackPanel>
72+
</DataTemplate>
73+
</ItemsControl.ItemTemplate>
74+
</ItemsControl>
75+
76+
<mah:MetroHeader Content="External Services"
77+
FontWeight="Bold"
78+
FontSize="16"
79+
Foreground="{DynamicResource MahApps.Brushes.Accent}"
80+
Margin="0,20,0,10"/>
81+
82+
<ItemsControl ItemsSource="{Binding Services}">
83+
<ItemsControl.ItemTemplate>
84+
<DataTemplate>
85+
<StackPanel Orientation="Horizontal" Margin="0,5" VerticalAlignment="Center">
86+
<TextBlock Text="" FontSize="16" Margin="0,0,5,0" VerticalAlignment="Center" />
87+
<TextBlock ToolTip="{Binding Url}">
88+
<Hyperlink NavigateUri="{Binding Url}" RequestNavigate="Hyperlink_RequestNavigate">
89+
<Run Text="{Binding Name}" />
90+
</Hyperlink>
91+
</TextBlock>
92+
</StackPanel>
93+
</DataTemplate>
94+
</ItemsControl.ItemTemplate>
95+
</ItemsControl>
96+
97+
<mah:MetroHeader Content="External Tools"
98+
FontWeight="Bold"
99+
FontSize="16"
100+
Foreground="{DynamicResource MahApps.Brushes.Accent}"
101+
Margin="0,20,0,10"/>
102+
<ItemsControl ItemsSource="{Binding Tools}">
103+
<ItemsControl.ItemTemplate>
104+
<DataTemplate>
105+
<StackPanel Orientation="Horizontal" Margin="0,5" VerticalAlignment="Center">
106+
<TextBlock Text="" FontSize="16" Margin="0,0,5,0" VerticalAlignment="Center" />
107+
<TextBlock ToolTip="{Binding Url}">
108+
<Hyperlink NavigateUri="{Binding Url}" RequestNavigate="Hyperlink_RequestNavigate">
109+
<Run Text="{Binding Name}" />
110+
</Hyperlink>
111+
</TextBlock>
112+
</StackPanel>
113+
</DataTemplate>
114+
</ItemsControl.ItemTemplate>
115+
</ItemsControl>
116+
</StackPanel>
117+
</ScrollViewer>
118+
</mah:MetroTabItem>
119+
120+
<mah:MetroTabItem Header="Notes">
121+
<!-- Usage tips -->
122+
</mah:MetroTabItem>
123+
</mah:MetroTabControl>
124+
</Grid>
125+
</mah:MetroWindow>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using MahApps.Metro.Controls;
2+
using System.Diagnostics;
3+
using System.Windows.Navigation;
4+
5+
namespace CodeSnip.Views.AboutView
6+
{
7+
8+
public partial class AboutWindow : MetroWindow
9+
{
10+
protected AboutWindow()
11+
{
12+
InitializeComponent();
13+
DataContext = new AboutWindowModel();
14+
}
15+
16+
public AboutWindow(MetroWindow parent) : this()
17+
{
18+
Owner = parent;
19+
}
20+
21+
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
22+
{
23+
try
24+
{
25+
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri) { UseShellExecute = true });
26+
}
27+
catch (Exception ex)
28+
{
29+
Debug.WriteLine($"Failed to open URL: {ex.Message}");
30+
}
31+
e.Handled = true;
32+
}
33+
}
34+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using System.Collections.ObjectModel;
3+
using System.Reflection;
4+
5+
6+
namespace CodeSnip.Views.AboutView
7+
{
8+
public partial class AboutWindowModel : ObservableObject
9+
{
10+
[ObservableProperty]
11+
private string? title;
12+
13+
[ObservableProperty]
14+
private string? description;
15+
16+
[ObservableProperty]
17+
private string? company;
18+
19+
[ObservableProperty]
20+
private string? version;
21+
22+
[ObservableProperty]
23+
private string? copyright;
24+
25+
public static string Url => "https://github.com/mx7b7/codesnip-wpf/";
26+
27+
public ObservableCollection<LibraryInfo> Libraries { get; } =
28+
[
29+
new() { Name = "AvalonEdit", Url = new Uri("https://github.com/icsharpcode/AvalonEdit") },
30+
new() { Name = "CommunityToolkit.Mvvm", Url = new Uri("https://github.com/CommunityToolkit/dotnet") },
31+
new() { Name = "Dapper", Url = new Uri("https://github.com/DapperLib/Dapper") },
32+
new() { Name = "MahApps.Metro", Url = new Uri("https://github.com/MahApps/MahApps.Metro") },
33+
new() { Name = "System.Data.SQLite.Core", Url = new Uri("https://system.data.sqlite.org/") }
34+
];
35+
36+
public ObservableCollection<ServicesInfo> Services { get; } =
37+
[
38+
new() { Name = "Compiler Explorer", Url = new Uri("https://godbolt.org/") }
39+
];
40+
41+
public ObservableCollection<ToolsInfo> Tools { get; } =
42+
[
43+
new() { Name = "black", Url = new Uri("https://black.readthedocs.io/en/stable/") },
44+
new() { Name = "clang-format", Url = new Uri("https://clang.llvm.org/docs/ClangFormat.html") },
45+
new() { Name = "csharpier", Url = new Uri("https://csharpier.com/") },
46+
new() { Name = "dfmt", Url = new Uri("https://github.com/dlang-community/dfmt") },
47+
new() { Name = "rustfmt", Url = new Uri("https://github.com/rust-lang/rustfmt") },
48+
new() { Name = "ruff", Url = new Uri("https://github.com/astral-sh/ruff") }
49+
];
50+
51+
public AboutWindowModel()
52+
{
53+
var assembly = Assembly.GetExecutingAssembly();
54+
Title = assembly.GetCustomAttribute<AssemblyTitleAttribute>()?.Title ?? "Unknown";
55+
Description = assembly.GetCustomAttribute<AssemblyDescriptionAttribute>()?.Description ?? string.Empty;
56+
Company = assembly.GetCustomAttribute<AssemblyCompanyAttribute>()?.Company ?? string.Empty;
57+
Version = assembly.GetName().Version?.ToString() ?? "1.0.0";
58+
Copyright = assembly.GetCustomAttribute<AssemblyCopyrightAttribute>()?.Copyright ?? string.Empty;
59+
}
60+
}
61+
62+
public class LibraryInfo
63+
{
64+
public string Name { get; set; } = string.Empty;
65+
public Uri Url { get; set; } = new Uri("https://example.com");
66+
}
67+
68+
public class ToolsInfo
69+
{
70+
public string Name { get; set; } = string.Empty;
71+
public Uri Url { get; set; } = new Uri("https://example.com");
72+
}
73+
74+
public class ServicesInfo
75+
{
76+
public string Name { get; set; } = string.Empty;
77+
public Uri Url { get; set; } = new Uri("https://example.com");
78+
}
79+
}

0 commit comments

Comments
 (0)