/// <summary>
        /// Initialises the base ShellItems, including the Desktop and all it's children and the children of My Computer.
        /// These items are also added to the TreeView and the navigation bar.
        /// </summary>
        private void InitBaseItems()
        {
            if (ShellBrowser == null)
            {
                ShellBrowser = new ShellBrowser();
            }

            desktopNode = new TreeNode(
                ShellBrowser.DesktopItem.Text,
                ShellBrowser.DesktopItem.ImageIndex,
                ShellBrowser.DesktopItem.SelectedImageIndex);
            desktopNode.Tag  = ShellBrowser.DesktopItem;
            desktopNode.Name = desktopNode.Text;

            folderView.Nodes.Add(desktopNode);

            selectedNode = desktopNode;
            selectedItem = ShellBrowser.DesktopItem;

            ShellBrowser.DesktopItem.Expand(false, true, IntPtr.Zero);

            foreach (ShellItem desktopChild in ShellBrowser.DesktopItem.SubFolders)
            {
                TreeNode desktopChildNode = new TreeNode(
                    desktopChild.Text,
                    desktopChild.ImageIndex,
                    desktopChild.SelectedImageIndex);
                desktopChildNode.Tag  = desktopChild;
                desktopChildNode.Name = desktopChildNode.Text;

                if (desktopChildNode.Text == ShellBrowser.MyComputerName)
                {
                    myCompNode = desktopChildNode;
                    desktopChild.Expand(false, true, IntPtr.Zero);

                    foreach (ShellItem myCompChild in desktopChild.SubFolders)
                    {
                        TreeNode myCompChildNode = new TreeNode(
                            myCompChild.Text,
                            myCompChild.ImageIndex,
                            myCompChild.SelectedImageIndex);
                        myCompChildNode.Tag  = myCompChild;
                        myCompChildNode.Name = myCompChildNode.Text;

                        if (myCompChild.HasSubfolder)
                        {
                            myCompChildNode.Nodes.Add(string.Empty);
                        }

                        desktopChildNode.Nodes.Add(myCompChildNode);
                    }
                }
                else if (desktopChild.HasSubfolder)
                {
                    desktopChildNode.Nodes.Add(string.Empty);
                }

                desktopNode.Nodes.Add(desktopChildNode);
            }
        }
Beispiel #2
0
 protected override Rectangle GetFocusedItemRect()
 {
     if (HasFocus())
     {
         int code = ShellBrowser.ViewMode == FVM.DETAILS ? LVIR.LABEL : LVIR.BOUNDS;
         return(GetItemRect(ShellBrowser.GetFocusedIndex(), code).ToRectangle());
     }
     return(new Rectangle(0, 0, 0, 0));
 }
        /// <summary>
        /// Registers the neccesairy events
        /// </summary>
        /// <param name="br">The browser for which to support the ContextMenu</param>
        public BrowserTVContextMenuWrapper(ShellBrowser br)
        {
            this.br = br;

            br.FolderView.MouseUp += new System.Windows.Forms.MouseEventHandler(FolderView_MouseUp);
            br.FolderView.AfterLabelEdit += new NodeLabelEditEventHandler(FolderView_AfterLabelEdit);
            br.FolderView.BeforeLabelEdit += new NodeLabelEditEventHandler(FolderView_BeforeLabelEdit);
            br.FolderView.KeyDown += new KeyEventHandler(FolderView_KeyDown);

            this.CreateHandle(new CreateParams());
        }
Beispiel #4
0
        /// <summary>
        /// Registers the TreeView for drag/drop operations and uses this class as the IDropTarget
        /// </summary>
        /// <param name="br">The browser for which to support the drop</param>
        public BrowserTVDropWrapper(ShellBrowser br)
        {
            this.br = br;

            treeViewHandle = br.FolderView.Handle;
            NativeShellAPI.RegisterDragDrop(treeViewHandle, this);

            br.FolderView.HandleCreated   += new EventHandler(FolderView_HandleCreated);
            br.FolderView.HandleDestroyed += new EventHandler(FolderView_HandleDestroyed);

            ShellHelper.GetIDropTargetHelper(out dropHelperPtr, out dropHelper);
        }
        /// <summary>
        /// Registers the TreeView for drag/drop operations and uses this class as the IDropTarget
        /// </summary>
        /// <param name="br">The browser for which to support the drop</param>
        public BrowserTVDropWrapper(ShellBrowser br)
        {
            this.br = br;

            treeViewHandle = br.FolderView.Handle;
            NativeShellAPI.RegisterDragDrop(treeViewHandle, this);

            br.FolderView.HandleCreated += new EventHandler(FolderView_HandleCreated);
            br.FolderView.HandleDestroyed += new EventHandler(FolderView_HandleDestroyed);

            ShellHelper.GetIDropTargetHelper(out dropHelperPtr, out dropHelper);
        }
Beispiel #6
0
        //[Test]
        public void CreateTest()
        {
            var form = new System.Windows.Forms.Form()
            {
                Size = new System.Drawing.Size(200, 200)
            };
            var shvw = new ShellBrowser()
            {
                Dock = System.Windows.Forms.DockStyle.Fill
            };

            shvw.BrowseObject(new ShellFolder(TestCaseSources.TempDir).PIDL.DangerousGetHandle(), SBSP.SBSP_ABSOLUTE);
            form.Controls.Add(shvw);
            form.ShowDialog();
        }
        private void shellListView1_AddItem(object sender, Shell.AddItemEventArgs e)
        {
            // get the path length
            string lLength = e.Item.FullPath.Length.ToString();

            // add the path length as subitem
            e.Item.SubItems.Add(lLength);

            // check whether the item is a link
            // note: the next few lines are just used for illustrative purposes.
            // the retrieval of the link target may take some time for large file lists
            string lLinkTarget = ShellBrowser.GetLinkTarget(e.Item.FullPath);

            // add the link target as subitem (if it`s not a link, an empty string was returned)
            e.Item.SubItems.Add(lLinkTarget);
        }
Beispiel #8
0
        public override bool IsTrackingItemName()
        {
            if (ShellBrowser.ViewMode == FVM.DETAILS)
            {
                return(true);
            }
            if (ShellBrowser.GetItemCount() == 0)
            {
                return(false);
            }
            RECT  rect          = PInvoke.ListView_GetItemRect(ListViewController.Handle, 0, 0, 2);
            Point mousePosition = Control.MousePosition;

            PInvoke.MapWindowPoints(IntPtr.Zero, ListViewController.Handle, ref mousePosition, 1);
            return((Math.Min(rect.left, rect.right) <= mousePosition.X) && (mousePosition.X <= Math.Max(rect.left, rect.right)));
        }
        /// <summary>
        /// Selects a path from an existing ShellItem, this ShellItem must be present in the browsers
        /// ShellBrowser, otherwise it can't be selected.
        /// </summary>
        /// <param name="specialFolder">The ShellItem to select</param>
        /// <returns>The TreeNode of the directory which was selected, this will be null if the directory
        /// doesn't exist</returns>
        public TreeNode SelectPath(ShellItem item, bool expandNode)
        {
            if (item == null)
            {
                return(null);
            }

            ShellItem[] path = ShellBrowser.GetPath(item);

            if (path != null)
            {
                TreeNode currentNode = desktopNode;
                for (int i = 1; i < path.Length; i++)
                {
                    ExtendTreeNode(currentNode, false);
                    foreach (TreeNode subNode in currentNode.Nodes)
                    {
                        if (path[i].Equals(subNode.Tag))
                        {
                            currentNode = subNode;
                            break;
                        }
                    }
                }

                if (expandNode)
                {
                    currentNode.Expand();
                }

                folderView.SelectedNode = currentNode;

                return(currentNode);
            }
            else
            {
                return(null);
            }
        }
