Skip to content
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

Code Quality: Refactored tab control #13197

Merged
merged 27 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7273b8d
Code Quality: Renamed all to TabView
0x5bfa Aug 14, 2023
5a393c6
Fix: Fixed build errors
0x5bfa Aug 14, 2023
1a08e3d
Removed ITabViewItemContainer interface
0x5bfa Aug 14, 2023
4ae121d
Removed TabViewItemControl
0x5bfa Aug 14, 2023
2520a35
Removed unneeded item properties
0x5bfa Aug 14, 2023
0dcb3d9
Moved files to the appropriate places for each
0x5bfa Aug 14, 2023
f327ebd
Revert "Moved files to the appropriate places for each"
0x5bfa Aug 14, 2023
8ee70dc
merge main into this branch
0x5bfa Aug 21, 2023
2213180
Updated
0x5bfa Aug 21, 2023
d1fc6f4
merge main into this branch
0x5bfa Aug 21, 2023
43cd8a3
update
0x5bfa Aug 21, 2023
bbb84da
Merge branch 'main' into 5bfa/Cleanup-MultitaskingControl
0x5bfa Aug 21, 2023
5b9fdd4
Fix
0x5bfa Aug 21, 2023
57fb3c9
Merge branch 'main' into 5bfa/Cleanup-MultitaskingControl
0x5bfa Aug 21, 2023
ffb1cf7
Fixed
0x5bfa Aug 22, 2023
9c4d0f8
Merge branch 'main' into 5bfa/Cleanup-MultitaskingControl
0x5bfa Aug 22, 2023
a2da86c
Merge branch 'main' into 5bfa/Cleanup-MultitaskingControl
0x5bfa Aug 24, 2023
d762893
Merge remote-tracking branch 'upstream/main' into 5bfa/Cleanup-Multit…
0x5bfa Sep 12, 2023
c2fa58d
Renamed
0x5bfa Sep 12, 2023
779c98b
Fix
0x5bfa Sep 12, 2023
ab0fe7d
merge main into this branch
0x5bfa Sep 12, 2023
5b6015c
Merge branch 'main' into 5bfa/Cleanup-MultitaskingControl
yaira2 Sep 13, 2023
7c87ed6
Fix
0x5bfa Sep 13, 2023
2b29253
Merge branch 'main' into 5bfa/Cleanup-MultitaskingControl
yaira2 Sep 21, 2023
4acff6d
Merge branch 'main' into 5bfa/Cleanup-MultitaskingControl
0x5bfa Sep 25, 2023
fe3949d
Fix
0x5bfa Sep 25, 2023
c50aeba
Merge branch '5bfa/Cleanup-MultitaskingControl' of https://github.com…
0x5bfa Sep 25, 2023
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
4 changes: 2 additions & 2 deletions src/Files.App/Actions/Navigation/DuplicateCurrentTabAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public DuplicateCurrentTabAction()

public async Task ExecuteAsync()
{
var arguments = context.CurrentTabItem.TabItemArguments;
var arguments = context.CurrentTabItem.NavigationParameter;
if (arguments is null)
await mainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
else
await mainPageViewModel.AddNewTabByParam(arguments.InitialPageType, arguments.NavigationArg, context.CurrentTabIndex + 1);
await mainPageViewModel.AddNewTabByParam(arguments.InitialPageType, arguments.NavigationParameter, context.CurrentTabIndex + 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public DuplicateSelectedTabAction()

public async Task ExecuteAsync()
{
var arguments = context.SelectedTabItem.TabItemArguments;
var arguments = context.SelectedTabItem.NavigationParameter;
if (arguments is null)
await mainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
else
await mainPageViewModel.AddNewTabByParam(arguments.InitialPageType, arguments.NavigationArg, context.SelectedTabIndex + 1);
await mainPageViewModel.AddNewTabByParam(arguments.InitialPageType, arguments.NavigationParameter, context.SelectedTabIndex + 1);
}
}
}
8 changes: 4 additions & 4 deletions src/Files.App/Actions/Navigation/ReopenClosedTabAction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.UserControls.MultitaskingControl;
using Files.App.UserControls.TabBar;

