Exemplo n.º 1
0
        private void RemoteFolder_ChildRemoved(RemoteObject sender, RemoteFolderChildEventArgs args)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new MethodInvoker(delegate { this.RemoteFolder_ChildRemoved(sender, args); }));

                return;
            }


            var removedItem = args.Target;

            if (!mObjectsNodes.TryGetValue(removedItem.InternalId, out var nodes))
            {
                return;
            }

            //copy it, as the DeleteTreeNodes_r will change it
            var nodesArray = nodes.ToArray();

            foreach (var node in nodesArray)
            {
                DeleteTreeNodes_r(node);
            }
        }
Exemplo n.º 2
0
        private void AddNewNode(RemoteObject remoteObject, TreeNode parent)
        {
            TreeNode newNode = parent.Nodes.Add(remoteObject.Name);

            newNode.Name = newNode.Text;
            newNode.Tag  = remoteObject;

            var iconKey = remoteObject.TryGetIconName();

            if (iconKey != null)
            {
                newNode.ImageKey         = iconKey;
                newNode.SelectedImageKey = iconKey;
            }

            if (remoteObject is RemoteFolder)
            {
                var subNode = newNode.Nodes.Add("dummy");
                subNode.Tag = this;
            }
            else if (iconKey == null)
            {
                newNode.ImageKey         = DefaultIcons.FILE_GEAR_ICON;
                newNode.SelectedImageKey = DefaultIcons.FILE_GEAR_ICON;
            }

            RegisterNode(remoteObject, newNode);
        }
Exemplo n.º 3
0
        private void RemoteObject_StateChanged(RemoteObject sender, EventArgs args)
        {
            if (sender.TryGetIconName() == null)
            {
                return;
            }

            UpdateNodesIcon(sender);
        }
Exemplo n.º 4
0
        internal void OnChildDestroyed(RemoteObject child)
        {
            //if children not cached, nothing to do...
            if (mChildren == null)
            {
                return;
            }

            mChildren.Remove(child.Name);

            if (ChildRemoved != null)
            {
                var args = new RemoteFolderChildEventArgs(child);
                ChildRemoved(this, args);
            }
        }
Exemplo n.º 5
0
        private void RemoteFolder_ChildAdded(RemoteObject sender, RemoteFolderChildEventArgs args)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new MethodInvoker(delegate { this.RemoteFolder_ChildAdded(sender, args); }));
            }
            else
            {
                var addedItem = args.Target;

                if (!mObjectsNodes.TryGetValue(addedItem.ParentInternalId, out var nodes))
                {
                    return;
                }

                foreach (var node in nodes)
                {
                    AddNewNode(addedItem, node);
                }
            }
        }
Exemplo n.º 6
0
        private void UpdateNodesIcon(RemoteObject remoteObject)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new MethodInvoker(delegate { this.UpdateNodesIcon(remoteObject); }));
            }
            else
            {
                if (!mObjectsNodes.TryGetValue(remoteObject.InternalId, out var nodes))
                {
                    return;
                }

                var customIcon = remoteObject.TryGetIconName();

                foreach (var node in nodes)
                {
                    node.ImageKey         = customIcon;
                    node.SelectedImageKey = customIcon;
                }
            }
        }
Exemplo n.º 7
0
        private void RegisterNode(RemoteObject obj, TreeNode node)
        {
            if (this.InvokeRequired)
            {
                throw new InvalidOperationException("InvokeRequired");
            }

            if (!mObjectsNodes.TryGetValue(obj.InternalId, out var nodes))
            {
                nodes = new List <TreeNode>();
                mObjectsNodes.Add(obj.InternalId, nodes);

                obj.StateChanged += RemoteObject_StateChanged;

                if (obj is RemoteFolder folder)
                {
                    folder.ChildAdded   += RemoteFolder_ChildAdded;
                    folder.ChildRemoved += RemoteFolder_ChildRemoved;
                }
            }

            nodes.Add(node);
        }
Exemplo n.º 8
0
 public RemoteFolderChildEventArgs(RemoteObject target)
 {
     Target = target ?? throw new ArgumentNullException(nameof(target));
 }