Skip to content

Commit d2325d5

Browse files
committed
Initialize third party file dialog support
1 parent ce93746 commit d2325d5

File tree

5 files changed

+315
-100
lines changed

5 files changed

+315
-100
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using Windows.Win32.Foundation;
3+
4+
namespace Flow.Launcher.Infrastructure.QuickSwitch.Interface
5+
{
6+
/// <summary>
7+
/// Interface for handling File Dialog instances in QuickSwitch.
8+
/// </summary>
9+
/// <remarks>
10+
/// Add models in QuickSwitch/Models folder and implement this interface.
11+
/// Then add the instance in QuickSwitch._quickSwitchDialogs.
12+
/// </remarks>
13+
internal interface IQuickSwitchDialog : IDisposable
14+
{
15+
internal IQuickSwitchDialogWindow DialogWindow { get; }
16+
17+
internal bool CheckDialogWindow(HWND hwnd);
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace Flow.Launcher.Infrastructure.QuickSwitch.Interface
4+
{
5+
internal interface IQuickSwitchDialogTab : IDisposable
6+
{
7+
internal string GetCurrentFolder();
8+
9+
internal string GetCurrentFile();
10+
11+
internal bool OpenFolder(string path);
12+
}
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using Windows.Win32.Foundation;
3+
4+
namespace Flow.Launcher.Infrastructure.QuickSwitch.Interface
5+
{
6+
internal interface IQuickSwitchDialogWindow : IDisposable
7+
{
8+
internal HWND Handle { get; }
9+
10+
internal IQuickSwitchDialogTab GetCurrentTab();
11+
}
12+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using Flow.Launcher.Infrastructure.QuickSwitch.Interface;
2+
using Windows.Win32;
3+
using Windows.Win32.Foundation;
4+
5+
namespace Flow.Launcher.Infrastructure.QuickSwitch.Models
6+
{
7+
internal class WindowsDialog : IQuickSwitchDialog
8+
{
9+
// The class name of a dialog window
10+
private const string WindowsDialogClassName = "#32770";
11+
12+
public IQuickSwitchDialogWindow DialogWindow { get; private set; }
13+
14+
public bool CheckDialogWindow(HWND hwnd)
15+
{
16+
if (GetWindowClassName(hwnd) == WindowsDialogClassName)
17+
{
18+
if (DialogWindow == null || DialogWindow.Handle != hwnd)
19+
{
20+
DialogWindow = new WindowsDialogWindow(hwnd);
21+
}
22+
return true;
23+
}
24+
return false;
25+
}
26+
27+
public void Dispose()
28+
{
29+
DialogWindow?.Dispose();
30+
DialogWindow = null;
31+
}
32+
33+
public static string GetWindowClassName(HWND handle)
34+
{
35+
return GetClassName(handle);
36+
37+
static unsafe string GetClassName(HWND handle)
38+
{
39+
fixed (char* buf = new char[256])
40+
{
41+
return PInvoke.GetClassName(handle, buf, 256) switch
42+
{
43+
0 => null,
44+
_ => new string(buf),
45+
};
46+
}
47+
}
48+
}
49+
}
50+
51+
internal class WindowsDialogWindow : IQuickSwitchDialogWindow
52+
{
53+
public HWND Handle { get; private set; }
54+
55+
public WindowsDialogWindow(HWND handle)
56+
{
57+
Handle = handle;
58+
}
59+
60+
public IQuickSwitchDialogTab GetCurrentTab()
61+
{
62+
return new WindowsDialogTab(Handle);
63+
}
64+
65+
public void Dispose()
66+
{
67+
Handle = HWND.Null;
68+
}
69+
}
70+
71+
internal class WindowsDialogTab : IQuickSwitchDialogTab
72+
{
73+
public HWND Handle { get; private set; }
74+
75+
public WindowsDialogTab(HWND handle)
76+
{
77+
Handle = handle;
78+
}
79+
80+
public string GetCurrentFolder()
81+
{
82+
// TODO
83+
return string.Empty;
84+
}
85+
86+
public string GetCurrentFile()
87+
{
88+
// TODO
89+
return string.Empty;
90+
}
91+
92+
public bool OpenFolder(string path)
93+
{
94+
return false;
95+
}
96+
97+
public void Dispose()
98+
{
99+
Handle = HWND.Null;
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)