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

Added collapsible sections to the sidebar #3661

Merged
merged 47 commits into from Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c3456d5
Added collapsible Drivers/Cloud Drivers on Sidebar control
oleitao Feb 21, 2021
d0a6ac8
-Rename to ChildItems
oleitao Feb 21, 2021
57ec6ef
Added favorites collapsible section
oleitao Feb 21, 2021
c727add
Keep track of the collapsed/expanded state by section
oleitao Feb 21, 2021
292bcbf
Squashed commit of the following:
gave92 Feb 21, 2021
51bf841
Merge remote-tracking branch 'origin/main' into rev_temp
gave92 Feb 21, 2021
d817535
Fix right click always opening Home
gave92 Feb 21, 2021
c662112
Separated home and quickaccess
gave92 Feb 21, 2021
addc62e
Do not select headers
gave92 Feb 21, 2021
1bd699e
Network drives collapsible section added
oleitao Feb 21, 2021
2cd016f
Added settings
yaira2 Feb 21, 2021
131743a
Merge commit 'refs/pull/3661/head' of https://github.com/duke7553/fil…
gave92 Feb 21, 2021
1ec99c2
Merge branch 'main' of https://github.com/duke7553/files-uwp into rev…
gave92 Feb 21, 2021
c812982
Added sections icons
oleitao Feb 21, 2021
bbcff35
Auto expand sections on hover
gave92 Feb 21, 2021
9864150
Merge branch 'collapsible-side-layout' of https://github.com/oleitao/…
oleitao Feb 22, 2021
66333b2
yaichenbaum changes review
oleitao Feb 22, 2021
183f240
yaichenbaum changes review
oleitao Feb 22, 2021
5d37d66
gave92 merge fix
oleitao Feb 22, 2021
45f3699
Merge commit 'refs/pull/3661/head' of https://github.com/duke7553/fil…
gave92 Feb 22, 2021
198441b
Removed unnecessary settings
gave92 Feb 22, 2021
11c53b8
Fix recyclebin context menu, Code cleanup
gave92 Feb 22, 2021
8094cb3
yaichenbaum rename the quick access section to favorites section
oleitao Feb 23, 2021
613c057
Expanded state be saved to AppSettings so it's persisted across app r…
oleitao Feb 23, 2021
95af988
Settings sidebar panels order fix
oleitao Feb 24, 2021
7a6902f
Removed sidebar settings page
gave92 Feb 24, 2021
d881ddb
Revert change to LocationItem
gave92 Feb 24, 2021
5172eb0
Merge remote-tracking branch 'origin/main' into rev_collapse
gave92 Feb 24, 2021
e4491d6
Removed SidebarViewModel
gave92 Feb 24, 2021
e3fa8ac
Update Files/Strings/en-US/Resources.resw
yaira2 Feb 24, 2021
9a88821
Removed extra settings
gave92 Feb 24, 2021
4362bdd
Merge commit 'refs/pull/3661/head' of https://github.com/duke7553/fil…
gave92 Feb 24, 2021
59454e2
Updated strings
yaira2 Feb 24, 2021
cc80fcb
Cleaning up settings page
gave92 Feb 24, 2021
1eb6fdd
Added Star icon on 'Favorites' section
oleitao Feb 24, 2021
29778d7
Move recyclebin to favorites
gave92 Feb 24, 2021
6d12496
Update Files/Views/Settings.xaml.cs
yaira2 Feb 24, 2021
abbd5dc
Merge commit 'refs/pull/3661/head' of https://github.com/duke7553/fil…
gave92 Feb 24, 2021
a2217a9
yaichenbaum fix review
oleitao Feb 24, 2021
a1e47e7
Move recyclebin at the end
gave92 Feb 24, 2021
4c97acd
Merge branch 'collapsible-side-layout' of https://github.com/oleitao/…
oleitao Feb 24, 2021
16312b1
Merge commit 'refs/pull/3661/head' of https://github.com/duke7553/fil…
gave92 Feb 24, 2021
41f1763
Update Files/Filesystem/Drives.cs
yaira2 Feb 24, 2021
1edbb62
Moved the home item into the favorites section
oleitao Feb 24, 2021
9977edb
review fixes
oleitao Feb 24, 2021
7b27328
gave92 fix review
oleitao Feb 24, 2021
04f363c
Added favorite section icon
oleitao Feb 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
122 changes: 109 additions & 13 deletions Files/DataModels/SidebarPinnedModel.cs
@@ -1,14 +1,19 @@
using Files.Controllers;
using Files.Common;
using Files.Controllers;
using Files.Filesystem;
using Files.ViewModels;
using Files.Views;
using Microsoft.Toolkit.Uwp.Extensions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;

