Skip to content

Feature: Updated the design for startup settings #13503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 13, 2023
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
6 changes: 3 additions & 3 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,6 @@
<data name="syncStatusColumn.Header" xml:space="preserve">
<value>Status</value>
</data>
<data name="SettingsOnStartupPages.Text" xml:space="preserve">
<value>Pages:</value>
</data>
<data name="SettingsPreferencesSystemDefaultLanguageOption" xml:space="preserve">
<value>Windows default</value>
</data>
Expand Down Expand Up @@ -3532,6 +3529,9 @@
<data name="ContributingArtist" xml:space="preserve">
<value>Contributing Artist</value>
</data>
<data name="AddPage" xml:space="preserve">
<value>Add page</value>
</data>
<data name="UnblockDownloadedFile" xml:space="preserve">
<value>Unblock downloaded file</value>
</data>
Expand Down
10 changes: 3 additions & 7 deletions src/Files.App/Utils/RecentItem/RecentItems.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Utils.Shell;
using Microsoft.Extensions.Logging;
using Microsoft.Win32;
using System.Collections.Specialized;
Expand Down Expand Up @@ -82,7 +81,7 @@ public async Task UpdateRecentFilesAsync()
/// </summary>
public async Task UpdateRecentFoldersAsync()
{
var enumeratedFolders = await Task.Run(ListRecentFoldersAsync); // run off the UI thread
var enumeratedFolders = await Task.Run(ListRecentFoldersAsync); // run off the UI thread
if (enumeratedFolders is not null)
{
lock (recentFolders)
Expand Down Expand Up @@ -114,7 +113,6 @@ public async Task<List<RecentItem>> ListRecentFilesAsync()
/// </summary>
public async Task<List<RecentItem>> ListRecentFoldersAsync()
{
var recentItems = new List<RecentItem>();
var excludeMask = FileAttributes.Hidden;
var linkFilePaths = Directory.EnumerateFiles(Constants.UserEnvironmentPaths.RecentItemsPath).Where(f => (new FileInfo(f).Attributes & excludeMask) == 0);

Expand Down Expand Up @@ -146,10 +144,8 @@ public async Task<List<RecentItem>> ListRecentFoldersAsync()
});
}

var recentFolderTasks = linkFilePaths.Select(GetRecentItemFromLink);
var result = await Task.WhenAll(recentFolderTasks);

return result.OfType<RecentItem>().ToList();
var recentItems = await Task.WhenAll(linkFilePaths.Select(GetRecentItemFromLink));
return recentItems.OfType<RecentItem>().ToList();
}

/// <summary>
Expand Down
73 changes: 7 additions & 66 deletions src/Files.App/ViewModels/Settings/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class GeneralViewModel : ObservableObject, IDisposable
private ReadOnlyCollection<IMenuFlyoutItemViewModel> addFlyoutItemsSource;

public AsyncRelayCommand ChangePageCommand { get; }
public RelayCommand RemovePageCommand { get; }
public RelayCommand<PageOnStartupViewModel> RemovePageCommand { get; }
public RelayCommand<string> AddPageCommand { get; }
public RelayCommand RestartCommand { get; }
public RelayCommand CancelRestartCommand { get; }
Expand Down Expand Up @@ -91,7 +91,7 @@ public int SelectedAppLanguageIndex
public GeneralViewModel()
{
ChangePageCommand = new AsyncRelayCommand(ChangePage);
RemovePageCommand = new RelayCommand(RemovePage);
RemovePageCommand = new RelayCommand<PageOnStartupViewModel>(RemovePage);
AddPageCommand = new RelayCommand<string>(async (path) => await AddPage(path));
RestartCommand = new RelayCommand(DoRestart);
CancelRestartCommand = new RelayCommand(DoCancelRestart);
Expand All @@ -110,7 +110,7 @@ public GeneralViewModel()

PagesOnStartupList.CollectionChanged += PagesOnStartupList_CollectionChanged;

_ = InitStartupSettingsRecentFoldersFlyout();
InitStartupSettingsRecentFoldersFlyout();
}

