Beispiel #1
0
        /// <summary>
        /// Inserts the specified folder into the tree, based on its path, recursively creating
        /// container nodes where necessary.
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="depth"></param>
        /// <param name="alphabetical"></param>
        protected void InsertFolder(IFolder folder, int depth, bool alphabetical)
        {
            if (depth == folder.FolderPath.Segments.Count)
            {
                SetFolder(folder);
            }
            else
            {
                var segment = folder.FolderPath.Segments[depth];

                // find an existing node at this path point
                var node = CollectionUtils.SelectFirst(_subTree.Items,
                                                       n => Equals(n.Folder.FolderPath.Segments[depth], segment));

                var isAddingLeafNode         = (depth == folder.FolderPath.Segments.Count - 1);
                var existingNodeIsAContainer = node != null && node.Folder is ContainerFolder;

                if (node == null || (isAddingLeafNode && !existingNodeIsAContainer))
                {
                    // create the node if it doesn't exist, or if this is the leaf node
                    node = new FolderTreeNode(_explorer, this, folder.FolderPath.SubPath(0, depth + 1));
                    if (alphabetical)
                    {
                        InsertChildAlphabetical(node, depth);
                    }
                    else
                    {
                        _subTree.Items.Add(node);
                    }
                }

                node.InsertFolder(folder, depth + 1, alphabetical);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Removes the specified node from the subtree of this node, assuming the specified node is
        /// a descendant (not necessarily an immediate child) of this node.  Also removes any empty
        /// parent container nodes of the specified node.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        protected bool RemoveNode(FolderTreeNode node)
        {
            if (_subTree.Items.Contains(node))
            {
                // important to null out the folder, to unsubscribe from events, etc. before removing from the collection
                node.SetFolder(null);
                _subTree.Items.Remove(node);
                return(true);
            }

            foreach (var child in _subTree.Items)
            {
                if (!child.RemoveNode(node))
                {
                    continue;
                }

                if (child.IsEmptyContainer())
                {
                    RemoveNode(child);
                }

                return(true);
            }

            return(false);
        }
 internal DragDropKind CanFolderAcceptDrop(FolderTreeNode treeNode, object dropData, DragDropKind kind)
 {
     if (treeNode.Folder != _selectedTreeNode && dropData is ISelection)
     {
         return(treeNode.Folder.CanAcceptDrop((dropData as ISelection).Items, kind));
     }
     return(DragDropKind.None);
 }
Beispiel #4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="explorer"></param>
        /// <param name="parent"></param>
        /// <param name="path"></param>
        public FolderTreeNode(FolderExplorerComponent explorer, FolderTreeNode parent, Path path)
        {
            _explorer = explorer;
            _parent   = parent;
            _subTree  = new Tree <FolderTreeNode>(GetBinding(_explorer));

            // always start with container folder
            SetFolder(new ContainerFolder(path, true));
        }
        internal DragDropKind FolderAcceptDrop(FolderTreeNode treeNode, object dropData, DragDropKind kind)
        {
            if (treeNode.Folder != _selectedTreeNode && dropData is ISelection)
            {
                // inform the target folder to accept the drop
                var result = treeNode.Folder.AcceptDrop((dropData as ISelection).Items, kind);

                // inform the source folder that a drag was completed
                _selectedTreeNode.Folder.DragComplete((dropData as ISelection).Items, result);
            }
            return(DragDropKind.None);
        }
Beispiel #6
0
        /// <summary>
        /// Inserts the specified node alphabetically as a child of this node.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="pathDepth"></param>
        private void InsertChildAlphabetical(FolderTreeNode node, int pathDepth)
        {
            var segment = node.Folder.FolderPath.Segments[pathDepth];

            // find the insertion point - the first node greater/equalto the node to be inserted
            var insertPoint = _subTree.Items.FindIndex(
                n => n.Folder.FolderPath.Segments[pathDepth].LocalizedText.CompareTo(segment.LocalizedText) >= 0);

            if (insertPoint > -1)
            {
                _subTree.Items.Insert(insertPoint, node);
            }
            else
            {
                _subTree.Items.Add(node);
            }
        }
        private void SelectFolder(FolderTreeNode node)
        {
            if (_selectedTreeNode != node)
            {
                if (_selectedTreeNode != null)
                {
                    _selectedTreeNode.Folder.CloseFolder();
                }

                if (node != null)
                {
                    node.Folder.OpenFolder();

                    // ensure the content of this nodes folder is up to date
                    node.Update();
                }

                _selectedTreeNode = node;
                EventsHelper.Fire(_selectedFolderChanged, this, EventArgs.Empty);
            }
        }
Beispiel #8
0
		/// <summary>
		/// Inserts the specified node alphabetically as a child of this node.
		/// </summary>
		/// <param name="node"></param>
		/// <param name="pathDepth"></param>
		private void InsertChildAlphabetical(FolderTreeNode node, int pathDepth)
		{
			var segment = node.Folder.FolderPath.Segments[pathDepth];

			// find the insertion point - the first node greater/equalto the node to be inserted
			var insertPoint = _subTree.Items.FindIndex(
				n => n.Folder.FolderPath.Segments[pathDepth].LocalizedText.CompareTo(segment.LocalizedText) >= 0);

			if (insertPoint > -1)
				_subTree.Items.Insert(insertPoint, node);
			else
				_subTree.Items.Add(node);
		}
Beispiel #9
0
		/// <summary>
		/// Inserts the specified folder into the tree, based on its path, recursively creating
		/// container nodes where necessary.
		/// </summary>
		/// <param name="folder"></param>
		/// <param name="depth"></param>
		/// <param name="alphabetical"></param>
		protected void InsertFolder(IFolder folder, int depth, bool alphabetical)
		{
			if (depth == folder.FolderPath.Segments.Count)
			{
				SetFolder(folder);
			}
			else
			{
				var segment = folder.FolderPath.Segments[depth];

				// find an existing node at this path point
				var node = CollectionUtils.SelectFirst(_subTree.Items,
					n => Equals(n.Folder.FolderPath.Segments[depth], segment));

				var isAddingLeafNode = (depth == folder.FolderPath.Segments.Count - 1);
				var existingNodeIsAContainer = node != null && node.Folder is ContainerFolder;

				if (node == null || (isAddingLeafNode && !existingNodeIsAContainer))
				{
					// create the node if it doesn't exist, or if this is the leaf node
					node = new FolderTreeNode(_explorer, this, folder.FolderPath.SubPath(0, depth + 1));
					if(alphabetical)
						InsertChildAlphabetical(node, depth);
					else
						_subTree.Items.Add(node);
				}

				node.InsertFolder(folder, depth + 1, alphabetical);
			}
		}
Beispiel #10
0
		/// <summary>
		/// Removes the specified node from the subtree of this node, assuming the specified node is
		/// a descendant (not necessarily an immediate child) of this node.  Also removes any empty
		/// parent container nodes of the specified node.
		/// </summary>
		/// <param name="node"></param>
		/// <returns></returns>
		protected bool RemoveNode(FolderTreeNode node)
		{
			if (_subTree.Items.Contains(node))
			{
				// important to null out the folder, to unsubscribe from events, etc. before removing from the collection
				node.SetFolder(null);
				_subTree.Items.Remove(node);
				return true;
			}

			foreach (var child in _subTree.Items)
			{
				if (!child.RemoveNode(node))
					continue;

				if (child.IsEmptyContainer())
					RemoveNode(child);

				return true;
			}

			return false;
		}
Beispiel #11
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="explorer"></param>
		/// <param name="parent"></param>
		/// <param name="path"></param>
		public FolderTreeNode(FolderExplorerComponent explorer, FolderTreeNode parent, Path path)
		{
			_explorer = explorer;
			_parent = parent;
			_subTree = new Tree<FolderTreeNode>(GetBinding(_explorer));

			// always start with container folder
			SetFolder(new ContainerFolder(path, true));
		}