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
44 changes: 20 additions & 24 deletions src/Files.App/ViewModels/Properties/CustomizationViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using CommunityToolkit.WinUI;
using Files.App.Utils.Shell;
using Microsoft.UI.Windowing;
using System.IO;
using Windows.Storage.Pickers;
using Microsoft.UI.Windowing;
using System.Windows.Input;

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

public readonly bool IsShortcut;

public ObservableCollection<IconFileInfo> DllIcons { get; }
public ObservableCollection<IconFileInfo> DllIcons { get; } = [];

private string _IconResourceItemPath;
public string IconResourceItemPath
{
get => _IconResourceItemPath;
set => SetProperty(ref _IconResourceItemPath, value);
set
{
if (SetProperty(ref _IconResourceItemPath, value))
{
DllIcons.Clear();

if (Path.Exists(_IconResourceItemPath))
{
var icons = Win32Helper.ExtractIconsFromDLL(_IconResourceItemPath);
if (icons?.Count is null or 0)
return;

foreach (var item in icons)
DllIcons.Add(item);
}
}
}
}

private IconFileInfo? _SelectedDllIcon;
Expand Down Expand Up @@ -64,10 +77,6 @@ public CustomizationViewModel(IShellPage appInstance, BaseProperties basePropert
IsShortcut = item.IsShortcut;
_selectedItemPath = item.ItemPath;

DllIcons = [];

// Get default
LoadIconsForPath(IconResourceItemPath);

RestoreDefaultIconCommand = new RelayCommand(ExecuteRestoreDefaultIconCommand);
OpenFilePickerCommand = new RelayCommand(ExecuteOpenFilePickerCommand);
Expand All @@ -93,7 +102,7 @@ private void ExecuteOpenFilePickerCommand()

var result = CommonDialogService.Open_FileOpenDialog(hWnd, false, extensions, Environment.SpecialFolder.MyComputer, out var filePath);
if (result)
LoadIconsForPath(filePath);
IconResourceItemPath = filePath;
}

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

return true;
}

private void LoadIconsForPath(string path)
{
IconResourceItemPath = path;
DllIcons.Clear();

var icons = Win32Helper.ExtractIconsFromDLL(path);
if (icons?.Count is null or 0)
return;

foreach(var item in icons)
DllIcons.Add(item);
}
}
}
5 changes: 1 addition & 4 deletions src/Files.App/Views/Properties/CustomizationPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<TextBox
x:Name="PickedDllFilePathTextBox"
IsReadOnly="True"
Text="{x:Bind CustomizationViewModel.IconResourceItemPath, Mode=OneWay}" />
<TextBox x:Name="PickedDllFilePathTextBox" Text="{x:Bind CustomizationViewModel.IconResourceItemPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

<Button
x:Name="PickDllFileButton"
Expand Down
Loading