void ExplorerTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            Cursor    oldCursor = this.Cursor;
            ShellItem item      = (ShellItem)e.Node.Tag;
            ShellItem shRoot    = (ShellItem)root.Tag;

            Cursor  = Cursors.WaitCursor;
            Enabled = false;
            if (!item.Equals(shRoot))
            {
                if (e.Node.Nodes.Count == 1 && e.Node.Nodes[0].Text.Equals(" : "))
                {
                    e.Node.Nodes.Clear();
                    List <ShellItem> subDirs = item.GetFolders(true);
                    TreeNode[]       nodes   = new TreeNode[subDirs.Count];
                    for (int i = 0; i < subDirs.Count; i++)
                    {
                        nodes[i] = MakeNode(subDirs[i]);
                    }
                    e.Node.Nodes.AddRange(nodes);
                }
                else
                {
                    RefreshNode(e.Node);
                }
            }
            Enabled = true;
            Cursor  = oldCursor;
        }
Exemple #2
0
        public void Uri()
        {
            string    desktopExpected     = "shell:///Desktop";
            string    myComputerExpected  = "shell:///MyComputerFolder";
            string    myDocumentsExpected = "shell:///Personal";
            ShellItem desktop1            = ShellItem.Desktop;
            ShellItem desktop2            = new ShellItem(desktopExpected);
            ShellItem myComputer          = new ShellItem(myComputerExpected);
            ShellItem myDocuments         = new ShellItem(Environment.SpecialFolder.MyDocuments);
            ShellItem myDocumentsChild    = myDocuments["GongShellTestFolder"];
            ShellItem myDocumentsChild2   = new ShellItem(myDocumentsExpected + "/GongShellTestFolder");
            ShellItem myDocumentsChild3   = new ShellItem(myDocumentsExpected + "/GongShellTestFolder/Nested");
            ShellItem cDrive       = new ShellItem(@"C:\");
            ShellItem controlPanel = new ShellItem((Environment.SpecialFolder)CSIDL.CONTROLS);

            Assert.AreEqual(desktopExpected, desktop1.ToString());
            Assert.AreEqual(desktopExpected, desktop2.ToString());
            Assert.AreEqual(myComputerExpected, myComputer.ToString());
            Assert.AreEqual(myDocumentsExpected, myDocuments.ToString());
            Assert.AreEqual(myDocumentsExpected + "/GongShellTestFolder",
                            myDocumentsChild.ToString());
            Assert.AreEqual("file:///C:/", cDrive.ToString());
            Assert.IsTrue(myDocumentsChild.Equals(myDocumentsChild2));
            Assert.AreEqual(myDocumentsExpected + "/GongShellTestFolder/Nested",
                            myDocumentsChild3.ToString());
        }
Exemple #3
0
        public void SpecialFolders()
        {
            Environment.SpecialFolder myComputerFolder =
                Environment.SpecialFolder.MyComputer;
            Environment.SpecialFolder myPicturesFolder =
                Environment.SpecialFolder.MyPictures;
            ShellItem myComputer  = new ShellItem(myComputerFolder);
            ShellItem myComputer2 = new ShellItem(myComputer.ToUri());
            ShellItem myPictures  = new ShellItem(myPicturesFolder);
            ShellItem myPictures2 = new ShellItem(myPictures.ToUri());

            Assert.IsTrue(myComputer.Equals(myComputer2));
            Assert.AreEqual(Environment.GetFolderPath(myPicturesFolder), myPictures.FileSystemPath);
            Assert.AreEqual(myPictures, myPictures2);

            try
            {
                string path = myComputer.FileSystemPath;
                Assert.Fail("FileSystemPath from virtual folder should throw exception");
            }
            catch (ArgumentException)
            {
            }
            catch (Exception)
            {
                Assert.Fail("FileSystemPath from virtual folder should throw ArgumentException");
            }
        }
Exemple #4
0
        public void Compare()
        {
            ShellItem desktop1 = ShellItem.Desktop;
            ShellItem desktop2 = new ShellItem("shell:///Desktop");
            ShellItem item1    = new ShellItem(@"C:\Program Files");
            ShellItem item2    = item1.Parent[@"Program Files"];

            Assert.IsTrue(desktop1.Equals(desktop2));
            Assert.AreEqual(item1.FileSystemPath, item2.FileSystemPath);
            Assert.IsTrue(item1 == item2);
            Assert.IsFalse(item1 != item2);
        }
        /// <summary>
        /// If selectionChange is true, the current directory is changed after a TreeNode is selected, if that happens
        /// the ListView will be cleared and filled with the contents of the new directory and the
        /// SelectedFolderChangeEvent will be raised
        /// </summary>
        void folderView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (selectionChange)
            {
                ShellItem oldItem = selectedItem;
                ShellItem newItem = e.Node.Tag as ShellItem;

                if (!ShellItem.Equals(oldItem, newItem))
                {
                    OnSelectedFolderChanged(new SelectedFolderChangedEventArgs(folderView.SelectedNode));
                }
            }
        }
