From 3200d6979eb491872b41aecb5e35f1aad9cdac51 Mon Sep 17 00:00:00 2001 From: MakesYT <42534870+MakesYT@users.noreply.github.com> Date: Sun, 1 Oct 2023 11:51:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Class1.cs | 8 - Core/SDKs/CustomScenario/CustomScenario.cs | 22 +- Core/SDKs/SearchViewItem.cs | 11 +- Core/ViewModel/Pages/SettingPageViewModel.cs | 13 +- uToolkitopia/App.xaml | 3 +- uToolkitopia/App.xaml.cs | 12 +- uToolkitopia/Assets/ColorD.cs | 12 +- uToolkitopia/Controls/HotKeyShow.cs | 16 +- uToolkitopia/Controls/HotKeyShowItme.cs | 18 +- .../Controls/MessageBoxControl/MessageBox.cs | 286 +++++++++--------- uToolkitopia/Controls/ResetIsEnabled.cs | 12 +- uToolkitopia/Controls/SettingItems.cs | 36 +-- uToolkitopia/Controls/SettingItems.xaml | 2 +- uToolkitopia/Converter/ReverseBool.cs | 4 +- .../Converter/SearchWindow/CanIgnoreCtr.cs | 6 +- .../SearchWindow/PathToImageConverter.cs | 6 +- .../Converter/SearchWindow/StarBoolToText.cs | 2 +- .../TaskEditor/InterfacesToString.cs | 2 +- uToolkitopia/Services/BindingProxy.cs | 10 +- uToolkitopia/Services/ContentDialogService.cs | 14 +- .../Services/TaskEditorOpenService.cs | 8 +- uToolkitopia/View/ErrorDialog.xaml.cs | 2 +- uToolkitopia/View/HotKeyEditorWindow.xaml.cs | 13 +- uToolkitopia/View/MainWindow.xaml | 9 +- uToolkitopia/View/MainWindow.xaml.cs | 26 +- .../Plugin/CustomScenariosManagerPage.xaml | 23 +- .../Plugin/CustomScenariosManagerPage.xaml.cs | 6 +- .../View/Pages/Plugin/PluginManagerPage.xaml | 86 +++--- .../Plugin/SettingItemToControlConverter.cs | 6 +- uToolkitopia/View/Pages/SettingPage.xaml.cs | 10 +- uToolkitopia/View/SearchWindow.xaml | 9 +- uToolkitopia/View/TaskEditor.xaml | 20 +- uToolkitopia/View/TaskEditor.xaml.cs | 13 +- 33 files changed, 355 insertions(+), 371 deletions(-) delete mode 100644 Core/Class1.cs diff --git a/Core/Class1.cs b/Core/Class1.cs deleted file mode 100644 index f3c31a7..0000000 --- a/Core/Class1.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Core; - -public class Class1 -{ - public void main() - { - } -} \ No newline at end of file diff --git a/Core/SDKs/CustomScenario/CustomScenario.cs b/Core/SDKs/CustomScenario/CustomScenario.cs index feea422..faf1ea6 100644 --- a/Core/SDKs/CustomScenario/CustomScenario.cs +++ b/Core/SDKs/CustomScenario/CustomScenario.cs @@ -21,40 +21,40 @@ public partial class CustomScenario : ObservableRecipient private static readonly ILog Log = LogManager.GetLogger(nameof(CustomScenario)); [JsonIgnore] [ObservableProperty] [NotifyPropertyChangedRecipients] - public bool _isRunning = false; + private bool _isRunning = false; [JsonIgnore] [ObservableProperty] [NotifyPropertyChangedRecipients] - public bool executionAuto = false; + private bool executionAuto = false; [JsonIgnore] [ObservableProperty] [NotifyPropertyChangedRecipients] - public List autoScenarios = new(); + private List autoScenarios = new(); /// /// 手动执行 /// [JsonIgnore] [ObservableProperty] [NotifyPropertyChangedRecipients] - public bool executionManual = true; + private bool executionManual = true; [JsonIgnore] [ObservableProperty] [NotifyPropertyChangedRecipients] - public ObservableCollection keys = new(); + private ObservableCollection keys = new(); /// /// 间隔指定时间执行 /// [JsonIgnore] [ObservableProperty] [NotifyPropertyChangedRecipients] - public bool executionIntervalSpecifies = false; + private bool executionIntervalSpecifies = false; [JsonIgnore] [ObservableProperty] [NotifyPropertyChangedRecipients] - public List intervalSpecifiesTimeSpan; + private List intervalSpecifiesTimeSpan; /// /// 指定时间执行 /// [JsonIgnore] [ObservableProperty] [NotifyPropertyChangedRecipients] - public bool executionScheduleTime = false; + private bool executionScheduleTime = false; [JsonIgnore] [ObservableProperty] [NotifyPropertyChangedRecipients] - public TimeSpan scheduleTime; + private TimeSpan scheduleTime; public string? UUID { @@ -75,10 +75,10 @@ public BindingList connections } = new(); [JsonIgnore] [ObservableProperty] [NotifyPropertyChangedRecipients] - public string _name = "任务"; + private string _name = "任务"; [JsonIgnore] [ObservableProperty] [NotifyPropertyChangedRecipients] - public string _description = ""; + private string _description = ""; private Dictionary _tasks = new(); diff --git a/Core/SDKs/SearchViewItem.cs b/Core/SDKs/SearchViewItem.cs index a686517..3664399 100644 --- a/Core/SDKs/SearchViewItem.cs +++ b/Core/SDKs/SearchViewItem.cs @@ -102,16 +102,7 @@ public void Dispose() Icon = null; } - if (FileInfo != null) - { - FileInfo = null; - } - - if (Keys != null) - { - Keys.Clear(); - Keys = null; - } + GC.SuppressFinalize(this); } } diff --git a/Core/ViewModel/Pages/SettingPageViewModel.cs b/Core/ViewModel/Pages/SettingPageViewModel.cs index 8c7358d..e01c857 100644 --- a/Core/ViewModel/Pages/SettingPageViewModel.cs +++ b/Core/ViewModel/Pages/SettingPageViewModel.cs @@ -23,11 +23,9 @@ public partial class SettingPageViewModel : ObservableRecipient private static readonly ILog log = LogManager.GetLogger("SettingPageViewModel"); private bool _isInitializing = false; - [ObservableProperty] private ObservableCollection _maxHistoryOptions = new ObservableCollection - { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + [ObservableProperty] private ObservableCollection _maxHistoryOptions = new() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - [ObservableProperty] - private ObservableCollection _themeChoiceOptions = new ObservableCollection { "跟随系统", "深色", "浅色" }; + [ObservableProperty] private ObservableCollection _themeChoiceOptions = new() { "跟随系统", "深色", "浅色" }; [ObservableProperty] private bool _autoStart = true; [ObservableProperty] private bool _autoStartEverything = true; @@ -95,8 +93,7 @@ partial void OnThemeChoiceChanged(string value) } [RelayCommand] - private async Task DelKey(string key) - { + private async Task DelKey(string key) => await Application.Current.Dispatcher.BeginInvoke(() => { IgnoreItems.Remove(key); @@ -107,9 +104,7 @@ await Application.Current.Dispatcher.BeginInvoke(() => false); ConfigManger.Save(); }); - //ConfigManger.Config.ignoreItems.Remove(key); - } - + //ConfigManger.Config.ignoreItems.Remove(key); partial void OnInputSmoothingMillisecondsChanged(int value) { diff --git a/uToolkitopia/App.xaml b/uToolkitopia/App.xaml index 9ce3a64..790f238 100644 --- a/uToolkitopia/App.xaml +++ b/uToolkitopia/App.xaml @@ -3,8 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" xmlns:crt="clr-namespace:Kitopia.Converter" - xmlns:c="clr-namespace:Kitopia.Assets" - > + xmlns:c="clr-namespace:Kitopia.Assets"> diff --git a/uToolkitopia/App.xaml.cs b/uToolkitopia/App.xaml.cs index d02155a..943a459 100644 --- a/uToolkitopia/App.xaml.cs +++ b/uToolkitopia/App.xaml.cs @@ -326,20 +326,20 @@ private static IServiceProvider ConfigureServices() services.AddSingleton(sq => new MainWindow { DataContext = sq.GetService() }); services.AddTransient(e => new SettingPageViewModel { IsActive = true }); services.AddTransient(e => - new SettingPage() { DataContext = e.GetService() }); + new SettingPage { DataContext = e.GetService() }); services.AddTransient(e => new HomePageViewModel { IsActive = true }); - services.AddTransient(e => new HomePage() { DataContext = e.GetService() }); + services.AddTransient(e => new HomePage { DataContext = e.GetService() }); services.AddTransient(e => new PluginManagerPageViewModel { IsActive = true }); - services.AddTransient(e => new PluginManagerPage() + services.AddTransient(e => new PluginManagerPage { DataContext = e.GetService() }); services.AddSingleton(e => new PluginSettingViewModel { IsActive = true }); - services.AddSingleton(e => new PluginSetting() + services.AddSingleton(e => new PluginSetting { DataContext = e.GetService() }); services.AddTransient(e => new TaskEditorViewModel { IsActive = true }); - services.AddTransient(e => new TaskEditor() { DataContext = e.GetService() }); + services.AddTransient(e => new TaskEditor { DataContext = e.GetService() }); services.AddTransient(e => new CustomScenariosManagerPageViewModel { IsActive = true }); - services.AddTransient(e => new CustomScenariosManagerPage() + services.AddTransient(e => new CustomScenariosManagerPage { DataContext = e.GetService() }); return services.BuildServiceProvider(); diff --git a/uToolkitopia/Assets/ColorD.cs b/uToolkitopia/Assets/ColorD.cs index 4b0c231..0500d64 100644 --- a/uToolkitopia/Assets/ColorD.cs +++ b/uToolkitopia/Assets/ColorD.cs @@ -10,12 +10,6 @@ namespace Kitopia.Assets; public class ColorD : ResourceDictionary { - public static ColorD Instance - { - get; - set; - } - public ColorD() { Instance = this; @@ -23,6 +17,12 @@ public ColorD() Add("SystemAccentColorSecondary", ((SolidColorBrush)SystemParameters.WindowGlassBrush).Color); } + public static ColorD Instance + { + get; + set; + } + public void ReloadColor() { Remove("SystemAccentColorSecondary"); diff --git a/uToolkitopia/Controls/HotKeyShow.cs b/uToolkitopia/Controls/HotKeyShow.cs index ebd92ca..f91fd34 100644 --- a/uToolkitopia/Controls/HotKeyShow.cs +++ b/uToolkitopia/Controls/HotKeyShow.cs @@ -25,6 +25,14 @@ public enum KeyTypeE Shift = 0100 } + public static readonly DependencyProperty KeyTypeProperty = DependencyProperty.Register(nameof(KeyType), + typeof(KeyTypeE), typeof(System.Windows.Controls.Button), + new PropertyMetadata(KeyTypeE.Alt)); + + public static readonly DependencyProperty KeyNameProperty = DependencyProperty.Register(nameof(KeyName), + typeof(string), typeof(System.Windows.Controls.Button), + new PropertyMetadata("空格")); + [Bindable(true)] [Category("KeyType")] public KeyTypeE KeyType @@ -33,10 +41,6 @@ public KeyTypeE KeyType set => SetValue(KeyTypeProperty, value); } - public static readonly DependencyProperty KeyTypeProperty = DependencyProperty.Register(nameof(KeyType), - typeof(KeyTypeE), typeof(System.Windows.Controls.Button), - new PropertyMetadata(KeyTypeE.Alt)); - [Bindable(true)] [Category("KeyName")] public string KeyName @@ -44,8 +48,4 @@ public string KeyName get => (string)GetValue(KeyNameProperty); set => SetValue(KeyNameProperty, value); } - - public static readonly DependencyProperty KeyNameProperty = DependencyProperty.Register(nameof(KeyName), - typeof(string), typeof(System.Windows.Controls.Button), - new PropertyMetadata("空格")); } \ No newline at end of file diff --git a/uToolkitopia/Controls/HotKeyShowItme.cs b/uToolkitopia/Controls/HotKeyShowItme.cs index 4e7738d..6f7b1b6 100644 --- a/uToolkitopia/Controls/HotKeyShowItme.cs +++ b/uToolkitopia/Controls/HotKeyShowItme.cs @@ -82,15 +82,6 @@ public IconElement? Icon set => SetValue(IconProperty, value); } - /// - [Bindable(true)] - [Category("Appearance")] - public ControlAppearance Appearance - { - get => (ControlAppearance)GetValue(AppearanceProperty); - set => SetValue(AppearanceProperty, value); - } - /// /// Background when the user interacts with an element with a pointing device. /// @@ -145,4 +136,13 @@ public Brush PressedBorderBrush get => (Brush)GetValue(PressedBorderBrushProperty); set => SetValue(PressedBorderBrushProperty, value); } + + /// + [Bindable(true)] + [Category("Appearance")] + public ControlAppearance Appearance + { + get => (ControlAppearance)GetValue(AppearanceProperty); + set => SetValue(AppearanceProperty, value); + } } \ No newline at end of file diff --git a/uToolkitopia/Controls/MessageBoxControl/MessageBox.cs b/uToolkitopia/Controls/MessageBoxControl/MessageBox.cs index b053cb5..358bd6f 100644 --- a/uToolkitopia/Controls/MessageBoxControl/MessageBox.cs +++ b/uToolkitopia/Controls/MessageBoxControl/MessageBox.cs @@ -21,6 +21,149 @@ namespace Kitopia.Controls.MessageBoxControl; [ToolboxBitmap(typeof(MessageBox), "MessageBox.bmp")] public class MessageBox : Window { + protected TaskCompletionSource? Tcs; + + /// + /// Initializes a new instance of the class. + /// + public MessageBox() + { + Topmost = true; + SetValue(TemplateButtonCommandProperty, new RelayCommand(OnButtonClick)); + + PreviewMouseDoubleClick += static (_, args) => args.Handled = true; + + Loaded += static (sender, _) => + { + var self = (MessageBox)sender; + self.OnLoaded(); + }; + } + + [Obsolete($"Use {nameof(ShowDialogAsync)} instead")] + public new void Show() => throw new InvalidOperationException($"Use {nameof(ShowDialogAsync)} instead"); + + [Obsolete($"Use {nameof(ShowDialogAsync)} instead")] + public new bool? ShowDialog() => throw new InvalidOperationException($"Use {nameof(ShowDialogAsync)} instead"); + + [Obsolete($"Use {nameof(Close)} with MessageBoxResult instead")] + public new void Close() => + throw new InvalidOperationException($"Use {nameof(Close)} with MessageBoxResult instead"); + + /// + /// Displays a message box + /// + /// + /// + /// + /// + public async Task ShowDialogAsync(bool showAsDialog = true, + CancellationToken cancellationToken = default) + { + Tcs = new TaskCompletionSource(); + var tokenRegistration = + cancellationToken.Register(o => Tcs.TrySetCanceled((CancellationToken)o!), cancellationToken); + + try + { + RemoveTitleBarAndApplyMica(); + + if (showAsDialog) + { + base.ShowDialog(); + } + else + { + base.Show(); + } + + return await Tcs.Task; + } + finally + { +#if NET6_0_OR_GREATER + await tokenRegistration.DisposeAsync(); +#else + tokenRegistration.Dispose(); +#endif + } + } + + /// + /// Occurs after Loading event + /// + protected virtual void OnLoaded() + { + var rootElement = (UIElement)GetVisualChild(0)!; + + ResizeToContentSize(rootElement); + CenterWindowOnScreen(); + } + + /// + /// Sets Width and Height + /// + /// + protected virtual void ResizeToContentSize(UIElement rootElement) + { + var desiredSize = rootElement.DesiredSize; + + //left and right margin + const double margin = 12.0 * 2; + + Width = desiredSize.Width + margin; + Height = desiredSize.Height; + + ResizeWidth(rootElement); + ResizeHeight(rootElement); + } + + protected override void OnClosing(CancelEventArgs e) + { + base.OnClosing(e); + + if (e.Cancel) + { + return; + } + + Tcs?.TrySetResult(MessageBoxResult.None); + } + + protected virtual void CenterWindowOnScreen() + { + //TODO MessageBox should be displayed on the window on which the application + + var screenWidth = SystemParameters.PrimaryScreenWidth; + var screenHeight = SystemParameters.PrimaryScreenHeight; + + Left = screenWidth / 2 - Width / 2; + Top = screenHeight / 2 - Height / 2; + } + + /// + /// Occurs after the is clicked + /// + /// + protected virtual void OnButtonClick(MessageBoxButton button) + { + var result = button switch + { + MessageBoxButton.Primary => MessageBoxResult.Primary, + MessageBoxButton.Secondary => MessageBoxResult.Secondary, + _ => MessageBoxResult.None + }; + + Tcs?.TrySetResult(result); + base.Close(); + } + + private void RemoveTitleBarAndApplyMica() + { + UnsafeNativeMethods.RemoveWindowTitlebarContents(this); + WindowBackdrop.ApplyBackdrop(this, WindowBackdropType.Mica); + } + #region Static properties /// @@ -238,149 +381,6 @@ public bool IsPrimaryButtonEnabled #endregion - /// - /// Initializes a new instance of the class. - /// - public MessageBox() - { - Topmost = true; - SetValue(TemplateButtonCommandProperty, new RelayCommand(OnButtonClick)); - - PreviewMouseDoubleClick += static (_, args) => args.Handled = true; - - Loaded += static (sender, _) => - { - var self = (MessageBox)sender; - self.OnLoaded(); - }; - } - - protected TaskCompletionSource? Tcs; - - [Obsolete($"Use {nameof(ShowDialogAsync)} instead")] - public new void Show() => throw new InvalidOperationException($"Use {nameof(ShowDialogAsync)} instead"); - - [Obsolete($"Use {nameof(ShowDialogAsync)} instead")] - public new bool? ShowDialog() => throw new InvalidOperationException($"Use {nameof(ShowDialogAsync)} instead"); - - [Obsolete($"Use {nameof(Close)} with MessageBoxResult instead")] - public new void Close() => - throw new InvalidOperationException($"Use {nameof(Close)} with MessageBoxResult instead"); - - /// - /// Displays a message box - /// - /// - /// - /// - /// - public async Task ShowDialogAsync(bool showAsDialog = true, - CancellationToken cancellationToken = default) - { - Tcs = new TaskCompletionSource(); - var tokenRegistration = - cancellationToken.Register(o => Tcs.TrySetCanceled((CancellationToken)o!), cancellationToken); - - try - { - RemoveTitleBarAndApplyMica(); - - if (showAsDialog) - { - base.ShowDialog(); - } - else - { - base.Show(); - } - - return await Tcs.Task; - } - finally - { -#if NET6_0_OR_GREATER - await tokenRegistration.DisposeAsync(); -#else - tokenRegistration.Dispose(); -#endif - } - } - - /// - /// Occurs after Loading event - /// - protected virtual void OnLoaded() - { - var rootElement = (UIElement)GetVisualChild(0)!; - - ResizeToContentSize(rootElement); - CenterWindowOnScreen(); - } - - /// - /// Sets Width and Height - /// - /// - protected virtual void ResizeToContentSize(UIElement rootElement) - { - var desiredSize = rootElement.DesiredSize; - - //left and right margin - const double margin = 12.0 * 2; - - Width = desiredSize.Width + margin; - Height = desiredSize.Height; - - ResizeWidth(rootElement); - ResizeHeight(rootElement); - } - - protected override void OnClosing(CancelEventArgs e) - { - base.OnClosing(e); - - if (e.Cancel) - { - return; - } - - Tcs?.TrySetResult(MessageBoxResult.None); - } - - protected virtual void CenterWindowOnScreen() - { - //TODO MessageBox should be displayed on the window on which the application - - var screenWidth = SystemParameters.PrimaryScreenWidth; - var screenHeight = SystemParameters.PrimaryScreenHeight; - - Left = screenWidth / 2 - Width / 2; - Top = screenHeight / 2 - Height / 2; - } - - /// - /// Occurs after the is clicked - /// - /// - protected virtual void OnButtonClick(MessageBoxButton button) - { - var result = button switch - { - MessageBoxButton.Primary => MessageBoxResult.Primary, - MessageBoxButton.Secondary => MessageBoxResult.Secondary, - _ => MessageBoxResult.None - }; - - Tcs?.TrySetResult(result); - base.Close(); - } - - private void RemoveTitleBarAndApplyMica() - { - UnsafeNativeMethods.RemoveWindowTitlebarContents(this); - WindowBackdrop.ApplyBackdrop(this, WindowBackdropType.Mica); - } - #region Resize private methods private void ResizeWidth(UIElement element) diff --git a/uToolkitopia/Controls/ResetIsEnabled.cs b/uToolkitopia/Controls/ResetIsEnabled.cs index 1e7a5c9..070c8e9 100644 --- a/uToolkitopia/Controls/ResetIsEnabled.cs +++ b/uToolkitopia/Controls/ResetIsEnabled.cs @@ -1,6 +1,10 @@ -using System.Windows; +#region + +using System.Windows; using System.Windows.Controls; +#endregion + namespace Kitopia.Controls; public class ResetIsEnabled : ContentControl @@ -10,10 +14,10 @@ static ResetIsEnabled() IsEnabledProperty.OverrideMetadata( typeof(ResetIsEnabled), new UIPropertyMetadata( - defaultValue: true, - propertyChangedCallback: (_, __) => + true, + (_, __) => { }, - coerceValueCallback: (_, x) => x)); + (_, x) => x)); } } \ No newline at end of file diff --git a/uToolkitopia/Controls/SettingItems.cs b/uToolkitopia/Controls/SettingItems.cs index 84580d5..0ce71f1 100644 --- a/uToolkitopia/Controls/SettingItems.cs +++ b/uToolkitopia/Controls/SettingItems.cs @@ -12,6 +12,24 @@ namespace Kitopia.Controls; public class SettingItems : ContentControl { + [Bindable(true)] public static readonly DependencyProperty TitleFontSizeProperty = DependencyProperty.Register( + nameof(TitleFontSize), + typeof(int), typeof(SettingItems), + new FrameworkPropertyMetadata(15)); + + [Bindable(true)] public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( + nameof(Title), + typeof(string), typeof(SettingItems), + new FrameworkPropertyMetadata("")); + + public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(nameof(Description), + typeof(string), typeof(SettingItems), + new PropertyMetadata(null)); + + public static readonly DependencyProperty IconProperty = DependencyProperty.Register(nameof(Icon), + typeof(IconElement), typeof(SettingItems), + new PropertyMetadata(null, null, IconSourceElementConverter.ConvertToIconElement)); + [Bindable(true)] [Category("TitleFontSize")] public int TitleFontSize @@ -20,11 +38,6 @@ public int TitleFontSize set => SetValue(TitleFontSizeProperty, value); } - [Bindable(true)] public static readonly DependencyProperty TitleFontSizeProperty = DependencyProperty.Register( - nameof(TitleFontSize), - typeof(int), typeof(SettingItems), - new FrameworkPropertyMetadata(15)); - [Bindable(true)] [Category("Title")] public string Title @@ -33,11 +46,6 @@ public string Title set => SetValue(TitleProperty, value); } - [Bindable(true)] public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( - nameof(Title), - typeof(string), typeof(SettingItems), - new FrameworkPropertyMetadata("")); - [Bindable(true)] [Category("Description")] public string Description @@ -46,10 +54,6 @@ public string Description set => SetValue(DescriptionProperty, value); } - public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(nameof(Description), - typeof(string), typeof(SettingItems), - new PropertyMetadata(null)); - [Bindable(true)] [Category("Appearance")] @@ -58,8 +62,4 @@ public IconElement? Icon get => (IconElement)GetValue(IconProperty); set => SetValue(IconProperty, value); } - - public static readonly DependencyProperty IconProperty = DependencyProperty.Register(nameof(Icon), - typeof(IconElement), typeof(SettingItems), - new PropertyMetadata(null, null, IconSourceElementConverter.ConvertToIconElement)); } \ No newline at end of file diff --git a/uToolkitopia/Controls/SettingItems.xaml b/uToolkitopia/Controls/SettingItems.xaml index eb9023d..231b3ce 100644 --- a/uToolkitopia/Controls/SettingItems.xaml +++ b/uToolkitopia/Controls/SettingItems.xaml @@ -62,7 +62,7 @@ - + diff --git a/uToolkitopia/Converter/ReverseBool.cs b/uToolkitopia/Converter/ReverseBool.cs index 04925d2..42e62c4 100644 --- a/uToolkitopia/Converter/ReverseBool.cs +++ b/uToolkitopia/Converter/ReverseBool.cs @@ -17,9 +17,9 @@ public object Convert(object? value, Type targetType, object parameter, CultureI return false; } - return (bool)!(bool)value; + return !(bool)value; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => - (bool)!(bool)value; + !(bool)value; } \ No newline at end of file diff --git a/uToolkitopia/Converter/SearchWindow/CanIgnoreCtr.cs b/uToolkitopia/Converter/SearchWindow/CanIgnoreCtr.cs index 0376be2..1f65388 100644 --- a/uToolkitopia/Converter/SearchWindow/CanIgnoreCtr.cs +++ b/uToolkitopia/Converter/SearchWindow/CanIgnoreCtr.cs @@ -1,9 +1,13 @@ -using System; +#region + +using System; using System.Globalization; using System.Windows; using System.Windows.Data; using Core.SDKs; +#endregion + namespace Kitopia.Converter.SearchWindow; public class CanIgnoreCtr : IValueConverter diff --git a/uToolkitopia/Converter/SearchWindow/PathToImageConverter.cs b/uToolkitopia/Converter/SearchWindow/PathToImageConverter.cs index 2f73434..9918c18 100644 --- a/uToolkitopia/Converter/SearchWindow/PathToImageConverter.cs +++ b/uToolkitopia/Converter/SearchWindow/PathToImageConverter.cs @@ -15,9 +15,6 @@ namespace Kitopia.Converter.SearchWindow; public class PathToImageConverter : IValueConverter { - [DllImport("gdi32.dll")] - public static extern bool DeleteObject(IntPtr hObject); - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) @@ -45,4 +42,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); + + [DllImport("gdi32.dll")] + public static extern bool DeleteObject(IntPtr hObject); } \ No newline at end of file diff --git a/uToolkitopia/Converter/SearchWindow/StarBoolToText.cs b/uToolkitopia/Converter/SearchWindow/StarBoolToText.cs index 552f069..0e81f6d 100644 --- a/uToolkitopia/Converter/SearchWindow/StarBoolToText.cs +++ b/uToolkitopia/Converter/SearchWindow/StarBoolToText.cs @@ -41,5 +41,5 @@ public object Convert(object? value, Type targetType, object parameter, CultureI } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => - (bool)!(bool)value; + !(bool)value; } \ No newline at end of file diff --git a/uToolkitopia/Converter/TaskEditor/InterfacesToString.cs b/uToolkitopia/Converter/TaskEditor/InterfacesToString.cs index fe85907..0a1c6ab 100644 --- a/uToolkitopia/Converter/TaskEditor/InterfacesToString.cs +++ b/uToolkitopia/Converter/TaskEditor/InterfacesToString.cs @@ -38,5 +38,5 @@ public object Convert(object? value, Type targetType, object parameter, CultureI } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => - (bool)!(bool)value; + !(bool)value; } \ No newline at end of file diff --git a/uToolkitopia/Services/BindingProxy.cs b/uToolkitopia/Services/BindingProxy.cs index 8003819..698e881 100644 --- a/uToolkitopia/Services/BindingProxy.cs +++ b/uToolkitopia/Services/BindingProxy.cs @@ -8,15 +8,15 @@ namespace Kitopia.Services; public class BindingProxy : Freezable { - protected override Freezable CreateInstanceCore() => new BindingProxy(); + // Using a DependencyProperty as the backing store for Data. This enables animation, styling, binding, etc... + public static readonly DependencyProperty DataProperty = + DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new PropertyMetadata(null)); public object Data { - get => (object)GetValue(DataProperty); + get => GetValue(DataProperty); set => SetValue(DataProperty, value); } - // Using a DependencyProperty as the backing store for Data. This enables animation, styling, binding, etc... - public static readonly DependencyProperty DataProperty = - DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new PropertyMetadata(null)); + protected override Freezable CreateInstanceCore() => new BindingProxy(); } \ No newline at end of file diff --git a/uToolkitopia/Services/ContentDialogService.cs b/uToolkitopia/Services/ContentDialogService.cs index 809e1a8..321d533 100644 --- a/uToolkitopia/Services/ContentDialogService.cs +++ b/uToolkitopia/Services/ContentDialogService.cs @@ -1,8 +1,12 @@ -using System; +#region + +using System; using System.Windows.Controls; using Core.SDKs.Services; using Wpf.Ui.Controls; +#endregion + namespace Kitopia.Services; public class ContentDialogService : IContentDialog @@ -14,9 +18,9 @@ public void ShowDialogAsync(object contentPresenter, string title, object conten Title = title, Content = content, CloseButtonText = "关闭", - PrimaryButtonText = "确定", + PrimaryButtonText = "确定" }; - dialog.ShowAsync().ContinueWith((e) => + dialog.ShowAsync().ContinueWith(e => { switch (e.Result) { @@ -43,9 +47,9 @@ public void ShowDialog(object contentPresenter, string title, object content, st Content = content, CloseButtonText = CloseButtonText, SecondaryButtonText = SecondaryButtonText, - PrimaryButtonText = PrimaryButtonText, + PrimaryButtonText = PrimaryButtonText }; - dialog.ShowAsync().ContinueWith((e) => + dialog.ShowAsync().ContinueWith(e => { switch (e.Result) { diff --git a/uToolkitopia/Services/TaskEditorOpenService.cs b/uToolkitopia/Services/TaskEditorOpenService.cs index 99c4f91..896f664 100644 --- a/uToolkitopia/Services/TaskEditorOpenService.cs +++ b/uToolkitopia/Services/TaskEditorOpenService.cs @@ -11,21 +11,17 @@ namespace Kitopia.Services; public class TaskEditorOpenService : ITaskEditorOpenService { - public void Open() - { + public void Open() => Application.Current.Dispatcher.BeginInvoke(() => { ((TaskEditor)ServiceManager.Services!.GetService(typeof(TaskEditor))!)!.Show(); }); - } - public void Open(CustomScenario name) - { + public void Open(CustomScenario name) => Application.Current.Dispatcher.BeginInvoke(() => { var taskEditor = ((TaskEditor)ServiceManager.Services!.GetService(typeof(TaskEditor))!)!; taskEditor.LoadTask(name); taskEditor.Show(); }); - } } \ No newline at end of file diff --git a/uToolkitopia/View/ErrorDialog.xaml.cs b/uToolkitopia/View/ErrorDialog.xaml.cs index 01c66e6..5a89de9 100644 --- a/uToolkitopia/View/ErrorDialog.xaml.cs +++ b/uToolkitopia/View/ErrorDialog.xaml.cs @@ -37,7 +37,7 @@ public string ExecuteInCmd(string cmdline, string dir) using (var process = new Process()) { process.StartInfo.FileName = @"C:\Windows\System32\cmd.exe"; - if (!File.Exists($@"C:\Windows\System32\cmd.exe")) + if (!File.Exists(@"C:\Windows\System32\cmd.exe")) { process.StartInfo.FileName = @"C:\Windows\sysnative\cmd.exe"; } diff --git a/uToolkitopia/View/HotKeyEditorWindow.xaml.cs b/uToolkitopia/View/HotKeyEditorWindow.xaml.cs index f16d1a2..5e7100a 100644 --- a/uToolkitopia/View/HotKeyEditorWindow.xaml.cs +++ b/uToolkitopia/View/HotKeyEditorWindow.xaml.cs @@ -17,15 +17,19 @@ namespace Kitopia.View; public partial class HotKeyEditorWindow : FluentWindow { + private bool isFinnish; public string name; + private EKey? selectedKey; + private bool setSuccess; + public HotKeyEditorWindow(string name) { InitializeComponent(); this.name = name; Name.Text = $"快捷键:{name}"; - var hotKeyModel = ConfigManger.Config.hotKeys.FirstOrDefault((e) => + var hotKeyModel = ConfigManger.Config.hotKeys.FirstOrDefault(e => { if ($"{e.MainName}_{e.Name}".Equals(name)) { @@ -58,8 +62,6 @@ public HotKeyEditorWindow(string name) KeyName.Content = hotKeyModel.SelectKey.ToString(); } - private EKey? selectedKey; - private void HotKeyEditorWindow_OnKeyDown(object sender, KeyEventArgs e) { { @@ -119,9 +121,6 @@ private void HotKeyEditorWindow_OnKeyUp(object sender, KeyEventArgs e) { } - private bool isFinnish = false; - private bool setSuccess = false; - public bool GetResult() { while (!isFinnish) @@ -133,7 +132,7 @@ public bool GetResult() private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { - var hotKeyModel = ConfigManger.Config.hotKeys.FirstOrDefault((e) => + var hotKeyModel = ConfigManger.Config.hotKeys.FirstOrDefault(e => { if ($"{e.MainName}_{e.Name}".Equals(name)) { diff --git a/uToolkitopia/View/MainWindow.xaml b/uToolkitopia/View/MainWindow.xaml index ac1f09c..fb3e478 100644 --- a/uToolkitopia/View/MainWindow.xaml +++ b/uToolkitopia/View/MainWindow.xaml @@ -14,10 +14,10 @@ ExtendsContentIntoTitleBar="True" WindowBackdropType="Acrylic" d:DataContext="{d:DesignInstance viewModel:MainWindowViewModel}" - d:IsHidden="False" + d:IsHidden="False" Visibility="Hidden" WindowCornerPreference="Round" - Title="Kitopia" Height="742" Width="1200" > + Title="Kitopia" Height="742" Width="1200"> @@ -40,7 +40,7 @@ - + @@ -65,7 +65,8 @@ - diff --git a/uToolkitopia/View/MainWindow.xaml.cs b/uToolkitopia/View/MainWindow.xaml.cs index c0ba416..14edac3 100644 --- a/uToolkitopia/View/MainWindow.xaml.cs +++ b/uToolkitopia/View/MainWindow.xaml.cs @@ -30,6 +30,16 @@ public partial class MainWindow { private static readonly ILog log = LogManager.GetLogger(nameof(MainWindow)); + /// + /// 记录快捷键注册项的唯一标识符 + /// + private Dictionary m_HotKeySettings = new(); + + /// + /// 当前窗口句柄 + /// + private IntPtr m_Hwnd; + public MainWindow() { InitializeComponent(); @@ -121,16 +131,6 @@ public MainWindow() //Close(); } - /// - /// 记录快捷键注册项的唯一标识符 - /// - private Dictionary m_HotKeySettings = new(); - - /// - /// 当前窗口句柄 - /// - private IntPtr m_Hwnd; - protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); @@ -145,10 +145,10 @@ protected override void OnSourceInitialized(EventArgs e) hWndSource.AddHook(WndProc); } - AppDomain.CurrentDomain.ProcessExit += new EventHandler((_, _) => + AppDomain.CurrentDomain.ProcessExit += (_, _) => { //CustomScenarioExecutor.Exit(); - }); + }; log.Debug("注册热键"); InitHotKey(); @@ -301,7 +301,7 @@ private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wideParam, IntPtr longParam, } ServiceManager.Services.GetService()!.tx.SelectAll(); - ThreadPool.QueueUserWorkItem((e) => + ThreadPool.QueueUserWorkItem(e => { ServiceManager.Services.GetService()!.ReloadApps(); }); diff --git a/uToolkitopia/View/Pages/Plugin/CustomScenariosManagerPage.xaml b/uToolkitopia/View/Pages/Plugin/CustomScenariosManagerPage.xaml index 574d46b..22c9658 100644 --- a/uToolkitopia/View/Pages/Plugin/CustomScenariosManagerPage.xaml +++ b/uToolkitopia/View/Pages/Plugin/CustomScenariosManagerPage.xaml @@ -27,11 +27,11 @@ - + ItemsSource="{Binding Source= {x:Static config:CustomScenarioManger.CustomScenarios},NotifyOnSourceUpdated=True,NotifyOnTargetUpdated=True,Mode=OneWay}" + Margin="0,10,0,0"> @@ -42,16 +42,17 @@ Background="Transparent" Height="72" Margin="0" Padding="3"> - + - - - - + + + + - + - - diff --git a/uToolkitopia/View/Pages/Plugin/CustomScenariosManagerPage.xaml.cs b/uToolkitopia/View/Pages/Plugin/CustomScenariosManagerPage.xaml.cs index 5872489..e7c3c87 100644 --- a/uToolkitopia/View/Pages/Plugin/CustomScenariosManagerPage.xaml.cs +++ b/uToolkitopia/View/Pages/Plugin/CustomScenariosManagerPage.xaml.cs @@ -1,4 +1,8 @@ -using System.Windows.Controls; +#region + +using System.Windows.Controls; + +#endregion namespace Kitopia.View.Pages.Plugin; diff --git a/uToolkitopia/View/Pages/Plugin/PluginManagerPage.xaml b/uToolkitopia/View/Pages/Plugin/PluginManagerPage.xaml index b9a3e3a..cc97caa 100644 --- a/uToolkitopia/View/Pages/Plugin/PluginManagerPage.xaml +++ b/uToolkitopia/View/Pages/Plugin/PluginManagerPage.xaml @@ -28,11 +28,11 @@ - + MaxHeight="385" HorizontalContentAlignment="Stretch" + ItemsSource="{Binding Items,UpdateSourceTrigger=PropertyChanged}" + Margin="0,10,0,0"> @@ -42,46 +42,48 @@ Background="Transparent" Height="72" Margin="0" Padding="3"> - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - diff --git a/uToolkitopia/View/Pages/Plugin/SettingItemToControlConverter.cs b/uToolkitopia/View/Pages/Plugin/SettingItemToControlConverter.cs index a648305..f253db9 100644 --- a/uToolkitopia/View/Pages/Plugin/SettingItemToControlConverter.cs +++ b/uToolkitopia/View/Pages/Plugin/SettingItemToControlConverter.cs @@ -54,10 +54,8 @@ public object Convert(object value, Type targetType, object parameter, CultureIn return control; } - else - { - return null; - } + + return null; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => diff --git a/uToolkitopia/View/Pages/SettingPage.xaml.cs b/uToolkitopia/View/Pages/SettingPage.xaml.cs index 15ab025..d9512f5 100644 --- a/uToolkitopia/View/Pages/SettingPage.xaml.cs +++ b/uToolkitopia/View/Pages/SettingPage.xaml.cs @@ -38,16 +38,16 @@ private void ListBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e) var dataGrid = (DataGrid)sender; var dependencyObject = GetScrollViewer(dataGrid); - Rect bounds = dataGrid.TransformToAncestor(Window.GetWindow(this)) + var bounds = dataGrid.TransformToAncestor(Window.GetWindow(this)) .TransformBounds(new Rect(0.0, 0.0, dataGrid.ActualWidth, dataGrid.ActualHeight)); - Rect rect = new Rect(0.0, 0.0, this.WindowWidth, this.WindowHeight); + var rect = new Rect(0.0, 0.0, WindowWidth, WindowHeight); { if (!rect.Contains(bounds)) { e.Handled = true; var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta); - eventArg.RoutedEvent = UIElement.MouseWheelEvent; + eventArg.RoutedEvent = MouseWheelEvent; eventArg.Source = sender; var parent = ((Control)sender).Parent as UIElement; parent.RaiseEvent(eventArg); @@ -57,7 +57,7 @@ private void ListBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e) if (dependencyObject.ContentVerticalOffset >= dependencyObject.ScrollableHeight && e.Delta < 0) { var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta); - eventArg.RoutedEvent = UIElement.MouseWheelEvent; + eventArg.RoutedEvent = MouseWheelEvent; eventArg.Source = sender; var parent = ((Control)sender).Parent as UIElement; parent.RaiseEvent(eventArg); @@ -66,7 +66,7 @@ private void ListBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e) if (dependencyObject.ContentVerticalOffset == 0 && e.Delta > 0) { var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta); - eventArg.RoutedEvent = UIElement.MouseWheelEvent; + eventArg.RoutedEvent = MouseWheelEvent; eventArg.Source = sender; var parent = ((Control)sender).Parent as UIElement; parent.RaiseEvent(eventArg); diff --git a/uToolkitopia/View/SearchWindow.xaml b/uToolkitopia/View/SearchWindow.xaml index f6c6834..99ceda4 100644 --- a/uToolkitopia/View/SearchWindow.xaml +++ b/uToolkitopia/View/SearchWindow.xaml @@ -84,18 +84,19 @@ Background="Transparent" PreviewKeyDown="Button_PreviewKeyDown"> - + - - - + diff --git a/uToolkitopia/View/TaskEditor.xaml b/uToolkitopia/View/TaskEditor.xaml index 64ec6d4..60e6baa 100644 --- a/uToolkitopia/View/TaskEditor.xaml +++ b/uToolkitopia/View/TaskEditor.xaml @@ -44,10 +44,6 @@ Geometry="M0,0 L0,1 0.03,1 0.03,0.03 1,0.03 1,0 Z" Brush="{DynamicResource NodifyEditor.SelectionRectangleBackgroundBrush}" /> - - - @@ -212,9 +209,8 @@ - + @@ -249,16 +245,16 @@ - - + + - + - + diff --git a/uToolkitopia/View/TaskEditor.xaml.cs b/uToolkitopia/View/TaskEditor.xaml.cs index 9ab859d..ea282d2 100644 --- a/uToolkitopia/View/TaskEditor.xaml.cs +++ b/uToolkitopia/View/TaskEditor.xaml.cs @@ -25,10 +25,7 @@ public TaskEditor() Height = SystemParameters.PrimaryScreenHeight * 2 / 3; } - public void LoadTask(CustomScenario name) - { - ((TaskEditorViewModel)DataContext).Load(name); - } + public void LoadTask(CustomScenario name) => ((TaskEditorViewModel)DataContext).Load(name); protected override void OnSourceInitialized(EventArgs e) { @@ -39,7 +36,7 @@ protected override void OnSourceInitialized(EventArgs e) { WindowBackdrop.ApplyBackdrop(m_Hwnd, WindowBackdropType.Acrylic); }; - ((TaskEditorViewModel)DataContext).ContentPresenter = this.ContentPresenter; + ((TaskEditorViewModel)DataContext).ContentPresenter = ContentPresenter; } private void ListBox_OnMouseMove(object sender, MouseEventArgs e) @@ -64,11 +61,11 @@ private void NodifyEditor_Drop(object sender, DragEventArgs e) { if (e.OriginalSource is Border) { - var command = add.Command as ICommand; + var command = add.Command; if (command != null && command.CanExecute(fromListNode)) // Check if the command is not null and can be executed { - var point = e.GetPosition((IInputElement)Editor); + var point = e.GetPosition(Editor); point.X += Editor.ViewportLocation.X; point.Y += Editor.ViewportLocation.Y; fromListNode.Location = point; @@ -102,7 +99,7 @@ private void ListBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e) // 激发一个鼠标滚轮事件,冒泡给外层ListView接收到 var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta); - eventArg.RoutedEvent = UIElement.MouseWheelEvent; + eventArg.RoutedEvent = MouseWheelEvent; eventArg.Source = sender; var parent = ((Control)sender).Parent as UIElement; parent.RaiseEvent(eventArg);