Skip to content

Commit e2a0876

Browse files
authored
Merge pull request #74 from Flow-Launcher/explorer_prompt_deletion
Prompt deletion of file or folder
2 parents f177510 + a0f2ae7 commit e2a0876

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
@@ -9,7 +9,10 @@
99
using Flow.Launcher.Plugin.Explorer.Search;
1010
using Flow.Launcher.Plugin.Explorer.Search.FolderLinks;
1111
using System.Linq;
12-
using System.Reflection;
12+
using MessageBox = System.Windows.Forms.MessageBox;
13+
using MessageBoxIcon = System.Windows.Forms.MessageBoxIcon;
14+
using MessageBoxButton = System.Windows.Forms.MessageBoxButtons;
15+
using DialogResult = System.Windows.Forms.DialogResult;
1316

1417
namespace Flow.Launcher.Plugin.Explorer
1518
{
@@ -101,10 +104,25 @@ public List<Result> LoadContextMenus(Result selectedResult)
101104
{
102105
try
103106
{
107+
if (MessageBox.Show(
108+
string.Format(Context.API.GetTranslation("plugin_explorer_deletefilefolderconfirm"),fileOrFolder),
109+
string.Empty,
110+
MessageBoxButton.YesNo,
111+
MessageBoxIcon.Warning)
112+
== DialogResult.No)
113+
return false;
114+
104115
if (record.Type == ResultType.File)
105116
File.Delete(record.FullPath);
106117
else
107118
Directory.Delete(record.FullPath, true);
119+
120+
Task.Run(() =>
121+
{
122+
Context.API.ShowMsg(Context.API.GetTranslation("plugin_explorer_deletefilefoldersuccess"),
123+
string.Format(Context.API.GetTranslation("plugin_explorer_deletefilefoldersuccess_detail"), fileOrFolder),
124+
Constants.ExplorerIconImageFullPath);
125+
});
108126
}
109127
catch (Exception e)
110128
{
@@ -212,15 +230,11 @@ private Result CreateAddToIndexSearchExclusionListResult(SearchResult record)
212230
if(!Settings.IndexSearchExcludedSubdirectoryPaths.Any(x => x.Path == record.FullPath))
213231
Settings.IndexSearchExcludedSubdirectoryPaths.Add(new FolderLink { Path = record.FullPath });
214232

215-
var pluginDirectory = Directory.GetParent(Assembly.GetExecutingAssembly().Location.ToString());
216-
217-
var iconPath = pluginDirectory + "\\" + Constants.ExplorerIconImagePath;
218-
219233
Task.Run(() =>
220234
{
221235
Context.API.ShowMsg(Context.API.GetTranslation("plugin_explorer_excludedfromindexsearch_msg"),
222236
Context.API.GetTranslation("plugin_explorer_path") +
223-
" " + record.FullPath, iconPath);
237+
" " + record.FullPath, Constants.ExplorerIconImageFullPath);
224238

225239
// so the new path can be persisted to storage and not wait till next ViewModel save.
226240
Context.API.SaveAppAllSettings();

Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<!--Dialogues-->
66
<system:String x:Key="plugin_explorer_select_folder_link_warning">Please select a folder link</system:String>
77
<system:String x:Key="plugin_explorer_delete_folder_link">Are you sure you want to delete {0}?</system:String>
8+
<system:String x:Key="plugin_explorer_deletefilefolderconfirm">Are you sure you want to permanently delete this {0}?</system:String>
9+
<system:String x:Key="plugin_explorer_deletefilefoldersuccess">Deletion successful</system:String>
10+
<system:String x:Key="plugin_explorer_deletefilefoldersuccess_detail">Successfully deleted the {0}</system:String>
811

912
<!--Controls-->
1013
<system:String x:Key="plugin_explorer_delete">Delete</system:String>

Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
2+
using System.IO;
3+
using System.Reflection;
44

55
namespace Flow.Launcher.Plugin.Explorer.Search
66
{
@@ -25,5 +25,8 @@ internal static class Constants
2525
internal const char DirectorySeperator = '\\';
2626

2727
internal const string WindowsIndexingOptions = "srchadmin.dll";
28+
29+
internal static string ExplorerIconImageFullPath
30+
=> Directory.GetParent(Assembly.GetExecutingAssembly().Location.ToString()) + "\\" + ExplorerIconImagePath;
2831
}
2932
}

0 commit comments

Comments
 (0)