From 999d2b68832fa094e22dd1ca55a8f9b4642a16ad Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Sun, 29 May 2022 21:32:43 +0200 Subject: [PATCH] =?UTF-8?q?alterNERDtive-base:=20configuration=20GUI=20now?= =?UTF-8?q?=20has=20an=20=E2=80=9CApply=E2=80=9D=20button?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 + .../VoiceAttack-base/GlobalSuppressions.cs | 8 ++ plugins/VoiceAttack-base/SettingsDialog.xaml | 5 +- .../VoiceAttack-base/SettingsDialog.xaml.cs | 103 ++++++++++++------ .../VoiceAttack-base/VoiceAttack-base.csproj | 3 +- stylecop.json | 16 +++ 6 files changed, 103 insertions(+), 36 deletions(-) create mode 100644 plugins/VoiceAttack-base/GlobalSuppressions.cs create mode 100644 stylecop.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fbbc7c..ba8a809 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # devel +### Added + +* The Configuration GUI now has an “Apply” button. + ## EliteAttack 8.4 ### Added diff --git a/plugins/VoiceAttack-base/GlobalSuppressions.cs b/plugins/VoiceAttack-base/GlobalSuppressions.cs new file mode 100644 index 0000000..69e91a9 --- /dev/null +++ b/plugins/VoiceAttack-base/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", Justification = "", Scope = "namespace", Target = "~N:alterNERDtive")] diff --git a/plugins/VoiceAttack-base/SettingsDialog.xaml b/plugins/VoiceAttack-base/SettingsDialog.xaml index 80d7db4..c0dd3c8 100644 --- a/plugins/VoiceAttack-base/SettingsDialog.xaml +++ b/plugins/VoiceAttack-base/SettingsDialog.xaml @@ -16,8 +16,9 @@ - - + + + diff --git a/plugins/VoiceAttack-base/SettingsDialog.xaml.cs b/plugins/VoiceAttack-base/SettingsDialog.xaml.cs index 1fe51b2..3134a3b 100644 --- a/plugins/VoiceAttack-base/SettingsDialog.xaml.cs +++ b/plugins/VoiceAttack-base/SettingsDialog.xaml.cs @@ -1,4 +1,23 @@ -using System; +// +// Copyright 2019–2022 alterNERDtive. +// +// This file is part of alterNERDtive VoiceAttack profiles for Elite Dangerous. +// +// alterNERDtive VoiceAttack profiles for Elite Dangerous is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// alterNERDtive VoiceAttack profiles for Elite Dangerous is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with alterNERDtive VoiceAttack profiles for Elite Dangerous. If not, see <https://www.gnu.org/licenses/>. +// + +using System; using System.Collections.Generic; using System.Windows; using System.Windows.Controls; @@ -6,40 +25,34 @@ using System.Windows.Controls; namespace alterNERDtive { /// - /// Interaction logic for SettingsDialog.xaml + /// Interaction logic for SettingsDialog.xaml. /// public partial class SettingsDialog : UserControl { - private struct Setting - { - public string Profile { get; } - public dynamic Option { get; } - public dynamic Value { get; } - public dynamic UiElement { get; } - - public Setting(string profile, dynamic option, dynamic value, dynamic uiElement) - => (Profile, Option, Value, UiElement) = (profile, option, value, uiElement); - } - - private List values = new List(); + private readonly List values = new List(); private util.Configuration config; private util.VoiceAttackLog log; + /// + /// Initializes a new instance of the class. + /// + /// The plugin Configuration. + /// The plugin Log. public SettingsDialog(util.Configuration config, util.VoiceAttackLog log) { - InitializeComponent(); + this.InitializeComponent(); this.config = config; this.log = log; - foreach (TabItem tab in tabs.Items) + foreach (TabItem tab in this.tabs.Items) { string profile = tab.Name; if (profile == "general") { profile = "alterNERDtive-base"; } - + tab.IsEnabled = BasePlugin.IsProfileActive(profile); StackPanel panel = new StackPanel(); @@ -57,7 +70,7 @@ namespace alterNERDtive checkBox.IsChecked = value; checkBox.VerticalAlignment = VerticalAlignment.Center; row.Children.Add(checkBox); - values.Add(new Setting(profile, option, value, checkBox)); + this.values.Add(new Setting(profile, option, value, checkBox)); Label label = new Label(); label.Content = option.Description; @@ -76,7 +89,7 @@ namespace alterNERDtive TextBox input = new TextBox(); input.Text = value.ToString(); row.Children.Add(input); - values.Add(new Setting(profile, option, value, input)); + this.values.Add(new Setting(profile, option, value, input)); panel.Children.Add(row); } @@ -86,17 +99,11 @@ namespace alterNERDtive } } - private void cancelButton_Click(object sender, RoutedEventArgs e) + private bool ApplySettings() { - Window.GetWindow(this).Close(); - log.Log("Settings dialog cancelled.", util.LogLevel.DEBUG); - } + bool success = true; - private void okButton_Click(object sender, RoutedEventArgs reargs) - { - bool error = false; - - foreach (Setting setting in values) + foreach (Setting setting in this.values) { dynamic state = null; @@ -129,21 +136,51 @@ namespace alterNERDtive if (state != setting.Value) { - log.Log($@"Configuration changed via settings dialog: ""{setting.Profile}.{setting.Option.Name}"" → ""{state}""", util.LogLevel.DEBUG); - config.SetConfig(setting.Profile, setting.Option.Name, state); + this.log.Log($@"Configuration changed via settings dialog: ""{setting.Profile}.{setting.Option.Name}"" → ""{state}""", util.LogLevel.DEBUG); + this.config.SetConfig(setting.Profile, setting.Option.Name, state); } } catch (Exception e) when (e is ArgumentNullException || e is FormatException || e is OverflowException) { - log.Log($@"Invalid value for ""{setting.Profile}.{setting.Option.Name}"": ""{((TextBox)setting.UiElement).Text}""", util.LogLevel.ERROR); - error = true; + this.log.Log($@"Invalid value for ""{setting.Profile}.{setting.Option.Name}"": ""{((TextBox)setting.UiElement).Text}""", util.LogLevel.ERROR); + success = false; } } - if (!error) + return success; + } + + private void CancelButton_Click(object sender, RoutedEventArgs e) + { + Window.GetWindow(this).Close(); + this.log.Log("Settings dialog cancelled.", util.LogLevel.DEBUG); + } + + private void OkButton_Click(object sender, RoutedEventArgs e) + { + if (this.ApplySettings()) { Window.GetWindow(this).Close(); } } + + private void ApplyButton_Click(object sender, RoutedEventArgs reeargs) + { + this.ApplySettings(); + } + + private struct Setting + { + public Setting(string profile, dynamic option, dynamic value, dynamic uiElement) + => (this.Profile, this.Option, this.Value, this.UiElement) = (profile, option, value, uiElement); + + public string Profile { get; } + + public dynamic Option { get; } + + public dynamic Value { get; } + + public dynamic UiElement { get; } + } } } diff --git a/plugins/VoiceAttack-base/VoiceAttack-base.csproj b/plugins/VoiceAttack-base/VoiceAttack-base.csproj index 51c42a3..f0199ae 100644 --- a/plugins/VoiceAttack-base/VoiceAttack-base.csproj +++ b/plugins/VoiceAttack-base/VoiceAttack-base.csproj @@ -57,6 +57,7 @@ + SettingsDialog.xaml @@ -73,4 +74,4 @@ - + \ No newline at end of file diff --git a/stylecop.json b/stylecop.json new file mode 100644 index 0000000..afa53e0 --- /dev/null +++ b/stylecop.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "orderingRules": { + "usingDirectivesPlacement": "outsideNamespace" + }, + "documentationRules": { + "companyName": "alterNERDtive", + "copyrightText": "Copyright {year} {companyName}.\n\nThis file is part of {application}.\n\n{application} is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\n{application} is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with {application}. If not, see .", + "variables": { + "application": "alterNERDtive VoiceAttack profiles for Elite Dangerous", + "year": "2019–2022" + } + } + } +}