Skip to content

Commit

Permalink
Merge pull request #341 from character-map-uwp/code-clean-up
Browse files Browse the repository at this point in the history
Code clean up
  • Loading branch information
EdiWang authored Jun 14, 2024
2 parents 1023edf + 807f078 commit cf21f86
Show file tree
Hide file tree
Showing 43 changed files with 99 additions and 139 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -56,17 +55,17 @@ public static StringBuilder AppendLine(this StringBuilder s, int indentLevel, st
}

public static IEnumerable<ClassDeclarationSyntax> OfNamedClass<T>
(this IEnumerable<T> src, string name) where T: SyntaxNode
(this IEnumerable<T> src, string name) where T : SyntaxNode
{
return src.OfType<ClassDeclarationSyntax>()
.Where(c => c.Identifier.ValueText == name);
}

public static bool HasAttribute<T>(this T field, string name) where T: MemberDeclarationSyntax
public static bool HasAttribute<T>(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)));
}

Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static string GetName(string s)
foreach (var n in nodes.OfType<ClassDeclarationSyntax>()
.Where(c => c.HasGenericAttribute("SQLReader")))
{
string type = null;
string type = null;
string name = null;
bool single = false;

Expand Down Expand Up @@ -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)
{
Expand All @@ -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(',')));
}

Expand All @@ -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));
}
}
1 change: 0 additions & 1 deletion CharacterMap/CharacterMap/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CharacterMap.Controls;
using CharacterMapCX.Controls;
using SQLite;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Core;
Expand Down
13 changes: 6 additions & 7 deletions CharacterMap/CharacterMap/Controls/CharacterGridView.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
21 changes: 10 additions & 11 deletions CharacterMap/CharacterMap/Controls/CreateCollectionDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls;

namespace CharacterMap.Controls;

Expand All @@ -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<InstalledFont> _resultsPreview = [];

public double MinWidth => IsSmartCollection ? 450 : 0;
Expand All @@ -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<string> set)
{
Expand Down Expand Up @@ -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);
}
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion CharacterMap/CharacterMap/Controls/ExtendedListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected void OnAttached()

private void OnSelectedItemsChanged(object old, object nw)
{

}

void ItemsSourceChanged(DependencyObject source, DependencyProperty property)
Expand Down
9 changes: 4 additions & 5 deletions CharacterMap/CharacterMap/Controls/FilterFlyout.xaml.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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

Expand Down
10 changes: 1 addition & 9 deletions CharacterMap/CharacterMap/Controls/GlyphNamingControl.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion CharacterMap/CharacterMap/Controls/LabelButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace CharacterMap.Controls;
[DependencyProperty("IconContent")]
public sealed partial class LabelButton : Button
{
static IReadOnlyList<string> _previewStates { get; } = [ "PointerOver", "Pressed" ];
static IReadOnlyList<string> _previewStates { get; } = ["PointerOver", "Pressed"];

FrameworkElement _iconPresenter = null;

Expand Down
10 changes: 4 additions & 6 deletions CharacterMap/CharacterMap/Controls/PreviewTip.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -47,7 +45,7 @@ protected override void OnApplyTemplate()
{
_root = this.GetTemplateChild("LayoutRoot") as FrameworkElement;
_rv = _root.EnableCompositionTranslation().GetElementVisual();

TrySetClamping();

// Prepare closing animation
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -245,7 +243,7 @@ void Hide()
_root.SetHideAnimation(_hide);
else
_root.SetHideAnimation(null);

_root.Visibility = Visibility.Collapsed;
}
}
Expand Down
2 changes: 1 addition & 1 deletion CharacterMap/CharacterMap/Controls/UXButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Update(string text, CharacterCasing casing)
[DependencyProperty<CharacterCasing>("LabelCasing", default, nameof(UpdateLabelText))]
public partial class UXButton : Button//, IThemeableControl
{
public UXButtonTemplateSettings TemplateSettings { get; } = new ();
public UXButtonTemplateSettings TemplateSettings { get; } = new();

bool _isTemplateApplied = false;

Expand Down
3 changes: 1 addition & 2 deletions CharacterMap/CharacterMap/Controls/UXSlider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls;

namespace CharacterMap.Controls;

Expand Down
4 changes: 2 additions & 2 deletions CharacterMap/CharacterMap/Controls/XamlTitleBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -84,7 +84,7 @@ void SetHeight(double d)
if (IsAutoHeightEnabled)
Height = d;

TemplateSettings.GridHeight = new (d);
TemplateSettings.GridHeight = new(d);
TemplateSettings.Height = d;
}

Expand Down
7 changes: 4 additions & 3 deletions CharacterMap/CharacterMap/Core/ExportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<StorageFile> PickFileAsync(string fileName, string key, IList<string> values, PickerLocationId suggestedLocation = PickerLocationId.PicturesLibrary)
Expand Down Expand Up @@ -539,8 +539,9 @@ internal static async Task<ExportGlyphsResult> 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
Expand Down
7 changes: 3 additions & 4 deletions CharacterMap/CharacterMap/Core/FontFinder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Diagnostics;
using Windows.Storage.Search;
using Windows.UI.Text;
using WoffToOtf;
Expand Down Expand Up @@ -641,8 +640,8 @@ public static bool IsSystemSymbolFamily(FontVariant variant) => variant != null


public static FontQueryResults QueryFontList(
string query,
IEnumerable<InstalledFont> fontList,
string query,
IEnumerable<InstalledFont> fontList,
UserCollectionsService fontCollections,
IFontCollection collection = null,
BasicFontFilter filter = null)
Expand Down Expand Up @@ -688,7 +687,7 @@ public static FontQueryResults QueryFontList(

return new(fontList, filterTitle, true);
}

return new(fontList, null, false);
}

Expand Down
2 changes: 1 addition & 1 deletion CharacterMap/CharacterMap/Core/FontVariant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public static FontVariant CreateDefault(DWriteFontFace face)
return new FontVariant(face, null)
{
PreferredName = "",
Characters = [ new(0) ]
Characters = [new(0)]
};
}

Expand Down
Loading

0 comments on commit cf21f86

Please sign in to comment.