11using AutoHDR . Profiles ;
22using CodectoryCore . UI . Wpf ;
3+ using Newtonsoft . Json ;
34using System ;
45using System . Collections . Generic ;
56using System . Collections . ObjectModel ;
67using System . Linq ;
8+ using System . Runtime . Serialization ;
79using System . Text ;
810using System . Threading . Tasks ;
911
1012namespace AutoHDR
1113{
14+ [ JsonObject ( MemberSerialization . OptIn ) ]
1215 public class ApplicationProfileAssignment : BaseViewModel
1316 {
1417 private int _position = - 1 ;
1518 private ApplicationItem _application = null ;
1619
17- private Profiles . Profile _profile = null ;
1820
1921 private static SortableObservableCollection < ApplicationProfileAssignment > Assignments => Globals . Instance . Settings . ApplicationProfileAssignments ;
2022
23+ [ JsonProperty ]
2124 public ApplicationItem Application { get => _application ; set { _application = value ; OnPropertyChanged ( ) ; }
2225 }
2326
24- public Profile Profile {
25- get => _profile ;
26- set { _profile = value ; OnPropertyChanged ( ) ; Globals . Instance . SaveSettings ( ) ; }
27+ private Guid _profileGuid = Guid . Empty ;
28+
29+ [ JsonProperty ]
30+ public Guid ProfileGUID
31+ {
32+ get => _profileGuid ;
33+ set
34+ {
35+ _profileGuid = value ;
36+ OnPropertyChanged ( ) ;
37+ OnPropertyChanged ( nameof ( Profile ) ) ;
38+ }
2739 }
2840
29- public int Position { get => _position ; set { _position = value ; OnPropertyChanged ( ) ; Globals . Instance . SaveSettings ( ) ; } }
41+ public Profile Profile {
42+ get
43+ {
44+ if ( Globals . Instance . Settings . ApplicationProfiles . Any ( p => p . GUID . Equals ( _profileGuid ) ) )
45+ return Globals . Instance . Settings . ApplicationProfiles . First ( p => p . GUID . Equals ( _profileGuid ) ) ;
46+ else
47+ return null ;
48+ }
49+ set
50+ {
51+ if ( value == null )
52+ { _profileGuid = Guid . Empty ;
53+ return ;
54+ }
55+ _profileGuid = value . GUID . Equals ( Guid . Empty ) ? Guid . NewGuid ( ) : value . GUID ; OnPropertyChanged ( ) ; OnPropertyChanged ( nameof ( ProfileGUID ) ) ;
56+ }
57+ }
58+
59+ [ JsonProperty ]
60+
61+ public int Position { get => _position ; set { _position = value ; OnPropertyChanged ( ) ; } }
3062
3163
3264 private ApplicationProfileAssignment ( )
@@ -48,9 +80,7 @@ public void RemoveAssignment()
4880 a . Position = a . Position - 1 ;
4981 }
5082 Assignments . Remove ( this ) ;
51- Assignments . Sort ( x => x . Position , System . ComponentModel . ListSortDirection . Ascending ) ;
52- Globals . Instance . SaveSettings ( ) ;
53- }
83+ Assignments . Sort ( x => x . Position , System . ComponentModel . ListSortDirection . Ascending ) ; }
5484
5585 public void ChangePosition ( bool up )
5686 {
@@ -65,8 +95,6 @@ public void ChangePosition(bool up)
6595 }
6696 Position = newPosition ;
6797 Assignments . Sort ( x => x . Position , System . ComponentModel . ListSortDirection . Ascending ) ;
68-
69- Globals . Instance . SaveSettings ( ) ;
7098 }
7199
72100
@@ -77,7 +105,6 @@ public static ApplicationProfileAssignment NewAssigment(ApplicationItem applicat
77105 assigment . Position = GetNextPosition ( ) ;
78106 Assignments . Add ( assigment ) ;
79107 Assignments . Sort ( x => x . Position , System . ComponentModel . ListSortDirection . Ascending ) ;
80- Globals . Instance . SaveSettings ( ) ;
81108 return assigment ;
82109 }
83110
0 commit comments