示例#1
0
        public ContextMenuStrip GetFileMenuTest(
            [PexAssumeUnderTest] Sonnenberg.ContextMenu.Program target,
            string menuType,
            string clickedItemPath,
            ShellExtInitServer shellServer
            )
        {
            ContextMenuStrip result
                = target.GetFileMenu(menuType, clickedItemPath, shellServer);

            return(result);
        }
示例#2
0
        public ContextMenuStrip GetFileMenu(string menuType, string clickedItemPath, ShellExtInitServer shellServer)
        {
            if (null != shellServer)
            {
                return(FileMenu(menuType, clickedItemPath, shellServer));
            }

            var message = $"{Strings.shellserverArgumentMissingError}";
            var ex      = new Exception(message);

            log.Error(message);
            MessageBox.Show(message);

            throw ex;
        }
示例#3
0
        private ContextMenuStrip FileMenu(string menuType, string clickedItemPath, ShellExtInitServer shellServer)
        {
            var toolStripMenuItem = new ToolStripMenuItem
            {
                Text  = Strings.menuStripNameFileMenu,
                Image = Resources.imgSonnenberg,
                Name  = "Sonnenberg"
            };

            toolStripMenuItem = CreateCountLinesMenuItem(toolStripMenuItem, clickedItemPath, shellServer);
            toolStripMenuItem = CreateCopyPathMenuItem(toolStripMenuItem, menuType, clickedItemPath);

            _contextMenuStrip.Items.Add(toolStripMenuItem);

            return(_contextMenuStrip);
        }
示例#4
0
        private static string ShellStartUpDirectory(string clickedItemType, ShellExtInitServer shellServer)
        {
            switch (clickedItemType)
            {
            case "FolderShortcut":

                return(ShortcutTarget(ClickedItemPath(clickedItemType, (Program)shellServer)));

            case "Folder":

                return(shellServer.SelectedItemPaths.First());

            default:

                return("");
            }
        }
示例#5
0
        private static string ClickedItemType(ShellExtInitServer shellServer)
        {
            if (shellServer.FolderPath != null)
            {
                return("Directory");
            }

            var clickedItemType = "Unsupported";
            var clickedItemPath = shellServer.SelectedItemPaths.First();

            if (null == clickedItemPath)
            {
                throw new ArgumentNullException(clickedItemType, Strings.clickedItemPathArgumentNullException);
            }

            try
            {
                var ext            = Path.GetExtension(clickedItemPath);
                var fileAttributes = File.GetAttributes(clickedItemPath);

                // @todo: Works in the debugger, but fails for shortcuts in release mode...
                if (".lnk" != ext)
                {
                    clickedItemType = (fileAttributes & FileAttributes.Directory) != 0 ? "Folder" : "File";
                }
                else
                {
                    clickedItemType = "Folder" == ShortcutTargetType(clickedItemPath) ? "FolderShortcut" : "FileShortcut";
                }

                return(clickedItemType);
            }
            catch (ArgumentNullException ex)
            {
                log.Error($"{ex.Message} | Path: {clickedItemPath} | (GetClickedItemType)");

                throw;
            }
        }
示例#6
0
 private static string ClickedItemContainingFolder(string clickedItemType, ShellExtInitServer shellServer)
 {
     return("Directory" == clickedItemType?Path.GetDirectoryName(shellServer.FolderPath) : Path.GetDirectoryName(shellServer.SelectedItemPaths.First()));
 }
示例#7
0
 private static string ClickedItemPath(string menuType, ShellExtInitServer shellServer)
 {
     return("Directory" == menuType ? shellServer.FolderPath : shellServer.SelectedItemPaths.First());
 }
示例#8
0
        private ToolStripMenuItem CreateCountLinesMenuItem(ToolStripMenuItem toolStripMenuItem, string clickedItemPath, ShellExtInitServer shellServer)
        {
            if ("Text" == new FileTypes().GetFileType(Path.GetExtension(clickedItemPath)))
            {
                return(toolStripMenuItem);
            }

            var countLines         = new CountLines();
            var countLinesMenuItem = countLines.CreateToolStripMenuItem(shellServer.SelectedItemPaths);

            toolStripMenuItem.DropDownItems.Add(countLinesMenuItem);

            var countCleanLinesMenuItem = countLines.CreateToolStripMenuItem(shellServer.SelectedItemPaths, true);

            toolStripMenuItem.DropDownItems.Add(countCleanLinesMenuItem);

            return(toolStripMenuItem);
        }