Skip to content

Commit 94b337e

Browse files
authored
Feature: Added an optional home button (#16122)
1 parent d9c9bbb commit 94b337e

File tree

11 files changed

+121
-4
lines changed

11 files changed

+121
-4
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Actions
5+
{
6+
internal sealed class NavigateHomeAction : ObservableObject, IAction
7+
{
8+
private readonly IContentPageContext context;
9+
10+
public string Label
11+
=> "Home".GetLocalizedResource();
12+
13+
public string Description
14+
=> "NavigateHomeDescription".GetLocalizedResource();
15+
16+
public RichGlyph Glyph
17+
=> new("\uE80F");
18+
19+
public bool IsExecutable
20+
=> context.PageType is not ContentPageTypes.Home;
21+
22+
public NavigateHomeAction()
23+
{
24+
context = Ioc.Default.GetRequiredService<IContentPageContext>();
25+
26+
context.PropertyChanged += Context_PropertyChanged;
27+
}
28+
29+
public Task ExecuteAsync(object? parameter = null)
30+
{
31+
context.ShellPage!.NavigateHome();
32+
33+
return Task.CompletedTask;
34+
}
35+
36+
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
37+
{
38+
switch (e.PropertyName)
39+
{
40+
case nameof(IContentPageContext.PageType):
41+
OnPropertyChanged(nameof(IsExecutable));
42+
break;
43+
}
44+
}
45+
}
46+
}

src/Files.App/Data/Commands/Manager/CommandCodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public enum CommandCodes
179179
NavigateBack,
180180
NavigateForward,
181181
NavigateUp,
182+
NavigateHome,
182183

183184
// Other
184185
DuplicateCurrentTab,

src/Files.App/Data/Commands/Manager/CommandManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public IRichCommand this[HotKey hotKey]
175175
public IRichCommand NavigateBack => commands[CommandCodes.NavigateBack];
176176
public IRichCommand NavigateForward => commands[CommandCodes.NavigateForward];
177177
public IRichCommand NavigateUp => commands[CommandCodes.NavigateUp];
178+
public IRichCommand NavigateHome => commands[CommandCodes.NavigateHome];
178179
public IRichCommand DuplicateCurrentTab => commands[CommandCodes.DuplicateCurrentTab];
179180
public IRichCommand DuplicateSelectedTab => commands[CommandCodes.DuplicateSelectedTab];
180181
public IRichCommand CloseTabsToTheLeftCurrent => commands[CommandCodes.CloseTabsToTheLeftCurrent];
@@ -366,6 +367,7 @@ public IEnumerator<IRichCommand> GetEnumerator() =>
366367
[CommandCodes.NavigateBack] = new NavigateBackAction(),
367368
[CommandCodes.NavigateForward] = new NavigateForwardAction(),
368369
[CommandCodes.NavigateUp] = new NavigateUpAction(),
370+
[CommandCodes.NavigateHome] = new NavigateHomeAction(),
369371
[CommandCodes.DuplicateCurrentTab] = new DuplicateCurrentTabAction(),
370372
[CommandCodes.DuplicateSelectedTab] = new DuplicateSelectedTabAction(),
371373
[CommandCodes.CloseTabsToTheLeftCurrent] = new CloseTabsToTheLeftCurrentAction(),

src/Files.App/Data/Commands/Manager/ICommandManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
164164
IRichCommand NavigateBack { get; }
165165
IRichCommand NavigateForward { get; }
166166
IRichCommand NavigateUp { get; }
167+
IRichCommand NavigateHome { get; }
167168

168169
IRichCommand DuplicateCurrentTab { get; }
169170
IRichCommand DuplicateSelectedTab { get; }

src/Files.App/Data/Contracts/IAppearanceSettingsService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,10 @@ public interface IAppearanceSettingsService : IBaseSettingsService, INotifyPrope
106106
/// Gets or sets a value whether the tab actions button should be displayed.
107107
/// </summary>
108108
bool ShowTabActions { get; set; }
109+
110+
/// <summary>
111+
/// Gets or sets a value whether the home button should be displayed.
112+
/// </summary>
113+
bool ShowHomeButton { get; set; }
109114
}
110115
}

src/Files.App/Services/Settings/AppearanceSettingsService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ public bool ShowTabActions
145145
set => Set(value);
146146
}
147147