namespace Files.DataModels
Expand All @@ -17,6 +22,8 @@ public class SidebarPinnedModel
{
private SidebarPinnedController controller;

private LocationItem favoriteSection, homeSection;

[JsonIgnore]
public SettingsViewModel AppSettings => App.AppSettings;

Expand All @@ -28,6 +35,26 @@ public void SetController(SidebarPinnedController controller)
this.controller = controller;
}

public SidebarPinnedModel()
{
homeSection = new LocationItem()
{
Text = "SidebarHome".GetLocalized(),
Font = App.Current.Resources["FluentUIGlyphs"] as FontFamily,
Glyph = "\uea80",
IsDefaultLocation = true,
Path = "Home",
ChildItems = new ObservableCollection<INavigationControlItem>()
};
favoriteSection = new LocationItem()
{
Text = "SidebarFavorites".GetLocalized(),
Font = App.Current.Resources["FluentUIGlyphs"] as FontFamily,
Glyph = "\ueb83",
ChildItems = new ObservableCollection<INavigationControlItem>()
};
}

/// <summary>
/// Adds the default items to the navigation page
/// </summary>
Expand Down Expand Up @@ -63,6 +90,45 @@ public async void AddItem(string item)
}
}

public async Task ShowHideRecycleBinItemAsync(bool show)
{
await MainPage.SideBarItemsSemaphore.WaitAsync();
try
{
if (show)
{
var recycleBinItem = new LocationItem
{
Text = ApplicationData.Current.LocalSettings.Values.Get("RecycleBin_Title", "Recycle Bin"),
Font = Application.Current.Resources["RecycleBinIcons"] as FontFamily,
Glyph = "\uEF87",
IsDefaultLocation = true,
Path = App.AppSettings.RecycleBinPath
};
// Add recycle bin to sidebar, title is read from LocalSettings (provided by the fulltrust process)
// TODO: the very first time the app is launched localized name not available
if (!favoriteSection.ChildItems.Any(x => x.Path == App.AppSettings.RecycleBinPath))
{
favoriteSection.ChildItems.Add(recycleBinItem);
}
}
else
{
foreach (INavigationControlItem item in favoriteSection.ChildItems.ToList())
{
if (item is LocationItem && item.Path == App.AppSettings.RecycleBinPath)
{
favoriteSection.ChildItems.Remove(item);
}
}
}
}
finally
{
MainPage.SideBarItemsSemaphore.Release();
}
}

/// <summary>
/// Removes the item from the navigation page
/// </summary>
Expand Down Expand Up @@ -93,8 +159,8 @@ public bool MoveItem(INavigationControlItem locationItem, int oldIndex, int newI

if (oldIndex >= 0 && newIndex >= 0)
{
MainPage.SideBarItems.RemoveAt(oldIndex);
MainPage.SideBarItems.Insert(newIndex, locationItem);
favoriteSection.ChildItems.RemoveAt(oldIndex);
favoriteSection.ChildItems.Insert(newIndex, locationItem);
return true;
}

Expand Down Expand Up @@ -159,7 +225,7 @@ public void SwapItems(INavigationControlItem firstLocationItem, INavigationContr
/// <returns>Index of the item</returns>
public int IndexOfItem(INavigationControlItem locationItem)
{
return MainPage.SideBarItems.IndexOf(locationItem);
return favoriteSection.ChildItems.IndexOf(locationItem);
}

/// <summary>
Expand Down Expand Up @@ -189,8 +255,8 @@ public async Task AddItemToSidebarAsync(string path)
var res = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(path, item));
if (res || (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path))
{
int insertIndex = MainPage.SideBarItems.IndexOf(MainPage.SideBarItems.Last(x => x.ItemType == NavigationControlItemType.Location
&& !x.Path.Equals(App.AppSettings.RecycleBinPath))) + 1;
var lastItem = favoriteSection.ChildItems.LastOrDefault(x => x.ItemType == NavigationControlItemType.Location && !x.Path.Equals(App.AppSettings.RecycleBinPath));
int insertIndex = lastItem != null ? favoriteSection.ChildItems.IndexOf(lastItem) + 1 : 0;
var locationItem = new LocationItem
{
Font = App.Current.Resources["FluentUIGlyphs"] as FontFamily,
Expand All @@ -200,9 +266,9 @@ public async Task AddItemToSidebarAsync(string path)
Text = res.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\'))
};

if (!MainPage.SideBarItems.Contains(locationItem))
if (!favoriteSection.ChildItems.Contains(locationItem))
{
MainPage.SideBarItems.Insert(insertIndex, locationItem);
favoriteSection.ChildItems.Insert(insertIndex, locationItem);
}
}
else
Expand All @@ -212,6 +278,21 @@ public async Task AddItemToSidebarAsync(string path)
}
}

