mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
adding conetxt menu start
This commit is contained in:
parent
3f3deb8e2a
commit
bec52b81fd
3 changed files with 125 additions and 3 deletions
113
Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs
Normal file
113
Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,13 +9,14 @@ using Wox.Infrastructure.Storage;
|
||||||
|
|
||||||
namespace Wox.Plugin.Folder
|
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 static List<string> _driverNames;
|
||||||
private PluginInitContext _context;
|
private PluginInitContext _context;
|
||||||
|
|
||||||
private readonly Settings _settings;
|
private readonly Settings _settings;
|
||||||
private readonly PluginJsonStorage<Settings> _storage;
|
private readonly PluginJsonStorage<Settings> _storage;
|
||||||
|
private readonly IContextMenu _contextMenuLoader = new ContextMenuLoader();
|
||||||
|
|
||||||
public Main()
|
public Main()
|
||||||
{
|
{
|
||||||
|
|
@ -104,7 +105,8 @@ namespace Wox.Plugin.Folder
|
||||||
string changeTo = path.EndsWith("\\") ? path : path + "\\";
|
string changeTo = path.EndsWith("\\") ? path : path + "\\";
|
||||||
_context.API.ChangeQuery(string.IsNullOrEmpty(queryActionKeyword)? changeTo : queryActionKeyword + " " + changeTo);
|
_context.API.ChangeQuery(string.IsNullOrEmpty(queryActionKeyword)? changeTo : queryActionKeyword + " " + changeTo);
|
||||||
return false;
|
return false;
|
||||||
}
|
},
|
||||||
|
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = path }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -226,7 +228,8 @@ namespace Wox.Plugin.Folder
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
|
ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath}
|
||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
@ -263,5 +266,10 @@ namespace Wox.Plugin.Folder
|
||||||
{
|
{
|
||||||
return _context.API.GetTranslation("wox_plugin_folder_plugin_description");
|
return _context.API.GetTranslation("wox_plugin_folder_plugin_description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Result> LoadContextMenus(Result selectedResult)
|
||||||
|
{
|
||||||
|
return _contextMenuLoader.LoadContextMenus(selectedResult);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -58,6 +58,7 @@
|
||||||
<Compile Include="..\..\SolutionAssemblyInfo.cs">
|
<Compile Include="..\..\SolutionAssemblyInfo.cs">
|
||||||
<Link>Properties\SolutionAssemblyInfo.cs</Link>
|
<Link>Properties\SolutionAssemblyInfo.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="ContextMenuLoader.cs" />
|
||||||
<Compile Include="FolderLink.cs" />
|
<Compile Include="FolderLink.cs" />
|
||||||
<Compile Include="Main.cs" />
|
<Compile Include="Main.cs" />
|
||||||
<Compile Include="FolderPluginSettings.xaml.cs">
|
<Compile Include="FolderPluginSettings.xaml.cs">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue