@@ -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,103 +253,109 @@ 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- }
324-
325- var icoPath = ( record . Type == ResultType . File ) ? "Images\\ file.png" : "Images\\ folder.png" ;
274+ } ;
326275
327- if ( _settings . ShowWindowsContextMenu )
276+ if ( record . Type is ResultType . File )
328277 {
329- contextMenus . Add ( new Result
330- {
331- Title = _context . API . GetTranslation ( "flowlauncher_plugin_everything_show_windows_context_menu" ) ,
332- Action = ( context ) =>
333- {
334- var fileInfos = new FileInfo [ ] { new ( record . FullPath ) } ;
335-
336- var screenWithMouseCursor = System . Windows . Forms . Screen . FromPoint ( System . Windows . Forms . Cursor . Position ) ;
337- var xOfScreenCenter = screenWithMouseCursor . WorkingArea . Left + screenWithMouseCursor . WorkingArea . Width / 2 ;
338- var yOfScreenCenter = screenWithMouseCursor . WorkingArea . Top + screenWithMouseCursor . WorkingArea . Height / 2 ;
339- var showPosition = new System . Drawing . Point ( xOfScreenCenter , yOfScreenCenter ) ;
340-
341- new Peter . ShellContextMenu ( ) . ShowContextMenu ( fileInfos , showPosition ) ;
342-
343- return true ;
344- } ,
345- IcoPath = icoPath
346- } ) ;
278+ var notepadPath = string . IsNullOrEmpty ( _settings . EditorPath ) ? "notepad.exe" : _settings . EditorPath ;
279+ contextMenus . Add ( new Result
280+ {
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+ } ) ;
347302 }
348303
349- contextMenus . Add ( new Result
304+ if ( _settings . ShowWindowsContextMenu )
350305 {
351- Title = _context . API . GetTranslation ( "flowlauncher_plugin_everything_copy_path" ) ,
352- Action = ( context ) =>
306+ contextMenus . Add ( new Result
353307 {
354- Clipboard . SetDataObject ( record . FullPath ) ;
355- return true ;
356- } ,
357- IcoPath = icoPath
358- } ) ;
308+ Title = _context . API . GetTranslation ( "flowlauncher_plugin_everything_show_windows_context_menu" ) ,
309+ Action = ( context ) =>
310+ {
311+ var fileInfos = new FileInfo [ ] { new ( record . FullPath ) } ;
359312
360- contextMenus . Add ( new Result
361- {
362- Title = _context . API . GetTranslation ( "flowlauncher_plugin_everything_copy" ) ,
363- Action = ( context ) =>
313+ var screenWithMouseCursor = System . Windows . Forms . Screen . FromPoint ( System . Windows . Forms . Cursor . Position ) ;
314+ var xOfScreenCenter = screenWithMouseCursor . WorkingArea . Left + screenWithMouseCursor . WorkingArea . Width / 2 ;
315+ var yOfScreenCenter = screenWithMouseCursor . WorkingArea . Top + screenWithMouseCursor . WorkingArea . Height / 2 ;
316+ var showPosition = new System . Drawing . Point ( xOfScreenCenter , yOfScreenCenter ) ;
317+
318+ new Peter . ShellContextMenu ( ) . ShowContextMenu ( fileInfos , showPosition ) ;
319+
320+ return true ;
321+ } ,
322+ IcoPath = icoPath
323+ } ) ;
324+ }
325+
326+ contextMenus . Add (
327+ new ( )
364328 {
365- Clipboard . SetFileDropList ( new System . Collections . Specialized . StringCollection
329+ Title = _context . API . GetTranslation ( "flowlauncher_plugin_everything_copy_path" ) ,
330+ Action = _ =>
366331 {
367- record . FullPath
368- } ) ;
369- return true ;
370- } ,
371- IcoPath = icoPath
372- } ) ;
332+ Clipboard . SetDataObject ( record . FullPath ) ;
333+ return true ;
334+ } ,
335+ IcoPath = icoPath ,
336+ Glyph = new GlyphInfo ( "/Resources/#Segoe Fluent Icons" , "\ue8c8 " )
337+ } ) ;
338+ contextMenus . Add (
339+ new Result
340+ {
341+ Title = _context . API . GetTranslation ( "flowlauncher_plugin_everything_copy" ) ,
342+ Action = _ =>
343+ {
344+ Clipboard . SetFileDropList ( new System . Collections . Specialized . StringCollection
345+ {
346+ record . FullPath
347+ } ) ;
348+ return true ;
349+ } ,
350+ IcoPath = icoPath ,
351+ Glyph = new GlyphInfo ( "/Resources/#Segoe Fluent Icons" , "\ue8c8 " )
352+ } ) ;
373353
374- if ( record . Type == ResultType . File || record . Type == ResultType . Folder )
354+ if ( record . Type is ResultType . File or ResultType . Folder )
375355 contextMenus . Add ( new Result
376356 {
377357 Title = _context . API . GetTranslation ( "flowlauncher_plugin_everything_delete" ) ,
378- Action = ( context ) =>
358+ Action = _ =>
379359 {
380360 try
381361 {
@@ -392,9 +372,9 @@ public List<Result> LoadContextMenus(Result selectedResult)
392372
393373 return true ;
394374 } ,
395- IcoPath = icoPath
375+ IcoPath = icoPath ,
376+ Glyph = new ( "/Resources/#Segoe Fluent Icons" , "\ue74d " )
396377 } ) ;
397-
398378 return contextMenus ;
399379 }
400380
@@ -403,4 +383,5 @@ public Control CreateSettingPanel()
403383 return new EverythingSettings ( _settings , new SettingsViewModel ( _api , _settings , _context ) ) ;
404384 }
405385 }
386+
406387}
0 commit comments