4 using System.Collections.Generic;
7 using SiliconStudio.Core.IO;
8 using SiliconStudio.Presentation.Core;
10 namespace SiliconStudio.Presentation.Settings
20 private readonly SortedList<UFile, SettingsEntry> settings =
new SortedList<UFile, SettingsEntry>();
21 private readonly HashSet<UFile> modifiedSettings =
new HashSet<UFile>();
23 private FileSystemWatcher fileWatcher;
24 private UFile filePath;
25 private bool monitorFileModification;
33 this.parentProfile = parentProfile;
39 public UFile FilePath {
get {
return filePath; }
internal set { Utils.SetAndInvokeIfChanged(ref filePath, value, UpdateMonitoring); } }
44 public bool MonitorFileModification {
get {
return monitorFileModification; } set { Utils.SetAndInvokeIfChanged(ref monitorFileModification, value, UpdateMonitoring); } }
56 internal bool IsDiscarding {
get;
private set; }
61 if (fileWatcher != null)
63 fileWatcher.Changed -= SettingsFileChanged;
64 fileWatcher.Dispose();
70 var keys = SettingsService.GetAllSettingsKeys(
true);
71 foreach (var key
in keys)
73 if (modifiedSettings.Contains(key.Name))
74 key.NotifyChangesValidated(
this);
77 modifiedSettings.Clear();
83 while (ActionStack.CanUndo)
88 modifiedSettings.Clear();
96 internal void RegisterEntry(SettingsEntry entry)
98 if (entry == null)
throw new ArgumentNullException(
"entry");
99 Settings.Add(entry.Name, entry);
110 internal bool GetValue(
UFile name, out
object value,
bool searchInParent,
bool createInCurrentProfile)
112 if (name == null)
throw new ArgumentNullException(
"name");
113 SettingsEntry entry = GetEntry(name, searchInParent, createInCurrentProfile);
128 internal void SetValue(
UFile name,
object value)
130 if (name == null)
throw new ArgumentNullException(
"name");
133 if (!Settings.TryGetValue(name, out entry))
135 entry = SettingsEntry.CreateFromValue(
this, name, value);
136 Settings[name] = entry;
140 Settings[name].Value = value;
148 internal void NotifyEntryChanged(
UFile name)
150 modifiedSettings.Add(name);
160 private SettingsEntry GetEntry(
UFile name,
bool searchInParent,
bool createInCurrentProfile)
162 if (name == null)
throw new ArgumentNullException(
"name");
165 if (Settings.TryGetValue(name, out entry))
168 if (createInCurrentProfile)
170 entry = parentProfile.GetEntry(name,
true,
false);
171 entry = SettingsEntry.CreateFromValue(
this, name, entry.Value);
172 RegisterEntry(entry);
176 return parentProfile != null && searchInParent ? parentProfile.GetEntry(name,
true,
false) : null;
179 private void UpdateMonitoring()
181 if (fileWatcher != null)
183 fileWatcher.Changed -= SettingsFileChanged;
184 fileWatcher.Dispose();
186 if (MonitorFileModification && FilePath != null &&
File.Exists(FilePath))
188 fileWatcher =
new FileSystemWatcher(Path.Combine(Environment.CurrentDirectory, FilePath.GetFullDirectory()), FilePath.GetFileNameWithExtension());
189 fileWatcher.Changed += SettingsFileChanged;
190 fileWatcher.EnableRaisingEvents =
true;
194 private void SettingsFileChanged(
object sender, FileSystemEventArgs e)
199 var handler = FileModified;
202 var args =
new FileModifiedEventArgs(
this);
206 SettingsService.ReloadSettingsProfile(
this);
This class represents a collection of values for all registered SettingsKey. It may also contains val...
void ValidateSettingsChanges()
void DiscardSettingsChanges()
EventHandler< FileModifiedEventArgs > FileModified
Raised when the file corresponding to this profile is modified on the disk, and MonitorFileModificati...
This class represents a thread-safe stack of action items that can be undone/redone.
Defines a normalized file path. See UPath for details. This class cannot be inherited.