Skip to content
Closed
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
5 changes: 5 additions & 0 deletions src/Files.App/Data/Contracts/IAppearanceSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public interface IAppearanceSettingsService : IBaseSettingsService, INotifyPrope
/// </summary>
bool ShowStatusBar { get; set; }

/// <summary>
/// Gets or sets a value whether the horizontal bookmarks bar should be displayed.
/// </summary>
bool ShowBookmarksBar { get; set; }

/// <summary>
/// Gets or sets a value indicating how the status bar displays the item count.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Helpers/Application/AppLifecycleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ public static IServiceProvider ConfigureHost(AppModel appModel)
.AddSingleton<ToolbarCustomizationViewModel>()
.AddTransient<HomeViewModel>()
.AddSingleton<QuickAccessWidgetViewModel>()
.AddSingleton<BookmarksBarViewModel>()
.AddSingleton<DrivesWidgetViewModel>()
.AddSingleton<NetworkLocationsWidgetViewModel>()
.AddSingleton<FileTagsWidgetViewModel>()
Expand Down
7 changes: 7 additions & 0 deletions src/Files.App/Services/Settings/AppearanceSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ public bool ShowStatusBar
set => Set(value);
}

/// <inheritdoc/>
public bool ShowBookmarksBar
{
get => Get(true);
set => Set(value);
}

/// <inheritdoc/>
public StatusBarItemCountFormat StatusBarItemCountFormat
{
Expand Down
8 changes: 8 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -4611,6 +4611,14 @@
<data name="ShowStatusBar" xml:space="preserve">
<value>Show status bar</value>
</data>
<data name="ShowBookmarksBar" xml:space="preserve">
<value>Show bookmarks bar</value>
<comment>Setting that controls if the horizontal bookmarks bar is shown below the address bar</comment>
</data>
<data name="BookmarksBarEmptyHint" xml:space="preserve">
<value>Pin folders to the sidebar to see them here</value>
<comment>Hint shown in the bookmarks bar when no folders are pinned</comment>
</data>
<data name="ItemCountFormat" xml:space="preserve">
<value>Item count format</value>
</data>
Expand Down
104 changes: 104 additions & 0 deletions src/Files.App/UserControls/BookmarksBar.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<!-- Copyright (c) Files Community. Licensed under the MIT License. -->
<UserControl
x:Class="Files.App.UserControls.BookmarksBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dataitems="using:Files.App.Data.Items"
xmlns:helpers="using:Files.App.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<UserControl.Resources>
<!-- Context menu -->
<MenuFlyout x:Key="BookmarkFlyout">
<MenuFlyoutItem
Click="OpenInNewTab_Click"
Text="{helpers:ResourceString Name=OpenInNewTab}">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE8A7;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
Click="OpenInNewWindow_Click"
Text="{helpers:ResourceString Name=OpenInNewWindow}">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE8A7;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutSeparator />
<MenuFlyoutItem
Click="Unpin_Click"
Text="{helpers:ResourceString Name=UnpinFolderFromSidebar}">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE77A;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
</MenuFlyout>
</UserControl.Resources>

<Grid
x:Name="RootGrid"
MinHeight="28"
Padding="8,2,8,2"
BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}"
BorderThickness="0,0,0,1">

<!-- Bookmarks -->
<ScrollViewer
HorizontalScrollBarVisibility="Hidden"
HorizontalScrollMode="Auto"
VerticalScrollBarVisibility="Disabled"
VerticalScrollMode="Disabled">
<ItemsRepeater ItemsSource="{x:Bind ViewModel.Items, Mode=OneWay}">
<ItemsRepeater.Layout>
<StackLayout Orientation="Horizontal" Spacing="2" />
</ItemsRepeater.Layout>

<ItemsRepeater.ItemTemplate>
<DataTemplate x:DataType="dataitems:LocationItem">
<Button
Padding="8,4,8,4"
VerticalAlignment="Center"
AutomationProperties.Name="{x:Bind Text}"
Background="Transparent"
BorderThickness="0"
Click="Bookmark_Click"
CornerRadius="{StaticResource ControlCornerRadius}"
PointerPressed="Bookmark_PointerPressed"
RightTapped="Bookmark_RightTapped"
ToolTipService.ToolTip="{x:Bind ToolTip}">
<StackPanel
VerticalAlignment="Center"
Orientation="Horizontal"
Spacing="6">
<Image
Width="16"
Height="16"
VerticalAlignment="Center"
Source="{x:Bind Icon, Mode=OneWay}"
Stretch="Uniform" />
<TextBlock
VerticalAlignment="Center"
FontSize="12"
MaxLines="1"
Text="{x:Bind Text}"
TextTrimming="CharacterEllipsis" />
</StackPanel>
</Button>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</ScrollViewer>

