Skip to content

Commit

Permalink
add paginator until we got a virtualized wrappanel
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 authored and timunie committed Nov 11, 2024
1 parent 70294ea commit a399f0b
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 231 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using AsyncAwaitBestPractices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using FluentAvalonia.UI.Data;
using IconPacks.Avalonia;
using IconPacks.Avalonia.Attributes;
using MahApps.IconPacksBrowser.Avalonia.Helper;

namespace MahApps.IconPacksBrowser.Avalonia.ViewModels;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
using System;
using System.ComponentModel;
using System.Linq;
using IconPacks.Avalonia;
using IconPacks.Avalonia.Attributes;
using MahApps.IconPacksBrowser.Avalonia.Helper;

namespace MahApps.IconPacksBrowser.Avalonia.ViewModels;

public interface IIconViewModel
{
/// <summary>
/// Gets the unique identifier by returning "IcoNPackName|Name" combination
/// </summary>
string Identifier => $"{IconPackName}|{Name}";
string Name { get; set; }
string IconPackName { get; }
string Description { get; set; }
Type IconPackType { get; set; }
Type IconType { get; set; }
object Value { get; set; }
MetaDataAttribute MetaData { get; set; }
string? CopyToClipboardText { get; }
string? CopyToClipboardWpfGeometry { get; }
string? CopyToClipboardAsContentText { get; }
string? CopyToClipboardAsPathIconText { get; }
string? CopyToClipboardAsGeometryText { get; }
}

public class IconViewModel : ViewModelBase, IIconViewModel
{
public IconViewModel(Type enumType, Type packType, Enum k, MetaDataAttribute metaData)
{
Name = k.ToString();
Description = GetDescription(k);
IconPackType = packType;
IconType = enumType;
Value = k;
MetaData = metaData;
}

public string? CopyToClipboardText => ExportHelper.FillTemplate(ExportHelper.ClipboardWpf, new ExportParameters(this)); // $"<iconPacks:{IconPackType.Name} Kind=\"{Name}\" />";

public string? CopyToClipboardWpfGeometry =>
ExportHelper.FillTemplate(ExportHelper.ClipboardWpfGeometry, new ExportParameters(this)); // $"<iconPacks:{IconPackType.Name} Kind=\"{Name}\" />";

public string? CopyToClipboardAsContentText =>
ExportHelper.FillTemplate(ExportHelper.ClipboardContent, new ExportParameters(this)); // $"{{iconPacks:{IconPackType.Name.Replace("PackIcon", "")} Kind={Name}}}";

public string? CopyToClipboardAsPathIconText =>
ExportHelper.FillTemplate(ExportHelper.ClipboardUwp, new ExportParameters(this)); // $"<iconPacks:{IconPackType.Name.Replace("PackIcon", "PathIcon")} Kind=\"{Name}\" />";

public string? CopyToClipboardAsGeometryText => ExportHelper.FillTemplate(ExportHelper.ClipboardData, new ExportParameters(this)); // GetPackIconControlBase().Data;

public string Name { get; set; }

public string IconPackName => IconPackType.Name.Replace("PackIcon", "");

public string Description { get; set; }

public Type IconPackType { get; set; }

public Type IconType { get; set; }

public object Value { get; set; }

public MetaDataAttribute MetaData { get; set; }

internal PackIconControlBase? GetPackIconControlBase()
{
if (Activator.CreateInstance(IconPackType) is not PackIconControlBase iconPack) return null;

var kindProperty = IconPackType.GetProperty("Kind");
if (kindProperty == null) return null;
kindProperty.SetValue(iconPack, Value);

return iconPack;
}

internal static string GetDescription(Enum value)
{
var fieldInfo = value.GetType().GetField(value.ToString());
return fieldInfo?.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault() is DescriptionAttribute attribute ? attribute.Description : value.ToString();
}
using System;
using System.ComponentModel;
using System.Linq;
using IconPacks.Avalonia;
using IconPacks.Avalonia.Attributes;
using MahApps.IconPacksBrowser.Avalonia.Helper;

namespace MahApps.IconPacksBrowser.Avalonia.ViewModels;

public interface IIconViewModel
{
/// <summary>
/// Gets the unique identifier by returning "IconPackName|Name" combination
/// </summary>
string Identifier => $"{IconPackName}|{Name}";

string Name { get; set; }
string IconPackName { get; }
string Description { get; set; }
Type IconPackType { get; set; }
Type IconType { get; set; }
object Value { get; set; }
MetaDataAttribute MetaData { get; set; }
string? CopyToClipboardText { get; }
string? CopyToClipboardWpfGeometry { get; }
string? CopyToClipboardAsContentText { get; }
string? CopyToClipboardAsPathIconText { get; }
string? CopyToClipboardAsGeometryText { get; }
}

public class IconViewModel : ViewModelBase, IIconViewModel
{
public IconViewModel(Type enumType, Type packType, Enum k, MetaDataAttribute metaData)
{
Name = k.ToString();
Description = GetDescription(k);
IconPackType = packType;
IconType = enumType;
Value = k;
MetaData = metaData;
}

public string? CopyToClipboardText => ExportHelper.FillTemplate(ExportHelper.ClipboardWpf, new ExportParameters(this)); // $"<iconPacks:{IconPackType.Name} Kind=\"{Name}\" />";

public string? CopyToClipboardWpfGeometry =>
ExportHelper.FillTemplate(ExportHelper.ClipboardWpfGeometry, new ExportParameters(this)); // $"<iconPacks:{IconPackType.Name} Kind=\"{Name}\" />";

public string? CopyToClipboardAsContentText =>
ExportHelper.FillTemplate(ExportHelper.ClipboardContent, new ExportParameters(this)); // $"{{iconPacks:{IconPackType.Name.Replace("PackIcon", "")} Kind={Name}}}";

public string? CopyToClipboardAsPathIconText =>
ExportHelper.FillTemplate(ExportHelper.ClipboardUwp, new ExportParameters(this)); // $"<iconPacks:{IconPackType.Name.Replace("PackIcon", "PathIcon")} Kind=\"{Name}\" />";

public string? CopyToClipboardAsGeometryText => ExportHelper.FillTemplate(ExportHelper.ClipboardData, new ExportParameters(this)); // GetPackIconControlBase().Data;

public string Name { get; set; }

public string IconPackName => IconPackType.Name.Replace("PackIcon", "");

public string Description { get; set; }

public Type IconPackType { get; set; }

public Type IconType { get; set; }

public object Value { get; set; }

public MetaDataAttribute MetaData { get; set; }

internal PackIconControlBase? GetPackIconControlBase()
{
if (Activator.CreateInstance(IconPackType) is not PackIconControlBase iconPack) return null;

var kindProperty = IconPackType.GetProperty("Kind");
if (kindProperty == null) return null;
kindProperty.SetValue(iconPack, Value);

return iconPack;
}

internal static string GetDescription(Enum value)
{
var fieldInfo = value.GetType().GetField(value.ToString());
return fieldInfo?.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault() is DescriptionAttribute attribute ? attribute.Description : value.ToString();
}
}
Loading

0 comments on commit a399f0b

Please sign in to comment.