|
1 | 1 | // Copyright (c) 2024 Files Community |
2 | 2 | // Licensed under the MIT License. See the LICENSE. |
3 | 3 |
|
| 4 | +using System.Collections.Frozen; |
| 5 | +using System.Collections.Immutable; |
4 | 6 | using Files.App.Actions; |
5 | 7 | using Microsoft.AppCenter.Analytics; |
6 | 8 | using Microsoft.UI.Xaml; |
7 | 9 | using Microsoft.UI.Xaml.Controls; |
8 | 10 | using Microsoft.UI.Xaml.Input; |
9 | | -using System.Collections.Immutable; |
10 | 11 |
|
11 | 12 | namespace Files.App.Data.Commands |
12 | 13 | { |
13 | 14 | internal sealed class CommandManager : ICommandManager |
14 | 15 | { |
15 | 16 | private readonly IGeneralSettingsService settings = Ioc.Default.GetRequiredService<IGeneralSettingsService>(); |
16 | 17 |
|
17 | | - private readonly IImmutableDictionary<CommandCodes, IRichCommand> commands; |
18 | | - private IImmutableDictionary<HotKey, IRichCommand> hotKeys = new Dictionary<HotKey, IRichCommand>().ToImmutableDictionary(); |
| 18 | + private readonly FrozenDictionary<CommandCodes, IRichCommand> commands; |
| 19 | + private ImmutableDictionary<HotKey, IRichCommand> hotKeys = new Dictionary<HotKey, IRichCommand>().ToImmutableDictionary(); |
19 | 20 |
|
20 | 21 | public IRichCommand this[CommandCodes code] => commands.TryGetValue(code, out var command) ? command : None; |
21 | 22 | public IRichCommand this[string code] |
@@ -196,16 +197,18 @@ public CommandManager() |
196 | 197 | .Select(action => new ActionCommand(this, action.Key, action.Value)) |
197 | 198 | .Cast<IRichCommand>() |
198 | 199 | .Append(new NoneCommand()) |
199 | | - .ToImmutableDictionary(command => command.Code); |
| 200 | + .ToFrozenDictionary(command => command.Code); |
200 | 201 |
|
201 | 202 | settings.PropertyChanged += Settings_PropertyChanged; |
202 | 203 | UpdateHotKeys(); |
203 | 204 | } |
204 | 205 |
|
205 | 206 | IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); |
206 | | - public IEnumerator<IRichCommand> GetEnumerator() => commands.Values.GetEnumerator(); |
207 | 207 |
|
208 | | - private static IDictionary<CommandCodes, IAction> CreateActions() => new Dictionary<CommandCodes, IAction> |
| 208 | + public IEnumerator<IRichCommand> GetEnumerator() => |
| 209 | + (commands.Values as IEnumerable<IRichCommand>).GetEnumerator(); |
| 210 | + |
| 211 | + private static Dictionary<CommandCodes, IAction> CreateActions() => new Dictionary<CommandCodes, IAction> |
209 | 212 | { |
210 | 213 | [CommandCodes.OpenHelp] = new OpenHelpAction(), |
211 | 214 | [CommandCodes.ToggleFullScreen] = new ToggleFullScreenAction(), |
@@ -362,7 +365,7 @@ public CommandManager() |
362 | 365 |
|
363 | 366 | private void UpdateHotKeys() |
364 | 367 | { |
365 | | - ISet<HotKey> useds = new HashSet<HotKey>(); |
| 368 | + var useds = new HashSet<HotKey>(); |
366 | 369 |
|
367 | 370 | var customs = new Dictionary<CommandCodes, HotKeyCollection>(); |
368 | 371 | foreach (var custom in settings.Actions) |
|
0 commit comments