Skip to content

Commit 2bdfe24

Browse files
committed
Support result behaviours & Change keyboard for quick switch window & Add reset check
1 parent 5426be0 commit 2bdfe24

File tree

1 file changed

+42
-30
lines changed

1 file changed

+42
-30
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -358,36 +358,35 @@ public void ForwardHistory()
358358
[RelayCommand]
359359
private void LoadContextMenu()
360360
{
361-
// For quick switch mode, we need to navigate to the path
362-
if (IsQuickSwitch)
361+
// For quick switch and right click mode, we need to navigate to the path
362+
if (IsQuickSwitch && Settings.QuickSwitchResultBehaviour == QuickSwitchResultBehaviours.RightClick)
363363
{
364364
if (SelectedResults.SelectedItem != null && DialogWindowHandle != nint.Zero)
365365
{
366366
var result = SelectedResults.SelectedItem.Result;
367367
if (result is QuickSwitchResult quickSwitchResult)
368368
{
369369
Win32Helper.SetForegroundWindow(DialogWindowHandle);
370-
QuickSwitch.JumpToPath(Win32Helper.GetForegroundWindow(), quickSwitchResult.QuickSwitchPath);
370+
QuickSwitch.JumpToPath(DialogWindowHandle, quickSwitchResult.QuickSwitchPath);
371371
}
372372
}
373+
return;
373374
}
375+
374376
// For query mode, we load context menu
375-
else
377+
if (QueryResultsSelected())
376378
{
377-
if (QueryResultsSelected())
378-
{
379-
// When switch to ContextMenu from QueryResults, but no item being chosen, should do nothing
380-
// i.e. Shift+Enter/Ctrl+O right after Alt + Space should do nothing
381-
if (SelectedResults.SelectedItem != null)
382-
{
383-
SelectedResults = ContextMenu;
384-
}
385-
}
386-
else
379+
// When switch to ContextMenu from QueryResults, but no item being chosen, should do nothing
380+
// i.e. Shift+Enter/Ctrl+O right after Alt + Space should do nothing
381+
if (SelectedResults.SelectedItem != null)
387382
{
388-
SelectedResults = Results;
383+
SelectedResults = ContextMenu;
389384
}
390385
}
386+
else
387+
{
388+
SelectedResults = Results;
389+
}
391390
}
392391

393392
[RelayCommand]
@@ -452,16 +451,31 @@ private async Task OpenResultAsync(string index)
452451
return;
453452
}
454453

455-
var hideWindow = await result.ExecuteAsync(new ActionContext
454+
// For quick switch and left click mode, we need to navigate to the path
455+
if (IsQuickSwitch && Settings.QuickSwitchResultBehaviour == QuickSwitchResultBehaviours.LeftClick)
456456
{
457-
// not null means pressing modifier key + number, should ignore the modifier key
458-
SpecialKeyState = index is not null ? SpecialKeyState.Default : GlobalHotkey.CheckModifiers()
459-
})
460-
.ConfigureAwait(false);
461-
462-
if (hideWindow)
457+
if (SelectedResults.SelectedItem != null && DialogWindowHandle != nint.Zero)
458+
{
459+
if (result is QuickSwitchResult quickSwitchResult)
460+
{
461+
Win32Helper.SetForegroundWindow(DialogWindowHandle);
462+
QuickSwitch.JumpToPath(DialogWindowHandle, quickSwitchResult.QuickSwitchPath);
463+
}
464+
}
465+
}
466+
// For query mode, we execute the result
467+
else
463468
{
464-
Hide();
469+
var hideWindow = await result.ExecuteAsync(new ActionContext
470+
{
471+
// not null means pressing modifier key + number, should ignore the modifier key
472+
SpecialKeyState = index is not null ? SpecialKeyState.Default : GlobalHotkey.CheckModifiers()
473+
}).ConfigureAwait(false);
474+
475+
if (hideWindow)
476+
{
477+
Hide();
478+
}
465479
}
466480

467481
if (QueryResultsSelected())
@@ -1109,10 +1123,6 @@ private async Task QueryAsync(bool searchDelay, bool isReQuery = false)
11091123
{
11101124
await QueryResultsAsync(searchDelay, isReQuery);
11111125
}
1112-
else if (IsQuickSwitch)
1113-
{
1114-
return;
1115-
}
11161126
else if (ContextMenuSelected())
11171127
{
11181128
QueryContextMenu();
@@ -1581,7 +1591,7 @@ public bool ShouldIgnoreHotkeys()
15811591

15821592
#region Quick Switch
15831593

1584-
public bool IsQuickSwitch { get; private set; }
1594+
public bool IsQuickSwitch { get; private set; } = false;
15851595
public nint DialogWindowHandle { get; private set; } = nint.Zero;
15861596

15871597
private bool PreviousMainWindowVisibilityStatus { get; set; }
@@ -1632,6 +1642,8 @@ public async void SetupQuickSwitch(nint handle)
16321642

16331643
public void ResetQuickSwitch()
16341644
{
1645+
if (DialogWindowHandle == nint.Zero) return;
1646+
16351647
DialogWindowHandle = nint.Zero;
16361648
IsQuickSwitch = false;
16371649

@@ -1712,7 +1724,7 @@ public void Show()
17121724
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = true });
17131725

17141726
// Switch keyboard layout
1715-
if (StartWithEnglishMode && !IsQuickSwitch)
1727+
if (StartWithEnglishMode)
17161728
{
17171729
Win32Helper.SwitchToEnglishKeyboardLayout(true);
17181730
}
@@ -1779,7 +1791,7 @@ public async void Hide()
17791791
}, DispatcherPriority.Render);
17801792

17811793
// Switch keyboard layout
1782-
if (StartWithEnglishMode && !IsQuickSwitch)
1794+
if (StartWithEnglishMode)
17831795
{
17841796
Win32Helper.RestorePreviousKeyboardLayout();
17851797
}

0 commit comments

Comments
 (0)