<!-- Hint shown when nothing is pinned -->
<TextBlock
x:Name="EmptyHint"
Margin="8,0,0,0"
VerticalAlignment="Center"
FontSize="12"
Foreground="{ThemeResource TextFillColorTertiaryBrush}"
Text="{helpers:ResourceString Name=BookmarksBarEmptyHint}"
Visibility="Collapsed" />
</Grid>
</UserControl>
113 changes: 113 additions & 0 deletions src/Files.App/UserControls/BookmarksBar.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using Windows.System;
using Windows.UI.Core;
using WinRT;

namespace Files.App.UserControls
{
/// <summary>
/// Represents a horizontal bookmarks bar shown below the address bar.
/// </summary>
public sealed partial class BookmarksBar : UserControl
{
private IContentPageContext ContentPageContext { get; } = Ioc.Default.GetRequiredService<IContentPageContext>();
private IQuickAccessService QuickAccessService { get; } = Ioc.Default.GetRequiredService<IQuickAccessService>();

[DynamicWindowsRuntimeCast(typeof(MenuFlyout))]
private MenuFlyout? GetBookmarkFlyout() => Resources["BookmarkFlyout"] as MenuFlyout;

public BookmarksBarViewModel ViewModel { get; }

public BookmarksBar()
{
ViewModel = Ioc.Default.GetRequiredService<BookmarksBarViewModel>();
InitializeComponent();

ViewModel.Items.CollectionChanged += Items_CollectionChanged;
Loaded += BookmarksBar_Loaded;

UpdateEmptyHint();
}

private void BookmarksBar_Loaded(object sender, RoutedEventArgs e)
=> _ = ViewModel.RefreshAsync();

private void Items_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
=> UpdateEmptyHint();

private void UpdateEmptyHint()
{
if (EmptyHint is null)
return;

EmptyHint.Visibility = ViewModel.Items.Count is 0 ? Visibility.Visible : Visibility.Collapsed;
}

[DynamicWindowsRuntimeCast(typeof(FrameworkElement))]
private static LocationItem? GetItem(object? sender)
=> (sender as FrameworkElement)?.DataContext as LocationItem;

private async void Bookmark_Click(object sender, RoutedEventArgs e)
{
if (GetItem(sender) is not { Path: { } path })
return;

if (InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down))
{
await NavigationHelpers.OpenPathInNewTab(path);
return;
}

if (ContentPageContext.ShellPage is not { } shellPage)
return;

shellPage.NavigateWithArguments(
shellPage.InstanceViewModel.FolderSettings.GetLayoutType(path),
new NavigationArguments() { NavPathParam = path });
}

private async void Bookmark_PointerPressed(object sender, PointerRoutedEventArgs e)
{
if (!e.GetCurrentPoint(null).Properties.IsMiddleButtonPressed)
return;

if (GetItem(sender) is { Path: { } path })
await NavigationHelpers.OpenPathInNewTab(path);
}

[DynamicWindowsRuntimeCast(typeof(FrameworkElement))]
private void Bookmark_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
if (sender is not FrameworkElement element || GetItem(sender) is null || GetBookmarkFlyout() is not { } flyout)
return;

flyout.ShowAt(element, new FlyoutShowOptions() { Position = e.GetPosition(element) });
e.Handled = true;
}

private async void OpenInNewTab_Click(object sender, RoutedEventArgs e)
{
if (GetItem(GetBookmarkFlyout()?.Target) is { Path: { } path })
await NavigationHelpers.OpenPathInNewTab(path);
}

private async void OpenInNewWindow_Click(object sender, RoutedEventArgs e)
{
if (GetItem(GetBookmarkFlyout()?.Target) is { Path: { } path })
await NavigationHelpers.OpenPathInNewWindowAsync(path);
}

