Skip to content

Commit a3d095f

Browse files
committed
Change interface style
1 parent aeb152b commit a3d095f

File tree

3 files changed

+57
-34
lines changed

3 files changed

+57
-34
lines changed

Flow.Launcher.Infrastructure/QuickSwitch/Models/WindowsDialog.cs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,27 @@ namespace Flow.Launcher.Infrastructure.QuickSwitch.Models
1515
/// </summary>
1616
public class WindowsDialog : IQuickSwitchDialog
1717
{
18-
public IQuickSwitchDialogWindow DialogWindow { get; private set; }
19-
2018
private const string WindowsDialogClassName = "#32770";
2119

22-
public bool CheckDialogWindow(IntPtr hwnd)
20+
public IQuickSwitchDialogWindow CheckDialogWindow(IntPtr hwnd)
2321
{
24-
// Has it been checked?
25-
if (DialogWindow != null && DialogWindow.Handle == hwnd)
26-
{
27-
return true;
28-
}
29-
3022
// Is it a Win32 dialog box?
3123
if (GetClassName(new(hwnd)) == WindowsDialogClassName)
3224
{
3325
// Is it a windows file dialog?
3426
var dialogType = GetFileDialogType(new(hwnd));
3527
if (dialogType != DialogType.Others)
3628
{
37-
DialogWindow = new WindowsDialogWindow(hwnd, dialogType);
38-
39-
return true;
29+
return new WindowsDialogWindow(hwnd, dialogType);
4030
}
4131
}
42-
return false;
32+
33+
return null;
4334
}
4435

4536
public void Dispose()
4637
{
47-
DialogWindow?.Dispose();
48-
DialogWindow = null;
38+
4939
}
5040

5141
#region Help Methods
@@ -101,7 +91,7 @@ public IQuickSwitchDialogWindowTab GetCurrentTab()
10191

10292
public void Dispose()
10393
{
104-
Handle = HWND.Null;
94+
10595
}
10696
}
10797

@@ -219,7 +209,7 @@ public bool Open()
219209

220210
public void Dispose()
221211
{
222-
Handle = HWND.Null;
212+
223213
}
224214

225215
#endregion

Flow.Launcher.Infrastructure/QuickSwitch/QuickSwitch.cs

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public static class QuickSwitch
4848
private static IQuickSwitchExplorer _lastExplorer = null;
4949
private static readonly object _lastExplorerLock = new();
5050

51-
private static readonly List<IQuickSwitchDialog> _quickSwitchDialogs = new()
51+
private static readonly Dictionary<IQuickSwitchDialog, IQuickSwitchDialogWindow> _quickSwitchDialogs = new()
5252
{
53-
new WindowsDialog()
53+
{ new WindowsDialog(), null }
5454
};
5555

5656
private static IQuickSwitchDialogWindow _dialogWindow = null;
@@ -179,6 +179,12 @@ public static void SetupQuickSwitch(bool enabled)
179179
_quickSwitchExplorers[explorer] = null;
180180
}
181181

182+
// Remove dialog windows
183+
foreach (var dialog in _quickSwitchDialogs.Keys)
184+
{
185+
_quickSwitchDialogs[dialog] = null;
186+
}
187+
182188
// Remove dialog window handle
183189
var dialogWindowExists = false;
184190
lock (_dialogWindowLock)
@@ -402,14 +408,27 @@ uint dwmsEventTime
402408
// Check if it is a file dialog window
403409
var isDialogWindow = false;
404410
var dialogWindowChanged = false;
405-
foreach (var dialog in _quickSwitchDialogs)
411+
foreach (var dialog in _quickSwitchDialogs.Keys)
406412
{
407-
if (dialog.CheckDialogWindow(hwnd))
413+
IQuickSwitchDialogWindow dialogWindow;
414+
var existingDialogWindow = _quickSwitchDialogs[dialog];
415+
if (existingDialogWindow != null && existingDialogWindow.Handle == hwnd)
416+
{
417+
// If the dialog window is already in the list, no need to check again
418+
dialogWindow = existingDialogWindow;
419+
}
420+
else
421+
{
422+
dialogWindow = dialog.CheckDialogWindow(hwnd);
423+
}
424+
425+
// If the dialog window is found, set it
426+
if (dialogWindow != null)
408427
{
409428
lock (_dialogWindowLock)
410429
{
411430
dialogWindowChanged = _dialogWindow == null || _dialogWindow.Handle != hwnd;
412-
_dialogWindow = dialog.DialogWindow;
431+
_dialogWindow = dialogWindow;
413432
}
414433

415434
isDialogWindow = true;
@@ -667,21 +686,30 @@ private static IQuickSwitchDialogWindow GetDialogWindow(HWND hwnd)
667686
}
668687

669688
// Then check all dialog windows
670-
foreach (var dialog in _quickSwitchDialogs)
689+
foreach (var dialogWindow in _quickSwitchDialogs.Values)
671690
{
672-
if (dialog.DialogWindow.Handle == hwnd)
691+
if (dialogWindow.Handle == hwnd)
673692
{
674-
return dialog.DialogWindow;
693+
return dialogWindow;
675694
}
676695
}
677696

678-
// Finally search for the dialog window
679-
foreach (var dialog in _quickSwitchDialogs)
697+
// Finally search for the dialog window again
698+
foreach (var dialog in _quickSwitchDialogs.Keys)
680699
{
681-
if (dialog.CheckDialogWindow(hwnd))
700+
IQuickSwitchDialogWindow dialogWindow;
701+
var existingDialogWindow = _quickSwitchDialogs[dialog];
702+
if (existingDialogWindow != null && existingDialogWindow.Handle == hwnd)
682703
{
683-
return dialog.DialogWindow;
704+
// If the dialog window is already in the list, no need to check again
705+
dialogWindow = existingDialogWindow;
684706
}
707+
else
708+
{
709+
dialogWindow = dialog.CheckDialogWindow(hwnd);
710+
}
711+
712+
return dialogWindow;
685713
}
686714

687715
return null;
@@ -820,8 +848,9 @@ public static void Dispose()
820848
}
821849

822850
// Dispose dialogs
823-
foreach (var dialog in _quickSwitchDialogs)
851+
foreach (var dialog in _quickSwitchDialogs.Keys)
824852
{
853+
_quickSwitchDialogs[dialog]?.Dispose();
825854
dialog.Dispose();
826855
}
827856
_quickSwitchDialogs.Clear();

Flow.Launcher.Plugin/Interfaces/IQuickSwitchDialog.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ namespace Flow.Launcher.Plugins
1010
public interface IQuickSwitchDialog : IDisposable
1111
{
1212
/// <summary>
13-
///
13+
/// Check if the foreground window is a file dialog instance.
1414
/// </summary>
15-
IQuickSwitchDialogWindow DialogWindow { get; }
16-
17-
bool CheckDialogWindow(IntPtr hwnd);
15+
/// <param name="hwnd">
16+
/// The handle of the foreground window to check.
17+
/// </param>
18+
/// <returns>
19+
/// The window if the foreground window is a file dialog instance. Null if it is not.
20+
/// </returns>
21+
IQuickSwitchDialogWindow? CheckDialogWindow(IntPtr hwnd);
1822
}
1923

2024
public interface IQuickSwitchDialogWindow : IDisposable

0 commit comments

Comments
 (0)