コード例 #1
0
        public void Execute()
        {
            string path;
            var    selectedItem = this.treeViewModel.SelectedItem;

            if (selectedItem == null)
            {
                path = this.workspaceDirectoryModel.CurrentWorkspaceDirectory;
            }
            else
            {
                path = selectedItem.Path;
            }

            if (String.IsNullOrEmpty(path) || (!File.Exists(path) && !Directory.Exists(path)))
            {
                return;
            }

            var              uri       = new Uri(path);
            ShellItem        shellItem = new ShellItem(uri);
            ShellContextMenu menu      = new ShellContextMenu(shellItem);

            try
            {
                menu.ShowContextMenu(System.Windows.Forms.Control.MousePosition);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Failed to show Windows Explorer Context Menu");
            }
        }
コード例 #2
0
ファイル: PluginMain.cs プロジェクト: littlesome/LuaDevelop
        /// <summary>
        /// Shows the explorer shell menu
        /// </summary>
        private void TreeShowShellMenu()
        {
            String           parentDir             = null;
            ShellContextMenu scm                   = new ShellContextMenu();
            List <FileInfo>  selectedPathsAndFiles = new List <FileInfo>();

            for (Int32 i = 0; i < Tree.SelectedPaths.Length; i++)
            {
                String path = Tree.SelectedPaths[i];
                // only select files in the same directory
                if (parentDir == null)
                {
                    parentDir = Path.GetDirectoryName(path);
                }
                else if (Path.GetDirectoryName(path) != parentDir)
                {
                    continue;
                }
                selectedPathsAndFiles.Add(new FileInfo(path));
            }
            this.pluginUI.Menu.Hide(); /* Hide default menu */
            Point location = new Point(this.pluginUI.Menu.Bounds.Left, this.pluginUI.Menu.Bounds.Top);

            scm.ShowContextMenu(selectedPathsAndFiles.ToArray(), location);
        }
コード例 #3
0
        private void FileTreeItem_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            var item = this.FileTreeHitTest(e);

            if (item == null)
            {
                return;
            }

            if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
            {
                var viewModel = item.DataContext as FileSystemObjectVM;
                if (viewModel == null)
                {
                    return;
                }

                if (item.DataContext is IPackageFileSystemObjectVM)
                {
                    return;
                }

                ShellContextMenu.ShowFolderContextMenu(viewModel.Path);
                e.Handled = true;

                this.ViewModel.IsControlKeyPressed = false;
            }
        }
コード例 #4
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                ListViewItem item = GetItemAt(e.X, e.Y);
                if (item != null)
                {
                    item.Selected = true;

                    ShellContextMenu contextMenu = new ShellContextMenu();
                    using (PIDL pidl = ((PIDL)((PIDL)item.Tag).Clone()))
                    {
                        string path = pidl.PhysicalPath;

                        if (path.EndsWith("\\"))
                        {
                            path = path.Substring(0, path.Length - 1);
                        }
                        FileInfo[] fileinfo = { new FileInfo(pidl.PhysicalPath) };
                        contextMenu.ShowContextMenu(Handle, fileinfo, Cursor.Position);
                    }
                }
            }

            base.OnMouseDown(e);
        }
コード例 #5
0
        private void ShowContextMenu(object obj)
        {
            var button           = (Button)obj;
            var shellContextMenu = new ShellContextMenu();

            shellContextMenu.ShowContextMenu(new [] { new FileInfo(FilePath.Value) }, button.PointToScreen(new Point(0, 0)));
        }
