Skip to content

Commit 060929c

Browse files
committed
Add OneDrive Visibility Setting
1 parent 9a5cb99 commit 060929c

File tree

14 files changed

+306
-211
lines changed

14 files changed

+306
-211
lines changed

Files/App.xaml.cs

Lines changed: 2 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ public App()
7171
AppCenter.Start("682666d1-51d3-4e4a-93d0-d028d43baaa0", typeof(Analytics), typeof(Crashes));
7272

7373
AppSettings = new SettingsViewModel();
74-
PopulatePinnedSidebarItems();
75-
DetectWSLDistros();
76-
7774
}
7875

7976
private void CoreWindow_PointerPressed(CoreWindow sender, PointerEventArgs args)
@@ -189,171 +186,6 @@ private async void CoreWindow_KeyDown(CoreWindow sender, KeyEventArgs args)
189186
}
190187
}
191188

192-
private async void DetectWSLDistros()
193-
{
194-
try
195-
{
196-
var distroFolder = await StorageFolder.GetFolderFromPathAsync(@"\\wsl$\");
197-
if ((await distroFolder.GetFoldersAsync()).Count > 0)
198-
{
199-
AppSettings.AreLinuxFilesSupported = false;
200-
}
201-
202-
foreach (StorageFolder folder in await distroFolder.GetFoldersAsync())
203-
{
204-
Uri logoURI = null;
205-
if (folder.DisplayName.Contains("ubuntu", StringComparison.OrdinalIgnoreCase))
206-
{
207-
logoURI = new Uri("ms-appx:///Assets/WSL/ubuntupng.png");
208-
}
209-
else if (folder.DisplayName.Contains("kali", StringComparison.OrdinalIgnoreCase))
210-
{
211-
logoURI = new Uri("ms-appx:///Assets/WSL/kalipng.png");
212-
}
213-
else if (folder.DisplayName.Contains("debian", StringComparison.OrdinalIgnoreCase))
214-
{
215-
logoURI = new Uri("ms-appx:///Assets/WSL/debianpng.png");
216-
}
217-
else if (folder.DisplayName.Contains("opensuse", StringComparison.OrdinalIgnoreCase))
218-
{
219-
logoURI = new Uri("ms-appx:///Assets/WSL/opensusepng.png");
220-
}
221-
else if (folder.DisplayName.Contains("alpine", StringComparison.OrdinalIgnoreCase))
222-
{
223-
logoURI = new Uri("ms-appx:///Assets/WSL/alpinepng.png");
224-
}
225-
else
226-
{
227-
logoURI = new Uri("ms-appx:///Assets/WSL/genericpng.png");
228-
}
229-
230-
231-
linuxDistroItems.Add(new WSLDistroItem() { DistroName = folder.DisplayName, Path = folder.Path, Logo = logoURI });
232-
}
233-
}
234-
catch (Exception)
235-
{
236-
// WSL Not Supported/Enabled
237-
AppSettings.AreLinuxFilesSupported = false;
238-
}
239-
}
240-
241-
public static List<string> LinesToRemoveFromFile = new List<string>();
242-
243-
public async void PopulatePinnedSidebarItems()
244-
{
245-
AddDefaultLocations();
246-
247-
StorageFile ListFile;
248-
StorageFolder cacheFolder = ApplicationData.Current.LocalCacheFolder;
249-
ListFile = await cacheFolder.CreateFileAsync("PinnedItems.txt", CreationCollisionOption.OpenIfExists);
250-
251-
if (ListFile != null)
252-
{
253-
var ListFileLines = await FileIO.ReadLinesAsync(ListFile);
254-
foreach (string locationPath in ListFileLines)
255-
{
256-
try
257-
{
258-
StorageFolder fol = await StorageFolder.GetFolderFromPathAsync(locationPath);
259-
var name = fol.DisplayName;
260-
var content = name;
261-
var icon = "\uE8B7";
262-
263-
bool isDuplicate = false;
264-
foreach (INavigationControlItem sbi in sideBarItems)
265-
{
266-
if(sbi is LocationItem)
267-
{
268-
if (!string.IsNullOrWhiteSpace(sbi.Path) && !(sbi as LocationItem).IsDefaultLocation)
269-
{
270-
if (sbi.Path.ToString() == locationPath)
271-
{
272-
isDuplicate = true;
273-
274-
}
275-
}
276-
}
277-
278-
}
279-
280-
if (!isDuplicate)
281-
{
282-
sideBarItems.Add(new LocationItem() { IsDefaultLocation = false, Text = name, Glyph = icon, Path = locationPath });
283-
}
284-
}
285-
catch (UnauthorizedAccessException e)
286-
{
287-
Debug.WriteLine(e.Message);
288-
}
289-
catch (FileNotFoundException e)
290-
{
291-
Debug.WriteLine("Pinned item was deleted and will be removed from the file lines list soon: " + e.Message);
292-
LinesToRemoveFromFile.Add(locationPath);
293-
}
294-
catch (System.Runtime.InteropServices.COMException e)
295-
{
296-
Debug.WriteLine("Pinned item's drive was ejected and will be removed from the file lines list soon: " + e.Message);
297-
LinesToRemoveFromFile.Add(locationPath);
298-
}
299-
}
300-
301-
RemoveStaleSidebarItems();
302-
}
303-
}
304-
305-
private void AddDefaultLocations()
306-
{
307-
sideBarItems.Add(new LocationItem { Text = "Home", Glyph = "\uE737", IsDefaultLocation = true, Path = "Home" });
308-
sideBarItems.Add(new LocationItem { Text = "Desktop", Glyph = "\uE8FC", IsDefaultLocation = true, Path = AppSettings.DesktopPath });
309-
sideBarItems.Add(new LocationItem { Text = "Downloads", Glyph = "\uE896", IsDefaultLocation = true, Path = AppSettings.DownloadsPath });
310-
sideBarItems.Add(new LocationItem { Text = "Documents", Glyph = "\uE8A5", IsDefaultLocation = true, Path = AppSettings.DocumentsPath });
311-
sideBarItems.Add(new LocationItem { Text = "Pictures", Glyph = "\uEB9F", IsDefaultLocation = true, Path = AppSettings.PicturesPath });
312-
sideBarItems.Add(new LocationItem { Text = "Music", Glyph = "\uEC4F", IsDefaultLocation = true, Path = AppSettings.MusicPath });
313-
sideBarItems.Add(new LocationItem { Text = "Videos", Glyph = "\uE8B2", IsDefaultLocation = true, Path = AppSettings.VideosPath });
314-
}
315-
316-
public static async void RemoveStaleSidebarItems()
317-
{
318-
StorageFile ListFile;
319-
StorageFolder cacheFolder = ApplicationData.Current.LocalCacheFolder;
320-
ListFile = await cacheFolder.CreateFileAsync("PinnedItems.txt", CreationCollisionOption.OpenIfExists);
321-
322-
if (ListFile != null)
323-
{
324-
var ListFileLines = await FileIO.ReadLinesAsync(ListFile);
325-
foreach (string path in LinesToRemoveFromFile)
326-
{
327-
ListFileLines.Remove(path);
328-
}
329-
330-
await FileIO.WriteLinesAsync(ListFile, ListFileLines);
331-
ListFileLines = await FileIO.ReadLinesAsync(ListFile);
332-
333-
// Remove unpinned items from sidebar
334-
var sideBarItems_Copy = sideBarItems.ToList();
335-
foreach (INavigationControlItem location in sideBarItems)
336-
{
337-
if (location is LocationItem)
338-
{
339-
if (!(location as LocationItem).IsDefaultLocation)
340-
{
341-
if (!ListFileLines.Contains(location.Path.ToString()))
342-
{
343-
sideBarItems_Copy.Remove(location);
344-
}
345-
}
346-
}
347-
}
348-
sideBarItems.Clear();
349-
foreach(INavigationControlItem correctItem in sideBarItems_Copy)
350-
{
351-
sideBarItems.Add(correctItem);
352-
}
353-
LinesToRemoveFromFile.Clear();
354-
}
355-
}
356-
357189
public static INavigationControlItem rightClickedItem;
358190

359191
public static async void FlyoutItem_Click(object sender, RoutedEventArgs e)
@@ -365,8 +197,8 @@ public static async void FlyoutItem_Click(object sender, RoutedEventArgs e)
365197
{
366198
if (path == App.rightClickedItem.Path.ToString())
367199
{
368-
App.LinesToRemoveFromFile.Add(path);
369-
RemoveStaleSidebarItems();
200+
App.AppSettings.LinesToRemoveFromFile.Add(path);
201+
App.AppSettings.RemoveStaleSidebarItems();
370202
return;
371203
}
372204
}

Files/Controls/RibbonArea.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,7 @@
18671867
x:Name="PathViewInteract"
18681868
x:FieldModifier="public"
18691869
Margin="0"
1870-
VerticalAlignment="Stretch"
1870+
VerticalAlignment="Center"
18711871
HorizontalContentAlignment="Stretch"
18721872
VerticalContentAlignment="Stretch"
18731873
Background="{ThemeResource TextControlBackground}"

Files/Controls/Sidebar.xaml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -466,24 +466,12 @@
466466
</MenuFlyout.Items>
467467
</MenuFlyout>
468468
</ResourceDictionary>
469-
469+
470470
</ResourceDictionary.MergedDictionaries>
471471
</ResourceDictionary>
472472
</muxc:NavigationView.Resources>
473473

474474
</muxc:NavigationView>
475-
<!--<TextBlock Visibility="Visible" Margin="8,-16,0,0" Text="Drives" FontSize="14" FontWeight="SemiBold" Padding="0" VerticalAlignment="Stretch"/>
476-
<muxc:NavigationView Style="{StaticResource NavigationViewStyle_Fixed}" PaneTitle="Drives" OpenPaneLength="225" Padding="0" IsTitleBarAutoPaddingEnabled="False" PaneDisplayMode="Left" ItemInvoked="DrivesList_ItemInvoked" x:FieldModifier="public" IsPaneOpen="True" IsSettingsVisible="False" IsPaneToggleButtonVisible="False" IsBackButtonVisible="Collapsed" MenuItemsSource="{x:Bind local1:App.AppSettings.DrivesManager.Drives}" SelectionChanged="DrivesList_SelectionChanged" x:Name="DrivesList">
477-
<muxc:NavigationView.MenuItemTemplate>
478-
479-
</muxc:NavigationView.MenuItemTemplate>
480-
</muxc:NavigationView>
481-
<TextBlock x:Name="LinuxHeader" x:Load="{x:Bind local1:App.AppSettings.AreLinuxFilesSupported, Mode=OneWay}" Visibility="Visible" Margin="8,-16,0,0" Text="Linux Files" FontSize="14" FontWeight="SemiBold" Padding="0" VerticalAlignment="Stretch"/>
482-
<muxc:NavigationView Style="{StaticResource NavigationViewStyle_Fixed}" PaneTitle="Linux Files" x:Load="{x:Bind local1:App.AppSettings.AreLinuxFilesSupported, Mode=OneWay}" OpenPaneLength="225" Padding="0" IsTitleBarAutoPaddingEnabled="False" PaneDisplayMode="Left" ItemInvoked="LinuxList_ItemInvoked" x:FieldModifier="public" IsPaneOpen="True" IsSettingsVisible="False" IsPaneToggleButtonVisible="False" IsBackButtonVisible="Collapsed" MenuItemsSource="{x:Bind local1:App.linuxDistroItems, Mode=OneWay}" SelectionChanged="LinuxList_SelectionChanged" x:Name="LinuxList">
483-
<muxc:NavigationView.MenuItemTemplate>
484-
485-
</muxc:NavigationView.MenuItemTemplate>
486-
</muxc:NavigationView>-->
487475
</Grid>
488476
</Grid>
489477
</UserControl>

Files/Controls/Sidebar.xaml.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public sealed partial class Sidebar : UserControl
2424
public Sidebar()
2525
{
2626
this.InitializeComponent();
27-
SidebarNavView.SelectedItem = App.sideBarItems[0];
2827
}
2928

3029
private void Sidebar_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewItemInvokedEventArgs args)
@@ -103,7 +102,8 @@ private void Sidebar_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sende
103102
break;
104103
}
105104
}
106-
else if ((args.InvokedItemContainer.DataContext as INavigationControlItem).ItemType == NavigationControlItemType.Drive)
105+
else if ((args.InvokedItemContainer.DataContext as INavigationControlItem).ItemType == NavigationControlItemType.Drive ||
106+
(args.InvokedItemContainer.DataContext as INavigationControlItem).ItemType == NavigationControlItemType.OneDrive)
107107
{
108108
var clickedItem = args.InvokedItemContainer;
109109

@@ -167,6 +167,8 @@ protected override DataTemplate SelectTemplateCore(object item)
167167
return LocationNavItemTemplate;
168168
case NavigationControlItemType.Drive:
169169
return DriveNavItemTemplate;
170+
case NavigationControlItemType.OneDrive:
171+
return DriveNavItemTemplate;
170172
case NavigationControlItemType.LinuxDistro:
171173
return LinuxNavItemTemplate;
172174
case NavigationControlItemType.Header:

Files/Filesystem/DriveItem.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public class DriveItem : INavigationControlItem
2626
string INavigationControlItem.IconGlyph => glyph;
2727
string INavigationControlItem.Text => driveText;
2828
string INavigationControlItem.Path => tag;
29-
30-
NavigationControlItemType INavigationControlItem.ItemType => NavigationControlItemType.Drive;
29+
private NavigationControlItemType NavItemType = NavigationControlItemType.Drive;
30+
NavigationControlItemType INavigationControlItem.ItemType => NavItemType;
3131

3232
private StorageFolder _root;
3333

3434
public DriveItem()
3535
{
36-
36+
NavItemType = NavigationControlItemType.OneDrive;
3737
}
3838

3939
public DriveItem(StorageFolder root, Visibility progressBarVisibility, DriveType type)

Files/Filesystem/Drives.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,25 @@ public DrivesManager()
4444

4545
private async void DeviceWatcher_EnumerationCompleted(DeviceWatcher sender, object args)
4646
{
47+
if(App.sideBarItems.FirstOrDefault(x => x is HeaderTextItem && x.Text == "Drives") == null)
48+
{
49+
App.sideBarItems.Add(new HeaderTextItem() { Text = "Drives" });
50+
}
51+
foreach (DriveItem drive in Drives)
52+
{
53+
if (!App.sideBarItems.Contains(drive))
54+
{
55+
App.sideBarItems.Add(drive);
56+
}
57+
}
4758

59+
foreach(INavigationControlItem item in App.sideBarItems.ToList())
60+
{
61+
if(item is DriveItem && !Drives.Contains(item))
62+
{
63+
App.sideBarItems.Remove(item);
64+
}
65+
}
4866
}
4967

5068
private async void DeviceAdded(DeviceWatcher sender, DeviceInformation args)
@@ -180,11 +198,15 @@ private void GetVirtualDrivesList(IList<DriveItem> list)
180198
tag = "OneDrive",
181199
cloudGlyphVisibility = Visibility.Visible,
182200
driveGlyphVisibility = Visibility.Collapsed,
183-
Type = DriveType.VirtualDrive
201+
Type = DriveType.VirtualDrive,
184202
//itemVisibility = App.AppSettings.PinOneDriveToSideBar
185203
};
186204

