예제 #1
0
        public void AddFavorites([NotNull] IEnumerable <IItem> baseItems, int index)
        {
            Assert.ArgumentNotNull(baseItems, nameof(baseItems));

            if (Items.Count == 1 && Items[0] == DummyTreeViewItem.Instance)
            {
                Expand(false);
            }

            var favorites = FavoriteManager.GetFavorites();

            if (index < 0 || index > favorites.Count())
            {
                index = favorites.Count();
            }

            foreach (var item in baseItems)
            {
                var fullPath         = item.Name;
                var itemTreeViewItem = item as ItemTreeViewItem;
                if (itemTreeViewItem != null)
                {
                    fullPath = itemTreeViewItem.GetPath();
                }

                var favorite = new Favorite
                {
                    Name           = item.Name,
                    ItemVersionUri = new ItemVersionUri(item.ItemUri, LanguageManager.CurrentLanguage, Version.Latest),
                    FullPath       = fullPath,
                    Icon           = item.Icon
                };

                favorites.Insert(index, favorite);

                var favoriteTreeViewItem = new FavoriteTreeViewItem
                {
                    Text = favorite.Name
                };

                favoriteTreeViewItem.Initialize(favorite);

                Items.Insert(index, favoriteTreeViewItem);
            }

            FavoriteManager.Save();
        }
예제 #2
0
        public override bool GetChildren(GetChildrenDelegate callback, bool async)
        {
            Assert.ArgumentNotNull(callback, nameof(callback));

            var result = new List <BaseTreeViewItem>();

            var favorites = FavoriteManager.GetFavorites();

            foreach (var favorite in favorites)
            {
                var favoriteTreeViewItem = new FavoriteTreeViewItem
                {
                    Text = favorite.Name
                };

                favoriteTreeViewItem.Initialize(favorite);

                result.Add(favoriteTreeViewItem);
            }

            callback(result);

            return(true);
        }