mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-28 19:20:27 +12:00
Respect extension filter while populating actions list
This commit is contained in:
parent
223b88aa4b
commit
fbcea5a755
|
@ -52,21 +52,13 @@ public ExternalProgram(string name, string path) : this()
|
||||||
Path = path;
|
Path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExternalProgram(string name, string path, string args) : this(name, path)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(args))
|
|
||||||
{
|
|
||||||
Args += " " + args;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Run(string inputPath)
|
public string Run(string inputPath)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(Path) && File.Exists(Path) && !string.IsNullOrWhiteSpace(inputPath))
|
if (!string.IsNullOrEmpty(Path) && File.Exists(Path) && !string.IsNullOrWhiteSpace(inputPath))
|
||||||
{
|
{
|
||||||
inputPath = inputPath.Trim('"');
|
inputPath = inputPath.Trim('"');
|
||||||
|
|
||||||
if (CheckExtension(inputPath, Extensions))
|
if (CheckExtension(inputPath))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -139,7 +131,12 @@ public async Task<string> RunAsync(string inputPath)
|
||||||
return await Task.Run(() => Run(inputPath));
|
return await Task.Run(() => Run(inputPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CheckExtension(string path, string extensions)
|
public bool CheckExtension(string path)
|
||||||
|
{
|
||||||
|
return CheckExtension(path, Extensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CheckExtension(string path, string extensions)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrWhiteSpace(path))
|
if (!string.IsNullOrWhiteSpace(path))
|
||||||
{
|
{
|
||||||
|
|
|
@ -724,7 +724,6 @@ private void UpdateContextMenu(WorkerTask task = null)
|
||||||
tsmiUploadSelectedFile.Visible = uim.SelectedItem.IsFileExist;
|
tsmiUploadSelectedFile.Visible = uim.SelectedItem.IsFileExist;
|
||||||
tsmiDownloadSelectedURL.Visible = uim.SelectedItem.IsFileURL;
|
tsmiDownloadSelectedURL.Visible = uim.SelectedItem.IsFileURL;
|
||||||
tsmiEditSelectedFile.Visible = uim.SelectedItem.IsImageFile;
|
tsmiEditSelectedFile.Visible = uim.SelectedItem.IsImageFile;
|
||||||
tsmiRunAction.Visible = uim.SelectedItem.IsFileExist && Program.DefaultTaskSettings.ExternalPrograms.Count > 0;
|
|
||||||
UpdateActionsMenu(uim.SelectedItem.Info.FilePath);
|
UpdateActionsMenu(uim.SelectedItem.Info.FilePath);
|
||||||
tsmiDeleteSelectedItem.Visible = true;
|
tsmiDeleteSelectedItem.Visible = true;
|
||||||
tsmiDeleteSelectedFile.Visible = uim.SelectedItem.IsFileExist;
|
tsmiDeleteSelectedFile.Visible = uim.SelectedItem.IsFileExist;
|
||||||
|
@ -868,11 +867,16 @@ private void UpdateActionsMenu(string filePath)
|
||||||
{
|
{
|
||||||
tsmiRunAction.DropDownItems.Clear();
|
tsmiRunAction.DropDownItems.Clear();
|
||||||
|
|
||||||
if (Program.DefaultTaskSettings.ExternalPrograms.Count > 0 && !string.IsNullOrEmpty(filePath) && File.Exists(filePath))
|
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
|
||||||
{
|
{
|
||||||
foreach (ExternalProgram action in Program.DefaultTaskSettings.ExternalPrograms)
|
IEnumerable<ExternalProgram> actions = Program.DefaultTaskSettings.ExternalPrograms.
|
||||||
|
Where(x => !string.IsNullOrEmpty(x.Name) && x.CheckExtension(filePath));
|
||||||
|
|
||||||
|
if (actions.Count() > 0)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(action.Name))
|
tsmiRunAction.Visible = true;
|
||||||
|
|
||||||
|
foreach (ExternalProgram action in actions)
|
||||||
{
|
{
|
||||||
string name = action.Name.Truncate(50, "...");
|
string name = action.Name.Truncate(50, "...");
|
||||||
ToolStripMenuItem tsmi = new ToolStripMenuItem(name);
|
ToolStripMenuItem tsmi = new ToolStripMenuItem(name);
|
||||||
|
|
Loading…
Reference in a new issue