コード例 #6
0
        public static bool InvokeVerb(string Path, string Verb)
        {
            try
            {
                if (File.Exists(Path) || Directory.Exists(Path))
                {
                    using (ShellItem Item = ShellItem.Open(Path))
                        using (ShellContextMenu ContextMenu = new ShellContextMenu(Item))
                        {
                            Shell32.CMINVOKECOMMANDINFOEX InvokeCommand = new Shell32.CMINVOKECOMMANDINFOEX
                            {
                                lpVerb = new SafeResourceId(Verb, CharSet.Ansi),
                                nShow  = ShowWindowCommand.SW_SHOWNORMAL,
                                cbSize = Convert.ToUInt32(Marshal.SizeOf(typeof(Shell32.CMINVOKECOMMANDINFOEX)))
                            };

                            using (User32.SafeHMENU NewMenu = User32.CreatePopupMenu())
                            {
                                ContextMenu.ComInterface.QueryContextMenu(NewMenu, 0, 0, ushort.MaxValue, Shell32.CMF.CMF_EXTENDEDVERBS | Shell32.CMF.CMF_EXPLORE | Shell32.CMF.CMF_OPTIMIZEFORINVOKE);
                                ContextMenu.ComInterface.InvokeCommand(InvokeCommand);
                            }
                        }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
コード例 #7
0
        /// <summary>
        /// Shows the explorer shell menu
        /// </summary>
        private void ShowShellMenu(Object sender, EventArgs e)
        {
            Int32 count = this.fileView.SelectedItems.Count;

            FileInfo[]       selectedPathsAndFiles = new FileInfo[count];
            ShellContextMenu scm = new ShellContextMenu();

            for (Int32 i = 0; i < count; i++)
            {
                String path = this.fileView.SelectedItems[i].Tag.ToString();
                selectedPathsAndFiles[i] = new FileInfo(path);
            }
            if (count == 0)
            {
                String path = this.selectedPath.Text;
                if (!Directory.Exists(path))
                {
                    return;
                }
                selectedPathsAndFiles    = new FileInfo[1];
                selectedPathsAndFiles[0] = new FileInfo(path);
            }
            this.menu.Hide(); /* Hide default menu */
            Point location = new Point(this.menu.Bounds.Left, this.menu.Bounds.Top);

            scm.ShowContextMenu(selectedPathsAndFiles, location);
        }
コード例 #8
0
        private void ListView_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            FileSystemInfo fle = e.ListBoxItemContent() as FileSystemInfo;

            //FrameworkElement elem = sender as FrameworkElement;
            if (fle != null)
            {
                ListViewItem item = GetListViewItemClicked(e.OriginalSource, lv);
                if (item != null)
                {
                    if (e.RightButton == MouseButtonState.Pressed)
                    {
                        ShellContextMenu scm = new ShellContextMenu();
                        scm.CreateHandle();
                        scm.ShowContextMenu(fle.FullName, PointToScreen(item.TranslatePoint(new Point(0, 0), lv)));
                    }
                    else if (e.LeftButton == MouseButtonState.Pressed)
                    {
                        startPoint = e.GetPosition(null);

                        ActiveFilename = fle.FullName;
                        ActiveItem     = item;
                    }
                }
            }
        }
コード例 #9
0
        private void RightFiles_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            ShellContextMenu       scm   = new ShellContextMenu();
            List <FileInformation> items = new List <FileInformation>();

            foreach (var x in RightFiles.SelectedItems)
            {
                items.Add(((FileInformation)x));
            }

            if (items.Count > 0 && items[0].FileType == ".")
            {
                DirectoryInfo[] directories = new DirectoryInfo[1];
                directories[0] = new DirectoryInfo(PathRight.Text + items[0].FileName);
                scm.ShowContextMenu(new WindowInteropHelper(this).Handle, directories, (int)e.GetPosition(null).X, (int)e.GetPosition(null).Y);
                return;
            }

            FileInfo[] files = new FileInfo[1];
            if (items.Count > 0)
            {
                files[0] = new FileInfo(PathRight.Text + items[0].FileName);
            }
            else
            {
                files = new FileInfo[0];
            }

            scm.ShowContextMenu(new WindowInteropHelper(this).Handle, files, (int)e.GetPosition(null).X, (int)e.GetPosition(null).Y);
        }
コード例 #10
0
        private void Item_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            FileItem         item    = (FileItem)sender;
            ShellItem        myFile  = new ShellItem(new Uri(item.Filepath));
            ShellContextMenu ctxmenu = new ShellContextMenu(myFile);

            ctxmenu.ShowContextMenu(null, Helpers.GetMousePosition());
        }
コード例 #11
0
        public static void ShellContextMenuTest()
        {
            ShellContextMenu scm = new ShellContextMenu();

            FileInfo[] files = new FileInfo[1];
            files[0] = new FileInfo(@"c:\windows\notepad.exe");
            scm.ShowContextMenu(files, Cursor.Position);
        }
コード例 #12
0
        /// <summary>
        /// Show shell context menu for file.
        /// Todo: should be replaced with WPF-styled context menu.
        /// Todo: remove System.Windows.Forms.dll dependency.
        /// </summary>
        public void ShowContextMenu()
        {
            var scm   = new ShellContextMenu();
            var files = new FileInfo[1];

            files[0] = new FileInfo(AbsolutePath);
            scm.ShowContextMenu(files, Cursor.Position);
        }
