20
20
using Microsoft . VisualStudio . Threading ;
21
21
using System . Threading . Channels ;
22
22
using ISavable = Flow . Launcher . Plugin . ISavable ;
23
-
23
+ using System . Runtime . InteropServices ;
24
+ using System . Text ;
25
+ using SHDocVw ;
24
26
25
27
namespace Flow . Launcher . ViewModel
26
28
{
@@ -720,6 +722,62 @@ private void SetOpenResultModifiers()
720
722
OpenResultCommandModifiers = _settings . OpenResultModifiers ?? DefaultOpenResultModifiers ;
721
723
}
722
724
725
+ private static string GetActiveExplorerPath ( )
726
+ {
727
+ // get the active window
728
+ IntPtr handle = GetForegroundWindow ( ) ;
729
+
730
+ // Required ref: SHDocVw (Microsoft Internet Controls COM Object) - C:\Windows\system32\ShDocVw.dll
731
+ ShellWindows shellWindows = new SHDocVw . ShellWindows ( ) ;
732
+
733
+ // loop through all windows
734
+ foreach ( InternetExplorer window in shellWindows )
735
+ {
736
+ // match active window
737
+ if ( window . HWND == ( int ) handle )
738
+ {
739
+ // Required ref: Shell32 - C:\Windows\system32\Shell32.dll
740
+ var shellWindow = window . Document as Shell32 . IShellFolderViewDual2 ;
741
+
742
+ // will be null if you are in Internet Explorer for example
743
+ if ( shellWindow != null )
744
+ {
745
+ // Item without an index returns the current object
746
+ var currentFolder = shellWindow . Folder . Items ( ) . Item ( ) ;
747
+
748
+ // special folder - use window title
749
+ // for some reason on "Desktop" gives null
750
+ if ( currentFolder == null || currentFolder . Path . StartsWith ( "::" ) )
751
+ {
752
+ // Get window title instead
753
+ const int nChars = 256 ;
754
+ StringBuilder Buff = new StringBuilder ( nChars ) ;
755
+ if ( GetWindowText ( handle , Buff , nChars ) > 0 )
756
+ {
757
+ return Buff . ToString ( ) ;
758
+ }
759
+ }
760
+ else
761
+ {
762
+ return currentFolder . Path ;
763
+ }
764
+ }
765
+
766
+ break ;
767
+ }
768
+ }
769
+
770
+ return null ;
771
+ }
772
+
773
+ // COM Imports
774
+
775
+ [ DllImport ( "user32.dll" ) ]
776
+ private static extern IntPtr GetForegroundWindow ( ) ;
777
+
778
+ [ DllImport ( "user32.dll" ) ]
779
+ static extern int GetWindowText ( IntPtr hWnd , StringBuilder text , int count ) ;
780
+
723
781
public void ToggleFlowLauncher ( )
724
782
{
725
783
if ( ! MainWindowVisibilityStatus )
@@ -734,6 +792,9 @@ public void ToggleFlowLauncher()
734
792
735
793
public void Show ( )
736
794
{
795
+ string _explorerPath = GetActiveExplorerPath ( ) ;
796
+
797
+ ChangeQueryText ( $ "{ _explorerPath } \\ >") ;
737
798
if ( _settings . UseSound )
738
799
{
739
800
MediaPlayer media = new MediaPlayer ( ) ;
@@ -749,6 +810,8 @@ public void Show()
749
810
( ( MainWindow ) Application . Current . MainWindow ) . WindowAnimator ( ) ;
750
811
751
812
MainWindowOpacity = 1 ;
813
+
814
+
752
815
}
753
816
754
817
public async void Hide ( )
0 commit comments