Skip to content
This repository was archived by the owner on Jul 18, 2023. It is now read-only.

Commit ae5956f

Browse files
authored
Merge pull request #42 from Flow-Launcher/1.9Upgrade
Use API to OpenParent Folder & Use Glyph in ContextMenu
2 parents 15967b6 + 1c2eaa8 commit ae5956f

8 files changed

Lines changed: 115 additions & 124 deletions

File tree

.github/workflows/build.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [ $default-branch ]
6+
pull_request:
7+
branches: [ $default-branch ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: windows-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Setup .NET
17+
uses: actions/setup-dotnet@v1
18+
with:
19+
dotnet-version: 5.0.x
20+
- name: Restore dependencies
21+
run: dotnet restore
22+
- name: Build
23+
run: dotnet build --no-restore -c Release
24+
- name: Upload Artifact
25+
uses: actions/upload-artifact@v2
26+
with:
27+
name: Flow.Launcher.Plugin.Everything
28+
path: Output/Release/Flow.Launcher.Plugin.Everything
29+

EverythingSettings.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
ItemsSource="{Binding GetSortOptions, Mode=OneWay}"
7777
SelectedItem="{Binding SortOption}"
7878
SelectionChanged="onSelectionChange">
79+
ItemsSource="{Binding GetSortOptions, Mode=OneWay}"
7980
<ComboBox.ItemTemplate>
8081
<DataTemplate>
8182
<Grid>

Flow.Launcher.Plugin.Everything.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
</Content>
5353
</ItemGroup>
5454
<ItemGroup>
55-
<PackageReference Include="Flow.Launcher.Plugin" Version="2.0.0" />
55+
<PackageReference Include="Flow.Launcher.Plugin" Version="2.1.0" />
5656
<PackageReference Include="Droplex" Version="1.4.0" />
57-
<PackageReference Include="JetBrains.Annotations" Version="2021.2.0" />
57+
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
5858
<PackageReference Include="System.Runtime" Version="4.3.1" />
5959
</ItemGroup>
6060
<ItemGroup>

Helper/EnumNameConverter.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ namespace Flow.Launcher.Plugin.Everything.Helper
1111
{
1212
class EnumNameConverter : IValueConverter
1313
{
14-
private Dictionary<string, SortOption> translationRecord = new Dictionary<string, SortOption>();
15-
1614
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1715
{
1816
return value is SortOption option ? option.GetTranslatedName() : value;

Main.cs

Lines changed: 77 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public List<Result> Query(Query query)
5757
IcoPath = "Images\\warning.png",
5858
Action = _ =>
5959
{
60-
if (FilesFolders.FileExists(_settings.EverythingInstalledPath))
61-
FilesFolders.OpenPath(_settings.EverythingInstalledPath);
60+
if (_settings.EverythingInstalledPath.FileExists())
61+
_context.API.OpenDirectory(_settings.EverythingInstalledPath);
6262

6363
return true;
6464
}
@@ -109,23 +109,25 @@ private Result CreateResult(string keyword, SearchResult searchResult)
109109
case ResultType.Folder:
110110
if (!_settings.LaunchHidden)
111111
{
112-
Process.Start(_settings.ExplorerPath,
113-
_settings.ExplorerArgs.Replace(Settings.DirectoryPathPlaceHolder, $"\"{path}\""));
112+
_context.API.OpenDirectory(path);
114113
}
115114
else
116115
{
116+
// Launch hidden is no longer supported due to API change.
117+
// This the default behaviour kept
117118
ProcessStartInfo startInfo = new ProcessStartInfo();
118119
//Hide the process
119120
startInfo.UseShellExecute = false;
120121
startInfo.RedirectStandardOutput = true;
121122
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
122123
startInfo.CreateNoWindow = true;
123124
//Set file and args
124-
startInfo.FileName = _settings.ExplorerPath;
125-
startInfo.Arguments = _settings.ExplorerArgs.Replace(Settings.DirectoryPathPlaceHolder, $"\"{path}\"");
125+
startInfo.FileName = "explorer";
126+
startInfo.Arguments = $"\"{path}\"";
126127
//Start the process
127128
Process proc = Process.Start(startInfo);
128129
}
130+
129131
break;
130132
case ResultType.Volume:
131133
case ResultType.File:
@@ -158,34 +160,6 @@ private Result CreateResult(string keyword, SearchResult searchResult)
158160
return r;
159161
}
160162

161-
private List<ContextMenu> GetDefaultContextMenu()
162-
{
163-
List<ContextMenu> defaultContextMenus = new List<ContextMenu>();
164-
ContextMenu openFolderContextMenu = new ContextMenu
165-
{
166-
Name = _context.API.GetTranslation("flowlauncher_plugin_everything_open_containing_folder"),
167-
Command = _settings.ExplorerPath,
168-
Argument = $"{_settings.ExplorerArgs}",
169-
ImagePath = "Images\\folder.png"
170-
};
171-
172-
defaultContextMenus.Add(openFolderContextMenu);
173-
174-
string editorPath = string.IsNullOrEmpty(_settings.EditorPath) ? "notepad.exe" : _settings.EditorPath;
175-
176-
ContextMenu openWithEditorContextMenu = new ContextMenu
177-
{
178-
Name = string.Format(_context.API.GetTranslation("flowlauncher_plugin_everything_open_with_editor"), Path.GetFileNameWithoutExtension(editorPath)),
179-
Command = editorPath,
180-
Argument = $" {Settings.FilePathPlaceHolder}",
181-
ImagePath = editorPath
182-
};
183-
184-
defaultContextMenus.Add(openWithEditorContextMenu);
185-
186-
return defaultContextMenus;
187-
}
188-
189163
public void Init(PluginInitContext context)
190164
{
191165
_context = context;
@@ -279,80 +253,87 @@ public string GetTranslatedPluginDescription()
279253

280254
public List<Result> LoadContextMenus(Result selectedResult)
281255
{
282-
SearchResult record = selectedResult.ContextData as SearchResult;
283-
List<Result> contextMenus = new List<Result>();
284-
if (record == null) return contextMenus;
256+
if (selectedResult.ContextData is not SearchResult record)
257+
return new List<Result>();
285258

286-
List<ContextMenu> availableContextMenus = new List<ContextMenu>();
287-
availableContextMenus.AddRange(GetDefaultContextMenu());
288-
availableContextMenus.AddRange(_settings.ContextMenus);
259+
var icoPath = record.Type == ResultType.File ? "Images\\file.png" : "Images\\folder.png";
289260

290-
if (record.Type == ResultType.File)
261+
List<Result> contextMenus = new List<Result>
291262
{
292-
foreach (ContextMenu contextMenu in availableContextMenus)
263+
new()
293264
{
294-
var menu = contextMenu;
295-
contextMenus.Add(new Result
265+
Title = _context.API.GetTranslation("flowlauncher_plugin_everything_open_containing_folder"),
266+
Action = _ =>
296267
{
297-
Title = contextMenu.Name,
298-
Action = _ =>
299-
{
300-
var parentPath = Directory.GetParent(record.FullPath);
301-
302-
if ((menu.Argument.Trim() == Settings.DirectoryPathPlaceHolder || string.IsNullOrWhiteSpace(menu.Argument)) && _settings.ExplorerPath.Trim() == Settings.Explorer)
303-
menu.Argument = Settings.DefaultExplorerArgsWithFilePath;
304-
305-
string argument = menu.Argument.Replace(Settings.FilePathPlaceHolder, '"' + record.FullPath + '"')
306-
.Replace(Settings.DirectoryPathPlaceHolder, '"' + parentPath.ToString() + '"');
307-
308-
309-
try
310-
{
311-
Process.Start(menu.Command, argument);
312-
}
313-
catch
314-
{
315-
_context.API.ShowMsg(string.Format(_context.API.GetTranslation("flowlauncher_plugin_everything_canot_start"), record.FullPath), string.Empty, string.Empty);
316-
return false;
317-
}
318-
return true;
319-
},
320-
IcoPath = contextMenu.ImagePath
321-
});
268+
_context.API.OpenDirectory(Path.GetDirectoryName(record.FullPath), record.FullPath);
269+
return true;
270+
},
271+
IcoPath = icoPath,
272+
Glyph = new GlyphInfo("/Resources/#Segoe Fluent Icons", "\ue8de")
322273
}
323-
}
274+
};
324275

325-
var icoPath = (record.Type == ResultType.File) ? "Images\\file.png" : "Images\\folder.png";
326-
contextMenus.Add(new Result
276+
if (record.Type is ResultType.File)
327277
{
328-
Title = _context.API.GetTranslation("flowlauncher_plugin_everything_copy_path"),
329-
Action = (context) =>
278+
var notepadPath = string.IsNullOrEmpty(_settings.EditorPath) ? "notepad.exe" : _settings.EditorPath;
279+
contextMenus.Add(new Result
330280
{
331-
Clipboard.SetDataObject(record.FullPath);
332-
return true;
333-
},
334-
IcoPath = icoPath
335-
});
281+
Title = string.Format(
282+
_context.API.GetTranslation("flowlauncher_plugin_everything_open_with_editor"),
283+
Path.GetFileNameWithoutExtension(notepadPath)
284+
),
285+
Action = state =>
286+
{
287+
using var notepad = new Process();
288+
notepad.StartInfo = new ProcessStartInfo()
289+
{
290+
FileName = notepadPath,
291+
Arguments = record.FullPath
292+
};
293+
if (state.SpecialKeyState.CtrlPressed && state.SpecialKeyState.ShiftPressed)
294+
{
295+
notepad.StartInfo.Verb = "runAs";
296+
}
297+
Task.Run(() => notepad.Start());
298+
return true;
299+
},
300+
Glyph = new GlyphInfo("/Resources/#Segoe Fluent Icons", "\ue932")
301+
});
302+
}
336303

337-
contextMenus.Add(new Result
338-
{
339-
Title = _context.API.GetTranslation("flowlauncher_plugin_everything_copy"),
340-
Action = (context) =>
304+
contextMenus.Add(
305+
new()
341306
{
342-
Clipboard.SetFileDropList(new System.Collections.Specialized.StringCollection
307+
Title = _context.API.GetTranslation("flowlauncher_plugin_everything_copy_path"),
308+
Action = _ =>
343309
{
344-
record.FullPath
345-
});
346-
return true;
347-
},
348-
IcoPath = icoPath
349-
});
310+
Clipboard.SetDataObject(record.FullPath);
311+
return true;
312+
},
313+
IcoPath = icoPath,
314+
Glyph = new GlyphInfo("/Resources/#Segoe Fluent Icons", "\ue8c8")
315+
});
316+
contextMenus.Add(
317+
new Result
318+
{
319+
Title = _context.API.GetTranslation("flowlauncher_plugin_everything_copy"),
320+
Action = _ =>
321+
{
322+
Clipboard.SetFileDropList(new System.Collections.Specialized.StringCollection
323+
{
324+
record.FullPath
325+
});
326+
return true;
327+
},
328+
IcoPath = icoPath,
329+
Glyph = new GlyphInfo("/Resources/#Segoe Fluent Icons", "\ue8c8")
330+
});
350331

