/// <summary>
        /// Registers the neccesairy events
        /// </summary>
        /// <param name="br">The browser for which to support the ContextMenu</param>
        public BrowserLVContextMenuWrapper(Browser 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());
        }
        /// <summary>
        /// Registers the neccesairy events
        /// </summary>
        /// <param name="br">The browser for which to support the ContextMenu</param>
        public BrowserTVContextMenuWrapper(Browser 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());
        }
        /// <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(Browser br)
        {
            this.br = br;

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

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

            ShellHelper.GetIDropTargetHelper(out dropHelperPtr, out dropHelper);
        }
Esempio n. 4
0
 /// <summary>
 /// Registers the ListView.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 BrowserLVDragWrapper(Browser br)
 {
     this.br = br;
     br.FileView.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(Browser 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.SelectedItem;
                            }
                            else
                            {
                                pidls = new IntPtr[1];
                                pidls[0] = br.SelectedItem.PIDLRel.Ptr;
                                parent = (br.SelectedItem.ParentItem != null ? br.SelectedItem.ParentItem : br.SelectedItem);
                            }

                            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.SelectedItem.PIDLRel.Ptr;
                            ShellItem parent = (br.SelectedItem.ParentItem != null ? br.SelectedItem.ParentItem : br.SelectedItem);
                            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.SelectedItem;
                            }
                            else
                            {
                                pidls = new IntPtr[1];
                                pidls[0] = br.SelectedItem.PIDLRel.Ptr;
                                parent = (br.SelectedItem.ParentItem != null ? br.SelectedItem.ParentItem : br.SelectedItem);
                            }

                            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;
                }
            }
        }
        /// <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(Browser 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;

                            pidls = new IntPtr[1];
                            pidls[0] = br.SelectedItem.PIDLRel.Ptr;
                            parent = (br.SelectedItem.ParentItem != null ? br.SelectedItem.ParentItem : br.SelectedItem);

                            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.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.SelectedItem.PIDLRel.Ptr;
                            ShellItem parent = (br.SelectedItem.ParentItem != null ? br.SelectedItem.ParentItem : br.SelectedItem);
                            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;
                            pidls = new IntPtr[1];
                            pidls[0] = br.SelectedItem.PIDLRel.Ptr;
                            parent = (br.SelectedItem.ParentItem != null ? br.SelectedItem.ParentItem : br.SelectedItem);

                            if(pidls.Length > 0)
                                ContextMenuHelper.InvokeCommand(parent, pidls, "delete", new Point(0, 0));
                        }
                        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();
                            }
                        }

                        #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;
                }
            }
        }