187-
list.Add(oneDriveItem);
205+
var setting = ApplicationData.Current.LocalSettings.Values["PinOneDrive"];
206+
if (setting == null || (bool)setting == true)
207+
{
208+
list.Add(oneDriveItem);
209+
}
188210
}
189211

190212
public void Dispose()

Files/Filesystem/INavigationControlItem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public enum NavigationControlItemType
2121
Header,
2222
Drive,
2323
LinuxDistro,
24-
Location
24+
Location,
25+
OneDrive
2526
}
2627
}

Files/Filesystem/LocationItem.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ public class LocationItem : INavigationControlItem
2424

2525
public class HeaderTextItem : INavigationControlItem
2626
{
27-
string INavigationControlItem.IconGlyph => throw new NotImplementedException();
27+
string INavigationControlItem.IconGlyph => null;
28+
public string Text { get; set; }
2829

29-
string INavigationControlItem.Text => throw new NotImplementedException();
30+
string INavigationControlItem.Text => Text;
3031

31-
string INavigationControlItem.Path => throw new NotImplementedException();
32+
string INavigationControlItem.Path => null;
3233

3334
NavigationControlItemType INavigationControlItem.ItemType => NavigationControlItemType.Header;
3435
}

Files/IShellPage.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ public interface IShellPage
2323
public bool CanGoForward { get; set; }
2424
public string PathControlDisplayText { get; set; }
2525
public ObservableCollection<PathBoxItem> PathComponents { get; }
26-
//TODO: Modularize Sidebar and standardize its item types
27-
//public SidebarItem SelectedSidebarLocation { get; set; }
28-
public ObservableCollection<INavigationControlItem> NavigationControlItems { get; set; }
2926
public Type CurrentPageType { get; }
3027
}
3128
}

