Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SettingsEntryList.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 using System.Collections;
5 using System.Collections.Generic;
6 using System.Collections.Specialized;
7 using System.Linq;
8 
9 using SiliconStudio.ActionStack;
10 using SiliconStudio.Core.Extensions;
11 using SiliconStudio.Core.IO;
12 using SiliconStudio.Presentation.Collections;
13 
14 namespace SiliconStudio.Presentation.Settings
15 {
16  /// <summary>
17  /// An internal object that represent a list of typed values for a settings key into a <see cref="SettingsProfile"/>.
18  /// </summary>
19  /// <typeparam name="T">The type of values contained in the list.</typeparam>
20  internal sealed class SettingsEntryList<T> : SettingsEntry
21  {
23 
24  /// <summary>
25  /// Initializes a new instance of the <see cref="SettingsEntryList{T}"/> class.
26  /// </summary>
27  /// <param name="profile">The profile this <see cref="SettingsEntryList{T}"/>belongs to.</param>
28  /// <param name="name">The name associated to this <see cref="SettingsEntryList{T}"/>.</param>
29  /// <param name="listItems">The items to associate to this <see cref="SettingsEntryList{T}"/>.</param>
30  public SettingsEntryList(SettingsProfile profile, UFile name, IEnumerable listItems)
31  : base(profile, name)
32  {
33  if (listItems == null) throw new ArgumentNullException("listItems");
34  listItems.Cast<object>().ForEach(x => items.Add(x));
35  Value = items;
36  items.CollectionChanged += CollectionChanged;
37  ShouldNotify = true;
38  }
39 
40  /// <inheritdoc/>
41  internal override object GetSerializableValue()
42  {
43  return new List<object>(items.Cast<object>().Select(x => x != null ? x.ToString() : null));
44  }
45 
46  private void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
47  {
48  if (!Profile.IsDiscarding)
49  {
50  var action = new CollectionChangedActionItem(items, e);
51  Profile.ActionStack.Add(action);
52  Profile.NotifyEntryChanged(Name);
53  }
54  }
55  }
56 }
A class that wraps an instance of the ObservableList{T} class and implement the IList interface...
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Definition: UFile.cs:13