Skip to content

Commit bd3307c

Browse files
authored
Added legend window (#5)
1 parent 6ee1863 commit bd3307c

9 files changed

+440
-66
lines changed

CSharpCodeAnalyst/CSharpCodeAnalyst.csproj

+65-63
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,27 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<Content Include="..\ExternalApplications\DsmSuite.DsmViewer.View.deps.json" Link="ExternalApplications\DsmSuite.DsmViewer.View.deps.json">
14-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
15-
</Content>
16-
<Content Include="..\ExternalApplications\DsmSuite.DsmViewer.View.runtimeconfig.json" Link="ExternalApplications\DsmSuite.DsmViewer.View.runtimeconfig.json">
17-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18-
</Content>
19-
<Content Include="appsettings.json">
20-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21-
</Content>
22-
<Content Include="lamp.ico" />
13+
<Content Include="..\ExternalApplications\DsmSuite.DsmViewer.View.deps.json" Link="ExternalApplications\DsmSuite.DsmViewer.View.deps.json">
14+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
15+
</Content>
16+
<Content Include="..\ExternalApplications\DsmSuite.DsmViewer.View.runtimeconfig.json" Link="ExternalApplications\DsmSuite.DsmViewer.View.runtimeconfig.json">
17+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18+
</Content>
19+
<Content Include="appsettings.json">
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
</Content>
22+
<Content Include="lamp.ico" />
2323
</ItemGroup>
2424

2525

2626
<ItemGroup>
27-
<Resource Include="Resources\filter_32.png" />
28-
<Resource Include="Resources\undo_32.png" />
29-
<Resource Include="Resources\redo_32.png" />
30-
<Resource Include="Resources\clear_32.png" />
31-
<Resource Include="Resources\Collapse_16.png" />
27+
<Resource Include="Resources\help_32.png" />
28+
<Resource Include="Resources\legend_32.png" />
29+
<Resource Include="Resources\filter_32.png" />
30+
<Resource Include="Resources\undo_32.png" />
31+
<Resource Include="Resources\redo_32.png" />
32+
<Resource Include="Resources\clear_32.png" />
33+
<Resource Include="Resources\Collapse_16.png" />
3234
<Resource Include="Resources\complexity_32.png" />
3335
<Resource Include="Resources\cycle_32.png" />
3436
<Resource Include="Resources\document-xml.png" />
@@ -78,60 +80,60 @@
7880
</ItemGroup>
7981

8082
<ItemGroup>
81-
<Folder Include="ExternalApplications\" />
83+
<Folder Include="ExternalApplications\" />
8284
</ItemGroup>
8385

8486
<ItemGroup>
85-
<None Include="..\ExternalApplications\DsmSuite.Analyzer.Model.dll" Link="ExternalApplications\DsmSuite.Analyzer.Model.dll">
86-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
87-
</None>
88-
<None Include="..\ExternalApplications\DsmSuite.Common.Model.dll" Link="ExternalApplications\DsmSuite.Common.Model.dll">
89-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
90-
</None>
91-
<None Include="..\ExternalApplications\DsmSuite.Common.Util.dll" Link="ExternalApplications\DsmSuite.Common.Util.dll">
92-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
93-
</None>
94-
<None Include="..\ExternalApplications\DsmSuite.DsmViewer.Application.dll" Link="ExternalApplications\DsmSuite.DsmViewer.Application.dll">
95-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
96-
</None>
97-
<None Include="..\ExternalApplications\DsmSuite.DsmViewer.Model.dll" Link="ExternalApplications\DsmSuite.DsmViewer.Model.dll">
98-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
99-
</None>
100-
<None Include="..\ExternalApplications\DsmSuite.DsmViewer.View.dll" Link="ExternalApplications\DsmSuite.DsmViewer.View.dll">
101-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
102-
</None>
103-
<None Include="..\ExternalApplications\DsmSuite.DsmViewer.View.exe" Link="ExternalApplications\DsmSuite.DsmViewer.View.exe">
104-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
105-
</None>
106-
<None Include="..\ExternalApplications\DsmSuite.DsmViewer.ViewModel.dll" Link="ExternalApplications\DsmSuite.DsmViewer.ViewModel.dll">
107-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
108-
</None>
87+
<None Include="..\ExternalApplications\DsmSuite.Analyzer.Model.dll" Link="ExternalApplications\DsmSuite.Analyzer.Model.dll">
88+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
89+
</None>
90+
<None Include="..\ExternalApplications\DsmSuite.Common.Model.dll" Link="ExternalApplications\DsmSuite.Common.Model.dll">
91+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
92+
</None>
93+
<None Include="..\ExternalApplications\DsmSuite.Common.Util.dll" Link="ExternalApplications\DsmSuite.Common.Util.dll">
94+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
95+
</None>
96+
<None Include="..\ExternalApplications\DsmSuite.DsmViewer.Application.dll" Link="ExternalApplications\DsmSuite.DsmViewer.Application.dll">
97+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
98+
</None>
99+
<None Include="..\ExternalApplications\DsmSuite.DsmViewer.Model.dll" Link="ExternalApplications\DsmSuite.DsmViewer.Model.dll">
100+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
101+
</None>
102+
<None Include="..\ExternalApplications\DsmSuite.DsmViewer.View.dll" Link="ExternalApplications\DsmSuite.DsmViewer.View.dll">
103+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
104+
</None>
105+
<None Include="..\ExternalApplications\DsmSuite.DsmViewer.View.exe" Link="ExternalApplications\DsmSuite.DsmViewer.View.exe">
106+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
107+
</None>
108+
<None Include="..\ExternalApplications\DsmSuite.DsmViewer.ViewModel.dll" Link="ExternalApplications\DsmSuite.DsmViewer.ViewModel.dll">
109+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
110+
</None>
109111
</ItemGroup>
110112

111-
<ItemGroup>
112-
<Reference Include="Microsoft.Msagl">
113-
<HintPath>..\ReferencedAssemblies\Microsoft.Msagl.dll</HintPath>
114-
</Reference>
115-
<Reference Include="Microsoft.Msagl.Drawing">
116-
<HintPath>..\ReferencedAssemblies\Microsoft.Msagl.Drawing.dll</HintPath>
117-
</Reference>
118-
<Reference Include="Microsoft.Msagl.WpfGraphControl">
119-
<HintPath>..\ReferencedAssemblies\Microsoft.Msagl.WpfGraphControl.dll</HintPath>
120-
</Reference>
113+
<ItemGroup>
114+
<Reference Include="Microsoft.Msagl">
115+
<HintPath>..\ReferencedAssemblies\Microsoft.Msagl.dll</HintPath>
116+
</Reference>
117+
<Reference Include="Microsoft.Msagl.Drawing">
118+
<HintPath>..\ReferencedAssemblies\Microsoft.Msagl.Drawing.dll</HintPath>
119+
</Reference>
120+
<Reference Include="Microsoft.Msagl.WpfGraphControl">
121+
<HintPath>..\ReferencedAssemblies\Microsoft.Msagl.WpfGraphControl.dll</HintPath>
122+
</Reference>
121123
</ItemGroup>
122124

123-
<ItemGroup>
124-
<Compile Update="Resources\Strings.Designer.cs">
125-
<DesignTime>True</DesignTime>
126-
<AutoGen>True</AutoGen>
127-
<DependentUpon>Strings.resx</DependentUpon>
128-
</Compile>
129-
</ItemGroup>
125+
<ItemGroup>
126+
<Compile Update="Resources\Strings.Designer.cs">
127+
<DesignTime>True</DesignTime>
128+
<AutoGen>True</AutoGen>
129+
<DependentUpon>Strings.resx</DependentUpon>
130+
</Compile>
131+
</ItemGroup>
130132

131-
<ItemGroup>
132-
<EmbeddedResource Update="Resources\Strings.resx">
133-
<Generator>PublicResXFileCodeGenerator</Generator>
134-
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
135-
</EmbeddedResource>
136-
</ItemGroup>
133+
<ItemGroup>
134+
<EmbeddedResource Update="Resources\Strings.resx">
135+
<Generator>PublicResXFileCodeGenerator</Generator>
136+
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
137+
</EmbeddedResource>
138+
</ItemGroup>
137139
</Project>
+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<Window x:Class="CSharpCodeAnalyst.Help.LegendDialog"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:resources="clr-namespace:CSharpCodeAnalyst.Resources"
5+
Title="{x:Static resources:Strings.Legend_Title}"
6+
Width="400"
7+
ResizeMode="NoResize"
8+
SizeToContent="Height"
9+
WindowStartupLocation="CenterScreen">
10+
<Window.Resources>
11+
<Style x:Key="LegendRectangleStyle" TargetType="Rectangle">
12+
<Setter Property="Width" Value="80"/>
13+
<Setter Property="Height" Value="40"/>
14+
<Setter Property="Margin" Value="0,0,10,5"/>
15+
<Setter Property="Stroke" Value="Black"/>
16+
<Setter Property="StrokeThickness" Value="1"/>
17+
</Style>
18+
19+
<Style x:Key="LegenTextStyle" TargetType="TextBlock">
20+
<Setter Property="FontWeight" Value="Bold"/>
21+
<Setter Property="VerticalAlignment" Value="Center"/>
22+
<Setter Property="FontSize" Value="16"/>
23+
</Style>
24+
25+
</Window.Resources>
26+
<Grid Margin="10">
27+
<Grid.ColumnDefinitions>
28+
<ColumnDefinition Width="Auto"/>
29+
<ColumnDefinition Width="*"/>
30+
</Grid.ColumnDefinitions>
31+
<Grid.RowDefinitions>
32+
<RowDefinition Height="Auto"/>
33+
<RowDefinition Height="Auto"/>
34+
<RowDefinition Height="Auto"/>
35+
<RowDefinition Height="Auto"/>
36+
<RowDefinition Height="Auto"/>
37+
<RowDefinition Height="Auto"/>
38+
<RowDefinition Height="Auto"/>
39+
<RowDefinition Height="Auto"/>
40+
<RowDefinition Height="Auto"/>
41+
<RowDefinition Height="Auto"/>
42+
<RowDefinition Height="Auto"/>
43+
<RowDefinition Height="Auto"/>
44+
</Grid.RowDefinitions>
45+
46+
<Rectangle Grid.Row="0" Grid.Column="0" Fill="{Binding AssemblyColor}" Style="{StaticResource LegendRectangleStyle}"/>
47+
<TextBlock Grid.Row="0" Grid.Column="1" Text="{x:Static resources:Strings.Legend_Assembly}" Style="{StaticResource LegenTextStyle}" />
48+
49+
<Rectangle Grid.Row="1" Grid.Column="0" Fill="{Binding NamespaceColor}" Style="{StaticResource LegendRectangleStyle}"/>
50+
<TextBlock Grid.Row="1" Grid.Column="1" Text="{x:Static resources:Strings.Legend_Namespace}" Style="{StaticResource LegenTextStyle}"/>
51+
52+
<Rectangle Grid.Row="2" Grid.Column="0" Fill="{Binding ClassColor}" Style="{StaticResource LegendRectangleStyle}"/>
53+
<TextBlock Grid.Row="2" Grid.Column="1" Text="{x:Static resources:Strings.Legend_Class}" Style="{StaticResource LegenTextStyle}"/>
54+
55+
<Rectangle Grid.Row="3" Grid.Column="0" Fill="{Binding InterfaceColor}" Style="{StaticResource LegendRectangleStyle}"/>
56+
<TextBlock Grid.Row="3" Grid.Column="1" Text="{x:Static resources:Strings.Legend_Interface}" Style="{StaticResource LegenTextStyle}"/>
57+
58+
<Rectangle Grid.Row="4" Grid.Column="0" Fill="{Binding StructColor}" Style="{StaticResource LegendRectangleStyle}"/>
59+
<TextBlock Grid.Row="4" Grid.Column="1" Text="{x:Static resources:Strings.Legend_Struct}" Style="{StaticResource LegenTextStyle}"/>
60+
61+
<Rectangle Grid.Row="5" Grid.Column="0" Fill="{Binding RecordColor}" Style="{StaticResource LegendRectangleStyle}"/>
62+
<TextBlock Grid.Row="5" Grid.Column="1" Text="{x:Static resources:Strings.Legend_Record}" Style="{StaticResource LegenTextStyle}"/>
63+
64+
<Rectangle Grid.Row="6" Grid.Column="0" Fill="{Binding EnumColor}" Style="{StaticResource LegendRectangleStyle}"/>
65+
<TextBlock Grid.Row="6" Grid.Column="1" Text="{x:Static resources:Strings.Legend_Enum}" Style="{StaticResource LegenTextStyle}"/>
66+
67+
<Rectangle Grid.Row="7" Grid.Column="0" Fill="{Binding EventColor}" Style="{StaticResource LegendRectangleStyle}"/>
68+
<TextBlock Grid.Row="7" Grid.Column="1" Text="{x:Static resources:Strings.Legend_Event}" Style="{StaticResource LegenTextStyle}"/>
69+
70+
<Rectangle Grid.Row="8" Grid.Column="0" Fill="{Binding DelegateColor}" Style="{StaticResource LegendRectangleStyle}"/>
71+
<TextBlock Grid.Row="8" Grid.Column="1" Text="{x:Static resources:Strings.Legend_Delegate}" Style="{StaticResource LegenTextStyle}"/>
72+
73+
<Rectangle Grid.Row="9" Grid.Column="0" Fill="{Binding MethodColor}" Style="{StaticResource LegendRectangleStyle}"/>
74+
<TextBlock Grid.Row="9" Grid.Column="1" Text="{x:Static resources:Strings.Legend_Method}" Style="{StaticResource LegenTextStyle}"/>
75+
76+
<Rectangle Grid.Row="10" Grid.Column="0" Fill="{Binding PropertyColor}" Style="{StaticResource LegendRectangleStyle}"/>
77+
<TextBlock Grid.Row="10" Grid.Column="1" Text="{x:Static resources:Strings.Legend_Property}" Style="{StaticResource LegenTextStyle}"/>
78+
79+
<Rectangle Grid.Row="11" Grid.Column="0" Fill="{Binding FieldColor}" Style="{StaticResource LegendRectangleStyle}"/>
80+
<TextBlock Grid.Row="11" Grid.Column="1" Text="{x:Static resources:Strings.Legend_Field}" Style="{StaticResource LegenTextStyle}"/>
81+
82+
</Grid>
83+
</Window>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Contracts.Colors;
2+
using Contracts.Graph;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
using System.Windows.Data;
11+
using System.Windows.Documents;
12+
using System.Windows.Input;
13+
using System.Windows.Media;
14+
using System.Windows.Media.Imaging;
15+
using System.Windows.Shapes;
16+
17+
namespace CSharpCodeAnalyst.Help
18+
{
19+
public partial class LegendDialog : Window
20+
{
21+
public Brush NamespaceColor { get; } = new SolidColorBrush(GetColorFromRgb(ColorDefinitions.GetRbgOf(CodeElementType.Namespace)));
22+
public Brush ClassColor { get; } = new SolidColorBrush(GetColorFromRgb(ColorDefinitions.GetRbgOf(CodeElementType.Class)));
23+
public Brush InterfaceColor { get; } = new SolidColorBrush(GetColorFromRgb(ColorDefinitions.GetRbgOf(CodeElementType.Interface)));
24+
public Brush StructColor { get; } = new SolidColorBrush(GetColorFromRgb(ColorDefinitions.GetRbgOf(CodeElementType.Struct)));
25+
public Brush EnumColor { get; } = new SolidColorBrush(GetColorFromRgb(ColorDefinitions.GetRbgOf(CodeElementType.Enum)));
26+
public Brush MethodColor { get; } = new SolidColorBrush(GetColorFromRgb(ColorDefinitions.GetRbgOf(CodeElementType.Method)));
27+
public Brush PropertyColor { get; } = new SolidColorBrush(GetColorFromRgb(ColorDefinitions.GetRbgOf(CodeElementType.Property)));
28+
public Brush FieldColor { get; } = new SolidColorBrush(GetColorFromRgb(ColorDefinitions.GetRbgOf(CodeElementType.Field)));
29+
public Brush EventColor { get; } = new SolidColorBrush(GetColorFromRgb(ColorDefinitions.GetRbgOf(CodeElementType.Event)));
30+
public Brush DelegateColor { get; } = new SolidColorBrush(GetColorFromRgb(ColorDefinitions.GetRbgOf(CodeElementType.Delegate)));
31+
public Brush RecordColor { get; } = new SolidColorBrush(GetColorFromRgb(ColorDefinitions.GetRbgOf(CodeElementType.Record)));
32+
public Brush AssemblyColor { get; } = new SolidColorBrush(GetColorFromRgb(ColorDefinitions.GetRbgOf(CodeElementType.Assembly)));
33+
34+
public LegendDialog()
35+
{
36+
InitializeComponent();
37+
DataContext = this;
38+
}
39+
40+
private void CloseButton_Click(object sender, RoutedEventArgs e)
41+
{
42+
Close();
43+
}
44+
45+
private static Color GetColorFromRgb(int rgb)
46+
{
47+
return Color.FromRgb(
48+
(byte)((rgb >> 16) & 0xFF),
49+
(byte)((rgb >> 8) & 0xFF),
50+
(byte)(rgb & 0xFF)
51+
);
52+
}
53+
}
54+
}

CSharpCodeAnalyst/MainViewModel.cs

+15
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ internal MainViewModel(MessageBus messaging, ApplicationSettings? settings)
8484
FindCyclesCommand = new DelegateCommand(FindCycles);
8585
ShowGalleryCommand = new DelegateCommand(ShowGallery);
8686
ExportToDsiCommand = new DelegateCommand(ExportToDsi);
87+
ShowLegendCommand = new DelegateCommand(ShowLegend);
8788
OpenFilterDialogCommand = new DelegateCommand(OpenFilterDialog);
8889
ExportToPngCommand = new DelegateCommand<FrameworkElement>(ExportToPng);
8990
OpenSourceLocationCommand = new DelegateCommand<SourceLocation>(OpenSourceLocation);
@@ -198,6 +199,7 @@ public string LoadMessage
198199
public ICommand OpenSourceLocationCommand { get; }
199200
public ICommand SearchCommand { get; }
200201
public ICommand ExportToPngCommand { get; }
202+
public ICommand ShowLegendCommand { get; }
201203

202204

203205
public TreeViewModel? TreeViewModel
@@ -311,6 +313,19 @@ GraphSession AddSession(string name)
311313
}
312314
}
313315