namespace Files.App.Actions
{
Expand All @@ -20,15 +20,15 @@ public HotKey HotKey

public bool IsExecutable =>
context.Control is not null &&
!BaseMultitaskingControl.IsRestoringClosedTab &&
BaseMultitaskingControl.RecentlyClosedTabs.Count > 0;
!BaseTabBar.IsRestoringClosedTab &&
BaseTabBar.RecentlyClosedTabs.Count > 0;

public ReopenClosedTabAction()
{
context = Ioc.Default.GetRequiredService<IMultitaskingContext>();

context.PropertyChanged += Context_PropertyChanged;
BaseMultitaskingControl.StaticPropertyChanged += BaseMultitaskingControl_StaticPropertyChanged;
BaseTabBar.StaticPropertyChanged += BaseMultitaskingControl_StaticPropertyChanged;
}

public Task ExecuteAsync()
Expand Down
12 changes: 6 additions & 6 deletions src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Files.App.Services.Settings;
using Files.App.Storage.FtpStorage;
using Files.App.Storage.NativeStorage;
using Files.App.UserControls.MultitaskingControl;
using Files.App.UserControls.TabBar;
using Files.App.ViewModels.Settings;
using Files.Core.Services.SizeProvider;
using Files.Core.Storage;
Expand Down Expand Up @@ -352,11 +352,11 @@ private async void Window_Closed(object sender, WindowEventArgs args)
{
await SafetyExtensions.IgnoreExceptions(async () =>
{
var instance = MainPageViewModel.AppInstances.FirstOrDefault(x => x.Control.TabItemContent.IsCurrentInstance);
var instance = MainPageViewModel.AppInstances.FirstOrDefault(x => x.TabItemContent.IsCurrentInstance);
if (instance is null)
return;

var items = (instance.Control.TabItemContent as PaneHolderPage)?.ActivePane?.SlimContentPage?.SelectedItems;
var items = (instance.TabItemContent as PaneHolderPage)?.ActivePane?.SlimContentPage?.SelectedItems;
if (items is null)
return;

Expand Down Expand Up @@ -394,13 +394,13 @@ public static void SaveSessionTabs()

userSettingsService.GeneralSettingsService.LastSessionTabList = MainPageViewModel.AppInstances.DefaultIfEmpty().Select(tab =>
{
if (tab is not null && tab.TabItemArguments is not null)
if (tab is not null && tab.NavigationParameter is not null)
{
return tab.TabItemArguments.Serialize();
return tab.NavigationParameter.Serialize();
}
else
{
var defaultArg = new TabItemArguments() { InitialPageType = typeof(PaneHolderPage), NavigationArg = "Home" };
var defaultArg = new CustomTabViewItemParameter() { InitialPageType = typeof(PaneHolderPage), NavigationParameter = "Home" };
return defaultArg.Serialize();
}
})
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Data/Contexts/ContentPage/ContentPageContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.UserControls.MultitaskingControl;
using Files.App.UserControls.TabBar;
using System.Collections.Immutable;

namespace Files.App.Data.Contexts
Expand Down Expand Up @@ -123,7 +123,7 @@ private void Page_PropertyChanged(object? sender, PropertyChangedEventArgs e)
}
}

private void Page_ContentChanged(object? sender, TabItemArguments e) => Update();
private void Page_ContentChanged(object? sender, CustomTabViewItemParameter e) => Update();

private void PaneHolder_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.UserControls.MultitaskingControl;
using Files.App.UserControls.TabBar;
using System.ComponentModel;

namespace Files.App.Data.Contexts
{
public interface IMultitaskingContext : INotifyPropertyChanged
{
IMultitaskingControl? Control { get; }
ITabBar? Control { get; }

ushort TabCount { get; }

TabItem CurrentTabItem { get; }
TabBarItem CurrentTabItem { get; }
ushort CurrentTabIndex { get; }

TabItem SelectedTabItem { get; }
TabBarItem SelectedTabItem { get; }
ushort SelectedTabIndex { get; }
}
}
21 changes: 10 additions & 11 deletions src/Files.App/Data/Contexts/Multitasking/MultitaskingContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023 Files Community
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.UserControls.MultitaskingControl;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
using System.Collections.Specialized;
Expand All @@ -12,14 +11,14 @@ internal class MultitaskingContext : ObservableObject, IMultitaskingContext
{
private bool isPopupOpen = false;

private IMultitaskingControl? control;
public IMultitaskingControl? Control => control;
private ITabBar? control;
public ITabBar? Control => control;

private ushort tabCount = 0;
public ushort TabCount => tabCount;

public TabItem CurrentTabItem => MainPageViewModel.AppInstances[currentTabIndex];
public TabItem SelectedTabItem => MainPageViewModel.AppInstances[selectedTabIndex];
public TabBarItem CurrentTabItem => MainPageViewModel.AppInstances[currentTabIndex];
public TabBarItem SelectedTabItem => MainPageViewModel.AppInstances[selectedTabIndex];

private ushort currentTabIndex = 0;
public ushort CurrentTabIndex => currentTabIndex;
Expand All @@ -31,8 +30,8 @@ public MultitaskingContext()
{
MainPageViewModel.AppInstances.CollectionChanged += AppInstances_CollectionChanged;
App.AppModel.PropertyChanged += AppModel_PropertyChanged;
BaseMultitaskingControl.OnLoaded += BaseMultitaskingControl_OnLoaded;
HorizontalMultitaskingControl.SelectedTabItemChanged += HorizontalMultitaskingControl_SelectedTabItemChanged;
BaseTabBar.OnLoaded += BaseMultitaskingControl_OnLoaded;
TabBar.SelectedTabItemChanged += HorizontalMultitaskingControl_SelectedTabItemChanged;
FocusManager.GotFocus += FocusManager_GotFocus;
FocusManager.LosingFocus += FocusManager_LosingFocus;
}
Expand All @@ -46,13 +45,13 @@ private void AppModel_PropertyChanged(object? sender, PropertyChangedEventArgs e
if (e.PropertyName is nameof(AppModel.TabStripSelectedIndex))
UpdateCurrentTabIndex();
}
private void BaseMultitaskingControl_OnLoaded(object? sender, IMultitaskingControl control)
private void BaseMultitaskingControl_OnLoaded(object? sender, ITabBar control)
{
SetProperty(ref this.control, control, nameof(Control));
UpdateTabCount();
UpdateCurrentTabIndex();
}
private void HorizontalMultitaskingControl_SelectedTabItemChanged(object? sender, TabItem? e)
private void HorizontalMultitaskingControl_SelectedTabItemChanged(object? sender, TabBarItem? e)
{
isPopupOpen = e is not null;
int newSelectedIndex = e is null ? currentTabIndex : MainPageViewModel.AppInstances.IndexOf(e);
Expand All @@ -63,7 +62,7 @@ private void FocusManager_GotFocus(object? sender, FocusManagerGotFocusEventArgs
if (isPopupOpen)
return;

if (e.NewFocusedElement is FrameworkElement element && element.DataContext is TabItem tabItem)
if (e.NewFocusedElement is FrameworkElement element && element.DataContext is TabBarItem tabItem)
{
int newSelectedIndex = MainPageViewModel.AppInstances.IndexOf(tabItem);
UpdateSelectedTabIndex(newSelectedIndex);
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Data/Contexts/Page/PageContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.UserControls.MultitaskingControl;
using Files.App.UserControls.TabBar;
using Files.App.Views;
using System;
using System.ComponentModel;
Expand Down Expand Up @@ -38,7 +38,7 @@ private void Page_CurrentInstanceChanged(object? sender, PaneHolderPage? modifie
}
}

private void Page_ContentChanged(object? sender, TabItemArguments e)
private void Page_ContentChanged(object? sender, CustomTabViewItemParameter e)
{
UpdateContent();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Data.EventArguments
{
public class CurrentInstanceChangedEventArgs : EventArgs
{
public ITabBarItemContent CurrentInstance { get; set; }

public List<ITabBarItemContent> PageInstances { get; set; }
}
}
40 changes: 40 additions & 0 deletions src/Files.App/Data/Parameters/CustomTabViewItemParameter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using System.Text.Json;

namespace Files.App.Data.Parameters
{
public sealed class CustomTabViewItemParameter
{
private static readonly KnownTypesConverter _typesConverter = new();

public Type InitialPageType { get; set; }

public object NavigationParameter { get; set; }

public string Serialize()
{
return JsonSerializer.Serialize(this, _typesConverter.Options);
}

public static CustomTabViewItemParameter Deserialize(string obj)
{
var tabArgs = new CustomTabViewItemParameter();

var tempArgs = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(obj);
tabArgs.InitialPageType = Type.GetType(tempArgs[nameof(InitialPageType)].GetString());

try
{
tabArgs.NavigationParameter = JsonSerializer.Deserialize<PaneNavigationArguments>(tempArgs[nameof(NavigationParameter)].GetRawText());
}
catch (JsonException)
{
tabArgs.NavigationParameter = tempArgs[nameof(NavigationParameter)].GetString();
}

return tabArgs;
}
}
}
18 changes: 0 additions & 18 deletions src/Files.App/Files.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@
<Content Remove="Assets\FilesHome.png" />
</ItemGroup>

<ItemGroup>
<None Remove="Dialogs\ReleaseNotesDialog.xaml" />
<None Remove="UserControls\Sidebar\SideBarItem.xaml" />
<None Remove="UserControls\Sidebar\SideBarView.xaml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ByteSize" Version="2.1.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
Expand Down Expand Up @@ -138,16 +132,4 @@
<TrimmerRootAssembly Include="CommunityToolkit.WinUI.UI.Controls.Primitives" />
</ItemGroup>

<ItemGroup>
<Page Update="Dialogs\ReleaseNotesDialog.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
<Page Update="UserControls\SideBarControl\SideBarHost.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
<Page Update="UserControls\SideBarControl\SideBarItem.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/Files.App/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
global using global::Files.App.Data.TemplateSelectors;
global using global::Files.App.Services;
global using global::Files.App.UserControls;
global using global::Files.App.UserControls.TabBar;
global using global::Files.App.ViewModels;
global using global::Files.App.ViewModels.UserControls;
global using global::Files.App.Views;
Expand Down
12 changes: 6 additions & 6 deletions src/Files.App/Helpers/Navigation/MultitaskingTabsHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.UserControls.MultitaskingControl;
using Files.App.UserControls.TabBar;
using Files.App.ViewModels;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -10,7 +10,7 @@ namespace Files.App.Helpers
{
public static class MultitaskingTabsHelpers
{
public static void CloseTabsToTheLeft(TabItem clickedTab, IMultitaskingControl multitaskingControl)
public static void CloseTabsToTheLeft(TabBarItem clickedTab, ITabBar multitaskingControl)
{
if (multitaskingControl is not null)
{
Expand All @@ -21,7 +21,7 @@ public static void CloseTabsToTheLeft(TabItem clickedTab, IMultitaskingControl m
}
}

public static void CloseTabsToTheRight(TabItem clickedTab, IMultitaskingControl multitaskingControl)
public static void CloseTabsToTheRight(TabBarItem clickedTab, ITabBar multitaskingControl)
{
if (multitaskingControl is not null)
{
Expand All @@ -32,7 +32,7 @@ public static void CloseTabsToTheRight(TabItem clickedTab, IMultitaskingControl
}
}

public static void CloseOtherTabs(TabItem clickedTab, IMultitaskingControl multitaskingControl)
public static void CloseOtherTabs(TabBarItem clickedTab, ITabBar multitaskingControl)
{
if (multitaskingControl is not null)
{
Expand All @@ -41,10 +41,10 @@ public static void CloseOtherTabs(TabItem clickedTab, IMultitaskingControl multi
}
}

public static Task MoveTabToNewWindow(TabItem tab, IMultitaskingControl multitaskingControl)
public static Task MoveTabToNewWindow(TabBarItem tab, ITabBar multitaskingControl)
{
int index = MainPageViewModel.AppInstances.IndexOf(tab);
TabItemArguments tabItemArguments = MainPageViewModel.AppInstances[index].TabItemArguments;
CustomTabViewItemParameter tabItemArguments = MainPageViewModel.AppInstances[index].NavigationParameter;

multitaskingControl?.CloseTab(MainPageViewModel.AppInstances[index]);

Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.UserControls.MultitaskingControl;
using Files.App.UserControls.TabBar;
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
Expand Down Expand Up @@ -124,7 +124,7 @@ public async Task InitializeApplication(object activatedEventArgs)
{
case "tab":
rootFrame.Navigate(typeof(MainPage),
new MainPageNavigationArguments() { Parameter = TabItemArguments.Deserialize(unescapedValue), IgnoreStartupSettings = true },
new MainPageNavigationArguments() { Parameter = CustomTabViewItemParameter.Deserialize(unescapedValue), IgnoreStartupSettings = true },
new SuppressNavigationTransitionInfo());
break;

Expand Down
Loading
Loading