Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SettingsKey.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 
5 using SiliconStudio.Core.IO;
6 
7 namespace SiliconStudio.Presentation.Settings
8 {
9  /// <summary>
10  /// Arguments of the <see cref="SettingsKey.ChangesValidated"/> event.
11  /// </summary>
13  {
14  /// <summary>
15  /// Initializes a new instance of the <see cref="ChangesValidatedEventArgs"/> class.
16  /// </summary>
17  /// <param name="profile">The profile in which changes have been validated.</param>
19  {
20  Profile = profile;
21  }
22 
23  /// <summary>
24  /// Gets the <see cref="SettingsProfile"/> in which changes have been validated.
25  /// </summary>
26  public SettingsProfile Profile { get; private set; }
27 
28  /// <summary>
29  /// Gets whether the profile in which changes have been validated is the current profile or not.
30  /// </summary>
31  public bool IsCurrentProfile { get { return Profile == SettingsService.CurrentProfile; } }
32  }
33 
34  /// <summary>
35  /// This class represents property to store in the settings that is identified by a key.
36  /// </summary>
37  public abstract class SettingsKey
38  {
39  /// <summary>
40  /// The default value of the settings key.
41  /// </summary>
42  protected readonly object DefaultObjectValue;
43 
44  /// <summary>
45  /// Initializes a new instance of the <see cref="SettingsKey"/> class.
46  /// </summary>
47  /// <param name="name">The name of this settings key. Must be unique amongst the application.</param>
48  /// <param name="defaultValue">The default value associated to this settings key.</param>
49  protected SettingsKey(UFile name, object defaultValue)
50  {
51  Name = name;
52  DisplayName = name;
53  DefaultObjectValue = defaultValue;
54  IsEditable = true;
55  SettingsService.RegisterSettingsKey(name, defaultValue, this);
56  }
57 
58  /// <summary>
59  /// Gets the name of this <see cref="SettingsKey"/>.
60  /// </summary>
61  public UFile Name { get; private set; }
62 
63  /// <summary>
64  /// Gets the type of this <see cref="SettingsKey"/>.
65  /// </summary>
66  public abstract Type Type { get; }
67 
68  /// <summary>
69  /// Gets or sets whether this <see cref="SettingsKey"/> is editable by users.
70  /// </summary>
71  public bool IsEditable { get; set; }
72 
73  /// <summary>
74  /// Gets or sets the display name of the <see cref="SettingsKey"/>.
75  /// </summary>
76  /// <remarks>The default value is the name parameter given to the constructor of this class.</remarks>
77  public UFile DisplayName { get; set; }
78 
79  /// <summary>
80  /// Gets or sets the description of this <see cref="SettingsKey"/>.
81  /// </summary>
82  public string Description { get; set; }
83 
84  /// <summary>
85  /// Raised when the value of the settings key has been modified and the method <see cref="SettingsProfile.ValidateSettingsChanges"/> has been invoked.
86  /// </summary>
87  public event EventHandler<ChangesValidatedEventArgs> ChangesValidated;
88 
89  /// <summary>
90  /// Converts a value of a different type to the type associated with this <see cref="SettingsKey"/>. If the conversion is not possible,
91  /// this method will return the default value of the SettingsKey.
92  /// </summary>
93  /// <param name="value">The value to convert.</param>
94  /// <returns>The converted value if the conversion is possible, the default value otherwise.</returns>
95  internal abstract object ConvertValue(object value);
96 
97  /// <summary>
98  /// Notifes that the changes have been validated by <see cref="SettingsProfile.ValidateSettingsChanges"/>.
99  /// </summary>
100  /// <param name="profile">The profile in which the change has been validated.</param>
101  internal void NotifyChangesValidated(SettingsProfile profile)
102  {
103  var handler = ChangesValidated;
104  if (handler != null)
105  handler(this, new ChangesValidatedEventArgs(profile));
106  }
107  }
108 }
SettingsKey(UFile name, object defaultValue)
Initializes a new instance of the SettingsKey class.
Definition: SettingsKey.cs:49
This class represents a collection of values for all registered SettingsKey. It may also contains val...
Arguments of the SettingsKey.ChangesValidated event.
Definition: SettingsKey.cs:12
This class represents property to store in the settings that is identified by a key.
Definition: SettingsKey.cs:37
EventHandler< ChangesValidatedEventArgs > ChangesValidated
Raised when the value of the settings key has been modified and the method SettingsProfile.ValidateSettingsChanges has been invoked.
Definition: SettingsKey.cs:87
ChangesValidatedEventArgs(SettingsProfile profile)
Initializes a new instance of the ChangesValidatedEventArgs class.
Definition: SettingsKey.cs:18
readonly object DefaultObjectValue
The default value of the settings key.
Definition: SettingsKey.cs:42
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Definition: UFile.cs:13