1212using System . Threading . Tasks ;
1313using System . Windows ;
1414using System . Windows . Controls ;
15+ using System . Windows . Markup . Localizer ;
1516
1617namespace Flow . Launcher . Plugin . Everything
1718{
@@ -107,25 +108,7 @@ private Result CreateResult(string keyword, SearchResult searchResult)
107108 switch ( searchResult . Type )
108109 {
109110 case ResultType . Folder :
110- if ( ! _settings . LaunchHidden )
111- {
112- Process . Start ( _settings . ExplorerPath ,
113- _settings . ExplorerArgs . Replace ( Settings . DirectoryPathPlaceHolder , $ "\" { path } \" ") ) ;
114- }
115- else
116- {
117- ProcessStartInfo startInfo = new ProcessStartInfo ( ) ;
118- //Hide the process
119- startInfo . UseShellExecute = false ;
120- startInfo . RedirectStandardOutput = true ;
121- startInfo . WindowStyle = ProcessWindowStyle . Hidden ;
122- startInfo . CreateNoWindow = true ;
123- //Set file and args
124- startInfo . FileName = _settings . ExplorerPath ;
125- startInfo . Arguments = _settings . ExplorerArgs . Replace ( Settings . DirectoryPathPlaceHolder , $ "\" { path } \" ") ;
126- //Start the process
127- Process proc = Process . Start ( startInfo ) ;
128- }
111+ _context . API . OpenDirectory ( path ) ;
129112 break ;
130113 case ResultType . Volume :
131114 case ResultType . File :
@@ -279,80 +262,85 @@ public string GetTranslatedPluginDescription()
279262
280263 public List < Result > LoadContextMenus ( Result selectedResult )
281264 {
282- SearchResult record = selectedResult . ContextData as SearchResult ;
283- List < Result > contextMenus = new List < Result > ( ) ;
284- if ( record == null ) return contextMenus ;
265+ if ( selectedResult . ContextData is not SearchResult record )
266+ return new List < Result > ( ) ;
285267
286- List < ContextMenu > availableContextMenus = new List < ContextMenu > ( ) ;
287- availableContextMenus . AddRange ( GetDefaultContextMenu ( ) ) ;
288- availableContextMenus . AddRange ( _settings . ContextMenus ) ;
268+ var icoPath = record . Type == ResultType . File ? "Images\\ file.png" : "Images\\ folder.png" ;
289269
290- if ( record . Type == ResultType . File )
270+ List < Result > contextMenus = new List < Result >
291271 {
292- foreach ( ContextMenu contextMenu in availableContextMenus )
272+ new ( )
293273 {
294- var menu = contextMenu ;
295- contextMenus . Add ( new Result
274+ Title = _context . API . GetTranslation ( "flowlauncher_plugin_everything_open_containing_folder" ) ,
275+ Action = _ =>
296276 {
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- } ) ;
277+ _context . API . OpenDirectory ( Path . GetDirectoryName ( record . FullPath ) , record . FullPath ) ;
278+ return true ;
279+ } ,
280+ IcoPath = icoPath ,
281+ Glyph = new GlyphInfo ( "/Resources/#Segoe Fluent Icons" , "\ue8de " )
322282 }
323- }
283+ } ;
324284
325- var icoPath = ( record . Type == ResultType . File ) ? "Images\\ file.png" : "Images\\ folder.png" ;
326- contextMenus . Add ( new Result
285+ if ( record . Type is ResultType . File )
327286 {
328- Title = _context . API . GetTranslation ( "flowlauncher_plugin_everything_copy_path" ) ,
329- Action = ( context ) =>
287+ var notepadPath = string . IsNullOrEmpty ( _settings . EditorPath ) ? "notepad.exe" : _settings . EditorPath ;
288+ contextMenus . Add ( new Result
330289 {
331- Clipboard . SetDataObject ( record . FullPath ) ;
332- return true ;
333- } ,
334- IcoPath = icoPath
335- } ) ;
290+ Title = string . Format ( _context . API . GetTranslation ( "flowlauncher_plugin_everything_open_with_editor" ) ,
291+ Path . GetFileNameWithoutExtension ( notepadPath ) ) ,
292+ Action = state =>
293+ {
294+ using var notepad = new Process ( ) ;
295+ notepad . StartInfo = new ProcessStartInfo ( )
296+ {
297+ FileName = notepadPath ,
298+ Arguments = record . FullPath
299+ } ;
300+ if ( state . SpecialKeyState . CtrlPressed && state . SpecialKeyState . ShiftPressed )
301+ {
302+ notepad . StartInfo . Verb = "runAs" ;
303+ }
304+ Task . Run ( ( ) => notepad . Start ( ) ) ;
305+ return true ;
306+ } ,
307+ Glyph = new GlyphInfo ( "/Resources/#Segoe Fluent Icons" , "\ue932 " )
308+ } ) ;
309+ }
336310
337- contextMenus . Add ( new Result
338- {
339- Title = _context . API . GetTranslation ( "flowlauncher_plugin_everything_copy" ) ,
340- Action = ( context ) =>
311+ contextMenus . Add (
312+ new ( )
341313 {
342- Clipboard . SetFileDropList ( new System . Collections . Specialized . StringCollection
314+ Title = _context . API . GetTranslation ( "flowlauncher_plugin_everything_copy_path" ) ,
315+ Action = _ =>
343316 {
344- record . FullPath
345- } ) ;
346- return true ;
347- } ,
348- IcoPath = icoPath
349- } ) ;
317+ Clipboard . SetDataObject ( record . FullPath ) ;
318+ return true ;
319+ } ,
320+ IcoPath = icoPath ,
321+ Glyph = new GlyphInfo ( "/Resources/#Segoe Fluent Icons" , "\ue8c8 " )
322+ } ) ;
323+ contextMenus . Add (
324+ new Result
325+ {
326+ Title = _context . API . GetTranslation ( "flowlauncher_plugin_everything_copy" ) ,
327+ Action = _ =>
328+ {
329+ Clipboard . SetFileDropList ( new System . Collections . Specialized . StringCollection
330+ {
331+ record . FullPath
332+ } ) ;
333+ return true ;
334+ } ,
335+ IcoPath = icoPath ,
336+ Glyph = new GlyphInfo ( "/Resources/#Segoe Fluent Icons" , "\ue8c8 " )
337+ } ) ;
350338
351- if ( record . Type == ResultType . File || record . Type == ResultType . Folder )
339+ if ( record . Type is ResultType . File or ResultType . Folder )
352340 contextMenus . Add ( new Result
353341 {
354342 Title = _context . API . GetTranslation ( "flowlauncher_plugin_everything_delete" ) ,
355- Action = ( context ) =>
343+ Action = _ =>
356344 {
357345 try
358346 {
@@ -369,9 +357,9 @@ public List<Result> LoadContextMenus(Result selectedResult)
369357
370358 return true ;
371359 } ,
372- IcoPath = icoPath
360+ IcoPath = icoPath ,
361+ Glyph = new ( "/Resources/#Segoe Fluent Icons" , "\ue74d " )
373362 } ) ;
374-
375363 return contextMenus ;
376364 }
377365
@@ -380,4 +368,5 @@ public Control CreateSettingPanel()
380368 return new EverythingSettings ( _settings , new SettingsViewModel ( _api , _settings , _context ) ) ;
381369 }
382370 }
383- }
371+
372+ }
0 commit comments