Skip to content

Commit 428b4c5

Browse files
authored
Feature: Enabled support for inputting custom icon path (#16318)
1 parent e3fa11a commit 428b4c5

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

src/Files.App/ViewModels/Properties/CustomizationViewModel.cs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using CommunityToolkit.WinUI;
2-
using Files.App.Utils.Shell;
1+
using Microsoft.UI.Windowing;
32
using System.IO;
4-
using Windows.Storage.Pickers;
5-
using Microsoft.UI.Windowing;
63
using System.Windows.Input;
74

85
namespace Files.App.ViewModels.Properties
@@ -24,13 +21,29 @@ private static string DefaultIconDllFilePath
2421

2522
public readonly bool IsShortcut;
2623

27-
public ObservableCollection<IconFileInfo> DllIcons { get; }
24+
public ObservableCollection<IconFileInfo> DllIcons { get; } = [];
2825

2926
private string _IconResourceItemPath;
3027
public string IconResourceItemPath
3128
{
3229
get => _IconResourceItemPath;
33-
set => SetProperty(ref _IconResourceItemPath, value);
30+
set
31+
{
32+
if (SetProperty(ref _IconResourceItemPath, value))
33+
{
34+
DllIcons.Clear();
35+
36+
if (Path.Exists(_IconResourceItemPath))
37+
{
38+
var icons = Win32Helper.ExtractIconsFromDLL(_IconResourceItemPath);
39+
if (icons?.Count is null or 0)
40+
return;
41+
42+
foreach (var item in icons)
43+
DllIcons.Add(item);
44+
}
45+
}
46+
}
3447
}
3548

3649
private IconFileInfo? _SelectedDllIcon;
@@ -64,10 +77,6 @@ public CustomizationViewModel(IShellPage appInstance, BaseProperties basePropert
6477
IsShortcut = item.IsShortcut;
6578
_selectedItemPath = item.ItemPath;
6679

67-
DllIcons = [];
68-
69-
// Get default
70-
LoadIconsForPath(IconResourceItemPath);
7180

7281
RestoreDefaultIconCommand = new RelayCommand(ExecuteRestoreDefaultIconCommand);
7382
OpenFilePickerCommand = new RelayCommand(ExecuteOpenFilePickerCommand);
@@ -93,7 +102,7 @@ private void ExecuteOpenFilePickerCommand()
93102

94103
var result = CommonDialogService.Open_FileOpenDialog(hWnd, false, extensions, Environment.SpecialFolder.MyComputer, out var filePath);
95104
if (result)
96-
LoadIconsForPath(filePath);
105+
IconResourceItemPath = filePath;
97106
}
98107

99108
public async Task<bool> UpdateIcon()
@@ -126,18 +135,5 @@ await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() =>
126135

127136
return true;
128137
}
129-
130-
private void LoadIconsForPath(string path)
131-
{
132-
IconResourceItemPath = path;
133-
DllIcons.Clear();
134-
135-
var icons = Win32Helper.ExtractIconsFromDLL(path);
136-
if (icons?.Count is null or 0)
137-
return;
138-
139-
foreach(var item in icons)
140-
DllIcons.Add(item);
141-
}
142138
}
143139
}

src/Files.App/Views/Properties/CustomizationPage.xaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@
8181
<ColumnDefinition Width="Auto" />
8282
</Grid.ColumnDefinitions>
8383

84-
<TextBox
85-
x:Name="PickedDllFilePathTextBox"
86-
IsReadOnly="True"
87-
Text="{x:Bind CustomizationViewModel.IconResourceItemPath, Mode=OneWay}" />
84+
<TextBox x:Name="PickedDllFilePathTextBox" Text="{x:Bind CustomizationViewModel.IconResourceItemPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
8885

8986
<Button
9087
x:Name="PickDllFileButton"

0 commit comments

Comments
 (0)