/ src / settings-ui / Settings.UI.Library / ColorFormatModel.cs
ColorFormatModel.cs
  1  // Copyright (c) Microsoft Corporation
  2  // The Microsoft Corporation licenses this file to you under the MIT license.
  3  // See the LICENSE file in the project root for more information.
  4  
  5  using System.ComponentModel;
  6  using System.Runtime.CompilerServices;
  7  
  8  using ManagedCommon;
  9  
 10  namespace Microsoft.PowerToys.Settings.UI.Library
 11  {
 12      public class ColorFormatModel : INotifyPropertyChanged
 13      {
 14          private string _name;
 15          private string _format;
 16          private bool _isShown;
 17          private bool _canMoveUp = true;
 18          private bool _canMoveDown = true;
 19          private bool _canBeDeleted = true;
 20          private bool _isNew;
 21          private bool _isValid = true;
 22  
 23          public ColorFormatModel(string name, string format, bool isShown)
 24          {
 25              Name = name;
 26              Format = format;
 27              IsShown = isShown;
 28              IsNew = false;
 29          }
 30  
 31          public ColorFormatModel()
 32          {
 33              Format = "new Color (R = %Re, G = %Gr, B = %Bl)";
 34              IsShown = true;
 35              IsNew = true;
 36          }
 37  
 38          public string Name
 39          {
 40              get
 41              {
 42                  return _name;
 43              }
 44  
 45              set
 46              {
 47                  _name = value;
 48                  OnPropertyChanged(nameof(Name));
 49              }
 50          }
 51  
 52          public string Format
 53          {
 54              get
 55              {
 56                  return _format;
 57              }
 58  
 59              set
 60              {
 61                  _format = value;
 62                  OnPropertyChanged(nameof(Format));
 63                  OnPropertyChanged(nameof(Example));
 64              }
 65          }
 66  
 67          public bool IsShown
 68          {
 69              get
 70              {
 71                  return _isShown;
 72              }
 73  
 74              set
 75              {
 76                  _isShown = value;
 77                  OnPropertyChanged(nameof(IsShown));
 78              }
 79          }
 80  
 81          public bool CanMoveUp
 82          {
 83              get
 84              {
 85                  return _canMoveUp;
 86              }
 87  
 88              set
 89              {
 90                  if (value != _canMoveUp)
 91                  {
 92                      _canMoveUp = value;
 93                      OnPropertyChanged(nameof(CanMoveUp));
 94                  }
 95              }
 96          }
 97  
 98          public bool CanMoveDown
 99          {
100              get
101              {
102                  return _canMoveDown;
103              }
104  
105              set
106              {
107                  if (value != _canMoveDown)
108                  {
109                      _canMoveDown = value;
110                      OnPropertyChanged(nameof(CanMoveDown));
111                  }
112              }
113          }
114  
115          public bool CanBeDeleted
116          {
117              get
118              {
119                  return _canBeDeleted;
120              }
121  
122              set
123              {
124                  if (value != _canBeDeleted)
125                  {
126                      _canBeDeleted = value;
127                      OnPropertyChanged(nameof(CanBeDeleted));
128                  }
129              }
130          }
131  
132          public bool IsNew
133          {
134              get
135              {
136                  return _isNew;
137              }
138  
139              set
140              {
141                  _isNew = value;
142                  OnPropertyChanged(nameof(IsNew));
143              }
144          }
145  
146          public bool IsValid
147          {
148              get
149              {
150                  return _isValid;
151              }
152  
153              set
154              {
155                  _isValid = value;
156                  OnPropertyChanged(nameof(IsValid));
157              }
158          }
159  
160          public string Example
161          {
162              get
163              {
164                  // get string representation in 2 steps. First replace all color specific number values then in 2nd step replace color name with localisation
165                  return Helpers.ColorNameHelper.ReplaceName(ColorFormatHelper.GetStringRepresentation(null, _format), null);
166              }
167  
168              set
169              {
170              }
171          }
172  
173          public event PropertyChangedEventHandler PropertyChanged;
174  
175          private void OnPropertyChanged([CallerMemberName] string propertyName = null)
176          {
177              PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
178          }
179      }
180  }