/// <summary>
/// Adds the item to sidebar asynchronous.
/// </summary>
/// <param name="section">The section.</param>
private void AddItemToSidebarAsync(LocationItem section)
{
var lastItem = favoriteSection.ChildItems.LastOrDefault(x => x.ItemType == NavigationControlItemType.Location && !x.Path.Equals(App.AppSettings.RecycleBinPath));
int insertIndex = lastItem != null ? favoriteSection.ChildItems.IndexOf(lastItem) + 1 : 0;

if (!favoriteSection.ChildItems.Contains(section))
{
favoriteSection.ChildItems.Insert(insertIndex, section);
}
}

/// <summary>
/// Adds all items to the navigation sidebar
/// </summary>
Expand All @@ -220,17 +301,32 @@ public async Task AddAllItemsToSidebar()
await MainPage.SideBarItemsSemaphore.WaitAsync();
try
{
MainPage.SideBarItems.BeginBulkOperation();

if (homeSection != null)
gave92 marked this conversation as resolved.
Show resolved Hide resolved
{
AddItemToSidebarAsync(homeSection);
}

for (int i = 0; i < Items.Count(); i++)
{
string path = Items[i];
await AddItemToSidebarAsync(path);
}

if (!MainPage.SideBarItems.Contains(favoriteSection))
{
MainPage.SideBarItems.Add(favoriteSection);
}

MainPage.SideBarItems.EndBulkOperation();
}
finally
{
MainPage.SideBarItemsSemaphore.Release();
}

await ShowHideRecycleBinItemAsync(App.AppSettings.PinRecycleBinToSideBar);
}

