Skip to content

Commit be8fbb9

Browse files
authored
Fixed OneDrive selection (#816)
* Fixed OneDrive selection Removed unused Tag var * Removed separator accidentally added in aa56ffe
1 parent aa56ffe commit be8fbb9

File tree

8 files changed

+35
-21
lines changed

8 files changed

+35
-21
lines changed

Files/Filesystem/DriveItem.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ public class DriveItem : INavigationControlItem
99
{
1010
public string Glyph { get; set; }
1111
public string Text { get; set; }
12-
public string Path => Tag;
12+
public string Path { get; set; }
1313
public NavigationControlItemType ItemType { get; set; } = NavigationControlItemType.Drive;
1414
public ulong MaxSpace { get; set; } = 0;
1515
public ulong SpaceUsed { get; set; } = 0;
1616
public string SpaceText { get; set; }
17-
public string Tag { get; set; }
1817
public Visibility ItemVisibility { get; set; } = Visibility.Visible;
1918

2019
private DriveType _type;
@@ -37,7 +36,7 @@ public DriveItem(StorageFolder root, DriveType type)
3736
{
3837
Text = root.DisplayName;
3938
Type = type;
40-
Tag = root.Path;
39+
Path = root.Path;
4140

4241
var properties = Task.Run(async () =>
4342
{

Files/Filesystem/Drives.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ private async void DeviceAdded(DeviceWatcher sender, DeviceInformation args)
125125
}
126126

127127
// If drive already in list, skip.
128-
if (Drives.Any(x => x.Tag == root.Name))
128+
if (Drives.Any(x => x.Path == root.Name))
129129
{
130130
return;
131131
}
132132

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

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

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

157157
foreach (var drive in Drives)
158158
{
159-
if (drive.Type == DriveType.VirtualDrive || drives.Contains(drive.Tag))
159+
if (drive.Type == DriveType.VirtualDrive || drives.Contains(drive.Path))
160160
{
161161
continue;
162162
}
163163

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

166166
// Update the collection on the ui-thread.
167167
try
@@ -203,7 +203,7 @@ private async Task GetDrives(IList<DriveItem> list)
203203
foreach (var drive in drives)
204204
{
205205
// If drive already in list, skip.
206-
if (list.Any(x => x.Tag == drive.Name))
206+
if (list.Any(x => x.Path == drive.Name))
207207
{
208208
continue;
209209
}
@@ -258,7 +258,7 @@ private async Task GetDrives(IList<DriveItem> list)
258258

259259
var driveItem = new DriveItem(folder, type);
260260

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

263263
list.Add(driveItem);
264264
}
@@ -269,7 +269,7 @@ private void GetVirtualDrivesList(IList<DriveItem> list)
269269
var oneDriveItem = new DriveItem()
270270
{
271271
Text = "OneDrive",
272-
Tag = "OneDrive",
272+
Path = App.AppSettings.OneDrivePath,
273273
Type = DriveType.VirtualDrive,
274274
};
275275

Files/UserControls/ModernSidebar.xaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
BorderThickness="0.8"
4040
DataContext="{x:Bind}"
4141
Padding="0"
42-
Tag="{x:Bind Tag}"
42+
Tag="{x:Bind Path}"
4343
Visibility="{x:Bind ItemVisibility}"
4444
ToolTipService.ToolTip="{x:Bind SpaceText}">
4545
<muxc:NavigationViewItem.Icon>
@@ -92,7 +92,6 @@
9292
OpenPaneLength="200"
9393
PaneDisplayMode="Left"
9494
SelectedItem="{x:Bind SelectedSidebarItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
95-
<NavigationViewItemSeparator />
9695
<muxc:NavigationView.PaneFooter>
9796
<Grid Width="200">
9897
<Button

Files/UserControls/ModernSidebar.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private void Sidebar_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sende
6464
{
6565
//(App.CurrentInstance.OperationsControl as RibbonArea).RibbonViewModel.HomeItems.isEnabled = false;
6666
//(App.CurrentInstance.OperationsControl as RibbonArea).RibbonViewModel.ShareItems.isEnabled = false;
67-
string NavigationPath = ""; // path to navigate
67+
string NavigationPath; // path to navigate
6868

6969
if (args.InvokedItem == null)
7070
{

Files/UserControls/YourHome.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private async void RecentsView_ItemClick(object sender, ItemClickEventArgs e)
233233
{
234234
foreach (DriveItem drive in App.AppSettings.DrivesManager.Drives)
235235
{
236-
if (drive.Tag.ToString() == new DirectoryInfo(path).Root.ToString())
236+
if (drive.Path.ToString() == new DirectoryInfo(path).Root.ToString())
237237
{
238238
App.CurrentInstance.ContentFrame.Navigate(typeof(GenericFileBrowser), path);
239239
return;

Files/View Models/ItemViewModel.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,28 @@ public string WorkingDirectory
5555
{
5656
_WorkingDirectory = value;
5757

58-
App.CurrentInstance.SidebarSelectedItem = App.sideBarItems.FirstOrDefault(x => x.Path != null && value.StartsWith(x.Path, StringComparison.OrdinalIgnoreCase));
59-
if (App.CurrentInstance.SidebarSelectedItem == null)
58+
INavigationControlItem item = null;
59+
List<INavigationControlItem> sidebarItems = App.sideBarItems.Where(x => !string.IsNullOrWhiteSpace(x.Path)).ToList();
60+
61+
item = sidebarItems.FirstOrDefault(x => x.Path.Equals(value, StringComparison.OrdinalIgnoreCase));
62+
if (item == null)
63+
{
64+
item = sidebarItems.FirstOrDefault(x => x.Path.Equals(value + "\\", StringComparison.OrdinalIgnoreCase));
65+
}
66+
if (item == null)
6067
{
61-
App.CurrentInstance.SidebarSelectedItem = App.sideBarItems.FirstOrDefault(x => x.Path != null && x.Path.Equals(Path.GetPathRoot(value), StringComparison.OrdinalIgnoreCase));
68+
item = sidebarItems.FirstOrDefault(x => value.StartsWith(x.Path, StringComparison.OrdinalIgnoreCase));
69+
}
70+
if (item == null)
71+
{
72+
item = sidebarItems.FirstOrDefault(x => x.Path.Equals(Path.GetPathRoot(value), StringComparison.OrdinalIgnoreCase));
6273
}
6374

75+
if (App.CurrentInstance.SidebarSelectedItem != item)
76+
{
77+
App.CurrentInstance.SidebarSelectedItem = item;
78+
}
79+
6480
NotifyPropertyChanged("WorkingDirectory");
6581
}
6682
}

Files/View Models/SettingsViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ public FormFactorMode FormFactor
333333
set => Set(ref _FormFactor, value);
334334
}
335335

336+
public string OneDrivePath = Environment.GetEnvironmentVariable("OneDrive");
337+
336338
private void DetectOneDrivePreference()
337339
{
338340
if (localSettings.Values["PinOneDrive"] == null) { localSettings.Values["PinOneDrive"] = true; }
@@ -372,7 +374,7 @@ public bool PinOneDriveToSideBar
372374
var oneDriveItem = new DriveItem()
373375
{
374376
Text = "OneDrive",
375-
Tag = "OneDrive",
377+
Path = OneDrivePath,
376378
Type = Filesystem.DriveType.VirtualDrive,
377379
};
378380
App.sideBarItems.Add(oneDriveItem);
@@ -404,8 +406,6 @@ public bool PinOneDriveToSideBar
404406

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

407-
public string OneDrivePath = Environment.GetEnvironmentVariable("OneDrive");
408-
409409
private string _TempPath = (string)Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Environment", "TEMP", null);
410410

411411
public string TempPath

Files/Views/Pages/ModernShellPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private void Page_Loaded(object sender, RoutedEventArgs e)
140140
if (NavParams[0] >= 'A' && NavParams[0] <= 'Z' && NavParams[1] == ':')
141141
{
142142
NavigationPath = NavParams;
143-
SidebarControl.SelectedSidebarItem = App.AppSettings.DrivesManager.Drives.First(x => x.Tag.ToString().Equals($"{NavParams[0]}:\\", StringComparison.OrdinalIgnoreCase));
143+
SidebarControl.SelectedSidebarItem = App.AppSettings.DrivesManager.Drives.First(x => x.Path.ToString().Equals($"{NavParams[0]}:\\", StringComparison.OrdinalIgnoreCase));
144144
}
145145
else
146146
{

0 commit comments

Comments
 (0)