Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit cfd075c

Browse files
committed
added new VS-like error and warning buttons and copy errors button
1 parent 820f098 commit cfd075c

9 files changed

+255
-23
lines changed

Resources/Icons/icon-error.png

2.48 KB
Loading

Resources/Icons/icon-warning.png

1.14 KB
Loading

Spcode.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
<DependentUpon>LanguageChooserWindow.xaml</DependentUpon>
155155
</Compile>
156156
<Compile Include="UI\MainWindow\MainWindowErrorResultGrid.cs" />
157+
<Compile Include="UI\MainWindow\MainWindowErrorStatus.cs" />
157158
<Compile Include="UI\MainWindow\MainWindowLogBox.cs" />
158159
<Compile Include="UI\MainWindow\MainWindowServerQuery.cs" />
159160
<Compile Include="UI\MainWindow\MainWindowSPCompiler.cs" />
@@ -461,6 +462,8 @@
461462
<ClInclude Include="Resources\Misc\Templates\Template_Generic.sp" />
462463
<ClInclude Include="Resources\Misc\Templates\Template_TF2.sp" />
463464
<Content Include="Deploy\nsis-plugins\DotNetChecker.dll" />
465+
<Resource Include="Resources\Icons\icon-error.png" />
466+
<Resource Include="Resources\Icons\icon-warning.png" />
464467
<Content Include="Resources\License.txt" />
465468
<Content Include="Resources\Misc\Configurations\sm_1_10_0_6509\include\admin.inc" />
466469
<Content Include="Resources\Misc\Configurations\sm_1_10_0_6509\include\adminmenu.inc" />

UI/MainWindow/MainWindow.xaml

+124-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
<!-- Button style with pressed effects -->
3636

37-
<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
37+
<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
3838
<Setter Property="Background" Value="{DynamicResource WhiteBrush}"/>
3939
<Setter Property="Template">
4040
<Setter.Value>
@@ -55,6 +55,55 @@
5555
</Style.Triggers>
5656
</Style>
5757

58+
<Style x:Key="ButtonStyle2" TargetType="{x:Type Button}">
59+
<Setter Property="Background" Value="{DynamicResource WhiteBrush}"/>
60+
<Setter Property="Template">
61+
<Setter.Value>
62+
<ControlTemplate TargetType="{x:Type Button}">
63+
<Border Background="{TemplateBinding Background}" BorderBrush="{DynamicResource GrayBrush5}" BorderThickness="1">
64+
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
65+
</Border>
66+
</ControlTemplate>
67+
</Setter.Value>
68+
</Setter>
69+
<Style.Triggers>
70+
<Trigger Property="IsMouseOver" Value="True">
71+
<Setter Property="Background" Value="{DynamicResource GrayBrush7}"/>
72+
</Trigger>
73+
<Trigger Property="IsPressed" Value="True">
74+
<Setter Property="Background" Value="{DynamicResource GrayBrush8}"/>
75+
</Trigger>
76+
</Style.Triggers>
77+
</Style>
78+
79+
<Style x:Key="ToggleButtonStyle" TargetType="{x:Type ToggleButton}">
80+
<Setter Property="Background" Value="{DynamicResource WhiteBrush}"/>
81+
<Setter Property="Template">
82+
<Setter.Value>
83+
<ControlTemplate TargetType="{x:Type ToggleButton}">
84+
<Border Background="{TemplateBinding Background}" BorderBrush="{DynamicResource GrayBrush5}" BorderThickness="{TemplateBinding BorderThickness}">
85+
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
86+
</Border>
87+
<ControlTemplate.Triggers>
88+
<Trigger Property="IsChecked" Value="False">
89+
<Setter Property="BorderThickness" Value="0"/>
90+
</Trigger>
91+
<Trigger Property="IsChecked" Value="True">
92+
<Setter Property="BorderThickness" Value="1"/>
93+
</Trigger>
94+
</ControlTemplate.Triggers>
95+
</ControlTemplate>
96+
</Setter.Value>
97+
</Setter>
98+
<Style.Triggers>
99+
<Trigger Property="IsMouseOver" Value="True">
100+
<Setter Property="Background" Value="{DynamicResource GrayBrush7}"/>
101+
</Trigger>
102+
<Trigger Property="IsPressed" Value="True">
103+
<Setter Property="Background" Value="{DynamicResource GrayBrush8}"/>
104+
</Trigger>
105+
</Style.Triggers>
106+
</Style>
58107
<!--Button Images-->
59108

60109
<Image x:Key="ImgReload" Source="/SPCode;component/Resources/Icons/icon-reload.png" Width="16"/>
@@ -361,26 +410,38 @@
361410
</ListViewItem>
362411
</ListView>
363412

364-
<Button x:Name="BtExpandCollapse" Style="{StaticResource ButtonStyle}" Content="{StaticResource ImgExpand}"
413+
<Button x:Name="BtExpandCollapse" Style="{StaticResource ButtonStyle1}" Content="{StaticResource ImgExpand}"
365414
Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Right" Height="22" Width="22" Margin="0,3,2,0"
366415
Click="BtExpandCollapse_Click" ToolTip="Expand all directories"/>
367416