351-
if (record.Type == ResultType.File || record.Type == ResultType.Folder)
332+
if (record.Type is ResultType.File or ResultType.Folder)
352333
contextMenus.Add(new Result
353334
{
354335
Title = _context.API.GetTranslation("flowlauncher_plugin_everything_delete"),
355-
Action = (context) =>
336+
Action = _ =>
356337
{
357338
try
358339
{
@@ -369,9 +350,9 @@ public List<Result> LoadContextMenus(Result selectedResult)
369350

370351
return true;
371352
},
372-
IcoPath = icoPath
353+
IcoPath = icoPath,
354+
Glyph = new("/Resources/#Segoe Fluent Icons", "\ue74d")
373355
});
374-
375356
return contextMenus;
376357
}
377358

@@ -380,4 +361,5 @@ public Control CreateSettingPanel()
380361
return new EverythingSettings(_settings, new SettingsViewModel(_api, _settings, _context));
381362
}
382363
}
383-
}
364+
365+
}

Settings.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,6 @@ public class Settings
1111

1212
public string EditorPath { get; set; } = "";
1313

14-
internal const string Explorer = "explorer";
15-
16-
internal const string alternativeExplorerPath = "explorer.exe";
17-
18-
internal string explorerPath = Explorer;
19-
20-
public string ExplorerPath
21-
{
22-
get => explorerPath.Trim() switch
23-
{
24-
"" => Explorer,
25-
alternativeExplorerPath => Explorer,
26-
_ => explorerPath
27-
}; set => explorerPath = value;
28-
}
29-
public string ExplorerArgs { get; set; } = DirectoryPathPlaceHolder;
30-
31-
internal const string DirectoryPathPlaceHolder = "%s";
32-
33-
internal const string FilePathPlaceHolder = "%f";
34-
35-
internal const string DefaultExplorerArgsWithFilePath = "/select, %f";
36-
3714
public List<ContextMenu> ContextMenus = new List<ContextMenu>();
3815

3916
public int MaxSearchCount { get; set; } = DefaultMaxSearchCount;

crowdin.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
files:
2+
- source: Languages/en.xaml
3+
translation: /%original_path%/%two_letters_code%.xaml
4+
commit_message: '[ci skip]'

plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"ActionKeyword": "*",
44
"Name": "Everything",
55
"Description": "Search Everything",
6-
"Author": "qianlifeng,orzfly",
7-
"Version": "1.5.6",
6+
"Author": "qianlifeng, orzfly",
7+
"Version": "1.6.0",
88
"Language": "csharp",
99
"Website": "https://github.com/Flow-Launcher/Flow.Launcher.Plugin.Everything",
1010
"IcoPath": "Images\\find.png",

0 commit comments

Comments
 (0)