From 807f0783353ce69c0a40e28de93a737fffd97515 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Fri, 14 Jun 2024 10:13:08 +0900 Subject: [PATCH] code clean up --- .../Common/GeneratorExtensions.cs | 9 +++---- .../Readers/DependencyPropertyReader.cs | 2 +- .../Readers/FileNameReader.cs | 1 - .../Readers/SqliteStatementReader.cs | 12 ++++----- CharacterMap/CharacterMap/App.xaml.cs | 1 - .../Controls/CharacterGridView.cs | 13 +++++----- .../Controls/CreateCollectionDialog.xaml.cs | 21 ++++++++-------- .../CharacterMap/Controls/ExtendedListView.cs | 2 +- .../Controls/FilterFlyout.xaml.cs | 9 +++---- .../Controls/GlyphNamingControl.cs | 10 +------- .../CharacterMap/Controls/LabelButton.cs | 2 +- .../CharacterMap/Controls/PreviewTip.cs | 10 +++----- .../CharacterMap/Controls/UXButton.cs | 2 +- .../CharacterMap/Controls/UXSlider.cs | 3 +-- .../CharacterMap/Controls/XamlTitleBar.cs | 4 +-- .../CharacterMap/Core/ExportManager.cs | 7 +++--- CharacterMap/CharacterMap/Core/FontFinder.cs | 7 +++--- CharacterMap/CharacterMap/Core/FontVariant.cs | 2 +- .../CharacterMap/Core/InstalledFont.cs | 2 +- CharacterMap/CharacterMap/Core/Properties.cs | 25 ++++++++----------- .../CharacterMap/GlobalSuppressions.cs | 3 --- .../Helpers/CompositionFactory.cs | 2 +- .../CharacterMap/Helpers/Extensions.cs | 1 - .../CharacterMap/Helpers/FluentAnimation.cs | 6 ++--- .../CharacterMap/Helpers/ResourceHelper.cs | 3 +-- CharacterMap/CharacterMap/Helpers/Sqlite.cs | 2 -- .../Models/AddToCollectionResult.cs | 2 +- CharacterMap/CharacterMap/Models/Messages.cs | 2 +- .../CharacterMap/Models/UnicodeRange.cs | 4 +-- .../CharacterMap/Models/UnicodeRangeModel.cs | 4 +-- CharacterMap/CharacterMap/Models/Unihan.cs | 1 - .../CharacterMap.zh-CN.xlf | 2 +- .../Provider/SQLiteCollectionProvider.cs | 2 +- .../Provider/SQLiteGlyphProvider.cs | 1 - .../Services/LeakTrackingService.cs | 3 +-- .../Services/UserCollectionsService.cs | 2 +- .../Services/UserFontCollection.cs | 8 +++--- .../CollectionManagementViewModel.cs | 12 ++++----- .../ViewModels/GlyphFileNameViewModel.cs | 2 +- .../CharacterMap/ViewModels/MainViewModel.cs | 14 +++++------ .../ViewModels/SettingsViewModel.cs | 11 ++++---- .../CharacterMap/Views/MainPage.xaml.cs | 4 +-- .../Views/QuickCompareView.xaml.cs | 3 +-- 43 files changed, 99 insertions(+), 139 deletions(-) diff --git a/CharacterMap/CharacterMap.Generators/Common/GeneratorExtensions.cs b/CharacterMap/CharacterMap.Generators/Common/GeneratorExtensions.cs index 037430ec..dcd30a90 100644 --- a/CharacterMap/CharacterMap.Generators/Common/GeneratorExtensions.cs +++ b/CharacterMap/CharacterMap.Generators/Common/GeneratorExtensions.cs @@ -1,5 +1,4 @@ using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using System.Collections.Generic; using System.Linq; @@ -56,17 +55,17 @@ public static StringBuilder AppendLine(this StringBuilder s, int indentLevel, st } public static IEnumerable OfNamedClass - (this IEnumerable src, string name) where T: SyntaxNode + (this IEnumerable src, string name) where T : SyntaxNode { return src.OfType() .Where(c => c.Identifier.ValueText == name); } - public static bool HasAttribute(this T field, string name) where T: MemberDeclarationSyntax + public static bool HasAttribute(this T field, string name) where T : MemberDeclarationSyntax { string full = $"{name}Attribute"; return field.AttributeLists.Any(t => t.Attributes.Any( - a => a.Name is IdentifierNameSyntax i + a => a.Name is IdentifierNameSyntax i && (i.Identifier.ValueText == name || i.Identifier.ValueText == full))); } @@ -92,7 +91,7 @@ public static string GetQualifiedName(this ClassDeclarationSyntax c) public static string GetNamespace(this ClassDeclarationSyntax c) { if (c.Parent is FileScopedNamespaceDeclarationSyntax f) - return f.Name.ToString(); + return f.Name.ToString(); return ((NamespaceDeclarationSyntax)c.Parent).Name.ToString(); } diff --git a/CharacterMap/CharacterMap.Generators/Readers/DependencyPropertyReader.cs b/CharacterMap/CharacterMap.Generators/Readers/DependencyPropertyReader.cs index 0c2b6f59..a8f3a822 100644 --- a/CharacterMap/CharacterMap.Generators/Readers/DependencyPropertyReader.cs +++ b/CharacterMap/CharacterMap.Generators/Readers/DependencyPropertyReader.cs @@ -52,7 +52,7 @@ private bool IsPrimitive(string type) or "FlowDirection" or "ContentPlacement" or "GridLength" or "Orientation" or "GlyphAnnotation" or "FlyoutPlacementMode" or "TextWrapping" or "Stretch" or "Thickness" - or "TextAlignment" or "TimeSpan" or "BlendEffectMode" + or "TextAlignment" or "TimeSpan" or "BlendEffectMode" or "Point" or "TextLineBounds"; } } diff --git a/CharacterMap/CharacterMap.Generators/Readers/FileNameReader.cs b/CharacterMap/CharacterMap.Generators/Readers/FileNameReader.cs index 4c80894d..0101214d 100644 --- a/CharacterMap/CharacterMap.Generators/Readers/FileNameReader.cs +++ b/CharacterMap/CharacterMap.Generators/Readers/FileNameReader.cs @@ -1,7 +1,6 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; -using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/CharacterMap/CharacterMap.Generators/Readers/SqliteStatementReader.cs b/CharacterMap/CharacterMap.Generators/Readers/SqliteStatementReader.cs index 30a23fcf..d11ef7df 100644 --- a/CharacterMap/CharacterMap.Generators/Readers/SqliteStatementReader.cs +++ b/CharacterMap/CharacterMap.Generators/Readers/SqliteStatementReader.cs @@ -40,7 +40,7 @@ static string GetName(string s) foreach (var n in nodes.OfType() .Where(c => c.HasGenericAttribute("SQLReader"))) { - string type = null; + string type = null; string name = null; bool single = false; @@ -157,8 +157,8 @@ public override void Write(GeneratorExecutionContext context) if (data.Count == 0) return; - StringBuilder main = new (); - StringBuilder sb = new (); + StringBuilder main = new(); + StringBuilder sb = new(); foreach (var item in data) { @@ -176,8 +176,8 @@ public override void Write(GeneratorExecutionContext context) main.AppendLine( string.Format( item.Single ? TEMPLATE_S : TEMPLATE, - item.Type, - item.Name, + item.Type, + item.Name, sb.ToString().TrimEnd().TrimEnd(','))); } @@ -187,7 +187,7 @@ static string GetReader(string type) } - context.AddSource("SQLite3Readers.g.cs", + context.AddSource("SQLite3Readers.g.cs", SourceText.From(string.Format(TEMPLATE_0, main.ToString().TrimEnd()), Encoding.UTF8)); } } diff --git a/CharacterMap/CharacterMap/App.xaml.cs b/CharacterMap/CharacterMap/App.xaml.cs index ab44ae0a..ca71fe8a 100644 --- a/CharacterMap/CharacterMap/App.xaml.cs +++ b/CharacterMap/CharacterMap/App.xaml.cs @@ -1,5 +1,4 @@ using CharacterMap.Controls; -using CharacterMapCX.Controls; using SQLite; using Windows.ApplicationModel.Activation; using Windows.ApplicationModel.Core; diff --git a/CharacterMap/CharacterMap/Controls/CharacterGridView.cs b/CharacterMap/CharacterMap/Controls/CharacterGridView.cs index ff9203f6..cc8abbff 100644 --- a/CharacterMap/CharacterMap/Controls/CharacterGridView.cs +++ b/CharacterMap/CharacterMap/Controls/CharacterGridView.cs @@ -1,9 +1,7 @@ //#define DX -using CharacterMapCX.Controls; using Microsoft.Graphics.Canvas.Text; using Microsoft.Toolkit.Uwp.UI.Controls; -using Windows.Foundation.Metadata; using Windows.UI; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -84,7 +82,7 @@ partial void OnItemAnnotationChanged(GlyphAnnotation o, GlyphAnnotation n) public CharacterGridView() { _xamlDirect = XamlDirect.GetDefault(); - _templateSettings = new (); + _templateSettings = new(); this.ContainerContentChanging += OnContainerContentChanging; this.ChoosingItemContainer += OnChoosingItemContainer; @@ -151,11 +149,12 @@ private void OnContainerContentChanging(ListViewBase sender, ContainerContentCha // Set values we will use for the variations _templateSettings.Size = 40; _templateSettings.Annotation = GlyphAnnotation.None; - + // Brush we will as BG use to show each variation - SolidColorBrush bg = new () { - Color = tt.ActualTheme == ElementTheme.Dark ? Colors.White : Colors.Black, - Opacity = 0.05 + SolidColorBrush bg = new() + { + Color = tt.ActualTheme == ElementTheme.Dark ? Colors.White : Colors.Black, + Opacity = 0.05 }; StackPanel s = new(); diff --git a/CharacterMap/CharacterMap/Controls/CreateCollectionDialog.xaml.cs b/CharacterMap/CharacterMap/Controls/CreateCollectionDialog.xaml.cs index cd7fc95b..e259ced6 100644 --- a/CharacterMap/CharacterMap/Controls/CreateCollectionDialog.xaml.cs +++ b/CharacterMap/CharacterMap/Controls/CreateCollectionDialog.xaml.cs @@ -1,5 +1,4 @@ -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls; namespace CharacterMap.Controls; @@ -14,13 +13,13 @@ public string CollectionTitle [ObservableProperty] bool _isCollectionTitleValid; - [ObservableProperty] [NotifyPropertyChangedFor(nameof(MinWidth))] bool _isSmartCollection; + [ObservableProperty][NotifyPropertyChangedFor(nameof(MinWidth))] bool _isSmartCollection; [ObservableProperty] string _filterCharacters; [ObservableProperty] string _filterFilePath; [ObservableProperty] string _filterFoundry; [ObservableProperty] string _filterDesigner; [ObservableProperty] string _resultsLabel; - + [ObservableProperty] IReadOnlyList _resultsPreview = []; public double MinWidth => IsSmartCollection ? 450 : 0; @@ -39,10 +38,10 @@ public void Populate(IFontCollection c) { IsSmartCollection = true; - Populate("char:", Localization.Get("CharacterFilter"), s => FilterCharacters = s); - Populate("filepath:", Localization.Get("FilePathFilter"), s => FilterFilePath = s); - Populate("foundry:", Localization.Get("FoundryFilter"), s => FilterFoundry = s); - Populate("designer:", Localization.Get("DesignerFilter"), s => FilterDesigner = s); + Populate("char:", Localization.Get("CharacterFilter"), s => FilterCharacters = s); + Populate("filepath:", Localization.Get("FilePathFilter"), s => FilterFilePath = s); + Populate("foundry:", Localization.Get("FoundryFilter"), s => FilterFoundry = s); + Populate("designer:", Localization.Get("DesignerFilter"), s => FilterDesigner = s); void Populate(string id, string loc, Action set) { @@ -77,7 +76,7 @@ void Add(string id, string field) public void UpdateResults() { - SmartFontCollection collection = new () { Filters = GetFilterList() }; + SmartFontCollection collection = new() { Filters = GetFilterList() }; ResultsPreview = collection.GetFontFamilies(); ResultsLabel = Localization.Get("ResultsCountLabel", ResultsPreview.Count); } @@ -99,7 +98,7 @@ public sealed partial class CreateCollectionDialog : ContentDialog public CreateCollectionDialog(IFontCollection collection = null) { _collection = collection; - TemplateSettings = new (); + TemplateSettings = new(); this.InitializeComponent(); if (_collection != null) @@ -155,7 +154,7 @@ private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, Conten AddToCollectionResult result = null; // Check if we are creating a Smart Filter - if (TemplateSettings.GetFilterList() is { Count: > 0} filters) + if (TemplateSettings.GetFilterList() is { Count: > 0 } filters) { SmartFontCollection collection = await collections.CreateSmartCollectionAsync( TemplateSettings.CollectionTitle, diff --git a/CharacterMap/CharacterMap/Controls/ExtendedListView.cs b/CharacterMap/CharacterMap/Controls/ExtendedListView.cs index c1f62805..026d635f 100644 --- a/CharacterMap/CharacterMap/Controls/ExtendedListView.cs +++ b/CharacterMap/CharacterMap/Controls/ExtendedListView.cs @@ -119,7 +119,7 @@ protected void OnAttached() private void OnSelectedItemsChanged(object old, object nw) { - + } void ItemsSourceChanged(DependencyObject source, DependencyProperty property) diff --git a/CharacterMap/CharacterMap/Controls/FilterFlyout.xaml.cs b/CharacterMap/CharacterMap/Controls/FilterFlyout.xaml.cs index ac90cb3a..37c05ea5 100644 --- a/CharacterMap/CharacterMap/Controls/FilterFlyout.xaml.cs +++ b/CharacterMap/CharacterMap/Controls/FilterFlyout.xaml.cs @@ -1,7 +1,6 @@ using System.Windows.Input; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Media; namespace CharacterMap.Controls; @@ -83,7 +82,7 @@ private void Create() unicode.Items.Add(new MenuFlyoutSeparator()); } - // 2.1.2. Add *all* supported unicode ranges to the submenu + // 2.1.2. Add *all* supported unicode ranges to the submenu foreach (var filter in UnicodeRanges.AllFilters) unicode.Add(filter, style); @@ -132,9 +131,9 @@ private void Create() _defaultCount = Items.Count; if (AllFilters is null) - AllFilters = AllMenuItems().Where(c => Properties.GetFilter(c) is not null) - .Select(c => Properties.GetFilter(c)) - .ToList().AsReadOnly(); + AllFilters = AllMenuItems().Where(c => Properties.GetFilter(c) is not null) + .Select(c => Properties.GetFilter(c)) + .ToList().AsReadOnly(); #region Helpers diff --git a/CharacterMap/CharacterMap/Controls/GlyphNamingControl.cs b/CharacterMap/CharacterMap/Controls/GlyphNamingControl.cs index 5154eb05..bbe376dc 100644 --- a/CharacterMap/CharacterMap/Controls/GlyphNamingControl.cs +++ b/CharacterMap/CharacterMap/Controls/GlyphNamingControl.cs @@ -1,13 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.UI.Xaml; +using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Data; -using Windows.UI.Xaml.Documents; -using Windows.UI.Xaml.Input; -using Windows.UI.Xaml.Media; namespace CharacterMap.Controls; diff --git a/CharacterMap/CharacterMap/Controls/LabelButton.cs b/CharacterMap/CharacterMap/Controls/LabelButton.cs index 1a4bd041..8d1156ca 100644 --- a/CharacterMap/CharacterMap/Controls/LabelButton.cs +++ b/CharacterMap/CharacterMap/Controls/LabelButton.cs @@ -7,7 +7,7 @@ namespace CharacterMap.Controls; [DependencyProperty("IconContent")] public sealed partial class LabelButton : Button { - static IReadOnlyList _previewStates { get; } = [ "PointerOver", "Pressed" ]; + static IReadOnlyList _previewStates { get; } = ["PointerOver", "Pressed"]; FrameworkElement _iconPresenter = null; diff --git a/CharacterMap/CharacterMap/Controls/PreviewTip.cs b/CharacterMap/CharacterMap/Controls/PreviewTip.cs index 0b0daa47..14e376fd 100644 --- a/CharacterMap/CharacterMap/Controls/PreviewTip.cs +++ b/CharacterMap/CharacterMap/Controls/PreviewTip.cs @@ -1,10 +1,8 @@ using Windows.ApplicationModel; -using Windows.Foundation; using Windows.UI.Composition; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Hosting; using Windows.UI.Xaml.Media; namespace CharacterMap.Controls; @@ -47,7 +45,7 @@ protected override void OnApplyTemplate() { _root = this.GetTemplateChild("LayoutRoot") as FrameworkElement; _rv = _root.EnableCompositionTranslation().GetElementVisual(); - + TrySetClamping(); // Prepare closing animation @@ -133,14 +131,14 @@ void MoveTo(SelectorItem item) { this.Content = item.Content ?? item.DataContext; Vector3 t; - + if (Placement == PreviewPlacement.RightEdgeTopAligned) { var rect = item.GetBoundingRect((FrameworkElement)Window.Current.Content); // Let CenterPoint animation know item size _rv.Properties.InsertVector2("ItemSize", new Vector2((float)rect.Value.Width, (float)rect.Value.Height)); - + // Position to the top edge of the item var y = (rect.Value.Top + VerticalOffset); t = new Vector3((float)HorizontalOffset, (float)y, 0f); @@ -245,7 +243,7 @@ void Hide() _root.SetHideAnimation(_hide); else _root.SetHideAnimation(null); - + _root.Visibility = Visibility.Collapsed; } } diff --git a/CharacterMap/CharacterMap/Controls/UXButton.cs b/CharacterMap/CharacterMap/Controls/UXButton.cs index 034b079d..5ffaa1f2 100644 --- a/CharacterMap/CharacterMap/Controls/UXButton.cs +++ b/CharacterMap/CharacterMap/Controls/UXButton.cs @@ -26,7 +26,7 @@ public void Update(string text, CharacterCasing casing) [DependencyProperty("LabelCasing", default, nameof(UpdateLabelText))] public partial class UXButton : Button//, IThemeableControl { - public UXButtonTemplateSettings TemplateSettings { get; } = new (); + public UXButtonTemplateSettings TemplateSettings { get; } = new(); bool _isTemplateApplied = false; diff --git a/CharacterMap/CharacterMap/Controls/UXSlider.cs b/CharacterMap/CharacterMap/Controls/UXSlider.cs index e91ca2d1..c5154b4e 100644 --- a/CharacterMap/CharacterMap/Controls/UXSlider.cs +++ b/CharacterMap/CharacterMap/Controls/UXSlider.cs @@ -1,5 +1,4 @@ -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls; namespace CharacterMap.Controls; diff --git a/CharacterMap/CharacterMap/Controls/XamlTitleBar.cs b/CharacterMap/CharacterMap/Controls/XamlTitleBar.cs index d2ce7c06..471e9839 100644 --- a/CharacterMap/CharacterMap/Controls/XamlTitleBar.cs +++ b/CharacterMap/CharacterMap/Controls/XamlTitleBar.cs @@ -56,7 +56,7 @@ public sealed partial class XamlTitleBar : ContentControl private CoreWindow _window; private FrameworkElement _backgroundElement; - public XamlTitleBarTemplateSettings TemplateSettings { get; } = new (); + public XamlTitleBarTemplateSettings TemplateSettings { get; } = new(); public XamlTitleBar() { @@ -84,7 +84,7 @@ void SetHeight(double d) if (IsAutoHeightEnabled) Height = d; - TemplateSettings.GridHeight = new (d); + TemplateSettings.GridHeight = new(d); TemplateSettings.Height = d; } diff --git a/CharacterMap/CharacterMap/Core/ExportManager.cs b/CharacterMap/CharacterMap/Core/ExportManager.cs index 6b7d9ccf..6aa25779 100644 --- a/CharacterMap/CharacterMap/Core/ExportManager.cs +++ b/CharacterMap/CharacterMap/Core/ExportManager.cs @@ -439,7 +439,7 @@ private static IBuffer GetGlyphBuffer(DWriteFontFace fontface, uint unicodeIndex internal static string GetFileName( ExportOptions e, Character c, - string ext) + string ext) => e.GetFileName(c, ext); private static async Task PickFileAsync(string fileName, string key, IList values, PickerLocationId suggestedLocation = PickerLocationId.PicturesLibrary) @@ -539,8 +539,9 @@ internal static async Task ExportGlyphsToFolderAsync( // We need to create a new analysis for each individual glyph to properly // support export non-outline glyphs using var layout = CreateLayout(e.Options, c, e.PreferredStyle, 1024f); - e = e with { - Options = e.Options with { Analysis = interop.AnalyzeCharacterLayout(layout) } + e = e with + { + Options = e.Options with { Analysis = interop.AnalyzeCharacterLayout(layout) } }; // Export the glyph diff --git a/CharacterMap/CharacterMap/Core/FontFinder.cs b/CharacterMap/CharacterMap/Core/FontFinder.cs index e3e50990..c503b317 100644 --- a/CharacterMap/CharacterMap/Core/FontFinder.cs +++ b/CharacterMap/CharacterMap/Core/FontFinder.cs @@ -1,4 +1,3 @@ -using System.Diagnostics; using Windows.Storage.Search; using Windows.UI.Text; using WoffToOtf; @@ -641,8 +640,8 @@ public static bool IsSystemSymbolFamily(FontVariant variant) => variant != null public static FontQueryResults QueryFontList( - string query, - IEnumerable fontList, + string query, + IEnumerable fontList, UserCollectionsService fontCollections, IFontCollection collection = null, BasicFontFilter filter = null) @@ -688,7 +687,7 @@ public static FontQueryResults QueryFontList( return new(fontList, filterTitle, true); } - + return new(fontList, null, false); } diff --git a/CharacterMap/CharacterMap/Core/FontVariant.cs b/CharacterMap/CharacterMap/Core/FontVariant.cs index 310b6657..6905354b 100644 --- a/CharacterMap/CharacterMap/Core/FontVariant.cs +++ b/CharacterMap/CharacterMap/Core/FontVariant.cs @@ -324,7 +324,7 @@ public static FontVariant CreateDefault(DWriteFontFace face) return new FontVariant(face, null) { PreferredName = "", - Characters = [ new(0) ] + Characters = [new(0)] }; } diff --git a/CharacterMap/CharacterMap/Core/InstalledFont.cs b/CharacterMap/CharacterMap/Core/InstalledFont.cs index 1b7341e2..2486112e 100644 --- a/CharacterMap/CharacterMap/Core/InstalledFont.cs +++ b/CharacterMap/CharacterMap/Core/InstalledFont.cs @@ -59,7 +59,7 @@ public InstalledFont Clone() public static InstalledFont CreateDefault(DWriteFontFace face) { - InstalledFont font = new ("Segoe UI"); + InstalledFont font = new("Segoe UI"); font._variants.Add(FontVariant.CreateDefault(face)); return font; } diff --git a/CharacterMap/CharacterMap/Core/Properties.cs b/CharacterMap/CharacterMap/Core/Properties.cs index 7da87042..95cb106f 100644 --- a/CharacterMap/CharacterMap/Core/Properties.cs +++ b/CharacterMap/CharacterMap/Core/Properties.cs @@ -1,7 +1,4 @@ using CharacterMap.Controls; -using CharacterMap.Views; -using CharacterMapCX.Controls; -using CommunityToolkit.Mvvm.DependencyInjection; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls.Primitives; using Windows.Foundation.Collections; @@ -39,9 +36,9 @@ namespace CharacterMap.Core; [AttachedProperty("IconString")] [AttachedProperty("Icon")] [AttachedProperty] -[AttachedProperty("TargetContextFlyout")] -[AttachedProperty("ItemContainerTransitions")] -[AttachedProperty("ChildrenTransitions")] +[AttachedProperty("TargetContextFlyout")] +[AttachedProperty("ItemContainerTransitions")] +[AttachedProperty("ChildrenTransitions")] [AttachedProperty("UseAttachedStates")] // Allows an element to run Storyboards from it's own resources on VisualState events [AttachedProperty("SetContainerBackgroundTransition")] // Helper property for ItemContainerBackgroundTransition [AttachedProperty("ItemContainerBackgroundTransition")] // When attached to a ListView, automatically sets ItemContainer BackgroundTransitions @@ -222,7 +219,7 @@ static partial void OnDefaultToolChanged(DependencyObject d, DependencyPropertyC if (d is InkToolbar t && e.NewValue is InkToolbarToolButton b) t.ActiveTool = b; } - + #endregion #region TabViewItem IsCompact @@ -748,7 +745,7 @@ static void CompButtonAnimate(FrameworkElement source, string key, double offset } } - + } static partial void OnPointerOverAnimationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -1233,7 +1230,7 @@ static async partial void OnToolTipStyleKeyChanged(DependencyObject d, Dependenc var temp = ToolTipService.GetToolTip(d); if (temp is null) // Bad little hack to allow x:UID setters (or equivalent) to run await Task.Yield(); - + if (ToolTipService.GetToolTip(d) is { } tt) { if (tt is ToolTip t) @@ -1382,7 +1379,7 @@ static partial void OnHyperlinkChanged(DependencyObject d, DependencyPropertyCha static void B_Click(object sender, RoutedEventArgs e) { var link = GetHyperlink((DependencyObject)sender); - if (!string.IsNullOrWhiteSpace(link) + if (!string.IsNullOrWhiteSpace(link) && Uri.TryCreate(link, UriKind.RelativeOrAbsolute, out Uri uri)) _ = Launcher.LaunchUriAsync(uri); } @@ -1393,9 +1390,9 @@ static void B_Click(object sender, RoutedEventArgs e) #region Cursor - private static readonly object _cursorLock = new (); - private static readonly CoreCursor _defaultCursor = new (CoreCursorType.Arrow, 1); - private static readonly Dictionary _cursors = new () { { CoreCursorType.Arrow, _defaultCursor } }; + private static readonly object _cursorLock = new(); + private static readonly CoreCursor _defaultCursor = new(CoreCursorType.Arrow, 1); + private static readonly Dictionary _cursors = new() { { CoreCursorType.Arrow, _defaultCursor } }; static partial void OnCursorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { @@ -1476,7 +1473,7 @@ static partial void OnPreviewStringTriggerChanged(DependencyObject d, Dependency //var v = GetTag(l); // If we have an active "char" search we want to show this characters in the ToolTip instead - if (t.GetFirstAncestorOfType() is { } pt + if (t.GetFirstAncestorOfType() is { } pt && GetTag(pt) is MainViewModel vm && vm.FontSearch is { Length: > 4 } query && FontFinder.IsQuery(query, Localization.Get("CharacterFilter"), "char:", out string q)) diff --git a/CharacterMap/CharacterMap/GlobalSuppressions.cs b/CharacterMap/CharacterMap/GlobalSuppressions.cs index 996bff67..423a0b2e 100644 --- a/CharacterMap/CharacterMap/GlobalSuppressions.cs +++ b/CharacterMap/CharacterMap/GlobalSuppressions.cs @@ -11,7 +11,6 @@ global using CharacterMap.Provider; global using CharacterMap.Services; global using CharacterMap.ViewModels; -global using CharacterMapCX; global using CommunityToolkit.Mvvm.ComponentModel; global using CommunityToolkit.Mvvm.DependencyInjection; global using CommunityToolkit.Mvvm.Messaging; @@ -31,8 +30,6 @@ global using Windows.Storage; global using Windows.Storage.Pickers; global using Windows.Storage.Streams; - -global using static CharacterMap.Controls.ControlBase; global using DP = Windows.UI.Xaml.DependencyProperty; using System.Diagnostics.CodeAnalysis; diff --git a/CharacterMap/CharacterMap/Helpers/CompositionFactory.cs b/CharacterMap/CharacterMap/Helpers/CompositionFactory.cs index 01f3ecbf..8b707be1 100644 --- a/CharacterMap/CharacterMap/Helpers/CompositionFactory.cs +++ b/CharacterMap/CharacterMap/Helpers/CompositionFactory.cs @@ -298,7 +298,7 @@ public static CompositionAnimation CreateFade(Compositor c, float to, float? fro .SetInitialValueBeforeDelay() .SetDelayTime(TimeSpan.FromMilliseconds(delayMs)) .SetDuration(TimeSpan.FromMilliseconds(durationMs)); - + return o; }); } diff --git a/CharacterMap/CharacterMap/Helpers/Extensions.cs b/CharacterMap/CharacterMap/Helpers/Extensions.cs index 012269a6..bae11a17 100644 --- a/CharacterMap/CharacterMap/Helpers/Extensions.cs +++ b/CharacterMap/CharacterMap/Helpers/Extensions.cs @@ -1,5 +1,4 @@ using Microsoft.UI.Xaml.Controls; -using SQLite; using System.IO.Compression; using Windows.System; using Windows.UI.Core; diff --git a/CharacterMap/CharacterMap/Helpers/FluentAnimation.cs b/CharacterMap/CharacterMap/Helpers/FluentAnimation.cs index 7551873e..e3308277 100644 --- a/CharacterMap/CharacterMap/Helpers/FluentAnimation.cs +++ b/CharacterMap/CharacterMap/Helpers/FluentAnimation.cs @@ -83,7 +83,7 @@ private void OnStateChanging(object sender, VisualStateChangedEventArgs e) #if DEBUG //if (sender is FrameworkElement se && se.GetFirstAncestorOfType() is MenuFlyoutSubItem m) - // System.Diagnostics.Debug.WriteLine($"From {e.OldState?.Name} to {e.NewState.Name}"); + // System.Diagnostics.Debug.WriteLine($"From {e.OldState?.Name} to {e.NewState.Name}"); #endif // 1. Handle "PointerOver" @@ -257,7 +257,7 @@ private FrameworkElement GetTarget(Control c, DependencyProperty property, ref F { // Little hax to allow targeting a ContentPresenter.Content if (name.Contains(".") - && name.Split(".") is { Length: 2} parts + && name.Split(".") is { Length: 2 } parts && parts[1] == "Content" && c.GetDescendantsOfType().FirstOrDefault(d => d.Name == parts[0]) is ContentPresenter pres) { @@ -265,7 +265,7 @@ private FrameworkElement GetTarget(Control c, DependencyProperty property, ref F return pres.GetFirstDescendantOfType(); } } - return c.GetDescendantsOfType().FirstOrDefault(d => d.Name == name); + return c.GetDescendantsOfType().FirstOrDefault(d => d.Name == name); } return null; diff --git a/CharacterMap/CharacterMap/Helpers/ResourceHelper.cs b/CharacterMap/CharacterMap/Helpers/ResourceHelper.cs index 70a633f0..e3e1cf24 100644 --- a/CharacterMap/CharacterMap/Helpers/ResourceHelper.cs +++ b/CharacterMap/CharacterMap/Helpers/ResourceHelper.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using Windows.ApplicationModel; +using Windows.ApplicationModel; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; diff --git a/CharacterMap/CharacterMap/Helpers/Sqlite.cs b/CharacterMap/CharacterMap/Helpers/Sqlite.cs index f418ac15..593bc9ba 100644 --- a/CharacterMap/CharacterMap/Helpers/Sqlite.cs +++ b/CharacterMap/CharacterMap/Helpers/Sqlite.cs @@ -26,7 +26,6 @@ #define USE_SQLITEPCL_RAW using System.Collections; -using System.Diagnostics; #if !USE_SQLITEPCL_RAW using System.Runtime.InteropServices; #endif @@ -47,7 +46,6 @@ using Sqlite3Statement = SQLitePCL.sqlite3_stmt; using Sqlite3 = SQLitePCL.raw; using SQLitePCL; -using System.Diagnostics.Contracts; #else using Sqlite3DatabaseHandle = System.IntPtr; using Sqlite3BackupHandle = System.IntPtr; diff --git a/CharacterMap/CharacterMap/Models/AddToCollectionResult.cs b/CharacterMap/CharacterMap/Models/AddToCollectionResult.cs index a86e614f..c98865df 100644 --- a/CharacterMap/CharacterMap/Models/AddToCollectionResult.cs +++ b/CharacterMap/CharacterMap/Models/AddToCollectionResult.cs @@ -18,7 +18,7 @@ public AddToCollectionResult(bool success, IReadOnlyList fonts, I public string GetTitle() { - if (Fonts is null) + if (Fonts is null) return string.Empty; if (Fonts.Count == 1 && Fonts[0] is InstalledFont font) diff --git a/CharacterMap/CharacterMap/Models/Messages.cs b/CharacterMap/CharacterMap/Models/Messages.cs index 0c2aba3c..e93dd3e5 100644 --- a/CharacterMap/CharacterMap/Models/Messages.cs +++ b/CharacterMap/CharacterMap/Models/Messages.cs @@ -68,7 +68,7 @@ public class ToggleCompactOverlayMessage { } public record class AppSettingsChangedMessage(string PropertyName); public record class AppNotificationMessage(bool Local, object Data, int DurationInMilliseconds = 0); - + public enum DevValueType { diff --git a/CharacterMap/CharacterMap/Models/UnicodeRange.cs b/CharacterMap/CharacterMap/Models/UnicodeRange.cs index 3680e0dd..0648be05 100644 --- a/CharacterMap/CharacterMap/Models/UnicodeRange.cs +++ b/CharacterMap/CharacterMap/Models/UnicodeRange.cs @@ -1,6 +1,4 @@ -using System.Diagnostics; - -namespace CharacterMap.Models; +namespace CharacterMap.Models; public partial struct UnicodeRange { diff --git a/CharacterMap/CharacterMap/Models/UnicodeRangeModel.cs b/CharacterMap/CharacterMap/Models/UnicodeRangeModel.cs index 7f478e1d..14263765 100644 --- a/CharacterMap/CharacterMap/Models/UnicodeRangeModel.cs +++ b/CharacterMap/CharacterMap/Models/UnicodeRangeModel.cs @@ -1,6 +1,4 @@ -using System.Diagnostics; - -namespace CharacterMap.Models; +namespace CharacterMap.Models; [DebuggerDisplay("{Range.Name}, Selected: {IsSelected}")] public partial class UnicodeRangeModel : ObservableObject diff --git a/CharacterMap/CharacterMap/Models/Unihan.cs b/CharacterMap/CharacterMap/Models/Unihan.cs index bb6c35d9..647b1692 100644 --- a/CharacterMap/CharacterMap/Models/Unihan.cs +++ b/CharacterMap/CharacterMap/Models/Unihan.cs @@ -1,7 +1,6 @@ // Ignore Spelling: Unihan using SQLite; -using System.Diagnostics; namespace CharacterMap.Models; diff --git a/CharacterMap/CharacterMap/MultilingualResources/CharacterMap.zh-CN.xlf b/CharacterMap/CharacterMap/MultilingualResources/CharacterMap.zh-CN.xlf index ded9e0e7..1c94255c 100644 --- a/CharacterMap/CharacterMap/MultilingualResources/CharacterMap.zh-CN.xlf +++ b/CharacterMap/CharacterMap/MultilingualResources/CharacterMap.zh-CN.xlf @@ -2266,4 +2266,4 @@ Otherwise, "All Fonts" is selected by default on every launch. - + \ No newline at end of file diff --git a/CharacterMap/CharacterMap/Provider/SQLiteCollectionProvider.cs b/CharacterMap/CharacterMap/Provider/SQLiteCollectionProvider.cs index db74aa03..393af9ea 100644 --- a/CharacterMap/CharacterMap/Provider/SQLiteCollectionProvider.cs +++ b/CharacterMap/CharacterMap/Provider/SQLiteCollectionProvider.cs @@ -53,7 +53,7 @@ public async Task DeleteCollectionAsync(IFontCollection collection) return false; } - + public Task SaveCollectionAsync(IFontCollection c) { diff --git a/CharacterMap/CharacterMap/Provider/SQLiteGlyphProvider.cs b/CharacterMap/CharacterMap/Provider/SQLiteGlyphProvider.cs index d10fad3b..fafe635a 100644 --- a/CharacterMap/CharacterMap/Provider/SQLiteGlyphProvider.cs +++ b/CharacterMap/CharacterMap/Provider/SQLiteGlyphProvider.cs @@ -1,5 +1,4 @@ using SQLite; -using System.Globalization; using Windows.ApplicationModel; using Windows.UI.Xaml.Controls; diff --git a/CharacterMap/CharacterMap/Services/LeakTrackingService.cs b/CharacterMap/CharacterMap/Services/LeakTrackingService.cs index 32abda4c..d6295176 100644 --- a/CharacterMap/CharacterMap/Services/LeakTrackingService.cs +++ b/CharacterMap/CharacterMap/Services/LeakTrackingService.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using Windows.System; +using Windows.System; using Windows.UI.Xaml; namespace CharacterMap.Services; diff --git a/CharacterMap/CharacterMap/Services/UserCollectionsService.cs b/CharacterMap/CharacterMap/Services/UserCollectionsService.cs index 81f6d6b0..d6fdecce 100644 --- a/CharacterMap/CharacterMap/Services/UserCollectionsService.cs +++ b/CharacterMap/CharacterMap/Services/UserCollectionsService.cs @@ -71,7 +71,7 @@ await Task.Run(async () => { smart.Add(s); } - + } if (SymbolCollection == null) diff --git a/CharacterMap/CharacterMap/Services/UserFontCollection.cs b/CharacterMap/CharacterMap/Services/UserFontCollection.cs index fb68d220..1216ae3a 100644 --- a/CharacterMap/CharacterMap/Services/UserFontCollection.cs +++ b/CharacterMap/CharacterMap/Services/UserFontCollection.cs @@ -1,6 +1,4 @@ -using System.Collections.ObjectModel; - -namespace CharacterMap.Models; +namespace CharacterMap.Models; public interface IFontCollection { @@ -72,7 +70,7 @@ public IReadOnlyList GetFontFamilies() => [DebuggerDisplay("({Id}) Name: {Name}, {Filters.Count} Filters")] public class SmartFontCollection : IFontCollection { - static string ICON { get; } = new ('\uE945', 1); + static string ICON { get; } = new('\uE945', 1); public long Id { get; set; } public string Name { get; set; } @@ -82,7 +80,7 @@ public class SmartFontCollection : IFontCollection public IReadOnlyList Fonts { get; private set; } = []; public IReadOnlyList UpdateFonts() - { + { var fonts = FontFinder.Fonts.AsEnumerable(); foreach (var filter in Filters) diff --git a/CharacterMap/CharacterMap/ViewModels/CollectionManagementViewModel.cs b/CharacterMap/CharacterMap/ViewModels/CollectionManagementViewModel.cs index 65471eac..d3337d4d 100644 --- a/CharacterMap/CharacterMap/ViewModels/CollectionManagementViewModel.cs +++ b/CharacterMap/CharacterMap/ViewModels/CollectionManagementViewModel.cs @@ -5,7 +5,7 @@ public partial class CollectionManagementViewModel : ViewModelBase protected override bool CaptureContext => true; #region Properties - List _systemFontList; + List _systemFontList; [ObservableProperty] string _collectionExportProgress; [ObservableProperty] bool _isSaving = false; @@ -107,10 +107,10 @@ public void RefreshFontLists() void RefreshFontList() { // 1. Filter fonts - var systemFonts = string.IsNullOrWhiteSpace(Query) - ?_systemFontList.AsEnumerable() + var systemFonts = string.IsNullOrWhiteSpace(Query) + ? _systemFontList.AsEnumerable() : FontFinder.QueryFontList(Query, _systemFontList, CollectionService).FontList; - + // 2. Create binding lists FontList = new(systemFonts); } @@ -151,7 +151,7 @@ public void StartSave() async Task SaveAsync() { - if (SelectedCollection is null || IsSaving) + if (SelectedCollection is null || IsSaving) return; IsSaving = true; @@ -160,7 +160,7 @@ async Task SaveAsync() { if (SelectedCollection is UserFontCollection user) { - user.Fonts = [..CollectionFonts.Select(c => c.Name)]; + user.Fonts = [.. CollectionFonts.Select(c => c.Name)]; } await CollectionService.SaveCollectionAsync(SelectedCollection); } diff --git a/CharacterMap/CharacterMap/ViewModels/GlyphFileNameViewModel.cs b/CharacterMap/CharacterMap/ViewModels/GlyphFileNameViewModel.cs index 6aa67e7a..d2177521 100644 --- a/CharacterMap/CharacterMap/ViewModels/GlyphFileNameViewModel.cs +++ b/CharacterMap/CharacterMap/ViewModels/GlyphFileNameViewModel.cs @@ -43,7 +43,7 @@ void UpdateExample() FileNameTemplate = Template }; - Example = $"{Localization.Get("ExampleFormat", options.GetFileName(_defaultChar, "png"))}\n" + + Example = $"{Localization.Get("ExampleFormat", options.GetFileName(_defaultChar, "png"))}\n" + $"{Localization.Get("ExampleFormat", options.GetFileName(_defaultChar2, "png"))}"; } } diff --git a/CharacterMap/CharacterMap/ViewModels/MainViewModel.cs b/CharacterMap/CharacterMap/ViewModels/MainViewModel.cs index b56f23c1..82393fb3 100644 --- a/CharacterMap/CharacterMap/ViewModels/MainViewModel.cs +++ b/CharacterMap/CharacterMap/ViewModels/MainViewModel.cs @@ -3,9 +3,7 @@ using CommunityToolkit.Mvvm.Input; using System.Collections.Specialized; using System.Globalization; -using System.Runtime.ConstrainedExecution; using Windows.ApplicationModel.Core; -using Windows.Foundation.Diagnostics; namespace CharacterMap.ViewModels; @@ -13,9 +11,9 @@ public partial class MainViewModel : ViewModelBase { public event EventHandler FontListCreated; - private Debouncer _searchDebouncer { get; } = new (); + private Debouncer _searchDebouncer { get; } = new(); - private Debouncer _settingsDebouncer { get; } = new (); + private Debouncer _settingsDebouncer { get; } = new(); private Exception _startUpException = null; @@ -152,7 +150,7 @@ protected override void OnPropertyChangeNotified(string propertyName) private async Task LoadAsync(bool isFirstLoad = false) { IsLoadingFonts = true; - + if (InitialLoad != null && InitialLoad.IsCompleted is false && Task.CurrentId != InitialLoad.Id) @@ -178,11 +176,11 @@ await Task.WhenAll( // Restore selected filter on app launch // TODO: Doesn't work 100%. Why? - if (!IsSecondaryView - && isFirstLoad + if (!IsSecondaryView + && isFirstLoad && Settings.RestoreLastCollectionOnLaunch) { - switch(GetLastUsedCollection()) + switch (GetLastUsedCollection()) { case UserFontCollection uc: //Debug.WriteLine($"LAST USED COLLECTIN: {uc.Name}"); diff --git a/CharacterMap/CharacterMap/ViewModels/SettingsViewModel.cs b/CharacterMap/CharacterMap/ViewModels/SettingsViewModel.cs index 7d6b6e71..4f5318b1 100644 --- a/CharacterMap/CharacterMap/ViewModels/SettingsViewModel.cs +++ b/CharacterMap/CharacterMap/ViewModels/SettingsViewModel.cs @@ -1,5 +1,4 @@ -using SQLitePCL; -using Windows.ApplicationModel.Core; +using Windows.ApplicationModel.Core; using Windows.Globalization; using Windows.UI.Xaml; using Windows.UI.Xaml.Media; @@ -8,11 +7,11 @@ namespace CharacterMap.ViewModels; public partial class SettingsViewModel : ViewModelBase { - private Random _random { get; } = new (); + private Random _random { get; } = new(); protected override bool TrackAnimation => true; - public IReadOnlyList Annotations { get; } = + public IReadOnlyList Annotations { get; } = [ GlyphAnnotation.None, GlyphAnnotation.UnicodeHex, @@ -55,7 +54,7 @@ public partial class SettingsViewModel : ViewModelBase public AppSettings Settings { get; } = ResourceHelper.AppSettings; - + public SettingsViewModel() { @@ -104,7 +103,7 @@ public void UpdatePreviews(InstalledFont font, CharacterRenderingOptions options ImportedFaceCount = FontFinder.ImportedFaceCount; } - + private void RampOptions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { diff --git a/CharacterMap/CharacterMap/Views/MainPage.xaml.cs b/CharacterMap/CharacterMap/Views/MainPage.xaml.cs index bea20489..35c79ba3 100644 --- a/CharacterMap/CharacterMap/Views/MainPage.xaml.cs +++ b/CharacterMap/CharacterMap/Views/MainPage.xaml.cs @@ -25,7 +25,7 @@ public sealed partial class MainPage : ViewBase, IInAppNotificationPresenter, IP public MainViewModel ViewModel { get; } - private Debouncer _fontListDebouncer { get; } = new (); + private Debouncer _fontListDebouncer { get; } = new(); private UISettings _uiSettings { get; } @@ -377,7 +377,7 @@ void ShowSettings(int idx = 0) this.FindName(nameof(SettingsView)); SettingsView.Show( - FontMap.ViewModel.RenderingOptions, + FontMap.ViewModel.RenderingOptions, ViewModel.SelectedFont, idx); OnModalOpened(); } diff --git a/CharacterMap/CharacterMap/Views/QuickCompareView.xaml.cs b/CharacterMap/CharacterMap/Views/QuickCompareView.xaml.cs index f32878c8..25ab9774 100644 --- a/CharacterMap/CharacterMap/Views/QuickCompareView.xaml.cs +++ b/CharacterMap/CharacterMap/Views/QuickCompareView.xaml.cs @@ -1,5 +1,4 @@ -using CharacterMapCX.Controls; -using Microsoft.Toolkit.Uwp.UI.Controls; +using Microsoft.Toolkit.Uwp.UI.Controls; using Microsoft.UI.Xaml.Controls; using Windows.UI.ViewManagement; using Windows.UI.Xaml;