コード例 #13
0
ファイル: Form1.cs プロジェクト: BrightLight/vsshcon
        private void Popup(string filename, Point point)
        {
            //MessageBox.Show(filename);
            var contextMenu = new ShellContextMenu();
            var fileInfo    = new[] { new FileInfo(filename) };

            contextMenu.ShowContextMenu(fileInfo, point);
        }
コード例 #14
0
 public void TestRepeatFail()
 {
     for (int i = 0; i < 20; i++)
     {
         using ShellItem Item = ShellItem.Open(TestCaseSources.ImageFile);
         using ShellContextMenu ContextMenu = new ShellContextMenu(Item);
         TestContext.WriteLine(ContextMenu.ComInterface.GetType().Name);
     }
 }
コード例 #15
0
        public void CreateTest()
        {
            using var menu = new ShellContextMenu(new ShellItem(TestCaseSources.WordDoc));
            var items = menu.GetItems();

            for (var i = 0; i < items.Length; i++)
            {
                ShowMII(items[i], i);
            }
コード例 #16
0
        private void CairoDesktopWindow_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            // handle icon and desktop context menus
            if (e.OriginalSource.GetType() == typeof(System.Windows.Controls.ScrollViewer))
            {
                ShellContextMenu cm = new ShellContextMenu(Icons.Location.FullName, executeCustomAction);

                e.Handled = true;
            }
            else
            {
                Button btn = null;
                if (e.OriginalSource.GetType() == typeof(System.Windows.Controls.Image))
                {
                    Image     img  = e.OriginalSource as Image;
                    DockPanel dock = img.Parent as DockPanel;
                    btn = dock.Parent as Button;
                }
                else if (e.OriginalSource.GetType() == typeof(System.Windows.Controls.TextBlock))
                {
                    TextBlock txt  = e.OriginalSource as TextBlock;
                    Border    bdr  = txt.Parent as Border;
                    DockPanel dock = bdr.Parent as DockPanel;
                    btn = dock.Parent as Button;
                }
                else if (e.OriginalSource.GetType() == typeof(System.Windows.Controls.Border) && (e.OriginalSource as Border).Parent != null && (e.OriginalSource as Border).Parent.GetType() == typeof(System.Windows.Controls.DockPanel))
                {
                    Border    bdr  = e.OriginalSource as Border;
                    DockPanel dock = bdr.Parent as DockPanel;
                    btn = dock.Parent as Button;
                }
                else if (e.OriginalSource.GetType() == typeof(System.Windows.Controls.DockPanel))
                {
                    DockPanel dock = e.OriginalSource as DockPanel;
                    btn = dock.Parent as Button;
                }
                else if (e.OriginalSource.GetType() == typeof(System.Windows.Controls.Border))
                {
                    Border bdr = e.OriginalSource as Border;
                    btn = bdr.TemplatedParent as Button;
                }

                if (btn != null)
                {
                    string filePath = btn.CommandParameter as string;

                    ShellContextMenu cm = new ShellContextMenu(new string[] { filePath }, btn, ShellContextMenu.ExecuteAction);

                    e.Handled = true;
                }
                else
                {
                    CairoLogger.Instance.Debug("Desktop was right-clicked but it wasn't a recognized object.");
                }
            }
        }
コード例 #17
0
ファイル: UpYunMain.cs プロジェクト: wardchan/97world_UpYun
        /// <summary>
        /// 本地浏览器右键菜单“资源管理器菜单”条目事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LocalPopupMenuDefault_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShellContextMenu scm = new ShellContextMenu();

            FileInfo[] files = new FileInfo[1];
            Point      p     = this.ListViewLocal.PointToClient(new Point(menutrippoint.X, menutrippoint.Y));

            files[0] = new FileInfo(LocalPath + ListViewLocal.GetItemAt(p.X, p.Y).Text);
            scm.ShowContextMenu(files, menutrippoint);
        }
コード例 #18
0
 private void btnFile_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
 {
     // desktop icon context menu
     // not used for stacks, which use our own menu due to the shell menu causing stacks to close
     if (!currentlyRenaming)
     {
         ShellContextMenu cm = new ShellContextMenu(new SystemFile[] { file }, executeFileAction);
         e.Handled = true;
     }
 }
