adding conetxt menu start

This commit is contained in:
AT 2019-12-11 02:21:50 +02:00
parent 3f3deb8e2a
commit bec52b81fd
3 changed files with 125 additions and 3 deletions

View File

@ -0,0 +1,113 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows;
namespace Wox.Plugin.Folder
{
internal class ContextMenuLoader : IContextMenu
{
private readonly PluginInitContext _context;
public ContextMenuLoader(PluginInitContext context)
{
_context = context;
}
public List<Result> LoadContextMenus(Result selectedResult)
{
var contextMenus = new List<Result>();
if (selectedResult.ContextData is SearchResult record)
{
string editorPath = "notepad.exe"; // TODO add the ability to create a custom editor
var name = "Open With Editor: " + Path.GetFileNameWithoutExtension(editorPath);
contextMenus.Add(new Result
{
Title = name,
Action = _ =>
{
try
{
Process.Start(editorPath, record.FullPath);
}
catch
{
// TODO: update this
_context.API.ShowMsg(
string.Format(_context.API.GetTranslation("wox_plugin_everything_canot_start"),
record.FullPath), string.Empty, string.Empty);
return false;
}
return true;
},
IcoPath = editorPath
});
var icoPath = (record.Type == ResultType.File) ? "Images\\file.png" : "Images\\folder.png";
contextMenus.Add(new Result
{
Title = _context.API.GetTranslation("wox_plugin_everything_copy_path"),
Action = (context) =>
{
Clipboard.SetText(record.FullPath);
return true;
},
IcoPath = icoPath
});
contextMenus.Add(new Result
{
Title = _context.API.GetTranslation("wox_plugin_everything_copy"),
Action = (context) =>
{
Clipboard.SetFileDropList(new System.Collections.Specialized.StringCollection { record.FullPath });
return true;
},
IcoPath = icoPath
});
if (record.Type == ResultType.File || record.Type == ResultType.Folder)
contextMenus.Add(new Result
{
Title = _context.API.GetTranslation("wox_plugin_everything_delete"),
Action = (context) =>
{
try
{
if (record.Type == ResultType.File)
System.IO.File.Delete(record.FullPath);
else
System.IO.Directory.Delete(record.FullPath);
}
catch
{
_context.API.ShowMsg(string.Format(_context.API.GetTranslation("wox_plugin_everything_canot_delete"), record.FullPath), string.Empty, string.Empty);
return false;
}
return true;
},
IcoPath = icoPath
});
}
return contextMenus;
}
}
public class SearchResult
{
public string FullPath { get; set; }
public ResultType Type { get; set; }
}
public enum ResultType
{
Volume,
Folder,
File
}
}

View File

@ -9,13 +9,14 @@ using Wox.Infrastructure.Storage;
namespace Wox.Plugin.Folder
{
public class Main : IPlugin, ISettingProvider, IPluginI18n, ISavable
public class Main : IPlugin, ISettingProvider, IPluginI18n, ISavable, IContextMenu
{
private static List<string> _driverNames;
private PluginInitContext _context;
private readonly Settings _settings;
private readonly PluginJsonStorage<Settings> _storage;
private readonly IContextMenu _contextMenuLoader = new ContextMenuLoader();
public Main()
{
@ -104,7 +105,8 @@ namespace Wox.Plugin.Folder
string changeTo = path.EndsWith("\\") ? path : path + "\\";
_context.API.ChangeQuery(string.IsNullOrEmpty(queryActionKeyword)? changeTo : queryActionKeyword + " " + changeTo);
return false;
}
},
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = path }
};
}
@ -226,7 +228,8 @@ namespace Wox.Plugin.Folder
}
return true;
}
},
ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath}
};
return result;
}
@ -263,5 +266,10 @@ namespace Wox.Plugin.Folder
{
return _context.API.GetTranslation("wox_plugin_folder_plugin_description");
}
public List<Result> LoadContextMenus(Result selectedResult)
{
return _contextMenuLoader.LoadContextMenus(selectedResult);
}
}
}

View File

@ -58,6 +58,7 @@
<Compile Include="..\..\SolutionAssemblyInfo.cs">
<Link>Properties\SolutionAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ContextMenuLoader.cs" />
<Compile Include="FolderLink.cs" />
<Compile Include="Main.cs" />
<Compile Include="FolderPluginSettings.xaml.cs">