From 832e849a3bd2d3bd44f1dcc3d02ff014bbda881f Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 22 Jun 2020 08:43:59 +1000 Subject: [PATCH] Prompt deletion of file or folder --- .../ContextMenu.cs | 28 ++++++++++++++----- .../Languages/en.xaml | 3 ++ .../Search/Constants.cs | 7 +++-- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs b/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs index 90a3fb2e8ef..a214e6624a5 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -9,7 +9,10 @@ using Flow.Launcher.Plugin.Explorer.Search; using Flow.Launcher.Plugin.Explorer.Search.FolderLinks; using System.Linq; -using System.Reflection; +using MessageBox = System.Windows.Forms.MessageBox; +using MessageBoxIcon = System.Windows.Forms.MessageBoxIcon; +using MessageBoxButton = System.Windows.Forms.MessageBoxButtons; +using DialogResult = System.Windows.Forms.DialogResult; namespace Flow.Launcher.Plugin.Explorer { @@ -101,10 +104,25 @@ public List LoadContextMenus(Result selectedResult) { 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) { @@ -212,15 +230,11 @@ private Result CreateAddToIndexSearchExclusionListResult(SearchResult record) if(!Settings.IndexSearchExcludedSubdirectoryPaths.Any(x => x.Path == record.FullPath)) Settings.IndexSearchExcludedSubdirectoryPaths.Add(new FolderLink { Path = record.FullPath }); - var pluginDirectory = Directory.GetParent(Assembly.GetExecutingAssembly().Location.ToString()); - - var iconPath = pluginDirectory + "\\" + Constants.ExplorerIconImagePath; - Task.Run(() => { Context.API.ShowMsg(Context.API.GetTranslation("plugin_explorer_excludedfromindexsearch_msg"), Context.API.GetTranslation("plugin_explorer_path") + - " " + record.FullPath, iconPath); + " " + record.FullPath, Constants.ExplorerIconImageFullPath); // so the new path can be persisted to storage and not wait till next ViewModel save. Context.API.SaveAppAllSettings(); diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml index bc3f5664af3..01bd1a60fa1 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml @@ -5,6 +5,9 @@ Please select a folder link Are you sure you want to delete {0}? + Are you sure you want to permanently delete this {0}? + Deletion successful + Successfully deleted the {0} Delete diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs index 9c8a300bc8a..541b65d7f6b 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; -using System.Text; +using System.IO; +using System.Reflection; namespace Flow.Launcher.Plugin.Explorer.Search { @@ -23,5 +23,8 @@ internal static class Constants internal const char DirectorySeperator = '\\'; internal const string WindowsIndexingOptions = "srchadmin.dll"; + + internal static string ExplorerIconImageFullPath + => Directory.GetParent(Assembly.GetExecutingAssembly().Location.ToString()) + "\\" + ExplorerIconImagePath; } }