Skip to content

Commit 67be26a

Browse files
authored
Merge branch 'dev' into ui_wpf_modern
2 parents 9751ffc + 820304c commit 67be26a

File tree

15 files changed

+75
-116
lines changed

15 files changed

+75
-116
lines changed
Lines changed: 5 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using Windows.Win32;
62

73
namespace Flow.Launcher.Infrastructure
84
{
@@ -13,84 +9,23 @@ public static class FileExplorerHelper
139
/// </summary>
1410
public static string GetActiveExplorerPath()
1511
{
16-
var explorerWindow = GetActiveExplorer();
17-
string locationUrl = explorerWindow?.LocationURL;
18-
return !string.IsNullOrEmpty(locationUrl) ? GetDirectoryPath(new Uri(locationUrl).LocalPath) : null;
12+
var explorerPath = DialogJump.DialogJump.GetActiveExplorerPath();
13+
return !string.IsNullOrEmpty(explorerPath) ?
14+
GetDirectoryPath(new Uri(explorerPath).LocalPath) :
15+
null;
1916
}
2017

2118
/// <summary>
2219
/// Get directory path from a file path
2320
/// </summary>
2421
private static string GetDirectoryPath(string path)
2522
{
26-
if (!path.EndsWith("\\"))
23+
if (!path.EndsWith('\\'))
2724
{
2825
return path + "\\";
2926
}
3027

3128
return path;
3229
}
33-
34-
/// <summary>
35-
/// Gets the file explorer that is currently in the foreground
36-
/// </summary>
37-
private static dynamic GetActiveExplorer()
38-
{
39-
Type type = Type.GetTypeFromProgID("Shell.Application");
40-
if (type == null) return null;
41-
dynamic shell = Activator.CreateInstance(type);
42-
if (shell == null)
43-
{
44-
return null;
45-
}
46-
47-
var explorerWindows = new List<dynamic>();
48-
var openWindows = shell.Windows();
49-
for (int i = 0; i < openWindows.Count; i++)
50-
{
51-
var window = openWindows.Item(i);
52-
if (window == null) continue;
53-
54-
// find the desired window and make sure that it is indeed a file explorer
55-
// we don't want the Internet Explorer or the classic control panel
56-
// ToLower() is needed, because Windows can report the path as "C:\\Windows\\Explorer.EXE"
57-
if (Path.GetFileName((string)window.FullName)?.ToLower() == "explorer.exe")
58-
{
59-
explorerWindows.Add(window);
60-
}
61-
}
62-
63-
if (explorerWindows.Count == 0) return null;
64-
65-
var zOrders = GetZOrder(explorerWindows);
66-
67-
return explorerWindows.Zip(zOrders).MinBy(x => x.Second).First;
68-
}
69-
70-
/// <summary>
71-
/// Gets the z-order for one or more windows atomically with respect to each other. In Windows, smaller z-order is higher. If the window is not top level, the z order is returned as -1.
72-
/// </summary>
73-
private static IEnumerable<int> GetZOrder(List<dynamic> hWnds)
74-
{
75-
var z = new int[hWnds.Count];
76-
for (var i = 0; i < hWnds.Count; i++) z[i] = -1;
77-
78-
var index = 0;
79-
var numRemaining = hWnds.Count;
80-
PInvoke.EnumWindows((wnd, _) =>
81-
{
82-
var searchIndex = hWnds.FindIndex(x => new IntPtr(x.HWND) == wnd);
83-
if (searchIndex != -1)
84-
{
85-
z[searchIndex] = index;
86-
numRemaining--;
87-
if (numRemaining == 0) return false;
88-
}
89-
index++;
90-
return true;
91-
}, IntPtr.Zero);
92-
93-
return z;
94-
}
9530
}
9631
}

Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
using System.Text.Json.Serialization;
2+
using CommunityToolkit.Mvvm.DependencyInjection;
13
using Flow.Launcher.Plugin;
2-
using System.Text.Json.Serialization;
34

45
namespace Flow.Launcher.Infrastructure.UserSettings
56
{
67
public class CustomBrowserViewModel : BaseModel
78
{
9+
// We should not initialize API in static constructor because it will create another API instance
10+
private static IPublicAPI api = null;
11+
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
12+
813
public string Name { get; set; }
14+
[JsonIgnore]
15+
public string DisplayName => Name == "Default" ? API.GetTranslation("defaultBrowser_default") : Name;
916
public string Path { get; set; }
1017
public string PrivateArg { get; set; }
1118
public bool EnablePrivate { get; set; }
@@ -26,8 +33,10 @@ public CustomBrowserViewModel Copy()
2633
Editable = Editable
2734
};
2835
}
36+
37+
public void OnDisplayNameChanged()
38+
{
39+
OnPropertyChanged(nameof(DisplayName));
40+
}
2941
}
3042
}
31-
32-
33-

Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
using Flow.Launcher.Plugin;
1+
using System.Text.Json.Serialization;
2+
using CommunityToolkit.Mvvm.DependencyInjection;
3+
using Flow.Launcher.Plugin;
24

