示例#1
0
 internal ExplorerObjectNode FindNode(IExplorerObject exObject)
 {
     foreach (TreeNode node in treeView.Nodes)
     {
         ExplorerObjectNode n = FindNode(node, exObject);
         if (n != null)
         {
             return(n);
         }
     }
     return(null);
 }
示例#2
0
        void CatalogTreeControl_ExplorerObjectRenamed(IExplorerObject exObject)
        {
            if (exObject == null)
            {
                return;
            }
            ExplorerObjectNode node = FindNode(exObject);

            if (node != null)
            {
                node.Text = exObject.Name;
            }
        }
示例#3
0
        private void treeView_BeforeSelect(object sender, TreeViewCancelEventArgs e)
        {
            ExplorerObjectNode node = treeView.SelectedNode as ExplorerObjectNode;

            if (node == null)
            {
                return;
            }

            if (node.ExplorerObject is IExplorerParentObject && !node.IsExpanded)
            {
                ((IExplorerParentObject)node.ExplorerObject).DiposeChildObjects();
            }
        }
示例#4
0
        internal void InsertComputerChildNodes(IExplorerObject computerObject, TreeNode computer)
        {
            //DateTime t1 = DateTime.Now;
            ManagementObjectSearcher   query      = new ManagementObjectSearcher("SELECT Name,DriveType From Win32_LogicalDisk ");
            ManagementObjectCollection collection = query.Get();

            foreach (ManagementObject manObject in collection)
            {
                DriveObject        exObject = new DriveObject(computerObject, manObject["Name"].ToString(), (uint)manObject["DriveType"]);
                ExplorerObjectNode d        = new ExplorerObjectNode(exObject, exObject.ImageIndex);
                computer.Nodes.Add(d);
            }

            //TimeSpan ts = DateTime.Now-t1;
            //MessageBox.Show(ts.TotalMilliseconds.ToString());
        }
示例#5
0
        async internal Task <IExplorerObject> AddChildNode(IExplorerObject exObject)
        {
            if (!(treeView.SelectedNode is ExplorerObjectNode) || exObject == null)
            {
                return(exObject);
            }

            ExplorerObjectNode node = treeView.SelectedNode as ExplorerObjectNode;

            if (node.ExplorerObject is IExplorerParentObject)
            {
                await((IExplorerParentObject)node.ExplorerObject).Refresh();
                foreach (IExplorerObject child in await((IExplorerParentObject)node.ExplorerObject).ChildObjects())
                {
                    if (ExObjectComparer.Equals(child, exObject))
                    {
                        exObject = child;
                        break;
                    }
                }
            }

            if (exObject is IExplorerObjectDeletable)
            {
                ((IExplorerObjectDeletable)exObject).ExplorerObjectDeleted += new ExplorerObjectDeletedEvent(CatalogTreeControl_ExplorerObjectDeleted);
            }

            if (exObject is IExplorerObjectRenamable)
            {
                ((IExplorerObjectRenamable)exObject).ExplorerObjectRenamed += new ExplorerObjectRenamedEvent(CatalogTreeControl_ExplorerObjectRenamed);
            }

            if (!node.IsExpanded)
            {
                return(exObject);
            }

            int imageIndex = gView.Explorer.UI.Framework.UI.ExplorerIcons.ImageIndex(exObject);

            node.Nodes.Add(new ExplorerObjectNode(exObject, imageIndex));

            return(exObject);
        }
示例#6
0
        private void treeView_AfterCollapse(object sender, TreeViewEventArgs e)
        {
            if (e.Node is ComputerNode)
            {
                return;
            }

            ExplorerObjectNode node = e.Node as ExplorerObjectNode;

            if (node == null || node == treeView.SelectedNode)
            {
                return;
            }

            if (node.ExplorerObject is IExplorerParentObject)
            {
                ((IExplorerParentObject)node.ExplorerObject).DiposeChildObjects();
            }
            //Cursor = Cursors.WaitCursor;
            //RemoveAndDisposeChildNodes(e.Node);
            //e.Node.Nodes.Add(new DummyNode());
            //Cursor = Cursors.Default;
        }