コード例 #19
0
 void duh_ContextMenuRequested(object sender, PathEventArgs e)
 {
     ShellItem[] dirs = new ShellItem[1];
     dirs[0] = e.ShellItem;
     Point relativePoint = this.TransformToAncestor(Application.Current.MainWindow)
                           .Transform(new Point(0, 0));
     Point            realCoordinates = Application.Current.MainWindow.PointToScreen(relativePoint);
     ShellContextMenu cm = new ShellContextMenu(dirs);
     //cm.ShowContextMenu(new System.Drawing.Point((int)GetCursorPosition().X, (int)realCoordinates.Y + (int)this.Height));
 }
コード例 #20
0
 private void CairoDesktopWindow_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
 {
     // handle desktop context menu
     // we check source here so that we don't override the rename textbox context menu
     if (desktopManager.DesktopLocation != null && (e.OriginalSource.GetType() == typeof(ScrollViewer) || e.Source.GetType() == typeof(Desktop) || e.Source.GetType() == typeof(Grid)))
     {
         ShellContextMenu cm = new ShellContextMenu(desktopManager.DesktopLocation, executeFolderAction);
         e.Handled = true;
     }
 }
コード例 #21
0
ファイル: FileLister.cs プロジェクト: mkbiltek2019/Lesons_SAG
        private void curentDirectorylistView_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                ShellContextMenu shellMenu = new ShellContextMenu();

                FileInfo fileInfo = new FileInfo(Path.Combine(directoryCurentPath, curentDirectorylistView.SelectedItems[0].Text));
                shellMenu.ShowContextMenu(new[] { fileInfo }, PointToScreen(new Point(e.X, e.Y)));
            }
        }
コード例 #22
0
        private void RightHoldEvent()
        {
            List <Item> temp = new List <Item>();

            temp = selectedItems.Values.ToList();

            ShellContextMenu shellcontextmenu = new ShellContextMenu();

            List <DirectoryInfo> dir = new List <DirectoryInfo>();
            List <FileInfo>      fi  = new List <FileInfo>();


            List <Item> items = selectedItems.Values.ToList();

            try
            {
                if (items.Count == 0)
                {
                    if (GetCurrentSelectedItem() != null)
                    {
                        if (listView1.SelectedItems.GetType() == typeof(MyFile))
                        {
                            fi.Add(new FileInfo(GetCurrentSelectedItem().strParentPath + GetCurrentSelectedItem().StrName + GetCurrentSelectedItem().StrExt));
                        }
                        else
                        {
                            dir.Add(new DirectoryInfo((GetCurrentSelectedItem().strParentPath + (GetCurrentSelectedItem().StrName + "\\"))));
                        }
                    }
                    else
                    {
                        ItemsViewer     ParentForm = (ItemsViewer)this.Parent.Parent.Parent;
                        DirectoryInfo[] temp1      = new DirectoryInfo[1];
                        temp1[0] = new DirectoryInfo(ParentForm.StrCurrentPath);
                        shellcontextmenu.ShowContextMenu(temp1, MousePosition);
                    }
                }
                else
                {
                    foreach (Item i in items)
                    {
                        if (i.GetType() == typeof(MyFile))
                        {
                            fi.Add(new FileInfo(i.strParentPath + i.StrName + i.StrExt));
                        }
                        else
                        {
                            dir.Add(new DirectoryInfo(i.strParentPath + i.StrName + "\\"));
                        }
                    }
                }
                shellcontextmenu.ShowContextMenu(fi.ToArray(), dir.ToArray(), MousePosition);
            }
            catch { }
        }
コード例 #23
0
        public void CreateTest()
        {
            using var shi  = ShellItem.Open(TestCaseSources.TempDir);
            using var menu = new ShellContextMenu(shi);
            var items = menu.GetItems(CMF.CMF_EXTENDEDVERBS | CMF.CMF_EXPLORE | CMF.CMF_CANRENAME | CMF.CMF_ITEMMENU);

            for (var i = 0; i < items.Length; i++)
            {
                ShowMII(items[i], i);
            }
        }
コード例 #24
0
 private void UIElement_OnMouseRightButtonUp(object sender, MouseButtonEventArgs e)
 {
     if (sender is Button b)
     {
         var item  = (TreeViewItem)b.CommandParameter;
         var dinfo = new[] { new DirectoryInfo(item.Path) };
         var scm   = new ShellContextMenu();
         scm.ShowContextMenu(dinfo, System.Windows.Forms.Cursor.Position); //TODO: System.Windows.Forms && System.Drawing Reference just for this line...
         e.Handled = true;
     }
 }
