Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<IPublicAPI>();

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; }
Expand All @@ -26,8 +33,10 @@ public CustomBrowserViewModel Copy()
Editable = Editable
};
}

public void OnDisplayNameChanged()
{
OnPropertyChanged(nameof(DisplayName));
}
}
}



Original file line number Diff line number Diff line change
@@ -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<IPublicAPI>();

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\"";
Expand All @@ -21,5 +29,10 @@ public CustomExplorerViewModel Copy()
Editable = Editable
};
}

public void OnDisplayNameChanged()
{
OnPropertyChanged(nameof(DisplayName));
}
}
}
1 change: 0 additions & 1 deletion Flow.Launcher.Infrastructure/UserSettings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
16 changes: 15 additions & 1 deletion Flow.Launcher.Infrastructure/Win32Helper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
Expand Down Expand Up @@ -43,7 +43,7 @@
{
var cloaked = cloak ? 1 : 0;

return PInvoke.DwmSetWindowAttribute(

Check warning on line 46 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Dwm` is not a recognized word. (unrecognized-spelling)
GetWindowHandle(window),
DWMWINDOWATTRIBUTE.DWMWA_CLOAK,
&cloaked,
Expand All @@ -55,14 +55,14 @@
var backdropType = backdrop switch
{
BackdropTypes.Acrylic => DWM_SYSTEMBACKDROP_TYPE.DWMSBT_TRANSIENTWINDOW,
BackdropTypes.Mica => DWM_SYSTEMBACKDROP_TYPE.DWMSBT_MAINWINDOW,

Check warning on line 58 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`SYSTEMBACKDROP` is not a recognized word. (unrecognized-spelling)

Check warning on line 58 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`DWMSBT` is not a recognized word. (unrecognized-spelling)
BackdropTypes.MicaAlt => DWM_SYSTEMBACKDROP_TYPE.DWMSBT_TABBEDWINDOW,

Check warning on line 59 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`SYSTEMBACKDROP` is not a recognized word. (unrecognized-spelling)

Check warning on line 59 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`DWMSBT` is not a recognized word. (unrecognized-spelling)
_ => DWM_SYSTEMBACKDROP_TYPE.DWMSBT_AUTO

Check warning on line 60 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`SYSTEMBACKDROP` is not a recognized word. (unrecognized-spelling)

Check warning on line 60 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`DWMSBT` is not a recognized word. (unrecognized-spelling)
};

return PInvoke.DwmSetWindowAttribute(

Check warning on line 63 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`PInvoke` is not a recognized word. (unrecognized-spelling)

Check warning on line 63 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Dwm` is not a recognized word. (unrecognized-spelling)
GetWindowHandle(window),
DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE,

Check warning on line 65 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`DWMWA` is not a recognized word. (unrecognized-spelling)
&backdropType,
(uint)Marshal.SizeOf<int>()).Succeeded;
}
Expand Down Expand Up @@ -904,5 +904,19 @@
}

#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
}
}
3 changes: 3 additions & 0 deletions Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@
<system:String x:Key="fileManager_file_arg">Arg For File</system:String>
<system:String x:Key="fileManagerPathNotFound">The file manager '{0}' could not be located at '{1}'. Would you like to continue?</system:String>
<system:String x:Key="fileManagerPathError">File Manager Path Error</system:String>
<system:String x:Key="fileManagerExplorer">File Explorer</system:String>

<!-- DefaultBrowser Setting Dialog -->
<system:String x:Key="defaultBrowserTitle">Default Web Browser</system:String>
Expand All @@ -497,6 +498,8 @@
<system:String x:Key="defaultBrowser_newWindow">New Window</system:String>
<system:String x:Key="defaultBrowser_newTab">New Tab</system:String>
<system:String x:Key="defaultBrowser_parameter">Private Mode</system:String>
<system:String x:Key="defaultBrowser_default">Default</system:String>
<system:String x:Key="defaultBrowser_new_profile">New Profile</system:String>

<!-- Priority Setting Dialog -->
<system:String x:Key="changePriorityWindow">Change Priority</system:String>
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/SelectBrowserWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
SelectedIndex="{Binding SelectedCustomBrowserIndex}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding DisplayName}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Expand Down
3 changes: 2 additions & 1 deletion Flow.Launcher/SelectBrowserWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))
{
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/SelectFileManagerWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
SelectedIndex="{Binding SelectedCustomExplorerIndex}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding DisplayName}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Expand Down
5 changes: 3 additions & 2 deletions Flow.Launcher/SelectFileManagerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
Expand Down Expand Up @@ -219,6 +219,8 @@ private void UpdateEnumDropdownLocalizations()
DropdownDataGeneric<DialogJumpFileResultBehaviours>.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
Expand Down
4 changes: 2 additions & 2 deletions Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@
MaxWidth="250"
Margin="10 0 0 0"
Command="{Binding SelectFileManagerCommand}"
Content="{Binding Settings.CustomExplorer.Name}" />
Content="{Binding Settings.CustomExplorer.DisplayName}" />
</cc:Card>

<cc:Card
Expand All @@ -415,7 +415,7 @@
MaxWidth="250"
Margin="10 0 0 0"
Command="{Binding SelectBrowserCommand}"
Content="{Binding Settings.CustomBrowser.Name}" />
Content="{Binding Settings.CustomBrowser.DisplayName}" />
</cc:Card>

<cc:Card Title="{DynamicResource pythonFilePath}" Margin="0 14 0 0">
Expand Down
21 changes: 8 additions & 13 deletions Flow.Launcher/ViewModel/SelectBrowserViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}

Expand All @@ -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;
}
Expand Down
19 changes: 3 additions & 16 deletions Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Loading