示例#7
0
        internal ExplorerObjectNode FindNode(TreeNode parent, IExplorerObject exObject)
        {
            if (parent == null)
            {
                return(null);
            }

            if (parent is ExplorerObjectNode &&
                ExObjectComparer.Equals(((ExplorerObjectNode)parent).ExplorerObject, exObject))
            {
                return(parent as ExplorerObjectNode);
            }

            foreach (TreeNode node in parent.Nodes)
            {
                ExplorerObjectNode n = FindNode(node, exObject);
                if (n != null)
                {
                    return(n);
                }
            }
            return(null);
        }
示例#8
0
        /*
         * private void InsertNodeElementsTask(object parameters)
         * {
         *  TreeNode treenode = (TreeNode)((object[])parameters)[0];
         *  IExplorerObject exObject = (IExplorerObject)((object[])parameters)[1];
         *
         *  IStatusBar statusbar = (_app != null) ? _app.StatusBar : null;
         *  List<ExplorerObjectNode> treeNodes = new List<ExplorerObjectNode>();
         *
         *  List<IExplorerObject> childObjects = ((IExplorerParentObject)exObject).ChildObjects;
         *  if (childObjects == null) return;
         *  int pos = 0, count = childObjects.Count;
         *  if (statusbar != null) statusbar.ProgressVisible = true;
         *
         *  foreach (IExplorerObject exObj in childObjects)
         *  {
         *      if (exObj == null ||
         *          exObj is IExplorerObjectDoubleClick) continue;
         *
         *      if (statusbar != null)
         *      {
         *          statusbar.ProgressValue = (int)(((double)pos++ / (double)count) * 100.0);
         *          statusbar.Text = exObj.Name;
         *          statusbar.Refresh();
         *      }
         *
         *      if (_filter != null)
         *      {
         *          if (_filter.Match(exObj))
         *              continue;
         *          else if (!(exObj is IExplorerParentObject)) continue;
         *      }
         *      int imageIndex = FormExplorer.ImageIndex(exObj);
         *      treeNodes.Add(new ExplorerObjectNode(exObj, imageIndex));
         *
         *      if (exObj is IExplorerObjectDeletable)
         *          ((IExplorerObjectDeletable)exObj).ExplorerObjectDeleted += new ExplorerObjectDeletedEvent(CatalogTreeControl_ExplorerObjectDeleted);
         *      if (exObj is IExplorerObjectRenamable)
         *          ((IExplorerObjectRenamable)exObj).ExplorerObjectRenamed += new ExplorerObjectRenamedEvent(CatalogTreeControl_ExplorerObjectRenamed);
         *      if (exObj is IRefreshedEventHandler)
         *          ((IRefreshedEventHandler)exObj).Refreshed += new RefreshedEventHandler(CatalogTreeControl_Refreshed);
         *  }
         *
         *  if (treenode.Nodes.Count == 0)
         *  {
         *      treenode.Nodes.Add(new DummyNode());
         *      return;
         *  }
         * }
         *
         * private delegate void InsertNodeElementsCallback(TreeNode treeNode, List<ExplorerObjectNode> childNodes);
         * private void InsertNodeElements(TreeNode treeNode, List<ExplorerObjectNode> childNodes)
         * {
         *  if (this.InvokeRequired)
         *  {
         *      this.Invoke(new InsertNodeElementsCallback(InsertNodeElements), new object[] { treeNode, childNodes });
         *  }
         *  else
         *  {
         *      foreach (ExplorerObjectNode childNode in childNodes)
         *      {
         *          treeNode.Nodes.Add(childNode);
         *      }
         *  }
         * }
         */

        async private Task <bool> InsertNodeElements(TreeNode treenode)
        {
            if (!(treenode is ExplorerObjectNode))
            {
                return(true);
            }
            ExplorerObjectNode node     = (ExplorerObjectNode)treenode;
            IExplorerObject    exObject = node.ExplorerObject;

            if (exObject == null)
            {
                return(true);
            }

            try
            {
                Cursor = Cursors.WaitCursor;

                if (exObject is IExplorerParentObject)
                {
                    //System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(InsertNodeElementsTask));
                    //thread.Start(new object[] { treenode, exObject });

                    treenode.Nodes.Clear();
                    IStatusBar             statusbar    = (_app != null) ? _app.StatusBar : null;
                    List <IExplorerObject> childObjects = await((IExplorerParentObject)exObject).ChildObjects();
                    if (childObjects == null)
                    {
                        return(false);
                    }

                    int pos = 0, count = childObjects.Count;
                    if (statusbar != null)
                    {
                        statusbar.ProgressVisible = true;
                    }

                    foreach (IExplorerObject exObj in childObjects)
                    {
                        if (exObj == null ||
                            exObj is IExplorerObjectDoubleClick)
                        {
                            continue;
                        }

                        if (statusbar != null)
                        {
                            statusbar.ProgressValue = (int)((pos++ / (double)count) * 100.0);
                            statusbar.Text          = exObj.Name;
                            statusbar.Refresh();
                        }

                        if (_filter != null)
                        {
                            if (await _filter.Match(exObj))
                            {
                                continue;
                            }
                            else if (!(exObj is IExplorerParentObject))
                            {
                                continue;
                            }
                        }
                        int imageIndex = gView.Explorer.UI.Framework.UI.ExplorerIcons.ImageIndex(exObj);
                        treenode.Nodes.Add(new ExplorerObjectNode(exObj, imageIndex));

                        if (exObj is IExplorerObjectDeletable)
                        {
                            ((IExplorerObjectDeletable)exObj).ExplorerObjectDeleted += new ExplorerObjectDeletedEvent(CatalogTreeControl_ExplorerObjectDeleted);
                        }

                        if (exObj is IExplorerObjectRenamable)
                        {
                            ((IExplorerObjectRenamable)exObj).ExplorerObjectRenamed += new ExplorerObjectRenamedEvent(CatalogTreeControl_ExplorerObjectRenamed);
                        }

                        if (exObj is IRefreshedEventHandler)
                        {
                            ((IRefreshedEventHandler)exObj).Refreshed += new RefreshedEventHandler(CatalogTreeControl_Refreshed);
                        }
                    }

                    if (statusbar != null)
                    {
                        statusbar.ProgressVisible = false;
                        statusbar.Text            = String.Empty;
                        statusbar.Refresh();
                    }
                }

                if (treenode.Nodes.Count == 0)
                {
                    treenode.Nodes.Add(new DummyNode());
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;

                MessageBox.Show(ex.Message);
                treenode.Nodes.Add(new DummyNode());
                return(false);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
示例#9
0
        internal void RemoveChildNode(IExplorerObject exObject)
        {
            if (exObject == null)
            {
                return;
            }

            TreeNode node = treeView.SelectedNode;

            if (node == null)
            {
                return;
            }

            bool removed = false;

            if (node.IsExpanded)
            {
                int index = -1;
                foreach (TreeNode n in node.Nodes)
                {
                    if (!(n is ExplorerObjectNode))
                    {
                        continue;
                    }

                    IExplorerObject ex = ((ExplorerObjectNode)n).ExplorerObject;
                    if (ex == null)
                    {
                        continue;
                    }

                    if (ExObjectComparer.Equals(ex, exObject))
                    {
                        index = node.Nodes.IndexOf(n);
                        break;
                    }
                }
                if (index != -1)
                {
                    node.Nodes.RemoveAt(index);
                    removed = true;
                }
            }
            if (removed)
            {
                if (node.Nodes.Count == 0)
                {
                    node.Nodes.Add(new DummyNode());
                    node.Collapse();
                }
            }
            else
            {
                ExplorerObjectNode exNode = FindNode(exObject);

                if (exNode != null)
                {
                    if (exNode == treeView.SelectedNode)
                    {
                        treeView.SelectedNode = treeView.SelectedNode.Parent;
                        treeView.Nodes.Remove(exNode);

                        if (treeView.SelectedNode.Nodes.Count == 0)
                        {
                            treeView.SelectedNode.Nodes.Add(new DummyNode());
                            treeView.SelectedNode.Collapse();
                        }
                    }
                    else
                    {
                        treeView.Nodes.Remove(exNode);
                    }
                }
            }
        }