Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup controlinfo classes and json #1450

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions WinUIGallery/DataModel/ControlInfoData.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
{
"UniqueId": "Typography",
"Title": "Typography",
"HideSourceCodeAndRelatedControls": true,
"SourcePath": "/CommonStyles/TextBlock_themeresources.xaml",
"Docs": [
{
Expand All @@ -30,7 +29,6 @@
{
"UniqueId": "Icons",
"Title": "Icons",
"HideSourceCodeAndRelatedControls": true,
"Docs": [
{
"Title": "Iconography in Windows 11",
Expand All @@ -45,7 +43,6 @@
{
"UniqueId": "Colors",
"Title": "Colors",
"HideSourceCodeAndRelatedControls": true,
"Docs": [
{
"Title": "Colors in Windows 11",
Expand Down Expand Up @@ -73,7 +70,6 @@
"UniqueId": "AccessibilityColorContrast",
"Title": "Color Contrast",
"ImagePath": "ms-appx:///Assets/ControlImages/AppBarSeparator.png",
"HideSourceCodeAndRelatedControls": true,
"Docs": [
{
"Title": "Accessibility",
Expand All @@ -89,7 +85,6 @@
"UniqueId": "AccessibilityKeyboard",
"Title": "Keyboard Support",
"ImagePath": "ms-appx:///Assets/ControlImages/AppBarSeparator.png",
"HideSourceCodeAndRelatedControls": true,
"Docs": [
{
"Title": "Accessibility",
Expand Down Expand Up @@ -129,7 +124,6 @@
"UniqueId": "AccessibilityScreenReader",
"Title": "Screen Reader Support",
"ImagePath": "ms-appx:///Assets/ControlImages/AppBarSeparator.png",
"HideSourceCodeAndRelatedControls": true,
"Docs": [
{
"Title": "Accessibility",
Expand Down Expand Up @@ -813,10 +807,10 @@
{
"UniqueId": "InputValidation",
"Title": "InputValidation",
"Subtitle": "A feature to display developer-defined errors for text values",
"ApiNamespace": "Microsoft.UI.Xaml.Controls",
"Subtitle": "A feature that will display an error for invalid text. The app is notified when text has been changed by the user and is responsible for determining whether the text is valid and the error message",
"ImagePath": "ms-appx:///Assets/ControlImages/InputValidation.png",
"Description": "A feature to display developer-defined errors for text values",
"Description": "A feature that will display an error for invalid text. The app is notified when text has been changed by the user and is responsible for determining whether the text is valid and the error message",
"Content": "<p>Look at the <i>InputValidationPage.xaml</i> file in Visual Studio to see the full code for this page.</p>",
"RelatedControls": [
"TextBox",
Expand Down
48 changes: 6 additions & 42 deletions WinUIGallery/DataModel/ControlInfoDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,6 @@ public class Root
/// </summary>
public class ControlInfoDataItem
{
public ControlInfoDataItem(string uniqueId, string title, string apiNamespace, string subtitle, string imagePath, string iconGlyph, string badgeString, string description, string content, bool isNew, bool isUpdated, bool isPreview, bool hideSourceCodeAndRelatedControls, ObservableCollection<ControlInfoDocLink> docs, ObservableCollection<string> relatedControls, string sourcePath)
{
this.UniqueId = uniqueId;
this.Title = title;

this.ApiNamespace = apiNamespace;
this.Subtitle = subtitle;
this.Description = description;
this.ImagePath = imagePath;
this.IconGlyph = iconGlyph;
this.BadgeString = badgeString;
this.Content = content;
this.IsNew = isNew;
this.IsUpdated = isUpdated;
this.IsPreview = isPreview;
this.Docs = docs;
this.RelatedControls = relatedControls;
this.HideSourceCodeAndRelatedControls = hideSourceCodeAndRelatedControls;
this.SourcePath = sourcePath;
}

public string UniqueId { get; set; }
public string Title { get; set; }
public string ApiNamespace { get; set; }
Expand All @@ -67,7 +46,6 @@ public ControlInfoDataItem(string uniqueId, string title, string apiNamespace, s
public bool IsNew { get; set; }
public bool IsUpdated { get; set; }
public bool IsPreview { get; set; }
public bool HideSourceCodeAndRelatedControls { get; set; }
public ObservableCollection<ControlInfoDocLink> Docs { get; set; }
public ObservableCollection<string> RelatedControls { get; set; }

Expand Down Expand Up @@ -98,20 +76,6 @@ public ControlInfoDocLink(string title, string uri)
/// </summary>
public class ControlInfoDataGroup
{
public ControlInfoDataGroup(string uniqueId, string title, string subtitle, string imagePath, string iconGlyph, string description, string apiNamespace, string folder, bool isSpecialSection)
{
this.UniqueId = uniqueId;
this.Title = title;
this.ApiNamespace = apiNamespace;
this.Subtitle = subtitle;
this.Description = description;
this.ImagePath = imagePath;
this.IconGlyph = iconGlyph;
this.Folder = folder;
this.Items = new ObservableCollection<ControlInfoDataItem>();
this.IsSpecialSection = isSpecialSection;
}

public string UniqueId { get; set; }
public string Title { get; set; }
public string Subtitle { get; set; }
Expand All @@ -137,11 +101,11 @@ public override string ToString()
/// </summary>
public sealed class ControlInfoDataSource
{
private static readonly object _lock = new object();
private static readonly object _lock = new();

#region Singleton

private static ControlInfoDataSource _instance;
private static readonly ControlInfoDataSource _instance;

public static ControlInfoDataSource Instance
{
Expand All @@ -160,7 +124,7 @@ private ControlInfoDataSource() { }

#endregion

private IList<ControlInfoDataGroup> _groups = new List<ControlInfoDataGroup>();
private readonly IList<ControlInfoDataGroup> _groups = new List<ControlInfoDataGroup>();
public IList<ControlInfoDataGroup> Groups
{
get { return this._groups; }
Expand All @@ -173,7 +137,7 @@ public async Task<IEnumerable<ControlInfoDataGroup>> GetGroupsAsync()
return _instance.Groups;
}

public async Task<ControlInfoDataGroup> GetGroupAsync(string uniqueId)
public static async Task<ControlInfoDataGroup> GetGroupAsync(string uniqueId)
{
await _instance.GetControlInfoDataAsync();
// Simple linear search is acceptable for small data sets
Expand All @@ -182,7 +146,7 @@ public async Task<ControlInfoDataGroup> GetGroupAsync(string uniqueId)
return null;
}

public async Task<ControlInfoDataItem> GetItemAsync(string uniqueId)
public static async Task<ControlInfoDataItem> GetItemAsync(string uniqueId)
{
await _instance.GetControlInfoDataAsync();
// Simple linear search is acceptable for small data sets
Expand All @@ -191,7 +155,7 @@ public async Task<ControlInfoDataItem> GetItemAsync(string uniqueId)
return null;
}

public async Task<ControlInfoDataGroup> GetGroupFromItemAsync(string uniqueId)
public static async Task<ControlInfoDataGroup> GetGroupFromItemAsync(string uniqueId)
{
await _instance.GetControlInfoDataAsync();
var matches = _instance.Groups.Where((group) => group.Items.FirstOrDefault(item => item.UniqueId.Equals(uniqueId)) != null);
Expand Down
2 changes: 1 addition & 1 deletion WinUIGallery/ItemPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
{
NavigationRootPageArgs args = (NavigationRootPageArgs)e.Parameter;
var uniqueId = (string)args.Parameter;
var group = await ControlInfoDataSource.Instance.GetGroupFromItemAsync(uniqueId);
var group = await ControlInfoDataSource.GetGroupFromItemAsync(uniqueId);
var item = group?.Items.FirstOrDefault(x => x.UniqueId.Equals(uniqueId));

if (item != null)
Expand Down
2 changes: 1 addition & 1 deletion WinUIGallery/SectionPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
base.OnNavigatedTo(e);
NavigationRootPageArgs args = (NavigationRootPageArgs)e.Parameter;
NavigationRootPage navigationRootPage = args.NavigationRootPage;
var group = await ControlInfoDataSource.Instance.GetGroupAsync((string)args.Parameter);
var group = await ControlInfoDataSource.GetGroupAsync((string)args.Parameter);

var menuItem = (Microsoft.UI.Xaml.Controls.NavigationViewItemBase)navigationRootPage.NavigationView.MenuItems.Single(i => (string)((Microsoft.UI.Xaml.Controls.NavigationViewItemBase)i).Tag == group.UniqueId);
menuItem.IsSelected = true;
Expand Down