protected override ContextMenuStrip CreateMenu() { // if we are here then every selected item is guaranteed to: // - have an extension // - all extensions are the same // - extension is configured for having context menu var selectedItemPaths = new List <string>(this.SelectedItemPaths); if (!selectedItemPaths.Any() && this.FolderPath.Any()) { selectedItemPaths.Add(this.FolderPath); } var configDir = GetConfigDirFor(selectedItemPaths.First()); var items = BuildMenuFrom(configDir, selectedItemPaths.ToArgumentsString()); if (ConfiguredFileExtensions.Any(x => x.Matching("[any]"))) { var extraItems = BuildMenuFrom(GetConfigDirForAny(), selectedItemPaths.ToArgumentsString()); items = items.Concat(extraItems).ToArray(); } var menu = new ContextMenuStrip(); menu.Items.AddRange(items); return(menu); }
protected override bool CanShowMenu() { if (this.SelectedItemPaths.Count() == 1) { var path = this.SelectedItemPaths.First(); // Debug.Assert(false, "file/folder\n" + path); var ext = Path.GetExtension(path).Replace(".", ""); return (Directory.Exists(this.SelectedItemPaths.First()) || ConfiguredFileExtensions.Any(x => x.Matching(ext)) || ConfiguredFileExtensions.Any(x => x.Matching("[any]"))); } else { foreach (string item in ConfiguredFileExtensions) { var ext = "." + item; if (this.SelectedItemPaths.All(x => x.EndsWith(ext, StringComparison.OrdinalIgnoreCase))) { return(true); } else { return(ConfiguredFileExtensions.Any(x => x.Matching("[any]"))); } } } return(false); }
protected override bool CanShowMenu() { if ((Environment.TickCount - lastPopupTime) < 1000) { return(false); // the query is executed twice if the clicked item is a folder on the folder tree. so exit to avoid duplication } lastPopupTime = Environment.TickCount; // Debug.WriteLine("--------------------"); // Debug.WriteLine("this.SelectedItemPaths.Count: " + this.SelectedItemPaths.Count()); // Debug.WriteLine("this.FolderPath: " + this.FolderPath); // Debug.WriteLine("--------------------"); if (this.SelectedItemPaths.Count() == 1) { // Debug.Assert(false); var path = this.SelectedItemPaths.First(); // Debug.Assert(false, "file/folder\n" + path); var ext = Path.GetExtension(path).Replace(".", ""); return (Directory.Exists(this.SelectedItemPaths.First()) || ConfiguredFileExtensions.Any(x => x.Matching(ext)) || ConfiguredFileExtensions.Any(x => Path.GetFileName(path).MatchingAsExpression(x)) || ConfiguredFileExtensions.Any(x => x.Matching("[any]"))); } else { foreach (string item in ConfiguredFileExtensions) { var ext = "." + item; if (this.SelectedItemPaths.All(x => x.EndsWith(ext, StringComparison.OrdinalIgnoreCase))) { return(true); } else { if (this.SelectedItemPaths.Any()) { return(ConfiguredFileExtensions.Any(x => x.Matching("[any]"))); } else { return(ConfiguredFileExtensions.Any(x => x.Matching("[FOLDER]"))); } } } } return(false); }