private async void Unpin_Click(object sender, RoutedEventArgs e)
{
if (GetItem(GetBookmarkFlyout()?.Target) is { Path: { } path })
await QuickAccessService.UnpinFromSidebarAsync(path);
}
}
}
10 changes: 10 additions & 0 deletions src/Files.App/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ context.PageType is not ContentPageTypes.Home &&
context.PageType is not ContentPageTypes.ReleaseNotes &&
context.PageType is not ContentPageTypes.Settings;

public bool ShowBookmarksBar =>
AppearanceSettingsService.ShowBookmarksBar &&
context.PageType is not ContentPageTypes.Home &&
context.PageType is not ContentPageTypes.ReleaseNotes &&
context.PageType is not ContentPageTypes.Settings;

private bool canShowPrompts;

public void OnPageLoaded()
Expand Down Expand Up @@ -210,6 +216,9 @@ public MainPageViewModel()
case nameof(AppearanceSettingsService.ShowToolbar):
OnPropertyChanged(nameof(ShowToolbar));
break;
case nameof(AppearanceSettingsService.ShowBookmarksBar):
OnPropertyChanged(nameof(ShowBookmarksBar));
break;
}
};

Expand All @@ -219,6 +228,7 @@ public MainPageViewModel()
{
case nameof(context.PageType):
OnPropertyChanged(nameof(ShowToolbar));
OnPropertyChanged(nameof(ShowBookmarksBar));
break;
}
};
Expand Down
14 changes: 14 additions & 0 deletions src/Files.App/ViewModels/Settings/AppearanceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,20 @@ public bool ShowStatusBar
}
}

public bool ShowBookmarksBar
{
get => UserSettingsService.AppearanceSettingsService.ShowBookmarksBar;
set
{
if (value != UserSettingsService.AppearanceSettingsService.ShowBookmarksBar)
{
UserSettingsService.AppearanceSettingsService.ShowBookmarksBar = value;

OnPropertyChanged();
}
}
}

public bool ShowTabActions
{
get => UserSettingsService.AppearanceSettingsService.ShowTabActions;
Expand Down
69 changes: 69 additions & 0 deletions src/Files.App/ViewModels/UserControls/BookmarksBarViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using System.Collections.Specialized;

namespace Files.App.ViewModels.UserControls
{
/// <summary>
/// Represents view model of <see cref="UserControls.BookmarksBar"/>.
/// </summary>
public sealed partial class BookmarksBarViewModel : ObservableObject, IDisposable
{
private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();

/// <summary>
/// Gets the pinned folders shown in the bookmarks bar.
/// Mirrors the sidebar pinned section so both stay in sync.
/// </summary>
public ObservableCollection<LocationItem> Items { get; } = [];

public bool ShowBookmarksBar => UserSettingsService.AppearanceSettingsService.ShowBookmarksBar;

public BookmarksBarViewModel()
{
UserSettingsService.AppearanceSettingsService.PropertyChanged += AppearanceSettingsService_PropertyChanged;
App.QuickAccessManager.Model.DataChanged += OnPinnedFoldersChanged;

_ = RefreshAsync();
}

private void AppearanceSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IAppearanceSettingsService.ShowBookmarksBar))
OnPropertyChanged(nameof(ShowBookmarksBar));
}

private async void OnPinnedFoldersChanged(object? sender, NotifyCollectionChangedEventArgs e)
=> await RefreshAsync();

/// <summary>
/// Rebuilds the bar from the pinned folder items, skipping the built-in locations
/// (Home, Recycle Bin, drives) that are not user bookmarks.
/// </summary>
public async Task RefreshAsync()
{
if (MainWindow.Instance is not { } mainWindow)
return;

await mainWindow.DispatcherQueue.EnqueueOrInvokeAsync(() =>
{
var pinnedItems = App.QuickAccessManager.Model.PinnedFolderItems
.OfType<LocationItem>()
.Where(item => !item.IsDefaultLocation && !string.IsNullOrEmpty(item.Path))
.ToList();

Items.Clear();

foreach (var item in pinnedItems)
Items.Add(item);
});
}

public void Dispose()
{
UserSettingsService.AppearanceSettingsService.PropertyChanged -= AppearanceSettingsService_PropertyChanged;
App.QuickAccessManager.Model.DataChanged -= OnPinnedFoldersChanged;
}
}
}
Loading