/// <summary>
Expand All @@ -239,14 +335,14 @@ public async Task AddAllItemsToSidebar()
public void RemoveStaleSidebarItems()
{
// Remove unpinned items from sidebar
for (int i = 0; i < MainPage.SideBarItems.Count(); i++)
for (int i = 0; i < favoriteSection.ChildItems.Count(); i++)
{
if (MainPage.SideBarItems[i] is LocationItem)
if (favoriteSection.ChildItems[i] is LocationItem)
{
var item = MainPage.SideBarItems[i] as LocationItem;
var item = favoriteSection.ChildItems[i] as LocationItem;
if (!item.IsDefaultLocation && !Items.Contains(item.Path))
{
MainPage.SideBarItems.RemoveAt(i);
favoriteSection.ChildItems.RemoveAt(i);
}
}
}
Expand All @@ -260,7 +356,7 @@ public void RemoveStaleSidebarItems()
public string GetItemIcon(string path)
{
string iconCode;

if (path.Equals(AppSettings.DesktopPath, StringComparison.OrdinalIgnoreCase))
{
iconCode = "\ue9f1";
Expand Down
57 changes: 16 additions & 41 deletions Files/Filesystem/CloudDrivesManager.cs
@@ -1,10 +1,12 @@
using Files.Filesystem.Cloud;
using Files.UserControls.Widgets;
using Files.Views;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Uwp.Extensions;
using NLog;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
Expand Down Expand Up @@ -88,55 +90,28 @@ private async Task SyncSideBarItemsUI()
{
MainPage.SideBarItems.BeginBulkOperation();

var drivesSnapshot = Drives.ToList();
var drivesSection = MainPage.SideBarItems.FirstOrDefault(x => x is HeaderTextItem && x.Text == "SidebarCloudDrives".GetLocalized());

if (drivesSection != null && drivesSnapshot.Count == 0)
{
//No drives - remove the header
MainPage.SideBarItems.Remove(drivesSection);
}

if (drivesSection == null && drivesSnapshot.Count > 0)
var section = MainPage.SideBarItems.FirstOrDefault(x => x.Text == "SidebarCloudDrives".GetLocalized()) as LocationItem;
if (section == null)
{
drivesSection = new HeaderTextItem()
section = new LocationItem()
{
Text = "SidebarCloudDrives".GetLocalized()
Text = "SidebarCloudDrives".GetLocalized(),
Font = App.Current.Resources["FluentUIGlyphs"] as Windows.UI.Xaml.Media.FontFamily,
Glyph = "\ue9b7",
SelectsOnInvoked = false,
ChildItems = new ObservableCollection<INavigationControlItem>()
};

//Get the last location item in the sidebar
var lastLocationItem = MainPage.SideBarItems.LastOrDefault(x => x is LocationItem);

if (lastLocationItem != null)
{
//Get the index of the last location item
var lastLocationItemIndex = MainPage.SideBarItems.IndexOf(lastLocationItem);
//Insert the drives title beneath it
MainPage.SideBarItems.Insert(lastLocationItemIndex + 1, drivesSection);
}
else
{
MainPage.SideBarItems.Add(drivesSection);
}
MainPage.SideBarItems.Add(section);
}

var sectionStartIndex = MainPage.SideBarItems.IndexOf(drivesSection);

//Remove all existing cloud drives from the sidebar
foreach (var item in MainPage.SideBarItems
.Where(x => x.ItemType == NavigationControlItemType.CloudDrive)
.ToList())
foreach (DriveItem drive in Drives.ToList())
{
MainPage.SideBarItems.Remove(item);
if (!section.ChildItems.Contains(drive))
{
section.ChildItems.Add(drive);
}
}

//Add all cloud drives to the sidebar
var insertAt = sectionStartIndex + 1;
foreach (var drive in drivesSnapshot.OrderBy(o => o.Text))
{
MainPage.SideBarItems.Insert(insertAt, drive);
insertAt++;
}
MainPage.SideBarItems.EndBulkOperation();
}
finally
Expand Down
53 changes: 19 additions & 34 deletions Files/Filesystem/Drives.cs
Expand Up @@ -8,6 +8,7 @@
using NLog;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -126,49 +127,33 @@ private async Task SyncSideBarItemsUI()
{
MainPage.SideBarItems.BeginBulkOperation();

var drivesSnapshot = Drives.ToList();
var drivesSection = MainPage.SideBarItems.FirstOrDefault(x => x is HeaderTextItem && x.Text == "SidebarDrives".GetLocalized());

if (drivesSection != null && drivesSnapshot.Count == 0)
{
//No drives - remove the header
MainPage.SideBarItems.Remove(drivesSection);
}

drivesSection = MainPage.SideBarItems.FirstOrDefault(x => x is HeaderTextItem && x.Text == "SidebarDrives".GetLocalized());

if (drivesSection == null && drivesSnapshot.Count > 0)
var section = MainPage.SideBarItems.FirstOrDefault(x => x.Text == "SidebarDrives".GetLocalized()) as LocationItem;
if (section == null)
{
drivesSection = new HeaderTextItem()
section = new LocationItem()
{
Text = "SidebarDrives".GetLocalized()
Text = "SidebarDrives".GetLocalized(),
Font = App.Current.Resources["FluentUIGlyphs"] as Windows.UI.Xaml.Media.FontFamily,
Glyph = "\uea9e",
SelectsOnInvoked = false,
ChildItems = new ObservableCollection<INavigationControlItem>()
};

MainPage.SideBarItems.Add(drivesSection);
MainPage.SideBarItems.Add(section);
}

var sectionStartIndex = MainPage.SideBarItems.IndexOf(drivesSection);
var insertAt = sectionStartIndex + 1;

//Remove all existing drives from the sidebar
while (insertAt < MainPage.SideBarItems.Count)
foreach (DriveItem drive in Drives.ToList())
{
var item = MainPage.SideBarItems[insertAt];
if (item.ItemType != NavigationControlItemType.Drive)
if (!section.ChildItems.Contains(drive))
{
break;
section.ChildItems.Add(drive);

if (drive.Type != DriveType.VirtualDrive)
{
DrivesWidget.ItemsAdded.Add(drive);
}
}
MainPage.SideBarItems.Remove(item);
DrivesWidget.ItemsAdded.Remove(item);
}

//Add all drives to the sidebar
foreach (var drive in drivesSnapshot)
{
MainPage.SideBarItems.Insert(insertAt, drive);
DrivesWidget.ItemsAdded.Add(drive);
insertAt++;
}
MainPage.SideBarItems.EndBulkOperation();
}
finally
Expand Down Expand Up @@ -478,4 +463,4 @@ public void ResumeDeviceWatcher()
}
}
}
}
}