Skip to content

Commit 1f78203

Browse files
committed
Support file result behaviours
1 parent 2c6c7d1 commit 1f78203

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

Flow.Launcher.Infrastructure/QuickSwitch/QuickSwitch.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,22 @@ public static void JumpToPath(nint dialog, string path, Action action = null)
582582
bool result;
583583
if (isFile)
584584
{
585-
result = Win32Helper.FileJump(path, dialogHandle);
586-
Log.Debug(ClassName, $"File Jump: {path}");
585+
switch (_settings.QuickSwitchFileResultBehaviour)
586+
{
587+
case QuickSwitchFileResultBehaviours.FullPath:
588+
default:
589+
result = Win32Helper.FileJump(path, dialogHandle, forceFileName: true);
590+
Log.Debug(ClassName, $"File Jump FullPath: {path}");
591+
break;
592+
case QuickSwitchFileResultBehaviours.Directory:
593+
result = Win32Helper.DirJump(Path.GetDirectoryName(path), dialogHandle);
594+
Log.Debug(ClassName, $"File Jump Directory: {path}");
595+
break;
596+
case QuickSwitchFileResultBehaviours.DirectoryAndFileName:
597+
result = Win32Helper.FileJump(path, dialogHandle);
598+
Log.Debug(ClassName, $"File Jump DirectoryAndFileName: {path}");
599+
break;
600+
}
587601
}
588602
else
589603
{

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -698,24 +698,25 @@ private static bool TryGetNotoFont(string langKey, out string notoFont)
698698

699699
private static readonly InputSimulator _inputSimulator = new();
700700

701-
internal static bool FileJump(string filePath, HWND dialogHandle, bool altD = true)
701+
internal static bool FileJump(string filePath, HWND dialogHandle, bool forceFileName = false, bool altD = true)
702702
{
703-
return DirFileJump(Path.GetDirectoryName(filePath), filePath, dialogHandle, altD);
703+
if (forceFileName)
704+
{
705+
return DirFileJumpForFileName(filePath, dialogHandle);
706+
}
707+
else
708+
{
709+
return DirFileJump(Path.GetDirectoryName(filePath), filePath, dialogHandle, altD);
710+
}
704711
}
705712

706713
internal static bool DirJump(string dirPath, HWND dialogHandle, bool altD = true)
707714
{
708715
return DirFileJump(dirPath, null, dialogHandle, altD);
709716
}
710717

711-
private static unsafe bool DirFileJump(string dirPath, string filePath, HWND dialogHandle, bool altD = true, bool editFileName = false)
718+
private static unsafe bool DirFileJump(string dirPath, string filePath, HWND dialogHandle, bool altD = true)
712719
{
713-
// Directly edit file name input box.
714-
if (editFileName)
715-
{
716-
return DirFileJumpForFileName(filePath, dialogHandle);
717-
}
718-
719720
// Alt-D or Ctrl-L to focus on the path input box
720721
if (altD)
721722
{
@@ -752,7 +753,7 @@ private static unsafe bool DirFileJump(string dirPath, string filePath, HWND dia
752753
{
753754
// https://github.com/idkidknow/Flow.Launcher.Plugin.DirQuickJump/issues/1
754755
// The dialog is a legacy one, so we edit file name text box directly.
755-
return DirFileJumpForFileName(string.IsNullOrEmpty(filePath) ? dirPath : filePath, dialogHandle);
756+
return DirFileJumpForFileName(string.IsNullOrEmpty(filePath) ? dirPath : filePath, dialogHandle, true);
756757
}
757758

758759
var timeOut = !SpinWait.SpinUntil(() =>
@@ -784,7 +785,7 @@ private static unsafe bool DirFileJump(string dirPath, string filePath, HWND dia
784785
if (!string.IsNullOrEmpty(filePath))
785786
{
786787
// After navigating to the path, we then set the file name.
787-
return DirFileJump(null, Path.GetFileName(filePath), dialogHandle, altD, true);
788+
return DirFileJumpForFileName(Path.GetFileName(filePath), dialogHandle, true);
788789
}
789790

790791
return true;
@@ -793,7 +794,7 @@ private static unsafe bool DirFileJump(string dirPath, string filePath, HWND dia
793794
/// <summary>
794795
/// Edit file name text box in the file open dialog.
795796
/// </summary>
796-
private static bool DirFileJumpForFileName(string fileName, HWND dialogHandle)
797+
private static bool DirFileJumpForFileName(string fileName, HWND dialogHandle, bool openTwice = false)
797798
{
798799
var controlHandle = PInvoke.FindWindowEx(dialogHandle, HWND.Null, "ComboBoxEx32", null);
799800
controlHandle = PInvoke.FindWindowEx(controlHandle, HWND.Null, "ComboBox", null);
@@ -811,10 +812,13 @@ private static bool DirFileJumpForFileName(string fileName, HWND dialogHandle)
811812

812813
SetWindowText(controlHandle, fileName);
813814

814-
// Alt-O (equivalent to press the Open button) twice. In normal cases it suffices to press once,
815-
// but when the focus is on an irrelevant folder, that press once will just open the irrelevant one.
816-
_inputSimulator.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LMENU, VirtualKeyCode.VK_O);
817815
_inputSimulator.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LMENU, VirtualKeyCode.VK_O);
816+
if (openTwice)
817+
{
818+
// Alt-O (equivalent to press the Open button) twice. In normal cases it suffices to press once,
819+
// but when the focus is on an irrelevant folder, that press once will just open the irrelevant one.
820+
_inputSimulator.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LMENU, VirtualKeyCode.VK_O);
821+
}
818822

819823
return true;
820824
}

0 commit comments

Comments
 (0)