private async void DoRestart()
Expand Down Expand Up @@ -150,66 +150,16 @@ private void AddSupportedAppLanguages()
.IndexOf(AppLanguages.FirstOrDefault(dl => dl.LanguagID == languageID) ?? AppLanguages.First());
}

private async Task InitStartupSettingsRecentFoldersFlyout()
private void InitStartupSettingsRecentFoldersFlyout()
{
// create Browse and Recent flyout items
var recentsItem = new MenuFlyoutSubItemViewModel("JumpListRecentGroupHeader".GetLocalizedResource());
recentsItem.Items.Add(new MenuFlyoutItemViewModel("Home".GetLocalizedResource())
{
Command = AddPageCommand,
CommandParameter = "Home",
Tooltip = "Home".GetLocalizedResource()
});
await PopulateRecentItems(recentsItem);

// Ensure recent folders aren't stale since we don't update them with a watcher
// Then update the items source again to actually include those items
await App.RecentItemsManager.UpdateRecentFoldersAsync();
await PopulateRecentItems(recentsItem);
}

private Task PopulateRecentItems(MenuFlyoutSubItemViewModel menu)
{
try
{
var recentFolders = App.RecentItemsManager.RecentFolders;
var currentFolderMenus = menu.Items
.OfType<MenuFlyoutItemViewModel>()
.Where(m => m.Text != "Home".GetLocalizedResource())
.Select(m => m.Text)
.ToHashSet();

// Add separator if we need one and one wasn't added already
if (recentFolders.Any() && !currentFolderMenus.Any())
menu.Items.Add(new MenuFlyoutSeparatorViewModel());

foreach (var folder in recentFolders)
{
if (currentFolderMenus.Contains(folder.Name))
continue;

menu.Items.Add(new MenuFlyoutItemViewModel(folder.Name)
{
Command = AddPageCommand,
CommandParameter = folder.RecentPath,
Tooltip = folder.RecentPath
});
}
}
catch (Exception ex)
{
App.Logger.LogInformation(ex, "Could not fetch recent items");
}

// Update items source
AddFlyoutItemsSource = new List<IMenuFlyoutItemViewModel>()
{
new MenuFlyoutItemViewModel("Browse".GetLocalizedResource()) { Command = AddPageCommand },
menu,
}
.AsReadOnly();

return Task.CompletedTask;
recentsItem.Items.Add(new MenuFlyoutItemViewModel("Browse".GetLocalizedResource()) { Command = AddPageCommand });
}

private void PagesOnStartupList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
Expand Down Expand Up @@ -338,18 +288,9 @@ private FolderPicker InitializeWithWindow(FolderPicker obj)
return obj;
}

private void RemovePage()
private void RemovePage(PageOnStartupViewModel page)
{
int index = SelectedPageIndex;
if (index >= 0)
{
PagesOnStartupList.RemoveAt(index);

if (index > 0)
SelectedPageIndex = index - 1;
else if (PagesOnStartupList.Count > 0)
SelectedPageIndex = 0;
}
PagesOnStartupList.Remove(page);
}

