public List <Result> LoadContextMenus(Result selectedResult) { var contextMenus = new List <Result>(); if (selectedResult.ContextData is SearchResult record) { if (record.Type == ResultType.File) { contextMenus.Add(CreateOpenWithEditorResult(record)); } if (record.Type == ResultType.Folder && record.WindowsIndexed) { contextMenus.Add(CreateAddToIndexSearchExclusionListResult(record)); } contextMenus.Add(CreateOpenContainingFolderResult(record)); contextMenus.Add(CreateOpenWindowsIndexingOptions()); if (record.ShowIndexState) { contextMenus.Add(new Result { Title = "From index search: " + (record.WindowsIndexed ? "Yes" : "No"), SubTitle = "Location: " + record.FullPath, Score = 501, IcoPath = Constants.IndexImagePath }); } var icoPath = (record.Type == ResultType.File) ? Constants.FileImagePath : Constants.FolderImagePath; var fileOrFolder = (record.Type == ResultType.File) ? "file" : "folder"; if (!Settings.QuickAccessLinks.Any(x => x.Path == record.FullPath)) { contextMenus.Add(new Result { Title = Context.API.GetTranslation("plugin_explorer_add_to_quickaccess_title"), SubTitle = string.Format(Context.API.GetTranslation("plugin_explorer_add_to_quickaccess_subtitle"), fileOrFolder), Action = (context) => { Settings.QuickAccessLinks.Add(new AccessLink { Path = record.FullPath, Type = record.Type }); Context.API.ShowMsg(Context.API.GetTranslation("plugin_explorer_addfilefoldersuccess"), string.Format( Context.API.GetTranslation("plugin_explorer_addfilefoldersuccess_detail"), fileOrFolder), Constants.ExplorerIconImageFullPath); ViewModel.Save(); return(true); }, SubTitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_titletooltip"), TitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_titletooltip"), IcoPath = Constants.QuickAccessImagePath }); } else { contextMenus.Add(new Result { Title = Context.API.GetTranslation("plugin_explorer_remove_from_quickaccess_title"), SubTitle = string.Format(Context.API.GetTranslation("plugin_explorer_remove_from_quickaccess_subtitle"), fileOrFolder), Action = (context) => { Settings.QuickAccessLinks.Remove(Settings.QuickAccessLinks.FirstOrDefault(x => x.Path == record.FullPath)); Context.API.ShowMsg(Context.API.GetTranslation("plugin_explorer_removefilefoldersuccess"), string.Format( Context.API.GetTranslation("plugin_explorer_removefilefoldersuccess_detail"), fileOrFolder), Constants.ExplorerIconImageFullPath); ViewModel.Save(); return(true); }, SubTitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_remove_titletooltip"), TitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_remove_titletooltip"), IcoPath = Constants.RemoveQuickAccessImagePath }); } contextMenus.Add(new Result { Title = Context.API.GetTranslation("plugin_explorer_copypath"), SubTitle = $"Copy the current {fileOrFolder} path to clipboard", Action = (context) => { try { Clipboard.SetText(record.FullPath); return(true); } catch (Exception e) { var message = "Fail to set text in clipboard"; LogException(message, e); Context.API.ShowMsg(message); return(false); } }, IcoPath = Constants.CopyImagePath }); contextMenus.Add(new Result { Title = Context.API.GetTranslation("plugin_explorer_copyfilefolder") + $" {fileOrFolder}", SubTitle = $"Copy the {fileOrFolder} to clipboard", Action = (context) => { try { Clipboard.SetFileDropList(new System.Collections.Specialized.StringCollection { record.FullPath }); return(true); } catch (Exception e) { var message = $"Fail to set {fileOrFolder} in clipboard"; LogException(message, e); Context.API.ShowMsg(message); return(false); } }, IcoPath = icoPath }); if (record.Type == ResultType.File || record.Type == ResultType.Folder) { contextMenus.Add(new Result { Title = Context.API.GetTranslation("plugin_explorer_deletefilefolder") + $" {fileOrFolder}", SubTitle = Context.API.GetTranslation("plugin_explorer_deletefilefolder_subtitle") + $" {fileOrFolder}", Action = (context) => { try { if (MessageBox.Show( string.Format(Context.API.GetTranslation("plugin_explorer_deletefilefolderconfirm"), fileOrFolder), string.Empty, MessageBoxButton.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return(false); } if (record.Type == ResultType.File) { File.Delete(record.FullPath); } else { Directory.Delete(record.FullPath, true); } Task.Run(() => { Context.API.ShowMsg(Context.API.GetTranslation("plugin_explorer_deletefilefoldersuccess"), string.Format(Context.API.GetTranslation("plugin_explorer_deletefilefoldersuccess_detail"), fileOrFolder), Constants.ExplorerIconImageFullPath); }); } catch (Exception e) { var message = $"Fail to delete {fileOrFolder} at {record.FullPath}"; LogException(message, e); Context.API.ShowMsgError(message); return(false); } return(true); }, IcoPath = Constants.DeleteFileFolderImagePath }); } if (record.Type == ResultType.File && CanRunAsDifferentUser(record.FullPath)) { contextMenus.Add(new Result { Title = Context.API.GetTranslation("plugin_explorer_runasdifferentuser"), SubTitle = Context.API.GetTranslation("plugin_explorer_runasdifferentuser_subtitle"), Action = (context) => { try { Task.Run(() => ShellCommand.RunAsDifferentUser(record.FullPath.SetProcessStartInfo())); } catch (FileNotFoundException e) { var name = "Plugin: Folder"; var message = $"File not found: {e.Message}"; Context.API.ShowMsgError(name, message); } return(true); }, IcoPath = Constants.DifferentUserIconImagePath }); } } return(contextMenus); }
public List <Result> LoadContextMenus(Result selectedResult) { var contextMenus = new List <Result>(); if (selectedResult.ContextData is SearchResult record) { if (record.Type == ResultType.File) { contextMenus.Add(CreateOpenWithEditorResult(record)); contextMenus.Add(CreateOpenContainingFolderResult(record)); } var icoPath = (record.Type == ResultType.File) ? Main.FileImagePath : Main.FolderImagePath; var fileOrFolder = (record.Type == ResultType.File) ? "file" : "folder"; contextMenus.Add(new Result { Title = "Copy path", SubTitle = $"Copy the current {fileOrFolder} path to clipboard", Action = (context) => { try { Clipboard.SetText(record.FullPath); return(true); } catch (Exception e) { var message = "Fail to set text in clipboard"; LogException(message, e); _context.API.ShowMsg(message); return(false); } }, IcoPath = Main.CopyImagePath }); contextMenus.Add(new Result { Title = $"Copy {fileOrFolder}", SubTitle = $"Copy the {fileOrFolder} to clipboard", Action = (context) => { try { Clipboard.SetFileDropList(new System.Collections.Specialized.StringCollection { record.FullPath }); return(true); } catch (Exception e) { var message = $"Fail to set {fileOrFolder} in clipboard"; LogException(message, e); _context.API.ShowMsg(message); return(false); } }, IcoPath = icoPath }); if (record.Type == ResultType.File || record.Type == ResultType.Folder) { contextMenus.Add(new Result { Title = $"Delete {fileOrFolder}", SubTitle = $"Delete the selected {fileOrFolder}", Action = (context) => { try { if (record.Type == ResultType.File) { File.Delete(record.FullPath); } else { Directory.Delete(record.FullPath); } } catch (Exception e) { var message = $"Fail to delete {fileOrFolder} at {record.FullPath}"; LogException(message, e); _context.API.ShowMsg(message); return(false); } return(true); }, IcoPath = Main.DeleteFileFolderImagePath }); } if (record.Type == ResultType.File && CanRunAsDifferentUser(record.FullPath)) { contextMenus.Add(new Result { Title = "Run as different user", Action = (context) => { try { Task.Run(() => ShellCommand.RunAsDifferentUser(record.FullPath.SetProcessStartInfo())); } catch (FileNotFoundException e) { var name = "Plugin: Folder"; var message = $"File not found: {e.Message}"; _context.API.ShowMsg(name, message); } return(true); }, IcoPath = "Images/user.png" }); } } return(contextMenus); }
public List <Result> LoadContextMenus(Result selectedResult) { var contextMenus = new List <Result>(); if (selectedResult.ContextData is SearchResult record) { if (record.Type == ResultType.File) { contextMenus.Add(CreateOpenWithEditorResult(record)); } if (record.Type == ResultType.Folder && record.WindowsIndexed) { contextMenus.Add(CreateAddToIndexSearchExclusionListResult(record)); } contextMenus.Add(CreateOpenContainingFolderResult(record)); contextMenus.Add(CreateOpenWindowsIndexingOptions()); if (record.ShowIndexState) { contextMenus.Add(new Result { Title = "From index search: " + (record.WindowsIndexed ? "Yes" : "No"), SubTitle = "Location: " + record.FullPath, Score = 501, IcoPath = Constants.IndexImagePath }); } var icoPath = (record.Type == ResultType.File) ? Constants.FileImagePath : Constants.FolderImagePath; var fileOrFolder = (record.Type == ResultType.File) ? "file" : "folder"; contextMenus.Add(new Result { Title = Context.API.GetTranslation("plugin_explorer_copypath"), SubTitle = $"Copy the current {fileOrFolder} path to clipboard", Action = (context) => { try { Clipboard.SetText(record.FullPath); return(true); } catch (Exception e) { var message = "Fail to set text in clipboard"; LogException(message, e); Context.API.ShowMsg(message); return(false); } }, IcoPath = Constants.CopyImagePath }); contextMenus.Add(new Result { Title = Context.API.GetTranslation("plugin_explorer_copyfilefolder") + $" {fileOrFolder}", SubTitle = $"Copy the {fileOrFolder} to clipboard", Action = (context) => { try { Clipboard.SetFileDropList(new System.Collections.Specialized.StringCollection { record.FullPath }); return(true); } catch (Exception e) { var message = $"Fail to set {fileOrFolder} in clipboard"; LogException(message, e); Context.API.ShowMsg(message); return(false); } }, IcoPath = icoPath }); if (record.Type == ResultType.File || record.Type == ResultType.Folder) { contextMenus.Add(new Result { Title = Context.API.GetTranslation("plugin_explorer_deletefilefolder") + $" {fileOrFolder}", SubTitle = Context.API.GetTranslation("plugin_explorer_deletefilefolder_subtitle") + $" {fileOrFolder}", Action = (context) => { try { if (record.Type == ResultType.File) { File.Delete(record.FullPath); } else { Directory.Delete(record.FullPath, true); } } catch (Exception e) { var message = $"Fail to delete {fileOrFolder} at {record.FullPath}"; LogException(message, e); Context.API.ShowMsg(message); return(false); } return(true); }, IcoPath = Constants.DeleteFileFolderImagePath }); } if (record.Type == ResultType.File && CanRunAsDifferentUser(record.FullPath)) { contextMenus.Add(new Result { Title = Context.API.GetTranslation("plugin_explorer_runasdifferentuser"), SubTitle = Context.API.GetTranslation("plugin_explorer_runasdifferentuser_subtitle"), Action = (context) => { try { Task.Run(() => ShellCommand.RunAsDifferentUser(record.FullPath.SetProcessStartInfo())); } catch (FileNotFoundException e) { var name = "Plugin: Folder"; var message = $"File not found: {e.Message}"; Context.API.ShowMsg(name, message); } return(true); }, IcoPath = Constants.DifferentUserIconImagePath }); } } return(contextMenus); }