Пример #1
0
        public bool Replace(Favorite oldFavorite, Favorite newFavorite)
        {
            int index = this.Children.IndexOf(oldFavorite);

            if (index >= 0)
            {
                this.Children[index] = newFavorite;
                return(true);
            }
            else
            {
                foreach (Favorite child in this.Children)
                {
                    if (child is FavoriteFolder folder &&
                        folder.Replace(oldFavorite, newFavorite))
                    {
                        return(true);
                    }
                }
                return(false);
            }
        }
        private void UpdateInsertionMark(Favorite favorite, bool before)
        {
            if (favorite != null)
            {
                TreeNode?node = this.FindTreeNodeByFavorite(favorite);
                if (node != null)
                {
                    if (before)
                    {
                        Native.PostMessage(FavoritesTree.Handle, 0x111A, (IntPtr)0, node.Handle);
                        return;
                    }
                    else
                    {
                        Native.PostMessage(FavoritesTree.Handle, 0x111A, (IntPtr)1, node.Handle);
                        return;
                    }
                }
            }

            ClearInsertionMark();
        }
Пример #3
0
        public bool InsertBefore(Favorite reference, Favorite newFavorite)
        {
            int index = this.Children.IndexOf(reference);

            if (index >= 0)
            {
                this.Children.Insert(index, newFavorite);
                return(true);
            }
            else
            {
                foreach (Favorite child in this.Children)
                {
                    if (child is FavoriteFolder folder &&
                        folder.InsertBefore(reference, newFavorite))
                    {
                        return(true);
                    }
                }
                return(false);
            }
        }
Пример #4
0
        public Favorite?BreadthFirstSearch(Func <Favorite, bool> selector)
        {
            Queue <Favorite> toSearch = new Queue <Favorite>(new[] { this });

            while (toSearch.Count > 0)
            {
                Favorite f = toSearch.Dequeue();

                if (selector(f))
                {
                    return(f);
                }

                if (f is FavoriteFolder folder)
                {
                    foreach (Favorite child in folder.Children)
                    {
                        toSearch.Enqueue(child);
                    }
                }
            }

            return(null);
        }
 private void RemoveFavorite(Favorite favorite)
 {
     _favoriteRepos?.Remove(favorite);
     Settings.Default.FavoriteRepos = _favoriteRepos !;
     Settings.Default.Save();
 }
 public FavoritesDraggingItem(Favorite favorite, bool before)
 {
     Favorite = favorite;
     Before   = before;
 }
 private TreeNode?FindTreeNodeByFavorite(Favorite findNode)
 {
     return(FindTreeNodeByFavorite(findNode, FavoritesTree.Nodes));
 }
Пример #8
0
 public bool NestedContains(Favorite favorite)
 {
     return(this.Children.Contains(favorite) ||
            this.Children.OfType <FavoriteFolder>().Any((c) => c.NestedContains(favorite)));
 }
Пример #9
0
 public FavoriteFolder?FindParent(Favorite favorite)
 {
     return(this.BreadthFirstSearch((f) => f is FavoriteFolder ff && ff.Children.Contains(favorite)) as FavoriteFolder);
 }