368-
<Button x:Name="BtRefreshDir" Style="{StaticResource ButtonStyle}" Content="{StaticResource ImgReload}"
417+
<Button x:Name="BtRefreshDir" Style="{StaticResource ButtonStyle1}" Content="{StaticResource ImgReload}"
369418
Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Right" Height="22" Width="22" Margin="0,3,27,0"
370419
Click="BtRefreshDir_Click" ToolTip="Reload current directory"/>
371420

372421
</Grid>
422+
373423
<GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="5" Background="{DynamicResource GrayBrush5}" />
374-
<Button Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Top" Width="30" Height="30" Margin="0,5,0,0" Style="{DynamicResource ButtonStyle}" Click="CloseErrorResultGrid">
424+
425+
<!-- Begin Lower Grids -->
426+
427+
<!--Close Lower Grid Button-->
428+
<Button Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Top" Width="30" Height="30" Margin="0,5,0,0" Style="{DynamicResource ButtonStyle1}" Click="CloseErrorResultGrid">
375429
<Canvas Width="10" Height="10" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
376430
<Path Width="10" Height="10" Stretch="Fill" Fill="{DynamicResource AccentColorBrush}" Data="F1 M 26.9166,22.1667L 37.9999,33.25L 49.0832,22.1668L 53.8332,26.9168L 42.7499,38L 53.8332,49.0834L 49.0833,53.8334L 37.9999,42.75L 26.9166,53.8334L 22.1666,49.0833L 33.25,38L 22.1667,26.9167L 26.9166,22.1667 Z "/>
377431
</Canvas>
378432
</Button>
379-
<Grid Grid.Row="1" Margin="0,5,30,0">
433+
434+
<!-- Lower Grid -->
435+
436+
<!--#region Lower Grid-->
437+
<Grid Grid.Row="1" Margin="0,5,0,0">
438+
380439
<Grid.ColumnDefinitions>
381440
<ColumnDefinition Width="5*" />
382441
<ColumnDefinition Width="2*" />
383442
</Grid.ColumnDefinitions>
443+
444+
<!--Log TextBox-->
384445
<TextBox x:Name="LogTextbox" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="1" TextWrapping="Wrap"
385446
Margin="5,0,0,0" IsReadOnly="True" AcceptsReturn="True" AcceptsTab="True" VerticalScrollBarVisibility="Auto"
386447
PreviewMouseRightButtonDown="LogTextbox_PreviewMouseRightButtonDown">
@@ -390,9 +451,62 @@
390451
</ContextMenu>
391452
</TextBox.Resources>
392453
</TextBox>
393-
<GridSplitter Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Stretch" Width="5" Background="LightGray" />
394-
<DataGrid x:Name="ErrorResultGrid" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsReadOnly="True"
395-
SelectionMode="Single" AutoGenerateColumns="true" SelectionChanged="ErrorResultGrid_SelectionChanged">
454+
455+
<!--Grid Splitter between Log TextBox and Error Grid-->
456+
<GridSplitter Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Stretch" Width="5" Background="{DynamicResource GrayBrush5}" />
457+
458+
<!--New Error Status Bar-->
459+
460+
<!--Errors Button-->
461+
<ToggleButton x:Name="Status_ErrorButton"
462+
Style="{StaticResource ToggleButtonStyle}"
463+
HorizontalAlignment="Left" VerticalAlignment="Top"
464+
Margin="5,7,0,0"
465+
Click="Status_ErrorButton_Clicked">
466+
<StackPanel Orientation="Horizontal">
467+
<Image Source="/SPCode;component/Resources/Icons/icon-error.png"
468+
Width="16"
469+
HorizontalAlignment="Center" VerticalAlignment="Center"
470+
Margin="5,5,3,4"/>
471+
<TextBlock x:Name="Status_ErrorText"
472+
HorizontalAlignment="Left" VerticalAlignment="Top"
473+
Margin="3,4,2,2"/>
474+
</StackPanel>
475+
</ToggleButton>
476+
477+
<!--Warnings Button-->
478+
<ToggleButton x:Name="Status_WarningButton"
479+
Style="{StaticResource ToggleButtonStyle}"
480+
HorizontalAlignment="Left" VerticalAlignment="Top"
481+
Margin="100,7,0,0"
482+
Click="Status_WarningButton_Clicked">
483+
<StackPanel Orientation="Horizontal">
484+
<Image Source="/SPCode;component/Resources/Icons/icon-warning.png"
485+
Width="16"
486+
HorizontalAlignment="Center" VerticalAlignment="Center"
487+
Margin="5,5,3,4"/>
488+
<TextBlock x:Name="Status_WarningText"
489+
HorizontalAlignment="Left" VerticalAlignment="Top"
490+
Margin="3,4,2,2"/>
491+
</StackPanel>
492+
</ToggleButton>
493+
494+
<!--Copy Errors Button-->
495+
<Button x:Name="Status_CopyErrorsButton"
496+
HorizontalAlignment="Left" VerticalAlignment="Top"
497+
Margin="210,9,0,0"
498+
Style="{StaticResource ButtonStyle2}"
499+
Height="22"
500+
Width="99"
501+
Click="Status_CopyErrorsButton_Click"/>
502+
503+
<!--Error DataGrid-->
504+
<DataGrid x:Name="ErrorResultGrid"
505+
Grid.Column="0"
506+
IsReadOnly="True"
507+
SelectionMode="Single"
508+
AutoGenerateColumns="true"
509+
SelectionChanged="ErrorResultGrid_SelectionChanged" Margin="0,40,0,0">
396510

