1
- using System ;
2
- using System . ComponentModel ;
3
- using System . Linq ;
4
- using IconPacks . Avalonia ;
5
- using IconPacks . Avalonia . Attributes ;
6
- using MahApps . IconPacksBrowser . Avalonia . Helper ;
7
-
8
- namespace MahApps . IconPacksBrowser . Avalonia . ViewModels ;
9
-
10
- public interface IIconViewModel
11
- {
12
- /// <summary>
13
- /// Gets the unique identifier by returning "IcoNPackName |Name" combination
14
- /// </summary>
15
- string Identifier => $ "{ IconPackName } |{ Name } ";
16
-
17
- string Name { get ; set ; }
18
- string IconPackName { get ; }
19
- string Description { get ; set ; }
20
- Type IconPackType { get ; set ; }
21
- Type IconType { get ; set ; }
22
- object Value { get ; set ; }
23
- MetaDataAttribute MetaData { get ; set ; }
24
- string ? CopyToClipboardText { get ; }
25
- string ? CopyToClipboardWpfGeometry { get ; }
26
- string ? CopyToClipboardAsContentText { get ; }
27
- string ? CopyToClipboardAsPathIconText { get ; }
28
- string ? CopyToClipboardAsGeometryText { get ; }
29
- }
30
-
31
- public class IconViewModel : ViewModelBase , IIconViewModel
32
- {
33
- public IconViewModel ( Type enumType , Type packType , Enum k , MetaDataAttribute metaData )
34
- {
35
- Name = k . ToString ( ) ;
36
- Description = GetDescription ( k ) ;
37
- IconPackType = packType ;
38
- IconType = enumType ;
39
- Value = k ;
40
- MetaData = metaData ;
41
- }
42
-
43
- public string ? CopyToClipboardText => ExportHelper . FillTemplate ( ExportHelper . ClipboardWpf , new ExportParameters ( this ) ) ; // $"<iconPacks:{IconPackType.Name} Kind=\"{Name}\" />";
44
-
45
- public string ? CopyToClipboardWpfGeometry =>
46
- ExportHelper . FillTemplate ( ExportHelper . ClipboardWpfGeometry , new ExportParameters ( this ) ) ; // $"<iconPacks:{IconPackType.Name} Kind=\"{Name}\" />";
47
-
48
- public string ? CopyToClipboardAsContentText =>
49
- ExportHelper . FillTemplate ( ExportHelper . ClipboardContent , new ExportParameters ( this ) ) ; // $"{{iconPacks:{IconPackType.Name.Replace("PackIcon", "")} Kind={Name}}}";
50
-
51
- public string ? CopyToClipboardAsPathIconText =>
52
- ExportHelper . FillTemplate ( ExportHelper . ClipboardUwp , new ExportParameters ( this ) ) ; // $"<iconPacks:{IconPackType.Name.Replace("PackIcon", "PathIcon")} Kind=\"{Name}\" />";
53
-
54
- public string ? CopyToClipboardAsGeometryText => ExportHelper . FillTemplate ( ExportHelper . ClipboardData , new ExportParameters ( this ) ) ; // GetPackIconControlBase().Data;
55
-
56
- public string Name { get ; set ; }
57
-
58
- public string IconPackName => IconPackType . Name . Replace ( "PackIcon" , "" ) ;
59
-
60
- public string Description { get ; set ; }
61
-
62
- public Type IconPackType { get ; set ; }
63
-
64
- public Type IconType { get ; set ; }
65
-
66
- public object Value { get ; set ; }
67
-
68
- public MetaDataAttribute MetaData { get ; set ; }
69
-
70
- internal PackIconControlBase ? GetPackIconControlBase ( )
71
- {
72
- if ( Activator . CreateInstance ( IconPackType ) is not PackIconControlBase iconPack ) return null ;
73
-
74
- var kindProperty = IconPackType . GetProperty ( "Kind" ) ;
75
- if ( kindProperty == null ) return null ;
76
- kindProperty . SetValue ( iconPack , Value ) ;
77
-
78
- return iconPack ;
79
- }
80
-
81
- internal static string GetDescription ( Enum value )
82
- {
83
- var fieldInfo = value . GetType ( ) . GetField ( value . ToString ( ) ) ;
84
- return fieldInfo ? . GetCustomAttributes ( typeof ( DescriptionAttribute ) , false ) . FirstOrDefault ( ) is DescriptionAttribute attribute ? attribute . Description : value . ToString ( ) ;
85
- }
1
+ using System ;
2
+ using System . ComponentModel ;
3
+ using System . Linq ;
4
+ using IconPacks . Avalonia ;
5
+ using IconPacks . Avalonia . Attributes ;
6
+ using MahApps . IconPacksBrowser . Avalonia . Helper ;
7
+
8
+ namespace MahApps . IconPacksBrowser . Avalonia . ViewModels ;
9
+
10
+ public interface IIconViewModel
11
+ {
12
+ /// <summary>
13
+ /// Gets the unique identifier by returning "IconPackName |Name" combination
14
+ /// </summary>
15
+ string Identifier => $ "{ IconPackName } |{ Name } ";
16
+
17
+ string Name { get ; set ; }
18
+ string IconPackName { get ; }
19
+ string Description { get ; set ; }
20
+ Type IconPackType { get ; set ; }
21
+ Type IconType { get ; set ; }
22
+ object Value { get ; set ; }
23
+ MetaDataAttribute MetaData { get ; set ; }
24
+ string ? CopyToClipboardText { get ; }
25
+ string ? CopyToClipboardWpfGeometry { get ; }
26
+ string ? CopyToClipboardAsContentText { get ; }
27
+ string ? CopyToClipboardAsPathIconText { get ; }
28
+ string ? CopyToClipboardAsGeometryText { get ; }
29
+ }
30
+
31
+ public class IconViewModel : ViewModelBase , IIconViewModel
32
+ {
33
+ public IconViewModel ( Type enumType , Type packType , Enum k , MetaDataAttribute metaData )
34
+ {
35
+ Name = k . ToString ( ) ;
36
+ Description = GetDescription ( k ) ;
37
+ IconPackType = packType ;
38
+ IconType = enumType ;
39
+ Value = k ;
40
+ MetaData = metaData ;
41
+ }
42
+
43
+ public string ? CopyToClipboardText => ExportHelper . FillTemplate ( ExportHelper . ClipboardWpf , new ExportParameters ( this ) ) ; // $"<iconPacks:{IconPackType.Name} Kind=\"{Name}\" />";
44
+
45
+ public string ? CopyToClipboardWpfGeometry =>
46
+ ExportHelper . FillTemplate ( ExportHelper . ClipboardWpfGeometry , new ExportParameters ( this ) ) ; // $"<iconPacks:{IconPackType.Name} Kind=\"{Name}\" />";
47
+
48
+ public string ? CopyToClipboardAsContentText =>
49
+ ExportHelper . FillTemplate ( ExportHelper . ClipboardContent , new ExportParameters ( this ) ) ; // $"{{iconPacks:{IconPackType.Name.Replace("PackIcon", "")} Kind={Name}}}";
50
+
51
+ public string ? CopyToClipboardAsPathIconText =>
52
+ ExportHelper . FillTemplate ( ExportHelper . ClipboardUwp , new ExportParameters ( this ) ) ; // $"<iconPacks:{IconPackType.Name.Replace("PackIcon", "PathIcon")} Kind=\"{Name}\" />";
53
+
54
+ public string ? CopyToClipboardAsGeometryText => ExportHelper . FillTemplate ( ExportHelper . ClipboardData , new ExportParameters ( this ) ) ; // GetPackIconControlBase().Data;
55
+
56
+ public string Name { get ; set ; }
57
+
58
+ public string IconPackName => IconPackType . Name . Replace ( "PackIcon" , "" ) ;
59
+
60
+ public string Description { get ; set ; }
61
+
62
+ public Type IconPackType { get ; set ; }
63
+
64
+ public Type IconType { get ; set ; }
65
+
66
+ public object Value { get ; set ; }
67
+
68
+ public MetaDataAttribute MetaData { get ; set ; }
69
+
70
+ internal PackIconControlBase ? GetPackIconControlBase ( )
71
+ {
72
+ if ( Activator . CreateInstance ( IconPackType ) is not PackIconControlBase iconPack ) return null ;
73
+
74
+ var kindProperty = IconPackType . GetProperty ( "Kind" ) ;
75
+ if ( kindProperty == null ) return null ;
76
+ kindProperty . SetValue ( iconPack , Value ) ;
77
+
78
+ return iconPack ;
79
+ }
80
+
81
+ internal static string GetDescription ( Enum value )
82
+ {
83
+ var fieldInfo = value . GetType ( ) . GetField ( value . ToString ( ) ) ;
84
+ return fieldInfo ? . GetCustomAttributes ( typeof ( DescriptionAttribute ) , false ) . FirstOrDefault ( ) is DescriptionAttribute attribute ? attribute . Description : value . ToString ( ) ;
85
+ }
86
86
}
0 commit comments