316+
LegendDialog? _openedLegendDialog;
317+
318+
private void ShowLegend()
319+
{
320+
if (_openedLegendDialog == null)
321+
{
322+
_openedLegendDialog = new LegendDialog();
323+
_openedLegendDialog.Owner = Application.Current.MainWindow;
324+
_openedLegendDialog.Closed += (object? sender, EventArgs e) => _openedLegendDialog = null;
325+
_openedLegendDialog.Show();
326+
}
327+
}
328+
314329
private void OpenFilterDialog()
315330
{
316331
var filterDialog = new FilterDialog(_projectExclusionFilters);

CSharpCodeAnalyst/MainWindow.xaml

+19-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</RibbonApplicationMenu>
3939
</Ribbon.ApplicationMenu>
4040
<RibbonTab Header="Home">
41-
<RibbonGroup Header="{x:Static resources:Strings.File_Header}">
41+
<RibbonGroup Header="{x:Static resources:Strings.File_Header}" LargeImageSource="/Resources/save_project.png">
4242
<RibbonButton Label="{x:Static resources:Strings.ImportSolution_Label}"
4343
LargeImageSource="/Resources/import_solution.png"
4444
Command="{Binding LoadSolutionCommand}" />
@@ -68,14 +68,14 @@
6868

6969
</RibbonGroup>
7070

71-
<RibbonGroup Header="Tools">
71+
<RibbonGroup Header="Tools" LargeImageSource="/Resources/cycle_32.png">
7272
<RibbonButton Label="{x:Static resources:Strings.Find_Label}"
7373
LargeImageSource="/Resources/cycle_32.png"
7474
Command="{Binding FindCyclesCommand}" />
7575
</RibbonGroup>
7676

7777

78-
<RibbonGroup Header="{x:Static resources:Strings.CodeExplorer_Header}">
78+
<RibbonGroup Header="{x:Static resources:Strings.CodeExplorer_Header}" LargeImageSource="/Resources/four-arrows_32.png">
7979
<RibbonButton Label="{x:Static resources:Strings.Clear_Label}"
8080
LargeImageSource="/Resources/trash-can_32.png"
8181
Command="{Binding GraphClearCommand}">
@@ -192,6 +192,22 @@
192192
SelectedItem="{Binding GraphViewModel.SelectedHighlightOption}" />
193193
</Grid>
194194
</RibbonGroup>
195+
196+
197+
<!-- Help Ribbon Group -->
198+
<RibbonGroup Header="{x:Static resources:Strings.Help_Header}"
199+
LargeImageSource="/Resources/help_32.png">
200+
<RibbonButton Label="{x:Static resources:Strings.Legend_Label}"
201+
LargeImageSource="/Resources/legend_32.png"
202+
203+
Command="{Binding ShowLegendCommand}">
204+
<RibbonButton.ToolTip>
205+
<ToolTip Content="{x:Static resources:Strings.Legend_Tooltip}" />
206+
</RibbonButton.ToolTip>
207+
</RibbonButton>
208+
</RibbonGroup>
209+
210+
195211
</RibbonTab>
196212
</Ribbon>
197213

0 commit comments

Comments
 (0)