private async Task AddPage(string path = null)
Expand Down
119 changes: 64 additions & 55 deletions src/Files.App/Views/Settings/GeneralPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,66 +120,75 @@
</ComboBox>
<local:SettingsBlockControl.ExpandableContent>
<StackPanel>
<local:SettingsBlockControl HorizontalAlignment="Stretch" Visibility="{x:Bind ViewModel.OpenASpecificPageOnStartup, Mode=OneWay}">
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="16"
Text="{helpers:ResourceString Name=SettingsOnStartupPages/Text}" />
<CommandBar
Grid.Column="1"
Background="Transparent"
DefaultLabelPosition="Right"
IsOpen="False">
<AppBarButton Icon="Add" Label="{helpers:ResourceString Name=Add}">
<AppBarButton.Flyout>
<MenuFlyout helpers:MenuFlyoutHelper.ItemsSource="{x:Bind ViewModel.AddFlyoutItemsSource, Mode=OneWay}" Placement="Bottom" />
</AppBarButton.Flyout>
</AppBarButton>
<AppBarButton
Command="{x:Bind ViewModel.ChangePageCommand}"
Icon="Edit"
IsEnabled="{x:Bind ViewModel.IsPageListEditEnabled, Mode=OneWay}"
Label="{helpers:ResourceString Name=Edit}" />
<AppBarButton
Command="{x:Bind ViewModel.RemovePageCommand}"
Icon="Delete"
IsEnabled="{x:Bind ViewModel.IsPageListEditEnabled, Mode=OneWay}"
Label="{helpers:ResourceString Name=Remove}" />
</CommandBar>
<Grid
Padding="8"
HorizontalAlignment="Stretch"
RowSpacing="4"
Visibility="{x:Bind ViewModel.OpenASpecificPageOnStartup, Mode=OneWay}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Margin="12,0,0,0">
<Button.Flyout>
<MenuFlyout Placement="RightEdgeAlignedBottom">
<MenuFlyoutItem
Command="{x:Bind ViewModel.AddPageCommand}"
CommandParameter="Home"
Text="{helpers:ResourceString Name=Home}" />
<MenuFlyoutItem Command="{x:Bind ViewModel.AddPageCommand}" Text="{helpers:ResourceString Name=Browse}" />
</MenuFlyout>
</Button.Flyout>
<StackPanel Orientation="Horizontal" Spacing="8">
<FontIcon
VerticalAlignment="Center"
FontSize="14"
Glyph="&#xE710;" />
<TextBlock VerticalAlignment="Center" Text="{helpers:ResourceString Name=AddPage}" />
</StackPanel>
</Button>

<ListView
x:Name="PagesList"
Grid.Row="1"
Grid.ColumnSpan="2"
Margin="0,10"
HorizontalAlignment="Stretch"
AllowDrop="True"
CanReorderItems="True"
IsItemClickEnabled="True"
ItemsSource="{x:Bind ViewModel.PagesOnStartupList, Mode=TwoWay}"
SelectedIndex="{x:Bind ViewModel.SelectedPageIndex, Mode=TwoWay}"
SelectionMode="Single">
<ListView.ItemTemplate>
<DataTemplate xmlns:vm="using:Files.App.ViewModels.Settings" x:DataType="vm:PageOnStartupViewModel">
<ListView
x:Name="PagesList"
Grid.Row="1"
HorizontalAlignment="Stretch"
AllowDrop="True"
CanReorderItems="True"
IsItemClickEnabled="False"
ItemsSource="{x:Bind ViewModel.PagesOnStartupList, Mode=TwoWay}"
SelectedIndex="{x:Bind ViewModel.SelectedPageIndex, Mode=TwoWay}"
SelectionMode="None">
<ListView.Resources>
<SolidColorBrush x:Key="ButtonBackground" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBorderBrush" Color="Transparent" />
</ListView.Resources>
<ListView.ItemContainerStyle>
<Style BasedOn="{StaticResource DefaultListViewItemStyle}" TargetType="ListViewItem">
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="12,0" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate xmlns:vm="using:Files.App.ViewModels.Settings" x:DataType="vm:PageOnStartupViewModel">
<Grid HorizontalAlignment="Stretch">
<TextBlock
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{x:Bind Text}"
TextTrimming="CharacterEllipsis"
ToolTipService.ToolTip="{x:Bind Text}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</local:SettingsBlockControl>
<Button
HorizontalAlignment="Right"
AutomationProperties.Name="{helpers:ResourceString Name=Remove}"
Click="RemoveStartupPage"
ToolTipService.ToolTip="{helpers:ResourceString Name=Remove}">
<FontIcon FontSize="16" Glyph="&#xE74D;" />
</Button>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>

<local:SettingsBlockControl Title="{helpers:ResourceString Name=OpenNewInstance}" HorizontalAlignment="Stretch">
<ToggleSwitch
Expand Down
8 changes: 8 additions & 0 deletions src/Files.App/Views/Settings/GeneralPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.ViewModels.Settings;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace Files.App.Views.Settings
{
public sealed partial class GeneralPage : Page
{

public GeneralPage()
{
InitializeComponent();
}

private void RemoveStartupPage(object sender, RoutedEventArgs e)
{
ViewModel.RemovePageCommand.Execute((sender as FrameworkElement).DataContext as PageOnStartupViewModel);
}
}
}