Files/Interacts/Interaction.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ public async void PinItem_Click(object sender, RoutedEventArgs e)
163163

164164
if (!isDuplicate)
165165
{
166-
App.sideBarItems.Add(new LocationItem { Path = itemPath, Glyph = icon, IsDefaultLocation = false, Text = content });
166+
int insertIndex = App.sideBarItems.IndexOf(App.sideBarItems.Last(x => x.ItemType == NavigationControlItemType.Location)) + 1;
167+
App.sideBarItems.Insert(insertIndex, new LocationItem { Path = itemPath, Glyph = icon, IsDefaultLocation = false, Text = content });
167168
}
168169
}
169170
catch (UnauthorizedAccessException ex)
@@ -173,17 +174,17 @@ public async void PinItem_Click(object sender, RoutedEventArgs e)
173174
catch (FileNotFoundException ex)
174175
{
175176
Debug.WriteLine("Pinned item was deleted and will be removed from the file lines list soon: " + ex.Message);
176-
App.LinesToRemoveFromFile.Add(itemPath);
177+
App.AppSettings.LinesToRemoveFromFile.Add(itemPath);
177178
}
178179
catch (System.Runtime.InteropServices.COMException ex)
179180
{
180181
Debug.WriteLine("Pinned item's drive was ejected and will be removed from the file lines list soon: " + ex.Message);
181-
App.LinesToRemoveFromFile.Add(itemPath);
182+
App.AppSettings.LinesToRemoveFromFile.Add(itemPath);
182183
}
183184
}
184185
}
185186
}
186-
App.RemoveStaleSidebarItems();
187+
App.AppSettings.RemoveStaleSidebarItems();
187188
}
188189

189190
public void GetPath_Click(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)