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

Commit 987abd8

Browse files
committed
Minor changes
1 parent af2bb29 commit 987abd8

7 files changed

+337
-332
lines changed

App/AssemblyInfo1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@
3333
#if (DEBUG)
3434
[assembly: AssemblyVersion("1.13.*")]
3535
#else
36-
[assembly: AssemblyVersion("1.2.0.3")]
36+
[assembly: AssemblyVersion("1.3.0.0")]
3737
#endif

Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static void Main(string[] args)
7878
{
7979
if (Configs[i].Name == OptionsObject.Program_SelectedConfig)
8080
{
81-
Program.SelectedConfig = i;
81+
SelectedConfig = i;
8282
break;
8383
}
8484
}

UI/Windows/AboutWindow.xaml.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using MahApps.Metro.Controls;
2-
using System.Diagnostics;
1+
using System.Diagnostics;
32
using System.Reflection;
43
using System.Windows;
54
using System.Windows.Media;
@@ -12,29 +11,27 @@ namespace Spedit.UI.Windows
1211
/// <summary>
1312
/// Interaction logic for AboutWindow.xaml
1413
/// </summary>
15-
public partial class AboutWindow : MetroWindow
14+
public partial class AboutWindow
1615
{
1716
public AboutWindow()
1817
{
1918
InitializeComponent();
2019
Language_Translate();
2120
if (Program.OptionsObject.Program_AccentColor != "Red" || Program.OptionsObject.Program_Theme != "BaseDark")
2221
{ ThemeManager.ChangeAppStyle(this, ThemeManager.GetAccent(Program.OptionsObject.Program_AccentColor), ThemeManager.GetAppTheme(Program.OptionsObject.Program_Theme)); }
23-
Brush gridBrush = null;
24-
if (Program.OptionsObject.Program_Theme == "BaseDark")
25-
{ gridBrush = new SolidColorBrush(Color.FromArgb(0xC0, 0x10, 0x10, 0x10)); }
26-
else
27-
{ gridBrush = new SolidColorBrush(Color.FromArgb(0xC0, 0xE0, 0xE0, 0xE0)); }
22+
23+
Brush gridBrush = Program.OptionsObject.Program_Theme == "BaseDark" ?
24+
new SolidColorBrush(Color.FromArgb(0xC0, 0x10, 0x10, 0x10)) :
25+
new SolidColorBrush(Color.FromArgb(0xC0, 0xE0, 0xE0, 0xE0));
2826
gridBrush.Freeze();
2927
foreach (var c in ContentStackPanel.Children)
3028
{
31-
if (c is Grid)
29+
if (c is Grid g)
3230
{
33-
Grid g = (Grid)c;
34-
g.Background = gridBrush;
31+
g.Background = gridBrush;
3532
}
3633
}
37-
TitleBox.Text = $"SPEdit ({Assembly.GetEntryAssembly().GetName().Version.ToString()}) - {Program.Translations.GetLanguage("SPEditCap")}";
34+
TitleBox.Text = $"SPEdit ({Assembly.GetEntryAssembly()?.GetName().Version}) - {Program.Translations.GetLanguage("SPEditCap")}";
3835
LicenseField.Text = LicenseString;
3936
}
4037

UI/Windows/ConfigWindow.xaml.cs

Lines changed: 70 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,40 @@
1-
using MahApps.Metro;
2-
using MahApps.Metro.Controls;
3-
using MahApps.Metro.Controls.Dialogs;
4-
using Spedit.Interop;
5-
using Spedit.Utils;
6-
using System;
1+
using System;
72
using System.Collections.Generic;
8-
using System.ComponentModel;
3+
using System.Diagnostics;
94
using System.Globalization;
105
using System.IO;
11-
using System.Linq;
126
using System.Text;
137
using System.Windows;
148
using System.Windows.Controls;
15-
using System.Windows.Documents;
9+
using System.Windows.Forms;
1610
using System.Windows.Input;
17-
using System.Windows.Media;
1811
using System.Xml;
19-
using Microsoft.CSharp;
20-
using Microsoft.Win32;
12+
using MahApps.Metro;
13+
using MahApps.Metro.Controls.Dialogs;
14+
using Spedit.Interop;
15+
using Spedit.Utils;
16+
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
17+
using TextBox = System.Windows.Controls.TextBox;
2118

2219
namespace Spedit.UI.Windows
2320
{
2421
/// <summary>
2522
/// Interaction logic for AboutWindow.xaml
2623
/// </summary>
27-
public partial class ConfigWindow : MetroWindow
24+
public partial class ConfigWindow
2825
{
29-
private bool NeedsSMDefInvalidation = false;
30-
private bool AllowChange = false;
26+
private bool NeedsSMDefInvalidation;
27+
private bool AllowChange;
3128

3229
public ConfigWindow()
3330
{
3431
InitializeComponent();
3532
Language_Translate();
3633
if (Program.OptionsObject.Program_AccentColor != "Red" || Program.OptionsObject.Program_Theme != "BaseDark")
3734
{ ThemeManager.ChangeAppStyle(this, ThemeManager.GetAccent(Program.OptionsObject.Program_AccentColor), ThemeManager.GetAppTheme(Program.OptionsObject.Program_Theme)); }
38-
for (int i = 0; i < Program.Configs.Length; ++i)
35+
foreach (var config in Program.Configs)
3936
{
40-
ConfigListBox.Items.Add(new ListBoxItem() { Content = Program.Configs[i].Name });
37+
ConfigListBox.Items.Add(new ListBoxItem { Content = config.Name });
4138
}
4239
ConfigListBox.SelectedIndex = Program.SelectedConfig;
4340
}
@@ -82,11 +79,10 @@ private void LoadConfigToUI(int index)
8279

8380
private void NewButton_Clicked(object sender, RoutedEventArgs e)
8481
{
85-
Config c = new Config() { Name = "New Config", Standard = false, OptimizeLevel = 2, VerboseLevel = 1 };
86-
List<Config> configList = new List<Config>(Program.Configs);
87-
configList.Add(c);
82+
Config c = new Config { Name = "New Config", Standard = false, OptimizeLevel = 2, VerboseLevel = 1 };
83+
List<Config> configList = new List<Config>(Program.Configs) {c};
8884
Program.Configs = configList.ToArray();
89-
ConfigListBox.Items.Add(new ListBoxItem() { Content = Program.Translations.GetLanguage("NewConfig")});
85+
ConfigListBox.Items.Add(new ListBoxItem { Content = Program.Translations.GetLanguage("NewConfig")});
9086
}
9187

9288
private void DeleteButton_Clicked(object sender, RoutedEventArgs e)
@@ -95,7 +91,7 @@ private void DeleteButton_Clicked(object sender, RoutedEventArgs e)
9591
Config c = Program.Configs[index];
9692
if (c.Standard)
9793
{
98-
this.ShowMessageAsync(Program.Translations.GetLanguage("CannotDelConf"), Program.Translations.GetLanguage("YCannotDelConf"), MessageDialogStyle.Affirmative, this.MetroDialogOptions);
94+
this.ShowMessageAsync(Program.Translations.GetLanguage("CannotDelConf"), Program.Translations.GetLanguage("YCannotDelConf"), MessageDialogStyle.Affirmative, MetroDialogOptions);
9995
return;
10096
}
10197
List<Config> configList = new List<Config>(Program.Configs);
@@ -176,12 +172,16 @@ private void C_VerboseLevel_ValueChanged(object sender, RoutedPropertyChangedEve
176172
private void C_AutoCopy_Changed(object sender, RoutedEventArgs e)
177173
{
178174
if (!AllowChange) { return; }
175+
176+
Debug.Assert(C_AutoCopy.IsChecked != null, "C_AutoCopy.IsChecked != null");
179177
Program.Configs[ConfigListBox.SelectedIndex].AutoCopy = C_AutoCopy.IsChecked.Value;
180178
}
181179

182180
private void C_DeleteAfterCopy_Changed(object sender, RoutedEventArgs e)
183181
{
184182
if (!AllowChange) { return; }
183+
184+
Debug.Assert(C_DeleteAfterCopy.IsChecked != null, "C_DeleteAfterCopy.IsChecked != null");
185185
Program.Configs[ConfigListBox.SelectedIndex].DeleteAfterCopy = C_DeleteAfterCopy.IsChecked.Value;
186186
}
187187

@@ -227,8 +227,8 @@ private void C_RConIP_TextChanged(object sender, RoutedEventArgs e)
227227
private void C_RConPort_TextChanged(object sender, RoutedEventArgs e)
228228
{
229229
if (!AllowChange) { return; }
230-
ushort newPort;
231-
if (!ushort.TryParse(C_RConPort.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out newPort))
230+
231+
if (!ushort.TryParse(C_RConPort.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out var newPort))
232232
{
233233
newPort = 27015;
234234
C_RConPort.Text = "27015";
@@ -252,21 +252,20 @@ private void MetroWindow_Closed(object sender, EventArgs e)
252252
{
253253
if (NeedsSMDefInvalidation)
254254
{
255-
for (int i = 0; i < Program.Configs.Length; ++i)
255+
foreach (var config in Program.Configs)
256256
{
257-
Program.Configs[i].InvalidateSMDef();
257+
config.InvalidateSMDef();
258258
}
259259
}
260260
Program.MainWindow.FillConfigMenu();
261261
Program.MainWindow.ChangeConfig(Program.SelectedConfig);
262262
StringBuilder outString = new StringBuilder();
263-
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true, IndentChars = "\t", NewLineOnAttributes = false, OmitXmlDeclaration = true };
263+
XmlWriterSettings settings = new XmlWriterSettings { Indent = true, IndentChars = "\t", NewLineOnAttributes = false, OmitXmlDeclaration = true };
264264
using (XmlWriter writer = XmlWriter.Create(outString, settings))
265265
{
266266
writer.WriteStartElement("Configurations");
267-
for (int i = 0; i < Program.Configs.Length; ++i)
267+
foreach (var c in Program.Configs)
268268
{
269-
Config c = Program.Configs[i];
270269
writer.WriteStartElement("Config");
271270
writer.WriteAttributeString("Name", c.Name);
272271
StringBuilder SMDirOut = new StringBuilder();
@@ -349,32 +348,29 @@ public ICommand TextBoxButtonFolderCmd
349348
set { }
350349
get
351350
{
352-
if (this.textBoxButtonFolderCmd == null)
351+
if (textBoxButtonFolderCmd == null)
353352
{
354-
var cmd = new SimpleCommand();
355-
cmd.CanExecutePredicate = o =>
353+
var cmd = new SimpleCommand
356354
{
357-
return true;
358-
};
359-
cmd.ExecuteAction = o =>
360-
{
361-
if (o is TextBox)
355+
CanExecutePredicate = o => true,
356+
ExecuteAction = o =>
362357
{
363-
var dialog = new System.Windows.Forms.FolderBrowserDialog();
364-
var result = dialog.ShowDialog();
365-
if (result == System.Windows.Forms.DialogResult.OK)
358+
if (o is TextBox box)
366359
{
367-
((TextBox)o).Text = dialog.SelectedPath;
360+
var dialog = new FolderBrowserDialog();
361+
var result = dialog.ShowDialog();
362+
if (result == System.Windows.Forms.DialogResult.OK)
363+
{
364+
box.Text = dialog.SelectedPath;
365+
}
368366
}
369367
}
370368
};
371-
this.textBoxButtonFolderCmd = cmd;
369+
textBoxButtonFolderCmd = cmd;
372370
return cmd;
373371
}
374-
else
375-
{
376-
return textBoxButtonFolderCmd;
377-
}
372+
373+
return textBoxButtonFolderCmd;
378374
}
379375
}
380376

@@ -385,40 +381,42 @@ public ICommand TextBoxButtonFileCmd
385381
set { }
386382
get
387383
{
388-
if (this.textBoxButtonFileCmd == null)
384+
if (textBoxButtonFileCmd == null)
389385
{
390-
var cmd = new SimpleCommand();
391-
cmd.CanExecutePredicate = o =>
392-
{
393-
return true;
394-
};
395-
cmd.ExecuteAction = o =>
386+
var cmd = new SimpleCommand
396387
{
397-
if (o is TextBox)
388+
CanExecutePredicate = o => true,
389+
ExecuteAction = o =>
398390
{
399-
var dialog = new OpenFileDialog();
400-
dialog.Filter = "Executables *.exe|*.exe|All Files *.*|*.*";
401-
dialog.Multiselect = false;
402-
dialog.CheckFileExists = true; dialog.CheckPathExists = true;
403-
dialog.Title = Program.Translations.GetLanguage("SelectExe");
404-
var result = dialog.ShowDialog();
405-
if (result.Value)
391+
if (o is TextBox box)
406392
{
407-
FileInfo fInfo = new FileInfo(dialog.FileName);
408-
if (fInfo.Exists)
393+
var dialog = new OpenFileDialog
409394
{
410-
((TextBox)o).Text = fInfo.FullName;
395+
Filter = "Executables *.exe|*.exe|All Files *.*|*.*",
396+
Multiselect = false,
397+
CheckFileExists = true,
398+
CheckPathExists = true,
399+
Title = Program.Translations.GetLanguage("SelectExe")
400+
};
401+
var result = dialog.ShowDialog();
402+
403+
Debug.Assert(result != null, nameof(result) + " != null");
404+
if (result.Value)
405+
{
406+
FileInfo fInfo = new FileInfo(dialog.FileName);
407+
if (fInfo.Exists)
408+
{
409+
box.Text = fInfo.FullName;
410+
}
411411
}
412412
}
413413
}
414414
};
415-
this.textBoxButtonFileCmd = cmd;
415+
textBoxButtonFileCmd = cmd;
416416
return cmd;
417417
}
418-
else
419-
{
420-
return textBoxButtonFileCmd;
421-
}
418+
419+
return textBoxButtonFileCmd;
422420
}
423421
}
424422

@@ -435,16 +433,13 @@ public bool CanExecute(object parameter)
435433

436434
public event EventHandler CanExecuteChanged
437435
{
438-
add { CommandManager.RequerySuggested += value; }
439-
remove { CommandManager.RequerySuggested -= value; }
436+
add => CommandManager.RequerySuggested += value;
437+
remove => CommandManager.RequerySuggested -= value;
440438
}
441439

442440
public void Execute(object parameter)
443441
{
444-
if (ExecuteAction != null)
445-
{
446-
ExecuteAction(parameter);
447-
}
442+
ExecuteAction?.Invoke(parameter);
448443
}
449444
}
450445

0 commit comments

Comments
 (0)