397511
<DataGrid.ItemContainerStyle>
398512
<Style TargetType="DataGridRow">
@@ -407,7 +521,9 @@
407521
<DataGridTextColumn x:Name="MenuC_Details" Header="Details" Width="9*" Binding="{Binding Details}" />
408522
</DataGrid.Columns>
409523
</DataGrid>
524+
410525
</Grid>
526+
<!--#endregion-->
411527
</Grid>
412528

413529
<Rectangle Grid.Row="2" x:Name="BlendEffectPlane" IsHitTestVisible="False" Opacity="0" Fill="{DynamicResource AccentColorBrush4}" Grid.ColumnSpan="3" />

UI/MainWindow/MainWindow.xaml.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public MainWindow(SplashScreen sc)
127127
ChangeObjectBrowserToDirectory(Program.OptionsObject.Program_ObjectBrowserDirectory);
128128

129129
// Translate
130-
Language_Translate(true);
130+
Language_Translate();
131131

132132
// Load previously opened files
133133
if (Program.OptionsObject.LastOpenFiles != null)
@@ -192,6 +192,10 @@ public MainWindow(SplashScreen sc)
192192

193193
// Passes the Logging Box to the LoggingControl class
194194
LoggingControl.LogBox = LogTextbox;
195+
196+
// Set error status buttons state
197+
Status_ErrorButton.IsChecked = true;
198+
Status_WarningButton.IsChecked = true;
195199
}
196200
#endregion
197201

@@ -253,7 +257,11 @@ private async void MetroWindow_Closing(object sender, CancelEventArgs e)
253257

254258
// Build list of unsaved files to show
255259
var sb = new StringBuilder();
256-
editors.Where(x => x.NeedsSave).ToList().ForEach(y => sb.AppendLine($" - {y.Parent.Title.Substring(1)}"));
260+
261+
foreach (var editor in editors.Where(x => x.NeedsSave))
262+
{
263+
sb.AppendLine($" - {editor.Parent.Title.Substring(1)}");
264+
}
257265

258266
var result = await this.ShowMessageAsync("Save all files?", $"Unsaved files:\n{sb}",
259267
MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, ClosingDialogOptions);

UI/MainWindow/MainWindowCommands.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ private async void Command_CloseAll()
368368
return;
369369
}
370370

371-
editors.ToList().ForEach(x => x.Close());
372-
dasm?.ToList().ForEach(y => y.Close());
371+
foreach (var editor in editors) editor.Close();
372+
foreach (var editor in dasm) editor.Close();
373373
}
374374
catch (Exception ex)
375375
{
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls.Primitives;
8+
using SPCode.Interop;
9+
using SPCode.Utils;
10+
11+
namespace SPCode.UI
12+
{
13+
public partial class MainWindow
14+
{
15+
public bool HideErrors = false;
16+
public bool HideWarnings = false;
17+
18+
private void Status_ErrorButton_Clicked(object sender, RoutedEventArgs e)
19+
{
20+
var isChecked = (sender as ToggleButton).IsChecked.Value;
21+
HideErrors = !isChecked;
22+
if (CurrentErrors.Count == 0 && CurrentWarnings.Count == 0)
23+
{
24+
return;
25+
}
26+
27+
UpdateErrorGrid();
28+
}
29+
30+
private void Status_WarningButton_Clicked(object sender, RoutedEventArgs e)
31+
{
32+
var isChecked = (sender as ToggleButton).IsChecked.Value;
33+
HideWarnings = !isChecked;
34+
35+
if (CurrentErrors.Count == 0 && CurrentWarnings.Count == 0)
36+
{
37+
return;
38+
}
39+
40+
UpdateErrorGrid();
41+
}
42+
43+
private void Status_CopyErrorsButton_Click(object sender, RoutedEventArgs e)
44+
{
45+
if (CurrentErrorString != null)
46+
{
47+
Clipboard.SetText(CurrentErrorString);
48+
}
49+
}
50+
51+
private void UpdateErrorGrid()
52+
{
53+
ErrorResultGrid.Items.Clear();
54+
var listBuffer = new List<ErrorDataGridRow>();
55+
56+
if (!HideWarnings)
57+
{
58+
listBuffer.AddRange(CurrentWarnings);
59+
}
60+
61+
if (!HideErrors)
62+
{
63+
listBuffer.AddRange(CurrentErrors);
64+
}
65+
66+
listBuffer.OrderBy(x => int.Parse(x.Line)).ToList().ForEach(y => ErrorResultGrid.Items.Add(y));
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)