コード例 #1
0
        public void TestAutoUpdatingSortedObservableCollection()
        {
            var collection = new AutoUpdatingSortedObservableCollection <Dummy> {
                new Dummy("sss"), new Dummy("eee")
            };

            var dummy = new Dummy("ggg");

            collection.Add(dummy);

            var sorted = new[] { "eee", "ggg", "sss" };

            for (int i = 0; i < collection.Count; ++i)
            {
                Assert.That(collection[i].Name == sorted[i]);
                Assert.That(collection.BinarySearch(sorted[i], (d, s) => String.Compare(d.Name, s, StringComparison.Ordinal)) == i);
            }

            dummy.Name = "aaa";
            sorted     = new[] { "aaa", "eee", "sss" };
            for (int i = 0; i < collection.Count; ++i)
            {
                Assert.That(collection[i].Name == sorted[i]);
                Assert.That(collection.BinarySearch(sorted[i], (d, s) => String.Compare(d.Name, s, StringComparison.Ordinal)) == i);
            }

            dummy.Name = "zzz";
            sorted     = new[] { "eee", "sss", "zzz" };
            for (int i = 0; i < collection.Count; ++i)
            {
                Assert.That(collection[i].Name == sorted[i]);
                Assert.That(collection.BinarySearch(sorted[i], (d, s) => String.Compare(d.Name, s, StringComparison.Ordinal)) == i);
            }
        }
コード例 #2
0
ファイル: TestCore.cs プロジェクト: Kryptos-FR/xenko-reloaded
        public void TestAutoUpdatingSortedObservableCollection()
        {
            var collection = new AutoUpdatingSortedObservableCollection<Dummy> { new Dummy("sss"), new Dummy("eee") };

            var dummy = new Dummy("ggg");
            collection.Add(dummy);

            var sorted = new[] { "eee", "ggg", "sss" };

            for (int i = 0; i < collection.Count; ++i)
            {
                Assert.That(collection[i].Name == sorted[i]);
                Assert.That(collection.BinarySearch(sorted[i], (d, s) => String.Compare(d.Name, s, StringComparison.Ordinal)) == i);
            }

            dummy.Name = "aaa";
            sorted = new[] { "aaa", "eee", "sss" };
            for (int i = 0; i < collection.Count; ++i)
            {
                Assert.That(collection[i].Name == sorted[i]);
                Assert.That(collection.BinarySearch(sorted[i], (d, s) => String.Compare(d.Name, s, StringComparison.Ordinal)) == i);
            }

            dummy.Name = "zzz";
            sorted = new[] { "eee", "sss", "zzz" };
            for (int i = 0; i < collection.Count; ++i)
            {
                Assert.That(collection[i].Name == sorted[i]);
                Assert.That(collection.BinarySearch(sorted[i], (d, s) => String.Compare(d.Name, s, StringComparison.Ordinal)) == i);
            }
        }
コード例 #3
0
        protected EntityHierarchyItemViewModel([NotNull] EntityHierarchyEditorViewModel editor, [NotNull] EntityHierarchyViewModel asset, [NotNull] IEnumerable <EntityDesign> childEntities)
            : base(editor, asset)
        {
            if (childEntities == null)
            {
                throw new ArgumentNullException(nameof(childEntities));
            }

            // note: we want to ignore case and diacritics (e.g. accentuation) when sorting the folders
            Folders = new AutoUpdatingSortedObservableCollection <EntityFolderViewModel>((x, y) => string.Compare(x.Name, y.Name, StringComparison.InvariantCultureIgnoreCase));

            // Note: we make sure that empty folders and null folders are grouped together
            // TODO: implement a more robust folder grouping method that trims, etc.
            // TODO: also ensure that empty folder are serialized as null (or vice-versa) to avoid this kind of issue
            foreach (var folderGroup in childEntities.GroupBy(x => !string.IsNullOrWhiteSpace(x.Folder) ? x.Folder : null).OrderBy(x => x.Key))
            {
                if (!EntityFolderViewModel.GenerateFolder(this, folderGroup.Key, folderGroup))
                {
                    foreach (var child in folderGroup)
                    {
                        var viewModel = (EntityViewModel)Editor.CreatePartViewModel(Asset, child);
                        subEntities.Add(viewModel);
                    }
                }
            }

            AddItems(Folders);
            AddItems(subEntities);

            // We register the collection changed handler after having added already-existing children
            Folders.CollectionChanged     += FolderCollectionChanged;
            subEntities.CollectionChanged += SubEntityCollectionChanged;

            // Add policies for adding/inserting assets
            // TODO: make it work with plugins (discovery, registration, override...)
            addAssetPolicies = new List <IAddAssetPolicy>
            {
                new AddModelAssetPolicy <ModelAsset>(),
                new AddModelAssetPolicy <PrefabModelAsset>(),
                new AddModelAssetPolicy <ProceduralModelAsset>(),
                new AddPrefabAssetPolicy(),
                new AddSceneAssetPolicy(),
                new AddScriptSourceFileAssetPolicy(),
                new AddSpriteSheetAssetPolicy(),
                new AddSpriteStudioModelAssetPolicy(),
                new AddTextureAssetPolicy(),
                new AddVideoAssetPolicy(),
                new AddUIPageAssetPolicy(),
            };
        }