148+
/// <inheritdoc/>
149+
public bool ShowHomeButton
150+
{
151+
get => Get(false);
152+
set => Set(value);
153+
}
154+
148155
protected override void RaiseOnSettingChangedEvent(object sender, SettingChangedEventArgs e)
149156
{
150157
base.RaiseOnSettingChangedEvent(sender, e);

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3935,4 +3935,10 @@
39353935
<data name="CPUThreads" xml:space="preserve">
39363936
<value>CPU threads</value>
39373937
</data>
3938+
<data name="NavigateHomeDescription" xml:space="preserve">
3939+
<value>Navigate to the home page</value>
3940+
</data>
3941+
<data name="ShowHomeButton" xml:space="preserve">
3942+
<value>Show home button in the toolbar</value>
3943+
</data>
39383944
</root>

src/Files.App/UserControls/AddressToolbar.xaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@
265265

266266
<Button
267267
x:Name="Back"
268-
x:FieldModifier="public"
269268
AccessKey="B"
270269
AccessKeyInvoked="Button_AccessKeyInvoked"
271270
AutomationProperties.FullDescription="{x:Bind ViewModel.Commands.NavigateBack.Description, Mode=OneWay}"
@@ -295,7 +294,6 @@
295294

296295
<Button
297296
x:Name="Forward"
298-
x:FieldModifier="public"
299297
AccessKey="F"
300298
AccessKeyInvoked="Button_AccessKeyInvoked"
301299
AutomationProperties.FullDescription="{x:Bind ViewModel.Commands.NavigateForward.Description, Mode=OneWay}"
@@ -325,7 +323,6 @@
325323

326324
<Button
327325
x:Name="Up"
328-
x:FieldModifier="public"
329326
AccessKey="U"
330327
AccessKeyInvoked="Button_AccessKeyInvoked"
331328
AutomationProperties.FullDescription="{x:Bind ViewModel.Commands.NavigateUp.Description, Mode=OneWay}"
@@ -339,7 +336,6 @@
339336

340337
<Button
341338
x:Name="Refresh"
342-
x:FieldModifier="public"
343339
AccessKey="R"
344340
AccessKeyInvoked="Button_AccessKeyInvoked"
345341
AutomationProperties.Name="{x:Bind Commands.RefreshItems.Label}"
@@ -349,6 +345,19 @@
349345
ToolTipService.ToolTip="{x:Bind Commands.RefreshItems.LabelWithHotKey, Mode=OneWay}">
350346
<FontIcon FontSize="14" Glyph="{x:Bind Commands.RefreshItems.Glyph.BaseGlyph}" />
351347
</Button>
348+
349+
<Button
350+
x:Name="HomeButton"
351+
x:Load="{x:Bind ViewModel.ShowHomeButton, Mode=OneWay}"
352+
AccessKey="H"
353+
AccessKeyInvoked="Button_AccessKeyInvoked"
354+
AutomationProperties.Name="{x:Bind Commands.NavigateHome.Label}"
355+
Command="{x:Bind Commands.NavigateHome, Mode=OneWay}"
356+
IsEnabled="{x:Bind Commands.NavigateHome.IsExecutable, Mode=OneWay}"
357+
Style="{StaticResource AddressToolbarButtonStyle}"
358+
ToolTipService.ToolTip="{x:Bind Commands.NavigateHome.LabelWithHotKey, Mode=OneWay}">
359+
<FontIcon FontSize="14" Glyph="{x:Bind Commands.NavigateHome.Glyph.BaseGlyph}" />
360+
</Button>
352361
</StackPanel>
353362

354363
<!-- Path Box -->

src/Files.App/ViewModels/Settings/AppearanceViewModel.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,5 +301,19 @@ public bool ShowTabActions
301301
}
302302
}
303303
}
304+
305+
public bool ShowHomeButton
306+
{
307+
get => UserSettingsService.AppearanceSettingsService.ShowHomeButton;
308+
set
309+
{
310+
if (value != UserSettingsService.AppearanceSettingsService.ShowHomeButton)
311+
{
312+
UserSettingsService.AppearanceSettingsService.ShowHomeButton = value;
313+
314+
OnPropertyChanged();
315+
}
316+
}
317+
}
304318
}
305319
}

src/Files.App/ViewModels/UserControls/AddressToolbarViewModel.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public sealed class AddressToolbarViewModel : ObservableObject, IAddressToolbarV
2121
private const int MAX_SUGGESTIONS = 10;
2222

2323
private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();
24+
private IAppearanceSettingsService AppearanceSettingsService { get; } = Ioc.Default.GetRequiredService<IAppearanceSettingsService>();
2425

2526
private readonly IDialogService _dialogService = Ioc.Default.GetRequiredService<IDialogService>();
2627

@@ -169,6 +170,9 @@ public string? PathText
169170
}
170171
}
171172

173+
public bool ShowHomeButton
174+
=> AppearanceSettingsService.ShowHomeButton;
175+
172176
public ObservableCollection<NavigationBarSuggestionItem> NavigationBarSuggestions = [];
173177

174178
private CurrentInstanceViewModel instanceViewModel;
@@ -213,6 +217,16 @@ public AddressToolbarViewModel()
213217
SearchBox.Escaped += SearchRegion_Escaped;
214218
UserSettingsService.OnSettingChangedEvent += UserSettingsService_OnSettingChangedEvent;
215219
UpdateService.PropertyChanged += UpdateService_OnPropertyChanged;
220+
221+
AppearanceSettingsService.PropertyChanged += (s, e) =>
222+
{
223+
switch (e.PropertyName)
224+
{
225+
case nameof(AppearanceSettingsService.ShowHomeButton):
226+
OnPropertyChanged(nameof(ShowHomeButton));
227+
break;
228+
}
229+
};
216230
}
217231

218232
private async void UpdateService_OnPropertyChanged(object? sender, PropertyChangedEventArgs e)

0 commit comments

Comments
 (0)