コード例 #25
0
 private void listView2_MouseUp(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         if (listView2.FocusedItem.Bounds.Contains(e.Location) == true)
         {
             ShellContextMenu ctxMnu = new ShellContextMenu();
             ctxMnu.ShowContextMenu(new DirectoryInfo[] { (new DirectoryInfo(@"C:\Windows")) }, this.PointToScreen(new Point(e.X, e.Y)));
         }
     }
 }
コード例 #26
0
        internal void MouseDown(DataGridView dgv, MouseEventArgs e)
        {
            if (ContainsMenu)
            {
                TriggerMenuOpener(); // Touchscreen
            }

            if (IsLoading)
            {
                waitMenuOpen.Click();
            }

            if (e != null &&
                e.Button == MouseButtons.Right &&
                FileInfo != null &&
                dgv != null &&
                dgv.Rows.Count > RowIndex &&
                (DateTime.Now - ContextMenuClosed).TotalMilliseconds > 200)
            {
                IsContextMenuOpen = true;
                Color colorbefore = dgv.Rows[RowIndex].DefaultCellStyle.SelectionBackColor;
                dgv.Rows[RowIndex].DefaultCellStyle.SelectionBackColor =
                    MenuDefines.ColorSelectedItem;

                ShellContextMenu ctxMnu   = new ShellContextMenu();
                Point            location = dgv.FindForm().Location;
                Point            point    = new Point(
                    e.X + location.X + dgv.Location.X,
                    e.Y + location.Y + dgv.Location.Y);
                if (ContainsMenu)
                {
                    DirectoryInfo[] dir = new DirectoryInfo[1];
                    dir[0] = new DirectoryInfo(TargetFilePathOrig);
                    ctxMnu.ShowContextMenu(dir, point);
                }
                else
                {
                    FileInfo[] arrFI = new FileInfo[1];
                    arrFI[0] = new FileInfo(TargetFilePathOrig);
                    ctxMnu.ShowContextMenu(arrFI, point);
                }

                if (!dgv.IsDisposed)
                {
                    dgv.Rows[RowIndex].DefaultCellStyle.SelectionBackColor = colorbefore;
                }

                IsContextMenuOpen = false;
                ContextMenuClosed = DateTime.Now;
            }
        }
コード例 #27
0
ファイル: localHandler.cs プロジェクト: xuri02/Explorer
        public LocalHandler(string currentPath = "")
        {
            this.history = new List <string> {
                this.RootPath, this.RootPath, this._currentPath
            };

            try {
                this.OnSetCurrentPath?.Invoke("", currentPath);
                this._currentPath      = string.IsNullOrEmpty(currentPath) ? SettingsHandler.ROOT_FOLDER : currentPath;
                this._shellContextMenu = new ShellContextMenu();
            } catch (Exception e) {
                OnOnError(e);
            }
        }
コード例 #28
0
        private void CairoDesktopWindow_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            // handle icon and desktop context menus
            if (e.OriginalSource.GetType() == typeof(System.Windows.Controls.ScrollViewer))
            {
                ShellContextMenu cm = new ShellContextMenu(Icons.Location, executeFolderAction);

                e.Handled = true;
            }
            else
            {
                ShellContextMenu.OpenContextMenuFromIcon(e, executeFileAction);
            }
        }
コード例 #29
0
        private void tv_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            TreeViewItem    item = GetTreeViewItemClicked(e.OriginalSource, tv);
            FolderViewModel fvm  = GetFolderItem(item);

            if (fvm != null)
            {
                if (e.RightButton == MouseButtonState.Pressed)
                {
                    ShellContextMenu scm = new ShellContextMenu();
                    scm.CreateHandle();
                    scm.ShowContextMenu(fvm.FolderPath, PointToScreen(item.TranslatePoint(new Point(0, 0), tv)));
                }
            }
        }
コード例 #30
0
        public override void ShowContextMenu(IEnumerable <IItem> selectedItems)
        {
            var scm = new ShellContextMenu();

            if (selectedItems == null && Path != null)
            {
                var dirInfo = new[] { new DirectoryInfo(Path) };
                scm.ShowContextMenu(dirInfo, Cursor.Position);
            }
            else if (selectedItems != null)
            {
                var fileInfos = selectedItems.Select(getFileInfo).Where(i => i != null).ToArray();
                scm.ShowContextMenu(fileInfos, Cursor.Position);
            }
        }