Beispiel #10
0
        public override void BuildDialogControls(IVaultDialog dialog, IVaultDialogTab tab)
        {
            // File dialog emulation

            var shellBrowser = new ShellBrowser();

            shellBrowser.Dock              = DockStyle.Fill;
            shellBrowser.ListViewMode      = View.List;
            shellBrowser.Multiselect       = false;
            shellBrowser.ShowFolders       = false;
            shellBrowser.ShowFoldersButton = true;

            var lbFileName = new Label {
                Text = Resources.Dialogs_BrowseForFile_FileNameLabel, Padding = new Padding(2, 7, 5, 3)
            };
            var tbFileName = new TextBox()
            {
                Dock = DockStyle.Fill
            };
            var pn1 = new Panel()
            {
                Dock = DockStyle.Left
            };

            pn1.Controls.Add(lbFileName);
            pn1.Width = 70;
            var pn2 = new Panel()
            {
                Dock = DockStyle.Fill, Padding = new Padding(5, 5, 2, 5)
            };

            pn2.Controls.Add(tbFileName);

            var pnFileName = new Panel()
            {
                Dock = DockStyle.Bottom
            };

            pnFileName.Controls.Add(pn2);
            pnFileName.Controls.Add(pn1);
            pnFileName.Height = tbFileName.Height + 10;
            var pnShellBrowser = new Panel()
            {
                Dock = DockStyle.Fill
            };

            pnShellBrowser.Controls.Add(shellBrowser);
            tab.TabPage.Controls.Add(pnShellBrowser);
            tab.TabPage.Controls.Add(pnFileName);

            Action refreshTextBox = () =>
            {
                var shellItem = shellBrowser.SelectedItem;
                tbFileName.Text = shellItem == null ? String.Empty : shellItem.Text;
            };

            shellBrowser.FileView.SelectedIndexChanged += (o, e) => refreshTextBox();
            shellBrowser.FolderView.AfterSelect        += (o, e) => refreshTextBox();

            // Ensuring consistent OK button availability

            Action refreshOkAvailability = () =>
            {
                var shellItem = shellBrowser.SelectedItem;
                var fileName  = tbFileName.Text;

                if (fileName == (shellItem == null ? String.Empty : shellItem.Text) ||
                    fileName == (shellItem == null ? String.Empty : shellItem.Path))
                {
                    // filename in the text box corresponds to selected file/dir
                    dialog.OkButton.Enabled = shellItem != null && shellItem.IsFileSystem && !shellItem.IsFolder && !shellItem.IsLink;
                }
                else
                {
                    dialog.OkButton.Enabled = fileName.IsNeitherNullNorEmpty();
                }
            };

            dialog.TabActivated    += (o, e) => refreshOkAvailability();
            tbFileName.TextChanged += (o, e) => refreshOkAvailability();

            // Processing file selection: via OK, via ENTER, or via double-click on a file

            Action <String> processSelectFile = fpath =>
            {
                var resolved = fpath.ResolveShellPathAsFileSystemPath(shellBrowser);
                if (resolved == null)
                {
                    MessageBox.Show(
                        Resources.Dialogs_BrowseForFile_NotAFileSystemLocation_Message,
                        Resources.Dialogs_BrowseForFile_NotAFileSystemLocation_Title,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
                else
                {
                    // the logic below only accepts full paths
                    Path.IsPathRooted(resolved).AssertTrue();

                    if (Directory.Exists(resolved))
                    {
                        MessageBox.Show(
                            Resources.Dialogs_BrowseForFile_FolderIsNotValidHere_Message,
                            Resources.Dialogs_BrowseForFile_FolderIsNotValidHere_Title,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                    else
                    {
                        // remember directory-container of the selected file
                        AppDomain.CurrentDomain.SetData(this.GetType().FullName, resolved);

                        if (dialog.Action == VaultAction.Create ||
                            dialog.Action == VaultAction.Export)
                        {
                            if (File.Exists(resolved))
                            {
                                if (MessageBox.Show(
                                        Resources.VaultFormat_ExistingFileBasedVault_Message,
                                        Resources.VaultFormat_ExistingFileBasedVault_Title,
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Exclamation) == DialogResult.Yes)
                                {
                                    File.Delete(resolved);
                                }
                                else
                                {
                                    return;
                                }
                            }
                            else
                            {
                                var parentDir = Path.GetDirectoryName(resolved);
                                parentDir.EnsureDirectoryExists();
                                // the file itself will be created by vault logic
                            }

                            IVault vault;
                            var    dialogForm = tab.TabPage.Parent.Parent.Parent;
                            var    oldCursor  = dialogForm.Cursor;
                            dialogForm.Cursor = Cursors.WaitCursor;

                            try
                            {
                                vault = OpenCore(resolved);
                            }
                            finally
                            {
                                dialogForm.Cursor = oldCursor;
                            }

                            if (vault != null)
                            {
                                dialog.EndDialog(vault);
                            }
                        }
                        else if (dialog.Action == VaultAction.Open ||
                                 dialog.Action == VaultAction.Import)
                        {
                            if (!File.Exists(resolved))
                            {
                                MessageBox.Show(
                                    Resources.Dialogs_BrowseForFile_FileDoesNotExist_Message,
                                    Resources.Dialogs_BrowseForFile_FileDoesNotExist_Title,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                            }
                            else
                            {
                                IVault vault;
                                var    dialogForm = tab.TabPage.Parent.Parent.Parent;
                                var    oldCursor  = dialogForm.Cursor;
                                dialogForm.Cursor = Cursors.WaitCursor;

                                try
                                {
                                    vault = OpenCore(resolved);
                                }
                                finally
                                {
                                    dialogForm.Cursor = oldCursor;
                                }

                                if (vault != null)
                                {
                                    dialog.EndDialog(vault);
                                }
                            }
                        }
                        else
                        {
                            AssertionHelper.Fail();
                        }
                    }
                }
            };

            // ENTER over the filename textbox
            tbFileName.KeyDown += (o, e) =>
            {
                if (e.KeyCode == Keys.Enter && !e.Alt && !e.Shift && !e.Control)
                {
                    processSelectFile(tbFileName.Text);
                }
            };

            // OK click
            dialog.OkButton.Click += (o, e) =>
            {
                if (dialog.ActiveTab == tab)
                {
                    processSelectFile(tbFileName.Text);
                }
            };

            // double-click or ENTER over the files list
            Action onValidItemActivated = () =>
            {
                var shellItem = shellBrowser.SelectedItem;
                shellItem.AssertNotNull();
                shellItem.IsFileSystem.AssertTrue();
                shellItem.IsFolder.AssertFalse();
                shellItem.IsLink.AssertFalse();

                processSelectFile(shellItem.Text);
            };

            // Stuff that needs to be run on after the handle is created

            shellBrowser.HandleCreated += (o, e) =>
            {
                // loads startup dir from appdomain-wide history
                var prevFile   = (String)AppDomain.CurrentDomain.GetData(this.GetType().FullName);
                var startupDir = Path.GetDirectoryName(prevFile);
                if (!Directory.Exists(startupDir))
                {
                    startupDir = null;
                }
                startupDir = startupDir ?? shellBrowser.ShellBrowserComponent.MyDocumentsPath;
                shellBrowser.SelectPath(startupDir, false);

                // selects previously selected file in the file view...
                var match = shellBrowser.FileView.Items.Cast <ListViewItem>().SingleOrDefaultDontCrash(lvi =>
                {
                    var si = lvi.Tag.AssertCast <ShellItem>();
                    return(si.Text.ResolveShellPathAsFileSystemPath(shellBrowser) == prevFile);
                });

                // ...if it still exists
                if (match != null)
                {
                    match.Selected = true;
                }

                // remember all changes of current directory
                Action storeCurrentDirInAppDomain = () =>
                {
                    var currentDir = ".".ResolveShellPathAsFileSystemPath(shellBrowser);
                    AppDomain.CurrentDomain.SetData(this.GetType().FullName, Path.Combine(currentDir, "aux"));
                };

                shellBrowser.FileView.SelectedIndexChanged += (o1, e1) => storeCurrentDirInAppDomain();
                shellBrowser.FolderView.AfterSelect        += (o1, e1) => storeCurrentDirInAppDomain();

                // make sure that double-clicking on a file doesn't open associated application
                // but just selects that file instead
                var fv             = shellBrowser.fileView;
                var itemActivate   = typeof(ListView).GetEvent("ItemActivate");
                var invocationList = itemActivate.GetInvocationList(fv);
                itemActivate.ClearInvocationList(fv);
                fv.ItemActivate += (o1, e1) =>
                {
                    refreshOkAvailability();
                    if (dialog.OkButton.Enabled)
                    {
                        onValidItemActivated();
                    }
                    else
                    {
                        invocationList.ForEach(d => d.DynamicInvoke(o1, e1));
                    }
                };
            };
        }
Beispiel #11
0
        protected override bool OnShellViewNotify(NMHDR nmhdr, ref Message msg)
        {
            // Process WM.NOTIFY.  These are all notifications from the
            // SysListView32 control.  We will not get ANY of these on
            // Windows 7, which means every single one of them has to
            // have an alternative somewhere for the ItemsView control,
            // or it's not going to happen.
            switch (nmhdr.code)
            {
            case -12:     // NM_CUSTOMDRAW
                // This is for drawing alternating row colors.  I doubt
                // very much we'll find an alternative for this...
                return(HandleCustomDraw(ref msg));

            case LVN.ITEMCHANGED: {
                // There are two things happening here.
                // 1. Notify plugins of selection changing: Handled through
                //    undocumented WM_USER+163 message
                // 2. Redraw for Full Row Select: Not happening

                /*
                 *  // TODO
                 *
                 *  IntPtr ptr;
                 *  if(QTUtility.instanceManager.TryGetButtonBarHandle(this.hwndExplorer, out ptr)) {
                 *      QTUtility2.SendCOPYDATASTRUCT(ptr, (IntPtr)13, null, (IntPtr)GetItemCount());
                 *  }
                 */
                bool       flag        = !QTUtility.IsXP && QTUtility.CheckConfig(Settings.ToggleFullRowSelect);
                NMLISTVIEW nmlistview2 = (NMLISTVIEW)Marshal.PtrToStructure(msg.LParam, typeof(NMLISTVIEW));
                if (nmlistview2.uChanged == 8 /*LVIF_STATE*/)
                {
                    uint num5  = nmlistview2.uNewState & LVIS.SELECTED;
                    uint num6  = nmlistview2.uOldState & LVIS.SELECTED;
                    uint num7  = nmlistview2.uNewState & LVIS.DROPHILITED;
                    uint num8  = nmlistview2.uOldState & LVIS.DROPHILITED;
                    uint num9  = nmlistview2.uNewState & LVIS.CUT;
                    uint num10 = nmlistview2.uOldState & LVIS.CUT;
                    if (flag)
                    {
                        if (nmlistview2.iItem != -1 && ((num5 != num6) || (num7 != num8) || (num9 != num10)) && ShellBrowser.ViewMode == FVM.DETAILS)
                        {
                            PInvoke.SendMessage(nmlistview2.hdr.hwndFrom, LVM.REDRAWITEMS, (IntPtr)nmlistview2.iItem, (IntPtr)nmlistview2.iItem);
                        }
                    }
                    if (num5 != num6)
                    {
                        OnSelectionChanged();
                    }
                }
                break;
            }

            case LVN.INSERTITEM:
            case LVN.DELETEITEM:
                // Handled through undocumented WM_USER+174 message
                if (!QTUtility.CheckConfig(Settings.NoShowSubDirTips))
                {
                    HideSubDirTip(1);
                }
                if (QTUtility.CheckConfig(Settings.AlternateRowColors) && (ShellBrowser.ViewMode == FVM.DETAILS))
                {
                    PInvoke.InvalidateRect(nmhdr.hwndFrom, IntPtr.Zero, true);
                }
                ShellViewController.DefWndProc(ref msg);
                OnItemCountChanged();
                return(true);

            case LVN.BEGINDRAG:
                // This won't be necessary it seems.  On Windows 7, when you
                // start to drag, a MOUSELEAVE message is sent, which hides
                // the SubDirTip anyway.
                ShellViewController.DefWndProc(ref msg);
                HideSubDirTip(0xff);
                return(true);

            case LVN.ITEMACTIVATE: {
                // Handled by catching Double Clicks and Enter keys.  Ugh...
                NMITEMACTIVATE nmitemactivate = (NMITEMACTIVATE)Marshal.PtrToStructure(msg.LParam, typeof(NMITEMACTIVATE));
                Keys           modKeys        =
                    (((nmitemactivate.uKeyFlags & 1) == 1) ? Keys.Alt : Keys.None) |
                    (((nmitemactivate.uKeyFlags & 2) == 2) ? Keys.Control : Keys.None) |
                    (((nmitemactivate.uKeyFlags & 4) == 4) ? Keys.Shift : Keys.None);
                if (OnItemActivated(modKeys))
                {
                    return(true);
                }
                break;
            }

            case LVN.ODSTATECHANGED:
                // FullRowSelect doesn't look possible anyway, so whatever.
                if (!QTUtility.IsXP && QTUtility.CheckConfig(Settings.ToggleFullRowSelect))
                {
                    NMLVODSTATECHANGE nmlvodstatechange = (NMLVODSTATECHANGE)Marshal.PtrToStructure(msg.LParam, typeof(NMLVODSTATECHANGE));
                    if (((nmlvodstatechange.uNewState & 2) == 2) && (ShellBrowser.ViewMode == FVM.DETAILS))
                    {
                        PInvoke.SendMessage(nmlvodstatechange.hdr.hwndFrom, LVM.REDRAWITEMS, (IntPtr)nmlvodstatechange.iFrom, (IntPtr)nmlvodstatechange.iTo);
                    }
                }
                break;

            case LVN.HOTTRACK:
                // Handled through WM_MOUSEMOVE.
                if (QTUtility.CheckConfig(Settings.ShowTooltipPreviews) || !QTUtility.CheckConfig(Settings.NoShowSubDirTips))
                {
                    NMLISTVIEW nmlistview = (NMLISTVIEW)Marshal.PtrToStructure(msg.LParam, typeof(NMLISTVIEW));
                    int        iItem      = CorrectHotItem(nmlistview.iItem);
                    if (iHotItem != iItem)
                    {
                        OnHotItemChanged(iItem);
                        iHotItem = iItem;
                    }
                }
                break;

            case LVN.KEYDOWN: {
                // Handled through WM_KEYDOWN.
                NMLVKEYDOWN nmlvkeydown = (NMLVKEYDOWN)Marshal.PtrToStructure(msg.LParam, typeof(NMLVKEYDOWN));
                if (OnKeyDown((Keys)nmlvkeydown.wVKey))
                {
                    msg.Result = (IntPtr)1;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            case LVN.GETINFOTIP: {
                // Handled through WM_NOTIFY / TTN_NEEDTEXT
                NMLVGETINFOTIP nmlvgetinfotip = (NMLVGETINFOTIP)Marshal.PtrToStructure(msg.LParam, typeof(NMLVGETINFOTIP));
                return(OnGetInfoTip(nmlvgetinfotip.iItem, GetHotItem() != nmlvgetinfotip.iItem));    // TODO there's got to be a better way.
            }

            case LVN.BEGINLABELEDIT:
                // This is just for file renaming, which there's no need to
                // mess with in Windows 7.
                ShellViewController.DefWndProc(ref msg);
                if (QTUtility.IsXP && !QTUtility.CheckConfig(Settings.ExtWhileRenaming))
                {
                    NMLVDISPINFO nmlvdispinfo = (NMLVDISPINFO)Marshal.PtrToStructure(msg.LParam, typeof(NMLVDISPINFO));
                    if (nmlvdispinfo.item.lParam != IntPtr.Zero)
                    {
                        using (IDLWrapper idl = ShellBrowser.ILAppend(nmlvdispinfo.item.lParam)) {
                            OnFileRename(idl);
                        }
                    }
                }
                break;

            case LVN.ENDLABELEDIT: {
                // TODO
                NMLVDISPINFO nmlvdispinfo2 = (NMLVDISPINFO)Marshal.PtrToStructure(msg.LParam, typeof(NMLVDISPINFO));
                OnEndLabelEdit(nmlvdispinfo2.item);
                break;
            }
            }
            return(false);
        }
Beispiel #12
0
 private int CorrectHotItem(int iItem)
 {
     if (QTUtility.IsXP && iItem == -1 && ShellBrowser.ViewMode == FVM.DETAILS && ShellBrowser.GetItemCount() > 0)
     {
         RECT  rect          = GetItemRect(0, LVIR.LABEL);
         Point mousePosition = Control.MousePosition;
         PInvoke.ScreenToClient(Handle, ref mousePosition);
         int minX = Math.Min(rect.left, rect.right);
         int maxX = Math.Max(rect.left, rect.right);
         if (minX <= mousePosition.X && mousePosition.X <= maxX)
         {
             iItem = HitTest(new Point(minX + 2, mousePosition.Y), false);
         }
     }
     return(iItem);
 }
Beispiel #13
0
        protected override bool HandleCursorLoop(Keys key)
        {
            int focusedIdx = ShellBrowser.GetFocusedIndex();
            int itemCount  = ShellBrowser.GetItemCount();
            int selectMe   = -1;
            int viewMode   = ShellBrowser.ViewMode;

            if (viewMode == FVM.TILE && QTUtility.IsXP)
            {
                viewMode = FVM.ICON;
            }
            switch (viewMode)
            {
            case FVM.CONTENT:
            case FVM.DETAILS:
            case FVM.TILE:
                if (key == Keys.Up && focusedIdx == 0)
                {
                    selectMe = itemCount - 1;
                }
                else if (key == Keys.Down && focusedIdx == itemCount - 1)
                {
                    selectMe = 0;
                }
                break;

            case FVM.ICON:
            case FVM.SMALLICON:
            case FVM.THUMBNAIL:
            case FVM.LIST:
                Keys   KeyNextItem, KeyPrevItem, KeyNextPage, KeyPrevPage;
                IntPtr MsgNextPage, MsgPrevPage;
                if (viewMode == FVM.LIST)
                {
                    KeyNextItem = Keys.Down;
                    KeyPrevItem = Keys.Up;
                    KeyNextPage = Keys.Right;
                    KeyPrevPage = Keys.Left;
                    MsgNextPage = (IntPtr)LVNI.TORIGHT;
                    MsgPrevPage = (IntPtr)LVNI.TOLEFT;
                }
                else
                {
                    KeyNextItem = Keys.Right;
                    KeyPrevItem = Keys.Left;
                    KeyNextPage = Keys.Down;
                    KeyPrevPage = Keys.Up;
                    MsgNextPage = (IntPtr)LVNI.BELOW;
                    MsgPrevPage = (IntPtr)LVNI.ABOVE;
                }

                int nextPageIdx = (int)PInvoke.SendMessage(Handle, LVM.GETNEXTITEM, (IntPtr)focusedIdx, MsgNextPage);
                if (nextPageIdx == -1 || nextPageIdx == focusedIdx)
                {
                    nextPageIdx = (int)PInvoke.SendMessage(Handle, LVM.GETNEXTITEM, (IntPtr)focusedIdx, MsgPrevPage);
                }
                else if (QTUtility.IsXP)
                {
                    int testIdx = (int)PInvoke.SendMessage(Handle, LVM.GETNEXTITEM, (IntPtr)nextPageIdx, MsgPrevPage);
                    if (testIdx != focusedIdx)
                    {
                        nextPageIdx = (int)PInvoke.SendMessage(Handle, LVM.GETNEXTITEM, (IntPtr)focusedIdx, MsgPrevPage);
                    }
                }
                if (nextPageIdx == -1 || nextPageIdx == focusedIdx)
                {
                    if (key == KeyNextItem)
                    {
                        if (focusedIdx == itemCount - 1)
                        {
                            selectMe = 0;
                        }
                        else
                        {
                            RECT thisRect = GetItemRect(focusedIdx);
                            RECT nextRect = GetItemRect(focusedIdx + 1);
                            if (viewMode == FVM.LIST)
                            {
                                if (nextRect.top < thisRect.top)
                                {
                                    selectMe = 0;
                                }
                            }
                            else if (nextRect.left < thisRect.left)
                            {
                                selectMe = 0;
                            }
                        }
                    }
                    else if (key == KeyPrevItem && focusedIdx == 0)
                    {
                        selectMe = itemCount - 1;
                    }
                    else if (key == KeyNextPage || key == KeyPrevPage)
                    {
                        if (QTUtility.IsXP)
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    int pageCount = Math.Abs(focusedIdx - nextPageIdx);
                    int page      = focusedIdx % pageCount;
                    if (key == KeyNextItem && (page == pageCount - 1 || focusedIdx == itemCount - 1))
                    {
                        selectMe = focusedIdx - page;
                    }
                    else if (key == KeyPrevItem && page == 0)
                    {
                        selectMe = Math.Min(focusedIdx + pageCount - 1, itemCount - 1);
                    }
                    else if (key == KeyNextPage && focusedIdx + pageCount >= itemCount)
                    {
                        selectMe = page;
                    }
                    else if (key == KeyPrevPage && focusedIdx < pageCount)
                    {
                        int x = itemCount - focusedIdx - 1;
                        selectMe = x - x % pageCount + focusedIdx;
                    }
                }
                break;
            }

            if (selectMe >= 0)
            {
                SetRedraw(false);
                ShellBrowser.SelectItem(selectMe);
                PInvoke.SendMessage(Handle, LVM.REDRAWITEMS, (IntPtr)focusedIdx, (IntPtr)focusedIdx);
                SetRedraw(true);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #14
0
        protected override Point GetSubDirTipPoint(bool fByKey)
        {
            int   iItem = fByKey ? ShellBrowser.GetFocusedIndex() : GetHotItem();
            int   x, y;
            Point ret;
            RECT  rect;

            switch (ShellBrowser.ViewMode)
            {
            case FVM.DETAILS:
                rect = GetItemRect(iItem, LVIR.LABEL);
                x    = rect.right;
                y    = rect.top;
                y   += (rect.bottom - y) / 2;
                ret  = new Point(x - 19, y - 7);
                break;

            case FVM.SMALLICON:
                rect = GetItemRect(iItem);
                x    = rect.right;
                y    = rect.top;
                x   -= (rect.bottom - y) / 2;
                y   += (rect.bottom - y) / 2;
                ret  = new Point(x - 9, y - 7);
                break;

            case FVM.CONTENT:
            case FVM.TILE:
                rect = GetItemRect(iItem, LVIR.ICON);
                y    = rect.bottom;
                x    = rect.right;
                ret  = new Point(x - 16, y - 16);
                break;

            case FVM.THUMBSTRIP:
            case FVM.THUMBNAIL:
                rect = GetItemRect(iItem, LVIR.ICON);
                if (QTUtility.IsXP)
                {
                    rect.right -= 13;
                }
                y   = rect.bottom;
                x   = rect.right;
                ret = new Point(x - 16, y - 16);
                break;

            case FVM.ICON:
                rect = GetItemRect(iItem, LVIR.ICON);
                if (QTUtility.IsXP)
                {
                    int  num3     = (int)PInvoke.SendMessage(Handle, LVM.GETITEMSPACING, IntPtr.Zero, IntPtr.Zero);
                    Size iconSize = SystemInformation.IconSize;
                    rect.right  = ((rect.left + (((num3 & 0xffff) - iconSize.Width) / 2)) + iconSize.Width) + 8;
                    rect.bottom = (rect.top + iconSize.Height) + 6;
                }
                y   = rect.bottom;
                x   = rect.right;
                ret = new Point(x - 16, y - 16);
                break;

            case FVM.LIST:
                if (QTUtility.IsXP)
                {
                    rect = GetItemRect(iItem, LVIR.ICON);
                    LVITEM structure = new LVITEM();
                    structure.pszText    = Marshal.AllocHGlobal(520);
                    structure.cchTextMax = 260;
                    structure.iItem      = iItem;
                    structure.mask       = 1;
                    IntPtr zero = Marshal.AllocHGlobal(Marshal.SizeOf(structure));
                    Marshal.StructureToPtr(structure, zero, false);
                    PInvoke.SendMessage(Handle, LVM.GETITEM, IntPtr.Zero, zero);
                    int num4 = (int)PInvoke.SendMessage(Handle, LVM.GETSTRINGWIDTH, IntPtr.Zero, structure.pszText);
                    num4 += 20;
                    Marshal.FreeHGlobal(structure.pszText);
                    Marshal.FreeHGlobal(zero);
                    rect.right  += num4;
                    rect.top    += 2;
                    rect.bottom += 2;
                }
                else
                {
                    rect = GetItemRect(iItem, LVIR.LABEL);
                }
                y   = rect.bottom;
                x   = rect.right;
                ret = new Point(x - 16, y - 16);
                break;

            default:
                rect = GetItemRect(iItem);
                y    = rect.bottom;
                x    = rect.right;
                ret  = new Point(x - 16, y - 16);
                break;
            }
            PInvoke.ClientToScreen(Handle, ref ret);
            return(ret);
        }
Beispiel #15
0
        protected override bool ListViewController_MessageCaptured(ref Message msg)
        {
            if (msg.Msg == WM_AFTERPAINT)
            {
                RefreshCache();
            }
            else if (msg.Msg == WM_ISITEMSVIEW)
            {
                msg.Result = (IntPtr)1;
                return(true);
            }

            if (base.ListViewController_MessageCaptured(ref msg))
            {
                return(true);
            }

            switch (msg.Msg)
            {
            case LVM.SCROLL: {
                int amount = msg.WParam.ToInt32();
                SetRedraw(false);
                AutomationManager.DoQuery(factory => {
                        AutomationElement elem = factory.FromHandle(Handle);
                        amount  /= SystemInformation.MouseWheelScrollDelta;
                        bool dec = amount < 0;
                        if (dec)
                        {
                            amount = -amount;
                        }
                        int lines = SystemInformation.MouseWheelScrollLines;
                        if (lines < 0)
                        {
                            elem.ScrollHorizontal(dec
                                    ? ScrollAmount.LargeDecrement
                                    : ScrollAmount.LargeIncrement, amount);
                        }
                        else
                        {
                            elem.ScrollHorizontal(dec
                                    ? ScrollAmount.SmallDecrement
                                    : ScrollAmount.SmallIncrement, amount * lines);
                        }
                        return(0);
                    });
                SetRedraw(true);
                return(true);
            }

            case WM.MOUSEACTIVATE: {
                int  res = (int)msg.Result;
                bool ret = OnMouseActivate(ref res);
                msg.Result = (IntPtr)res;
                return(ret);
            }

            case WM.LBUTTONDOWN: {
                // The ItemsView's window class doesn't have the CS_DBLCLKS
                // class style, which means we won't be receiving the
                // WM.LBUTTONDBLCLK message.  We'll just have to make do
                // without...
                Int64 now = DateTime.Now.Ticks;
                Point pt  = QTUtility2.PointFromLPARAM(msg.LParam);
                if ((now - lastLButtonTime) / 10000 <= SystemInformation.DoubleClickTime)
                {
                    Size size = SystemInformation.DoubleClickSize;
                    if (Math.Abs(pt.X - lastLButtonPoint.X) <= size.Width)
                    {
                        if (Math.Abs(pt.Y - lastLButtonPoint.Y) <= size.Height)
                        {
                            lastLButtonTime = 0;
                            return(OnDoubleClick(pt));
                        }
                    }
                }
                lastLButtonPoint = pt;
                lastLButtonTime  = now;
                return(false);
            }

            case WM.MOUSEMOVE: {
                Point pt = QTUtility2.PointFromLPARAM(msg.LParam);
                if (pt != lastMouseMovePoint)
                {
                    lastMouseMovePoint = pt;
                    if (focusedElement != null)
                    {
                        if (hotElement == null && focusedElement.FullRect.Contains(pt))
                        {
                            PInvoke.PostMessage(Handle, WM_AFTERPAINT, IntPtr.Zero, IntPtr.Zero);
                        }
                        else if (hotElement != null && hotElement.Index == focusedElement.Index && !focusedElement.FullRect.Contains(pt))
                        {
                            PInvoke.PostMessage(Handle, WM_AFTERPAINT, IntPtr.Zero, IntPtr.Zero);
                        }
                    }
                }
                break;
            }

            case WM.MOUSELEAVE:
                if (focusedElement != null)
                {
                    if (hotElement != null && hotElement.Index == focusedElement.Index)
                    {
                        PInvoke.PostMessage(Handle, WM_AFTERPAINT, IntPtr.Zero, IntPtr.Zero);
                    }
                }
                break;

            case WM.KEYDOWN:
                return(OnKeyDown((Keys)msg.WParam));

            case WM.LBUTTONUP:
            case WM.RBUTTONUP:
            case WM.MBUTTONUP:
                RefreshCache();
                break;

            case WM.NOTIFY: {
                NMHDR nmhdr = (NMHDR)Marshal.PtrToStructure(msg.LParam, typeof(NMHDR));
                if (nmhdr.code == -530 /* TTN_NEEDTEXT */)
                {
                    NMTTDISPINFO dispinfo = (NMTTDISPINFO)Marshal.PtrToStructure(msg.LParam, typeof(NMTTDISPINFO));
                    if ((dispinfo.uFlags & 0x20 /* TTF_TRACK */) != 0)
                    {
                        return(OnGetInfoTip(ShellBrowser.GetFocusedIndex(), true));
                    }
                    else
                    {
                        int i = GetHotItem();
                        if (i != -1 && IsTrackingItemName())
                        {
                            return(OnGetInfoTip(i, false));
                        }
                    }
                }
                break;
            }
            }
            return(false);
        }
Beispiel #16
0
        public override void BuildDialogControls(IVaultDialog dialog, IVaultDialogTab tab)
        {
            // File dialog emulation

            var shellBrowser = new ShellBrowser();

            shellBrowser.Dock              = DockStyle.Fill;
            shellBrowser.ListViewMode      = View.List;
            shellBrowser.Multiselect       = false;
            shellBrowser.ShowFolders       = true;
            shellBrowser.ShowFoldersButton = false;
            shellBrowser.browseSplitter.Panel2Collapsed = true; // hack!

            var lbFolderName = new Label {
                Text = Resources.Dialogs_BrowseForFolder_FolderNameLabel, Padding = new Padding(2, 7, 5, 3)
            };
            var tbFolderName = new TextBox()
            {
                Dock = DockStyle.Fill
            };
            var pn1 = new Panel()
            {
                Dock = DockStyle.Left
            };

            pn1.Controls.Add(lbFolderName);
            pn1.Width = 70;
            var pn2 = new Panel()
            {
                Dock = DockStyle.Fill, Padding = new Padding(5, 5, 2, 5)
            };

            pn2.Controls.Add(tbFolderName);

            var pnFolderName = new Panel()
            {
                Dock = DockStyle.Bottom
            };

            pnFolderName.Controls.Add(pn2);
            pnFolderName.Controls.Add(pn1);
            pnFolderName.Height = tbFolderName.Height + 10;
            var pnShellBrowser = new Panel()
            {
                Dock = DockStyle.Fill
            };

            pnShellBrowser.Controls.Add(shellBrowser);
            tab.TabPage.Controls.Add(pnShellBrowser);
            tab.TabPage.Controls.Add(pnFolderName);

            shellBrowser.HandleCreated += (o, e) =>
            {
                // loads startup dir from appdomain-wide history
                var startupDir = (String)AppDomain.CurrentDomain.GetData(this.GetType().FullName);
                if (!Directory.Exists(startupDir))
                {
                    startupDir = null;
                }
                startupDir = startupDir ?? shellBrowser.ShellBrowserComponent.MyDocumentsPath;
                shellBrowser.SelectPath(startupDir, false);

                // remember all changes of current directory
                Action storeCurrentDirInAppDomain = () =>
                {
                    var currentDir = ".".ResolveShellPathAsFileSystemPath(shellBrowser);
                    AppDomain.CurrentDomain.SetData(this.GetType().FullName, currentDir);
                };

                shellBrowser.FileView.SelectedIndexChanged += (o1, e1) => storeCurrentDirInAppDomain();
                shellBrowser.FolderView.AfterSelect        += (o1, e1) => storeCurrentDirInAppDomain();
            };

            Action refreshTextBox = () =>
            {
                var shellItem = shellBrowser.CurrentDirectory;
                tbFolderName.Text = shellItem == null ? String.Empty : ".";
            };

            shellBrowser.FileView.SelectedIndexChanged += (o, e) => refreshTextBox();
            shellBrowser.FolderView.AfterSelect        += (o, e) => refreshTextBox();

            // Ensuring consistent OK button availability

            Action refreshOkAvailability = () =>
            {
                var shellItem  = shellBrowser.CurrentDirectory; // hack
                var folderName = tbFolderName.Text;

                if (folderName == (shellItem == null ? String.Empty : shellItem.Text) ||
                    folderName == (shellItem == null ? String.Empty : shellItem.Path))
                {
                    // foldername in the text box corresponds to selected file/dir
                    dialog.OkButton.Enabled = shellItem != null && shellItem.IsFileSystem && shellItem.IsFolder && !shellItem.IsLink;
                }
                else
                {
                    dialog.OkButton.Enabled = folderName.IsNeitherNullNorEmpty();
                }
            };

            dialog.TabActivated      += (o, e) => refreshOkAvailability();
            tbFolderName.TextChanged += (o, e) => refreshOkAvailability();

            // Processing folder selection: via OK, via ENTER, or via double-click on a folder in the tree

            Action <String> processSelectFolder = path =>
            {
                var resolved = path.ResolveShellPathAsFileSystemPath(shellBrowser);
                if (resolved == null)
                {
                    MessageBox.Show(
                        Resources.Dialogs_BrowseForFolder_NotAFileSystemLocation_Message,
                        Resources.Dialogs_BrowseForFolder_NotAFileSystemLocation_Title,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
                else
                {
                    // the logic below only accepts full paths
                    Path.IsPathRooted(resolved).AssertTrue();

                    if (File.Exists(resolved))
                    {
                        MessageBox.Show(
                            Resources.Dialogs_BrowseForFolder_FileIsNotValidHere_Message,
                            Resources.Dialogs_BrowseForFolder_FileIsNotValidHere_Title,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                    else
                    {
                        // remember the selection
                        AppDomain.CurrentDomain.SetData(this.GetType().FullName, resolved);

                        if (dialog.Action == VaultAction.Create ||
                            dialog.Action == VaultAction.Export)
                        {
                            if (ApproveSavingToUri(resolved))
                            {
                                resolved.EnsureDirectoryExists();
                                var vault = OpenCore(resolved, true);

                                if (vault != null)
                                {
                                    dialog.EndDialog(vault);
                                }
                            }
                        }
                        else if (dialog.Action == VaultAction.Open ||
                                 dialog.Action == VaultAction.Import)
                        {
                            if (ApproveOpeningFromUri(resolved))
                            {
                                var vault = OpenCore(resolved, false);
                                if (vault != null)
                                {
                                    dialog.EndDialog(vault);
                                }
                            }
                        }
                        else
                        {
                            AssertionHelper.Fail();
                        }
                    }
                }
            };

            // disabled on purpose:
            // general guideline is having expand/collapse on double click
            // and even Windows' system browse for folder dialog respects this behaviour

//            shellBrowser.folderView.NodeMouseDoubleClick += (o, e) =>
//            {
//                refreshOkAvailability();
//                if (dialog.OkButton.Enabled)
//                {
//                    processSelectShellItem();
//                }
//            };

            dialog.OkButton.Click += (o, e) =>
            {
                if (dialog.ActiveTab == tab)
                {
                    processSelectFolder(tbFolderName.Text);
                }
            };

            tbFolderName.KeyDown += (o, e) =>
            {
                if (e.KeyCode == Keys.Enter && !e.Alt && !e.Shift && !e.Control)
                {
                    processSelectFolder(tbFolderName.Text);
                }
            };
        }
Beispiel #17
0
        // 使用箭头键时候环绕选择文件夹
        protected override bool HandleCursorLoop(Keys key)
        {
            int focusedIdx = ShellBrowser.GetFocusedIndex();
            int itemCount  = ShellBrowser.GetItemCount();
            int selectMe   = -1;
            FVM viewMode   = ShellBrowser.ViewMode;

            switch (viewMode)
            {
            case FVM.CONTENT:
            case FVM.DETAILS:
                if (key == Keys.Up && focusedIdx == 0)
                {
                    selectMe = itemCount - 1;
                }
                else if (key == Keys.Down && focusedIdx == itemCount - 1)
                {
                    selectMe = 0;
                }
                break;

            case FVM.ICON:
            case FVM.SMALLICON:
            case FVM.THUMBNAIL:
            case FVM.TILE:
            case FVM.LIST:
                Keys KeyNextItem, KeyPrevItem, KeyNextPage, KeyPrevPage;
                if (viewMode == FVM.LIST)
                {
                    KeyNextItem = Keys.Down;
                    KeyPrevItem = Keys.Up;
                    KeyNextPage = Keys.Right;
                    KeyPrevPage = Keys.Left;
                }
                else
                {
                    KeyNextItem = Keys.Right;
                    KeyPrevItem = Keys.Left;
                    KeyNextPage = Keys.Down;
                    KeyPrevPage = Keys.Up;
                }
                int pageCount = AutomationManager.DoQuery(factory => {
                    AutomationElement elem = factory.FromHandle(Handle);
                    if (elem == null)
                    {
                        return(-1);
                    }
                    return(viewMode == FVM.LIST ? elem.GetRowCount() : elem.GetColumnCount());
                });
                if (pageCount == -1)
                {
                    return(false);
                }
                int page = focusedIdx % pageCount;
                if (key == KeyNextItem && (page == pageCount - 1 || focusedIdx == itemCount - 1))
                {
                    selectMe = focusedIdx - page;
                }
                else if (key == KeyPrevItem && page == 0)
                {
                    selectMe = Math.Min(focusedIdx + pageCount - 1, itemCount - 1);
                }
                else if (key == KeyNextPage && focusedIdx + pageCount >= itemCount)
                {
                    selectMe = page;
                }
                else if (key == KeyPrevPage && focusedIdx < pageCount)
                {
                    int x = itemCount - focusedIdx - 1;
                    selectMe = x - x % pageCount + focusedIdx;
                }
                break;
            }
            if (selectMe >= 0)
            {
                ShellBrowser.SelectItem(selectMe);
                return(true);
            }
            else
            {
                return(false);
            }
        }
 /// <summary>
 /// Registers the TreeView.ItemDrag to receive the event when an item is being dragged
 /// </summary>
 /// <param name="br">The browser for which to support the drag</param>
 public BrowserTVDragWrapper(ShellBrowser br)
 {
     this.br = br;
     br.FolderView.ItemDrag += new ItemDragEventHandler(ItemDrag);
 }
        /// <summary>
        /// When keys are pressed, this method will check for known key combinations. For example copy and past with
        /// Ctrl + C and Ctrl + V.
        /// </summary>
        public static void ProcessKeyCommands(ShellBrowser br, object sender, KeyEventArgs e)
        {
            if (e.Control && !e.Shift && !e.Alt)
            {
                switch (e.KeyCode)
                {
                    case Keys.C:
                    case Keys.Insert:
                    case Keys.V:
                    case Keys.X:
                        #region Copy/Paste/Cut
                        {
                            Cursor.Current = Cursors.WaitCursor;
                            IntPtr[] pidls;
                            ShellItem parent;
                            if (sender.Equals(br.FileView) && e.KeyCode != Keys.V)
                            {
                                pidls = new IntPtr[br.FileView.SelectedItems.Count];
                                for (int i = 0; i < pidls.Length; i++)
                                {
                                    pidls[i] = ((ShellItem)br.FileView.SelectedItems[i].Tag).PIDLRel.Ptr;
                                }
                                parent = br.CurrentDirectory;
                            }
                            else
                            {
                                pidls = new IntPtr[1];
                                pidls[0] = br.CurrentDirectory.PIDLRel.Ptr;
                                parent = (br.CurrentDirectory.ParentItem != null ? br.CurrentDirectory.ParentItem : br.CurrentDirectory);
                            }

                            if (pidls.Length > 0)
                            {
                                string cmd;
                                if (e.KeyCode == Keys.C || e.KeyCode == Keys.Insert)
                                    cmd = "copy";
                                else if (e.KeyCode == Keys.V)
                                    cmd = "paste";
                                else
                                    cmd = "cut";

                                ContextMenuHelper.InvokeCommand(parent, pidls, cmd, new Point(0, 0));
                                Cursor.Current = Cursors.Default;
                            }
                            e.Handled = true;
                            e.SuppressKeyPress = true;
                        }
                        #endregion
                        break;

                    case Keys.A:
                        #region Select All
                        {
                            foreach (ListViewItem item in br.FileView.Items)
                                item.Selected = true;

                            br.FileView.Focus();
                        }
                        e.Handled = true;
                        e.SuppressKeyPress = true;
                        #endregion
                        break;

                    case Keys.N:
                        #region Create New Folder
                        if (!br.CreateNewFolder())
                            System.Media.SystemSounds.Beep.Play();

                        e.Handled = true;
                        e.SuppressKeyPress = true;
                        #endregion
                        break;

                    case Keys.Z:
                        break;

                    case Keys.Y:
                        break;
                }
            }
            else
            {
                switch (e.KeyCode)
                {
                    case Keys.Insert:
                        #region Paste
                        if (e.Shift && !e.Control && !e.Alt)
                        {
                            IntPtr[] pidls = new IntPtr[1];
                            pidls[0] = br.CurrentDirectory.PIDLRel.Ptr;
                            ShellItem parent = (br.CurrentDirectory.ParentItem != null ? br.CurrentDirectory.ParentItem : br.CurrentDirectory);
                            ContextMenuHelper.InvokeCommand(parent, pidls, "paste", new Point(0, 0));
                        }
                        e.Handled = true;
                        e.SuppressKeyPress = true;
                        #endregion
                        break;

                    case Keys.Delete:
                        #region Delete
                        if (!e.Control && !e.Alt)
                        {
                            IntPtr[] pidls;
                            ShellItem parent;
                            if (sender.Equals(br.FileView))
                            {
                                pidls = new IntPtr[br.FileView.SelectedItems.Count];
                                for (int i = 0; i < pidls.Length; i++)
                                {
                                    pidls[i] = ((ShellItem)br.FileView.SelectedItems[i].Tag).PIDLRel.Ptr;
                                }
                                parent = br.CurrentDirectory;
                            }
                            else
                            {
                                pidls = new IntPtr[1];
                                pidls[0] = br.CurrentDirectory.PIDLRel.Ptr;
                                parent = (br.CurrentDirectory.ParentItem != null ? br.CurrentDirectory.ParentItem : br.CurrentDirectory);
                            }

                            if (pidls.Length > 0)
                                ContextMenuHelper.InvokeCommand(parent, pidls, "delete", new Point(0, 0));
                        }
                        e.Handled = true;
                        e.SuppressKeyPress = true;
                        #endregion
                        break;

                    case Keys.F4:
                        #region AddressBox
                        {
                            br.NavAddressBox.Focus();
                            br.NavAddressBox.DroppedDown = true;
                        }
                        e.Handled = true;
                        e.SuppressKeyPress = true;
                        #endregion
                        break;

                    case Keys.F2:
                        #region Rename
                        if (sender.Equals(br.FolderView))
                        {
                            if (br.FolderView.SelectedNode != null)
                            {
                                br.FolderView.LabelEdit = true;
                                br.FolderView.SelectedNode.BeginEdit();
                            }
                        }
                        else if (sender.Equals(br.FileView))
                        {
                            if (br.FileView.SelectedOrder.Count > 0)
                            {
                                ArrayList temp = new ArrayList();
                                foreach (object obj in br.FileView.SelectedOrder)
                                    temp.Add(obj);

                                ListViewItem item = br.FileView.SelectedOrder[0] as ListViewItem;
                                item.BeginEdit();

                                for (int i = temp.Count - 1; i >= 0; i--)
                                {
                                    item = temp[i] as ListViewItem;
                                    item.Selected = false;
                                    item.Selected = true;
                                }
                            }
                        }
                        #endregion
                        break;

                    case Keys.Back:
                        #region Up
                        {
                            if (br.FolderView.SelectedNode != null && br.FolderView.SelectedNode.Parent != null)
                                br.FolderView.SelectedNode = br.FolderView.SelectedNode.Parent;
                        }
                        e.Handled = true;
                        e.SuppressKeyPress = true;
                        #endregion
                        break;
                }
            }
        }
Beispiel #20
0
 internal ShellItemCollection(ShellBrowser shellBrowser, SVGIO opt)
 {
     this.shellBrowser = shellBrowser;
     option            = opt;
 }
Beispiel #21
0
        public static String ResolveShellPathAsFileSystemPath(this String shellPath, ShellBrowser shellBrowser)
        {
            try
            {
                String resolved;
                if (Path.IsPathRooted(shellPath))
                {
                    resolved = shellPath;
                }
                else
                {
                    var parent = shellBrowser.CurrentDirectory;
                    parent.AssertNotNull();

                    Func <ShellItem, String> reallyRealPath = si =>
                    {
                        var realPath = ShellItem.GetRealPath(si);
                        Func <Func <String>, String> neverFail = f => { try { return(f()); } catch { return(null); } };
                        realPath = neverFail(() => Path.GetFullPath(realPath));

                        if (realPath == null)
                        {
                            var desktop = shellBrowser.ShellBrowserComponent.DesktopItem;
                            if (si == desktop)
                            {
                                realPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                            }
                            else if (si.Text == shellBrowser.ShellBrowserComponent.MyComputerName)
                            {
                                realPath = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
                            }
                            else
                            {
                                // todo. possibly map other bizarre folders
                                AssertionHelper.Fail();
                            }
                        }

                        realPath.AssertNotNull();
                        return(realPath);
                    };

                    // strategy 1. match children of current parent with the fpath
                    var match = parent.Cast <ShellItem>().SingleOrDefaultDontCrash(si => si.Text == shellPath);
                    if (match != null)
                    {
                        match.IsFileSystem.AssertTrue();
                        match.IsLink.AssertFalse();
                        resolved = reallyRealPath(match);
                    }
                    // strategy 2. resolve fpath as [parent's real path] + fpath
                    else
                    {
                        var parentResolved = reallyRealPath(parent);
                        resolved = Path.Combine(parentResolved, shellPath);
                    }
                }

                resolved.AssertNotNull();
                Path.IsPathRooted(resolved).AssertTrue();

                // canonicalize the path
                resolved = Path.GetFullPath(resolved);
                return(resolved);
            }
            catch (Exception)
            {
                // i know this is bad, but in this case user experience >> robustness
                return(null);
            }
        }
        /// <summary>
        /// Registers the neccesairy events
        /// </summary>
        /// <param name="br">The browser for which to support the ContextMenu</param>
        public BrowserLVContextMenuWrapper(ShellBrowser br, BrowserPluginWrapper pluginWrapper)
        {
            this.br = br;
            this.pluginWrapper = pluginWrapper;

            provider = new StreamStorageProvider(FileAccess.ReadWrite);
            viewPluginWorker = new BackgroundWorker();
            viewPluginWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
            viewPluginTimer = new System.Windows.Forms.Timer();
            viewPluginTimer.Tick += new EventHandler(viewPluginTimer_Tick);
            viewPluginTimer.Interval = 300;

            br.FileView.ShowItemToolTips = true;
            toolTipDelegate = new ToolTipDelegate(SetToolTip);

            br.SelectedFolderChanged += new SelectedFolderChangedEventHandler(br_SelectedFolderChanged);

            br.FileView.LabelEdit = true;
            br.FileView.MouseUp += new MouseEventHandler(FileView_MouseUp);
            br.FileView.ItemActivate += new EventHandler(FileView_ItemActivate);
            br.FileView.AfterLabelEdit += new LabelEditEventHandler(FileView_AfterLabelEdit);
            br.FileView.BeforeLabelEdit += new LabelEditEventHandler(FileView_BeforeLabelEdit);
            br.FileView.KeyDown += new KeyEventHandler(FileView_KeyDown);
            br.FileView.ItemSelectionChanged += new ListViewItemSelectionChangedEventHandler(FileView_ItemSelectionChanged);
            br.FileView.ItemMouseHover += new ListViewItemMouseHoverEventHandler(FileView_ItemMouseHover);

            this.CreateHandle(new CreateParams());
        }
Beispiel #23
0
 /// <summary>
 /// Registers the TreeView.ItemDrag to receive the event when an item is being dragged
 /// </summary>
 /// <param name="br">The browser for which to support the drag</param>
 public BrowserTVDragWrapper(ShellBrowser br)
 {
     this.br = br;
     br.FolderView.ItemDrag += new ItemDragEventHandler(ItemDrag);
 }
        public ShellListViewPane()
        {
            InitializeComponent();

            flowLayoutPanel1.HorizontalScroll.Visible = false;
            flowLayoutPanel1.VerticalScroll.Visible   = false;

            shellListView1.Enter += delegate(object _sender, EventArgs _e)
            {
                //Update all the Shell Components in the main form to react to this Pane.
                OnFocusChange(this, null);
                panel1.BorderStyle = BorderStyle.FixedSingle;
            };
            shellListView1.Leave += delegate(object _sender, EventArgs _e)
            {
                panel1.BorderStyle = BorderStyle.None;
            };

            #region Configuration Menu
            //Reset all the controls to default
            shellControlConnector1.ShowParentfolderItem = shellListView1.ShowParentFolder;
            showParentFolderToolStripMenuItem.Checked   = shellListView1.ShowParentFolder;
            showHiddenObjectsToolStripMenuItem.Checked  = shellListView1.ShowHidden;
            showOverlayIconsToolStripMenuItem.Checked   = shellListView1.ShowOverlayIcons;
            useSystemFontToolStripMenuItem.Checked      = shellListView1.UseSystemFont;
            fileSystemOnlyToolStripMenuItem.Checked     = shellListView1.FileSystemOnly;
            #endregion

            #region Checkboxes
            scanRecursivelyToolStripMenuItem.Checked =
                shellControlConnector1.SelectionList.CalculateSelectedFiles;
            toggleCheckboxesToolStripMenuItem.Checked = shellListView1.CheckBoxes;

            shellControlConnector1.SelectionList.SelectionChanged += delegate(object _sender, EventArgs _e)
            {
                CheckboxListIsCalculatingSize = true; //Keep track if we have finished calculating the size
            };
            shellControlConnector1.SelectionList.CompletedSizeCalculation += delegate(object _sender, EventArgs _e)
            {
                CheckboxListIsCalculatingSize = false;
            };
            #endregion

            #region Drives
            ShellBrowser browser = new ShellBrowser(ShellFolder.Drives); //Initialize a new Browser with the Root point at "This PC"
            while (browser.Next())                                       //Browse through all Items listed at Root Point
            {
                if (PathCollection.IsDrive(browser.FullPath) || browser.HasAttributes(SFGAOF.SFGAO_REMOVABLE))
                {
                    var path = browser.FullPath; //Read the DisplayPath from the ShellBrowser instance

                    //Create a button with the drive icon next to the text.
                    Button driveBtn = new Button
                    {
                        ImageAlign        = ContentAlignment.MiddleRight,
                        TextImageRelation = TextImageRelation.ImageBeforeText,
                        TextAlign         = ContentAlignment.MiddleCenter
                    };

                    int index = SystemImageList.GetIndexFromItemIdList(ItemIdList.Parse(path), false);
                    driveBtn.Image    = new SystemImageListHelper().GetIconAsBitmap(index);
                    driveBtn.Text     = path;
                    driveBtn.Width    = 0;
                    driveBtn.AutoSize = true;
                    driveBtn.Click   += delegate(object a, EventArgs b)
                    {
                        //When the button is clicked, go to the path by setting the FolderIdList Property.
                        shellListView1.FolderChanged(ItemIdList.Parse(path));
                    };
                    flowLayoutPanel1.Controls.Add(driveBtn);
                }
            }
            #endregion
        }