Exemple #6
0
        public bool GetListItem(ShellItem shellItem, out ListViewItem listItem)
        {
            listItem = null;

            foreach (ListViewItem item in Items)
            {
                if (shellItem.Equals(item.Tag))
                {
                    listItem = item;
                    return(true);
                }
            }

            return(false);
        }
        public int DragDrop(IntPtr pDataObj, ShellAPI.MK grfKeyState, ShellAPI.POINT pt, ref DragDropEffects pdwEffect)
        {
            OnDrop(new DropEventArgs(mouseButtons, br.FileView));

            if (!((mouseButtons & ShellAPI.MK.RBUTTON) != 0 ||
                  grfKeyState == ShellAPI.MK.CONTROL ||
                  grfKeyState == ShellAPI.MK.ALT ||
                  grfKeyState == (ShellAPI.MK.CONTROL | ShellAPI.MK.SHIFT)) && ShellItem.Equals(parentDragItem, parentDropItem))
            {
                ResetDrop();
                ReleaseCom();
                pdwEffect = DragDropEffects.None;

                if (dropHelper != null)
                {
                    dropHelper.Drop(pDataObj, ref pt, pdwEffect);
                }

                return(ShellAPI.S_OK);
            }

            ResetDrop();
            if (dropTarget != null)
            {
                dropTarget.DragDrop(pDataObj, grfKeyState, pt, ref pdwEffect);

                ReleaseCom();
                dropDataObject = IntPtr.Zero;
            }

            if (dropHelper != null)
            {
                dropHelper.Drop(pDataObj, ref pt, pdwEffect);
            }

            return(ShellAPI.S_OK);
        }
Exemple #8
0
 public void EqualityTest()
 {
     using var i        = new ShellItem(testDoc);
     using var l        = new ShellLink(testLinkDoc);
     using ShellItem lt = l.Target;
     Assert.That(i == lt, Is.True);
     Assert.That(i != lt, Is.False);
     Assert.That(i.Equals(lt), Is.True);
     Assert.That(i.CompareTo(lt), Is.Zero);
     Assert.That(i.CompareTo(l), Is.Not.Zero);
     Assert.That(((IComparable <ShellItem>)i).CompareTo(lt), Is.Zero);
     Assert.That(((IComparable <ShellItem>)i).CompareTo(l), Is.Not.Zero);
     Assert.That(i.Equals(lt.IShellItem), Is.True);
     Assert.That(i.Equals(lt.Name), Is.False);
     Assert.That(i.Equals((object)null), Is.False);
     Assert.That(i.Equals((IShellItem)null), Is.False);
     Assert.That(i.Equals((ShellItem)null), Is.False);
     Assert.That(i.GetHashCode(), Is.EqualTo(lt.GetHashCode()));
 }
Exemple #9
0
        public void SpecialFolders()
        {
            Environment.SpecialFolder myComputerFolder =
                Environment.SpecialFolder.MyComputer;
            Environment.SpecialFolder myPicturesFolder =
                Environment.SpecialFolder.MyPictures;
            ShellItem myComputer = new ShellItem(myComputerFolder);
            ShellItem myComputer2 = new ShellItem(myComputer.ToUri());
            ShellItem myPictures = new ShellItem(myPicturesFolder);
            ShellItem myPictures2 = new ShellItem(myPictures.ToUri());

            Assert.IsTrue(myComputer.Equals(myComputer2));
            Assert.AreEqual(Environment.GetFolderPath(myPicturesFolder), myPictures.FileSystemPath);
            Assert.AreEqual(myPictures, myPictures2);

            try
            {
                string path = myComputer.FileSystemPath;
                Assert.Fail("FileSystemPath from virtual folder should throw exception");
            }
            catch (ArgumentException)
            {
            }
            catch (Exception)
            {
                Assert.Fail("FileSystemPath from virtual folder should throw ArgumentException");
            }
        }