diff --git a/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs b/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs index 24584115d8c..9c795f952a9 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs @@ -1,11 +1,18 @@ +using System.Text.Json.Serialization; +using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Plugin; -using System.Text.Json.Serialization; namespace Flow.Launcher.Infrastructure.UserSettings { public class CustomBrowserViewModel : BaseModel { + // We should not initialize API in static constructor because it will create another API instance + private static IPublicAPI api = null; + private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService(); + public string Name { get; set; } + [JsonIgnore] + public string DisplayName => Name == "Default" ? API.GetTranslation("defaultBrowser_default") : Name; public string Path { get; set; } public string PrivateArg { get; set; } public bool EnablePrivate { get; set; } @@ -26,8 +33,10 @@ public CustomBrowserViewModel Copy() Editable = Editable }; } + + public void OnDisplayNameChanged() + { + OnPropertyChanged(nameof(DisplayName)); + } } } - - - diff --git a/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs b/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs index c54c30478b3..2af0bb0e53a 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs @@ -1,10 +1,18 @@ -using Flow.Launcher.Plugin; +using System.Text.Json.Serialization; +using CommunityToolkit.Mvvm.DependencyInjection; +using Flow.Launcher.Plugin; -namespace Flow.Launcher.ViewModel +namespace Flow.Launcher.Infrastructure.UserSettings { public class CustomExplorerViewModel : BaseModel { + // We should not initialize API in static constructor because it will create another API instance + private static IPublicAPI api = null; + private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService(); + public string Name { get; set; } + [JsonIgnore] + public string DisplayName => Name == "Explorer" ? API.GetTranslation("fileManagerExplorer") : Name; public string Path { get; set; } public string FileArgument { get; set; } = "\"%d\""; public string DirectoryArgument { get; set; } = "\"%d\""; @@ -21,5 +29,10 @@ public CustomExplorerViewModel Copy() Editable = Editable }; } + + public void OnDisplayNameChanged() + { + OnPropertyChanged(nameof(DisplayName)); + } } } diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 23f9047fef7..f70c4559b38 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -9,7 +9,6 @@ using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedModels; -using Flow.Launcher.ViewModel; namespace Flow.Launcher.Infrastructure.UserSettings { diff --git a/Flow.Launcher.Infrastructure/Win32Helper.cs b/Flow.Launcher.Infrastructure/Win32Helper.cs index 8117339254d..5d30b740d78 100644 --- a/Flow.Launcher.Infrastructure/Win32Helper.cs +++ b/Flow.Launcher.Infrastructure/Win32Helper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; @@ -904,5 +904,19 @@ public static void EnableWin32DarkMode(string colorScheme) } #endregion + + #region File / Folder Dialog + + public static string SelectFile() + { + var dlg = new OpenFileDialog(); + var result = dlg.ShowDialog(); + if (result == true) + return dlg.FileName; + + return string.Empty; + } + + #endregion } } diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index f7fd0c8e588..b38fe8aab67 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -487,6 +487,7 @@ Arg For File The file manager '{0}' could not be located at '{1}'. Would you like to continue? File Manager Path Error + File Explorer Default Web Browser @@ -497,6 +498,8 @@ New Window New Tab Private Mode + Default + New Profile Change Priority diff --git a/Flow.Launcher/SelectBrowserWindow.xaml b/Flow.Launcher/SelectBrowserWindow.xaml index d51d597b751..67c22b07d19 100644 --- a/Flow.Launcher/SelectBrowserWindow.xaml +++ b/Flow.Launcher/SelectBrowserWindow.xaml @@ -92,7 +92,7 @@ SelectedIndex="{Binding SelectedCustomBrowserIndex}"> - + diff --git a/Flow.Launcher/SelectBrowserWindow.xaml.cs b/Flow.Launcher/SelectBrowserWindow.xaml.cs index 565b4cbc338..290712aad62 100644 --- a/Flow.Launcher/SelectBrowserWindow.xaml.cs +++ b/Flow.Launcher/SelectBrowserWindow.xaml.cs @@ -1,6 +1,7 @@ using System.Windows; using System.Windows.Controls; using CommunityToolkit.Mvvm.DependencyInjection; +using Flow.Launcher.Infrastructure; using Flow.Launcher.ViewModel; namespace Flow.Launcher @@ -31,7 +32,7 @@ private void btnDone_Click(object sender, RoutedEventArgs e) private void btnBrowseFile_Click(object sender, RoutedEventArgs e) { - var selectedFilePath = _viewModel.SelectFile(); + var selectedFilePath = Win32Helper.SelectFile(); if (!string.IsNullOrEmpty(selectedFilePath)) { diff --git a/Flow.Launcher/SelectFileManagerWindow.xaml b/Flow.Launcher/SelectFileManagerWindow.xaml index b3b219d1c1e..cd4bec42466 100644 --- a/Flow.Launcher/SelectFileManagerWindow.xaml +++ b/Flow.Launcher/SelectFileManagerWindow.xaml @@ -102,7 +102,7 @@ SelectedIndex="{Binding SelectedCustomExplorerIndex}"> - + diff --git a/Flow.Launcher/SelectFileManagerWindow.xaml.cs b/Flow.Launcher/SelectFileManagerWindow.xaml.cs index d9c672aff67..5143f9a56f8 100644 --- a/Flow.Launcher/SelectFileManagerWindow.xaml.cs +++ b/Flow.Launcher/SelectFileManagerWindow.xaml.cs @@ -2,6 +2,7 @@ using System.Windows.Controls; using System.Windows.Navigation; using CommunityToolkit.Mvvm.DependencyInjection; +using Flow.Launcher.Infrastructure; using Flow.Launcher.ViewModel; namespace Flow.Launcher @@ -32,13 +33,13 @@ private void btnDone_Click(object sender, RoutedEventArgs e) private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) { - _viewModel.OpenUrl(e.Uri.AbsoluteUri); + App.API.OpenUrl(e.Uri.AbsoluteUri); e.Handled = true; } private void btnBrowseFile_Click(object sender, RoutedEventArgs e) { - var selectedFilePath = _viewModel.SelectFile(); + var selectedFilePath = Win32Helper.SelectFile(); if (!string.IsNullOrEmpty(selectedFilePath)) { diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index ec75ddf9040..b47b53654b4 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; @@ -219,6 +219,8 @@ private void UpdateEnumDropdownLocalizations() DropdownDataGeneric.UpdateLabels(DialogJumpFileResultBehaviours); // Since we are using Binding instead of DynamicResource, we need to manually trigger the update OnPropertyChanged(nameof(AlwaysPreviewToolTip)); + Settings.CustomExplorer.OnDisplayNameChanged(); + Settings.CustomBrowser.OnDisplayNameChanged(); } public string Language diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml index 81e15df6950..07cc7b6a750 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml @@ -403,7 +403,7 @@ MaxWidth="250" Margin="10 0 0 0" Command="{Binding SelectFileManagerCommand}" - Content="{Binding Settings.CustomExplorer.Name}" /> + Content="{Binding Settings.CustomExplorer.DisplayName}" /> + Content="{Binding Settings.CustomBrowser.DisplayName}" /> diff --git a/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs b/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs index 67bbbd9301f..e3a0e4e4404 100644 --- a/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs +++ b/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs @@ -17,8 +17,13 @@ public int SelectedCustomBrowserIndex get => selectedCustomBrowserIndex; set { - selectedCustomBrowserIndex = value; - OnPropertyChanged(nameof(CustomBrowser)); + // When one custom browser is selected and removed, the index will become -1, so we need to ignore this change + if (value < 0) return; + if (selectedCustomBrowserIndex != value) + { + selectedCustomBrowserIndex = value; + OnPropertyChanged(nameof(CustomBrowser)); + } } } @@ -40,22 +45,12 @@ public bool SaveSettings() return true; } - internal string SelectFile() - { - var dlg = new Microsoft.Win32.OpenFileDialog(); - var result = dlg.ShowDialog(); - if (result == true) - return dlg.FileName; - - return string.Empty; - } - [RelayCommand] private void Add() { CustomBrowsers.Add(new() { - Name = "New Profile" + Name = App.API.GetTranslation("defaultBrowser_new_profile") }); SelectedCustomBrowserIndex = CustomBrowsers.Count - 1; } diff --git a/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs b/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs index 77f004980b1..f6a32e3fed5 100644 --- a/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs +++ b/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs @@ -21,6 +21,8 @@ public int SelectedCustomExplorerIndex get => selectedCustomExplorerIndex; set { + // When one custom file manager is selected and removed, the index will become -1, so we need to ignore this change + if (value < 0) return; if (selectedCustomExplorerIndex != value) { selectedCustomExplorerIndex = value; @@ -98,27 +100,12 @@ private static bool IsFileManagerValid(string path) } } - internal void OpenUrl(string absoluteUri) - { - App.API.OpenUrl(absoluteUri); - } - - internal string SelectFile() - { - var dlg = new Microsoft.Win32.OpenFileDialog(); - var result = dlg.ShowDialog(); - if (result == true) - return dlg.FileName; - - return string.Empty; - } - [RelayCommand] private void Add() { CustomExplorers.Add(new() { - Name = "New Profile" + Name = App.API.GetTranslation("defaultBrowser_new_profile") }); SelectedCustomExplorerIndex = CustomExplorers.Count - 1; }