public void Load(XElement root) { if (root == null) { throw new ArgumentNullException(nameof(root)); } if (m_suppressibleValueChanged.Suppressed) { throw new InternalLogicException("Can't load config while there are unsaved changes to config"); } using (SuppressCallback()) //The following block will modify the data but during a load that shouldn't trigger ValueChanged { var a = root.Element(m_name); m_data.Clear(); if (a != null) { foreach (var node in a.Elements("Element")) { ConfigParameter <TValue> t = m_nodeFactory(); t.Load(node); m_data.Add(t.Value); } } m_suppressibleValueChanged.Dispose(); //Pretend we haven't changed anything, by destroying the old callback and making a new one } m_suppressibleValueChanged = new SuppressibleAction(() => ValueChanged.Execute()); }
public ConfigParameterList(string name, Func <ConfigParameter <TValue> > nodeFactory) { m_name = name; m_suppressibleValueChanged = new SuppressibleAction(() => ValueChanged.Execute()); m_data.Modified += () => { m_suppressibleValueChanged.TryExecute(); }; m_nodeFactory = nodeFactory; }
public MapConfig(string nodeName, Func <KeyValuePair <TKey, TData>, KeyValuePair <string, string> > serialize, Func <KeyValuePair <string, string>, KeyValuePair <TKey, TData> > deserialize, Func <TKey, TData> defaults) { m_nodeName = nodeName; m_serialize = serialize; m_deserialize = deserialize; m_defaults = defaults; m_valueChanged = new SuppressibleAction(() => ValueChanged.Execute()); }
public static void TestZeroSuppressions() { bool triggered = false; SuppressibleAction action = new SuppressibleAction(() => { triggered = true; }); { Assert.False(action.Suppressed); var executed = action.TryExecute(); Assert.True(executed); Assert.True(triggered); } }
public AudioProvider(FileInfo projectPath, GetFilePath getFilePath, Func <string, bool> fileLocationOk, IProject project, IAudioProviderCustomization customization) { m_projectPath = projectPath.Directory; m_project = project; m_customization = customization; Func <IEnumerable <Tuple <Id <FileInProject>, DocumentPath> >, IEnumerable <IAudioFile> > load = files => files.Select(file => new AudioFile(file.Item1, file.Item2, this)); Func <DirectoryInfo, AudioFile> makeEmpty = path => { throw new NotSupportedException("Can't create new audio files within the editor"); }; Func <Id <FileInProject>, MissingAudioFile> makeMissing = file => new MissingAudioFile(file, getFilePath(file), this); m_audioFiles = new ProjectElementList <IAudioFile>(getFilePath, fileLocationOk, load, makeEmpty, makeMissing); UpdateQueued = new SuppressibleAction(() => { ReallyUpdateUsage(); }); //For now just update everything }
public ProjectElementList(GetFilePath getFilePath, Func <string, bool> fileLocationOk, Func <IEnumerable <Tuple <Id <FileInProject>, DocumentPath> >, IEnumerable <TElement> > loader, Func <DirectoryInfo, TElement> makeEmpty) { m_getFilePath = getFilePath; m_data = new CallbackDictionary <Id <FileInProject>, TElement>(); m_data.Removing += (key, element) => { element.Removed(); }; m_data.Clearing += () => { m_data.Values.ForAll(element => { element.Removed(); }); }; m_loader = loader; m_makeEmpty = makeEmpty; m_fileLocationOk = fileLocationOk; m_suppressibleGotChanged = new SuppressibleAction(() => { GotChanged.Execute(); }); Added += a => m_suppressibleGotChanged.TryExecute(); Removed += a => m_suppressibleGotChanged.TryExecute(); }
public static void TestOneSuppression() { bool triggered = false; SuppressibleAction action = new SuppressibleAction(() => { triggered = true; }); { using (action.SuppressCallback()) { Assert.True(action.Suppressed); var executed = action.TryExecute(); Assert.False(executed); Assert.False(triggered); } Assert.True(triggered); Assert.False(action.Suppressed); } }
protected override void Dispose(bool disposing) { m_valueChanged.Dispose(); m_valueChanged = null; }