コード例 #1
0
 internal void ExportAsAttributes(XmlElement to)
 {
     foreach (KeyValuePair <string, SettingDataM> p in this)
     {
         SettingDataM ds = p.Value;
         if (p.Key == "MainFormRectangle") // TODO: generalize method
         {
             var r = (Rectangle)ds.Value;
             to.SetAttribute(p.Key, $"{r.Left}|{r.Top}|{r.Right}|{r.Bottom}");
             continue;
         }
         if (ds.DataType == typeof(float))
         {
             to.SetAttribute(p.Key,
                             ((float)ds.Value).ToString(CultureInfo.InvariantCulture));
             continue;
         }
         if (ds.DataType == typeof(double))
         {
             to.SetAttribute(p.Key,
                             ((double)ds.Value).ToString(CultureInfo.InvariantCulture));
             continue;
         }
         if (ds.DataType == typeof(decimal))
         {
             to.SetAttribute(p.Key,
                             ((decimal)ds.Value).ToString(CultureInfo.InvariantCulture));
             continue;
         }
         to.SetAttribute(p.Key, ds.Value.ToString());
     }
 }
コード例 #2
0
 private void UnsubscribeFromSettingData(SettingDataM ds)
 {
     ds.Changed          -= Ds_Changed;
     ds.Saved            -= Ds_Saved;
     ds.ResetToDefault   -= Ds_ResetToDefault;
     ds.ResetToLastSaved -= Ds_ResetToLastSaved;
 }
コード例 #3
0
 private void SubscribeToSettingData(SettingDataM ds)
 {
     ds.Changed          += Ds_Changed;
     ds.Saved            += Ds_Saved;
     ds.ResetToDefault   += Ds_ResetToDefault;
     ds.ResetToLastSaved += Ds_ResetToLastSaved;
 }
コード例 #4
0
        public SettingDataVM(SettingDataM model)
        {
            Actions = new ObservableCollection <NamedCommandVM>();
            HeaderWithoutAccelerator = "";

            M = model;
            M.PropertyChanged += M_PropertyChanged;

            SyncToViewModel();
        }
コード例 #5
0
        internal static bool SettingsCollectionsHaveEqualValues(
            Dictionary <string, SettingDataM> d1,
            Dictionary <string, SettingDataM> d2)
        {
            foreach (KeyValuePair <string, SettingDataM> p in d1)
            {
                SettingDataM ds  = p.Value;
                SettingDataM ds2 = d2[p.Key];

                // settings without a default value (which means
                // they can reset to different values on different moments)
                // should not be compared by values
                if (ds.DefaultValueComputation != null &&
                    ds2.DefaultValueComputation != null)
                {
                    continue;
                }

                if (p.Key == "MainFormRectangle") // TODO: generalize
                {
                    if ((ds.Value == null && ds2.Value != null) ||
                        (ds.Value != null && ds2.Value == null))
                    {
                        // TODO: remove comment:
                        // For the DataFile to be saved on first load,
                        // I must ignore this setting (when it has
                        // a null value)
                        // that changes its value
                        // on first load to an unknown rectangle.
                        return(false);
                    }
                    else if (ds.Value != null &&
                             !ds.Value.Equals(ds2.Value))
                    {
                        return(false);
                    }
                }
                else if (ds.Value != null && ds2.Value != null)
                {
                    if (!ds.Value.ToString().Equals(ds2.Value.ToString()))
                    {
                        return(false);
                    }
                }
                else if (ds.Value == null && ds2.Value != null ||
                         ds.Value != null && ds2.Value == null)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #6
0
        internal bool Add(SettingDataM ds)
        {
            if (Contains(ds.Name))
            {
                UnsubscribeFromSettingData(SettingsData[ds.Name]);

                SettingsData.Remove(ds.Name);

                SettingsData.Add(ds.Name, ds);

                SubscribeToSettingData(ds);

                return(true);
            }
            else
            {
                SettingsData.Add(ds.Name, ds);

                SubscribeToSettingData(ds);

                return(true);
            }
        }
コード例 #7
0
 public TimeSpanSettingDataVM(SettingDataM m) : base(m)
 {
 }
コード例 #8
0
 public AudioFileSettingDataVM(SettingDataM m) : base(m)
 {
 }
コード例 #9
0
 public ImageFileSettingDataVM(SettingDataM m) : base(m)
 {
 }
コード例 #10
0
 internal bool Contains(SettingDataM ds)
 {
     return(SettingsData.ContainsValue(ds));
 }
コード例 #11
0
 public IntegerSettingDataVM(SettingDataM m) : base(m)
 {
 }
コード例 #12
0
 public CheckBoxSettingDataVM(SettingDataM m) : base(m)
 {
 }