public ContextMenuStrip GetFileMenuTest( [PexAssumeUnderTest] Sonnenberg.ContextMenu.Program target, string menuType, string clickedItemPath, ShellExtInitServer shellServer ) { ContextMenuStrip result = target.GetFileMenu(menuType, clickedItemPath, shellServer); return(result); }
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; }
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); }
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(""); } }
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; } }
private static string ClickedItemContainingFolder(string clickedItemType, ShellExtInitServer shellServer) { return("Directory" == clickedItemType?Path.GetDirectoryName(shellServer.FolderPath) : Path.GetDirectoryName(shellServer.SelectedItemPaths.First())); }
private static string ClickedItemPath(string menuType, ShellExtInitServer shellServer) { return("Directory" == menuType ? shellServer.FolderPath : shellServer.SelectedItemPaths.First()); }
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); }