Пример #1
0
        /// <summary>
        /// When a new directory is selected, this method is called to clear the ListView and fill it with
        /// the contents of the new directory
        /// </summary>
        /// <param name="oldItem">The ShellItem of the previous selected directory</param>
        /// <param name="newItem">The ShellItem of the new selected directory</param>
        private bool SetNewPath(ShellItem oldItem, ShellItem newItem)
        {
            Cursor.Current = Cursors.WaitCursor;

            if (oldItem != newItem && newItem.Expand(true, false, Handle))
            {
                ShellBrowserComponent.UpdateCondition.ContinueUpdate = false;

                fileView.BeginUpdate();
                fileView.Items.Clear();
                fileView.ClearSelections();

                if (oldItem != null)
                {
                    bool used = false;
                    foreach (ShellBrowser br in ShellBrowserComponent.Browsers)
                    {
                        if (!this.Equals(br) && oldItem.Equals(br.CurrentDirectory))
                        {
                            used = true;
                            break;
                        }
                    }

                    if (!used)
                        oldItem.Clear(true, false);
                }

                currentDirectory = newItem;

                ListViewItem[] newListItemsArray = new ListViewItem[newItem.Count];
                string[] subItems = new string[fileView.Columns.Count - 1];
                for (int i = 0; i < newListItemsArray.Length; i++)
                {
                    newListItemsArray[i] = GetListViewItem(subItems, newItem[i]);
                }
                fileView.SetSorting(true);
                fileView.Items.AddRange(newListItemsArray);
                fileView.SetSorting(false);

                fileView.EndUpdate();

                Cursor.Current = Cursors.Default;
                return true;
            }
            else
            {
                Cursor.Current = Cursors.Default;
                return (oldItem == newItem);
            }
        }
Пример #2
0
        public static string GetRealPath(ShellItem item)
        {
            if (item.Equals(item.browser.DesktopItem))
            {
                return "::{450d8fba-ad25-11d0-98a8-0800361b1103}";
            }
            else if (item.Type == item.Browser.SystemFolderName)
            {
                IntPtr strr = Marshal.AllocCoTaskMem(NativeShellAPI.MAX_PATH * 2 + 4);
                Marshal.WriteInt32(strr, 0, 0);
                StringBuilder buf = new StringBuilder(NativeShellAPI.MAX_PATH);

                if (item.ParentItem.ShellFolder.GetDisplayNameOf(
                                item.PIDLRel.Ptr,
                                NativeShellAPI.SHGNO.FORPARSING,
                                strr) == NativeShellAPI.S_OK)
                {
                    NativeShellAPI.StrRetToBuf(strr, item.PIDLRel.Ptr, buf, NativeShellAPI.MAX_PATH);
                }

                Marshal.FreeCoTaskMem(strr);

                return buf.ToString();
            }
            else
                return item.Path;
        }
Пример #3
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;
        }