Skip to content
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
5 changes: 2 additions & 3 deletions Files/Filesystem/DriveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ public class DriveItem : INavigationControlItem
{
public string Glyph { get; set; }
public string Text { get; set; }
public string Path => Tag;
public string Path { get; set; }
public NavigationControlItemType ItemType { get; set; } = NavigationControlItemType.Drive;
public ulong MaxSpace { get; set; } = 0;
public ulong SpaceUsed { get; set; } = 0;
public string SpaceText { get; set; }
public string Tag { get; set; }
public Visibility ItemVisibility { get; set; } = Visibility.Visible;

private DriveType _type;
Expand All @@ -37,7 +36,7 @@ public DriveItem(StorageFolder root, DriveType type)
{
Text = root.DisplayName;
Type = type;
Tag = root.Path;
Path = root.Path;

var properties = Task.Run(async () =>
{
Expand Down
14 changes: 7 additions & 7 deletions Files/Filesystem/Drives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ private async void DeviceAdded(DeviceWatcher sender, DeviceInformation args)
}

// If drive already in list, skip.
if (Drives.Any(x => x.Tag == root.Name))
if (Drives.Any(x => x.Path == root.Name))
{
return;
}

var driveItem = new DriveItem(root, DriveType.Removable);

Logger.Info($"Drive added: {driveItem.Tag}, {driveItem.Type}");
Logger.Info($"Drive added: {driveItem.Path}, {driveItem.Type}");

// Update the collection on the ui-thread.
try
Expand All @@ -156,12 +156,12 @@ private async void DeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate a

foreach (var drive in Drives)
{
if (drive.Type == DriveType.VirtualDrive || drives.Contains(drive.Tag))
if (drive.Type == DriveType.VirtualDrive || drives.Contains(drive.Path))
{
continue;
}

Logger.Info($"Drive removed: {drive.Tag}");
Logger.Info($"Drive removed: {drive.Path}");

// Update the collection on the ui-thread.
try
Expand Down Expand Up @@ -203,7 +203,7 @@ private async Task GetDrives(IList<DriveItem> list)
foreach (var drive in drives)
{
// If drive already in list, skip.
if (list.Any(x => x.Tag == drive.Name))
if (list.Any(x => x.Path == drive.Name))
{
continue;
}
Expand Down Expand Up @@ -258,7 +258,7 @@ private async Task GetDrives(IList<DriveItem> list)

var driveItem = new DriveItem(folder, type);

Logger.Info($"Drive added: {driveItem.Tag}, {driveItem.Type}");
Logger.Info($"Drive added: {driveItem.Path}, {driveItem.Type}");

list.Add(driveItem);
}
Expand All @@ -269,7 +269,7 @@ private void GetVirtualDrivesList(IList<DriveItem> list)
var oneDriveItem = new DriveItem()
{
Text = "OneDrive",
Tag = "OneDrive",
Path = App.AppSettings.OneDrivePath,
Type = DriveType.VirtualDrive,
};

Expand Down
3 changes: 1 addition & 2 deletions Files/UserControls/ModernSidebar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
BorderThickness="0.8"
DataContext="{x:Bind}"
Padding="0"
Tag="{x:Bind Tag}"
Tag="{x:Bind Path}"
Visibility="{x:Bind ItemVisibility}"
ToolTipService.ToolTip="{x:Bind SpaceText}">
<muxc:NavigationViewItem.Icon>
Expand Down Expand Up @@ -92,7 +92,6 @@
OpenPaneLength="200"
PaneDisplayMode="Left"
SelectedItem="{x:Bind SelectedSidebarItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<NavigationViewItemSeparator />
<muxc:NavigationView.PaneFooter>
<Grid Width="200">
<Button
Expand Down
2 changes: 1 addition & 1 deletion Files/UserControls/ModernSidebar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void Sidebar_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sende
{
//(App.CurrentInstance.OperationsControl as RibbonArea).RibbonViewModel.HomeItems.isEnabled = false;
//(App.CurrentInstance.OperationsControl as RibbonArea).RibbonViewModel.ShareItems.isEnabled = false;
string NavigationPath = ""; // path to navigate
string NavigationPath; // path to navigate

if (args.InvokedItem == null)
{
Expand Down
2 changes: 1 addition & 1 deletion Files/UserControls/YourHome.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private async void RecentsView_ItemClick(object sender, ItemClickEventArgs e)
{
foreach (DriveItem drive in App.AppSettings.DrivesManager.Drives)
{
if (drive.Tag.ToString() == new DirectoryInfo(path).Root.ToString())
if (drive.Path.ToString() == new DirectoryInfo(path).Root.ToString())
{
App.CurrentInstance.ContentFrame.Navigate(typeof(GenericFileBrowser), path);
return;
Expand Down
22 changes: 19 additions & 3 deletions Files/View Models/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,28 @@ public string WorkingDirectory
{
_WorkingDirectory = value;

App.CurrentInstance.SidebarSelectedItem = App.sideBarItems.FirstOrDefault(x => x.Path != null && value.StartsWith(x.Path, StringComparison.OrdinalIgnoreCase));
if (App.CurrentInstance.SidebarSelectedItem == null)
INavigationControlItem item = null;
List<INavigationControlItem> sidebarItems = App.sideBarItems.Where(x => !string.IsNullOrWhiteSpace(x.Path)).ToList();

item = sidebarItems.FirstOrDefault(x => x.Path.Equals(value, StringComparison.OrdinalIgnoreCase));
if (item == null)
{
item = sidebarItems.FirstOrDefault(x => x.Path.Equals(value + "\\", StringComparison.OrdinalIgnoreCase));
}
if (item == null)
{
App.CurrentInstance.SidebarSelectedItem = App.sideBarItems.FirstOrDefault(x => x.Path != null && x.Path.Equals(Path.GetPathRoot(value), StringComparison.OrdinalIgnoreCase));
item = sidebarItems.FirstOrDefault(x => value.StartsWith(x.Path, StringComparison.OrdinalIgnoreCase));
}
if (item == null)
{
item = sidebarItems.FirstOrDefault(x => x.Path.Equals(Path.GetPathRoot(value), StringComparison.OrdinalIgnoreCase));
}

if (App.CurrentInstance.SidebarSelectedItem != item)
{
App.CurrentInstance.SidebarSelectedItem = item;
}

NotifyPropertyChanged("WorkingDirectory");
}
}
Expand Down
6 changes: 3 additions & 3 deletions Files/View Models/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ public FormFactorMode FormFactor
set => Set(ref _FormFactor, value);
}

public string OneDrivePath = Environment.GetEnvironmentVariable("OneDrive");

private void DetectOneDrivePreference()
{
if (localSettings.Values["PinOneDrive"] == null) { localSettings.Values["PinOneDrive"] = true; }
Expand Down Expand Up @@ -372,7 +374,7 @@ public bool PinOneDriveToSideBar
var oneDriveItem = new DriveItem()
{
Text = "OneDrive",
Tag = "OneDrive",
Path = OneDrivePath,
Type = Filesystem.DriveType.VirtualDrive,
};
App.sideBarItems.Add(oneDriveItem);
Expand Down Expand Up @@ -404,8 +406,6 @@ public bool PinOneDriveToSideBar

public string VideosPath = UserDataPaths.GetDefault().Videos;

public string OneDrivePath = Environment.GetEnvironmentVariable("OneDrive");

private string _TempPath = (string)Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Environment", "TEMP", null);

public string TempPath
Expand Down
2 changes: 1 addition & 1 deletion Files/Views/Pages/ModernShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private void Page_Loaded(object sender, RoutedEventArgs e)
if (NavParams[0] >= 'A' && NavParams[0] <= 'Z' && NavParams[1] == ':')
{
NavigationPath = NavParams;
SidebarControl.SelectedSidebarItem = App.AppSettings.DrivesManager.Drives.First(x => x.Tag.ToString().Equals($"{NavParams[0]}:\\", StringComparison.OrdinalIgnoreCase));
SidebarControl.SelectedSidebarItem = App.AppSettings.DrivesManager.Drives.First(x => x.Path.ToString().Equals($"{NavParams[0]}:\\", StringComparison.OrdinalIgnoreCase));
}
else
{
Expand Down