3-
namespace Flow.Launcher.ViewModel
5+
namespace Flow.Launcher.Infrastructure.UserSettings
46
{
57
public class CustomExplorerViewModel : BaseModel
68
{
9+
// We should not initialize API in static constructor because it will create another API instance
10+
private static IPublicAPI api = null;
11+
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
12+
713
public string Name { get; set; }
14+
[JsonIgnore]
15+
public string DisplayName => Name == "Explorer" ? API.GetTranslation("fileManagerExplorer") : Name;
816
public string Path { get; set; }
917
public string FileArgument { get; set; } = "\"%d\"";
1018
public string DirectoryArgument { get; set; } = "\"%d\"";
@@ -21,5 +29,10 @@ public CustomExplorerViewModel Copy()
2129
Editable = Editable
2230
};
2331
}
32+
33+
public void OnDisplayNameChanged()
34+
{
35+
OnPropertyChanged(nameof(DisplayName));
36+
}
2437
}
2538
}

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Flow.Launcher.Infrastructure.Storage;
1010
using Flow.Launcher.Plugin;
1111
using Flow.Launcher.Plugin.SharedModels;
12-
using Flow.Launcher.ViewModel;
1312

1413
namespace Flow.Launcher.Infrastructure.UserSettings
1514
{

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
44
using System.Diagnostics;
@@ -904,5 +904,19 @@ public static void EnableWin32DarkMode(string colorScheme)
904904
}
905905

906906
#endregion
907+
908+
#region File / Folder Dialog
909+
910+
public static string SelectFile()
911+
{
912+
var dlg = new OpenFileDialog();
913+
var result = dlg.ShowDialog();
914+
if (result == true)
915+
return dlg.FileName;
916+
917+
return string.Empty;
918+
}
919+
920+
#endregion
907921
}
908922
}

Flow.Launcher/Languages/en.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@
487487
<system:String x:Key="fileManager_file_arg">Arg For File</system:String>
488488
<system:String x:Key="fileManagerPathNotFound">The file manager '{0}' could not be located at '{1}'. Would you like to continue?</system:String>
489489
<system:String x:Key="fileManagerPathError">File Manager Path Error</system:String>
490+
<system:String x:Key="fileManagerExplorer">File Explorer</system:String>
490491

491492
<!-- DefaultBrowser Setting Dialog -->
492493
<system:String x:Key="defaultBrowserTitle">Default Web Browser</system:String>
@@ -497,6 +498,8 @@
497498
<system:String x:Key="defaultBrowser_newWindow">New Window</system:String>
498499
<system:String x:Key="defaultBrowser_newTab">New Tab</system:String>
499500
<system:String x:Key="defaultBrowser_parameter">Private Mode</system:String>
501+
<system:String x:Key="defaultBrowser_default">Default</system:String>
502+
<system:String x:Key="defaultBrowser_new_profile">New Profile</system:String>
500503

501504
<!-- Priority Setting Dialog -->
502505
<system:String x:Key="changePriorityWindow">Change Priority</system:String>

Flow.Launcher/SelectBrowserWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
SelectedIndex="{Binding SelectedCustomBrowserIndex}">
9393
<ComboBox.ItemTemplate>
9494
<DataTemplate>
95-
<TextBlock Text="{Binding Name}" />
95+
<TextBlock Text="{Binding DisplayName}" />
9696
</DataTemplate>
9797
</ComboBox.ItemTemplate>
9898
</ComboBox>

Flow.Launcher/SelectBrowserWindow.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Windows;
22
using System.Windows.Controls;
33
using CommunityToolkit.Mvvm.DependencyInjection;
4+
using Flow.Launcher.Infrastructure;
45
using Flow.Launcher.ViewModel;
56

67
namespace Flow.Launcher
@@ -31,7 +32,7 @@ private void btnDone_Click(object sender, RoutedEventArgs e)
3132

3233
private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
3334
{
34-
var selectedFilePath = _viewModel.SelectFile();
35+
var selectedFilePath = Win32Helper.SelectFile();
3536

3637
if (!string.IsNullOrEmpty(selectedFilePath))
3738
{

Flow.Launcher/SelectFileManagerWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
SelectedIndex="{Binding SelectedCustomExplorerIndex}">
103103
<ComboBox.ItemTemplate>
104104
<DataTemplate>
105-
<TextBlock Text="{Binding Name}" />
105+
<TextBlock Text="{Binding DisplayName}" />
106106
</DataTemplate>
107107
</ComboBox.ItemTemplate>
108108
</ComboBox>

Flow.Launcher/SelectFileManagerWindow.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Windows.Controls;
33
using System.Windows.Navigation;
44
using CommunityToolkit.Mvvm.DependencyInjection;
5+
using Flow.Launcher.Infrastructure;
56
using Flow.Launcher.ViewModel;
67

78
namespace Flow.Launcher
@@ -32,7 +33,7 @@ private void btnDone_Click(object sender, RoutedEventArgs e)
3233

3334
private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
3435
{
35-
var selectedFilePath = _viewModel.SelectFile();
36+
var selectedFilePath = Win32Helper.SelectFile();
3637

3738
if (!string.IsNullOrEmpty(selectedFilePath))
3839
{

0 commit comments

Comments
 (0)