Skip to content

Commit 95fec4e

Browse files
committed
Support User Customization of the Start pages
1 parent 9d20d96 commit 95fec4e

12 files changed

+677
-161
lines changed

Files UWP/App.xaml.cs

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
using Microsoft.AppCenter.Analytics;
1818
using Microsoft.AppCenter.Crashes;
1919
using Windows.UI.Xaml.Media;
20+
using Files.Filesystem;
21+
using System.IO;
22+
using System.Linq;
23+
using System.Collections.ObjectModel;
24+
using Windows.Devices.Enumeration;
25+
using System.Text.RegularExpressions;
2026

2127
namespace Files
2228
{
@@ -76,6 +82,120 @@ public App()
7682

7783
this.RequestedTheme = SettingsPages.Personalization.TV.ThemeValue;
7884
//Debug.WriteLine("!!Requested Theme!!" + RequestedTheme.ToString());
85+
86+
if (localSettings.Values["FavoritesDisplayed_Start"] == null)
87+
{
88+
localSettings.Values["FavoritesDisplayed_Start"] = true;
89+
}
90+
91+
if (localSettings.Values["RecentsDisplayed_Start"] == null)
92+
{
93+
localSettings.Values["RecentsDisplayed_Start"] = true;
94+
}
95+
96+
if (localSettings.Values["DrivesDisplayed_Start"] == null)
97+
{
98+
localSettings.Values["DrivesDisplayed_Start"] = false;
99+
}
100+
101+
if (localSettings.Values["FavoritesDisplayed_NewTab"] == null)
102+
{
103+
localSettings.Values["FavoritesDisplayed_NewTab"] = true;
104+
}
105+
106+
if (localSettings.Values["RecentsDisplayed_NewTab"] == null)
107+
{
108+
localSettings.Values["RecentsDisplayed_NewTab"] = true;
109+
}
110+
111+
if (localSettings.Values["DrivesDisplayed_NewTab"] == null)
112+
{
113+
localSettings.Values["DrivesDisplayed_NewTab"] = false;
114+
}
115+
116+
FindDrives();
117+
//DeviceWatcher watcher = DeviceInformation.CreateWatcher();
118+
//watcher.Added += (sender, info) => FindDrives();
119+
//watcher.Removed += (sender, info) => FindDrives();
120+
//watcher.Start();
121+
}
122+
123+
private async void FindDrives()
124+
{
125+
foundDrives.Clear();
126+
var knownRemDevices = new ObservableCollection<string>();
127+
foreach (var f in await KnownFolders.RemovableDevices.GetFoldersAsync())
128+
{
129+
var path = f.Path;
130+
knownRemDevices.Add(path);
131+
}
132+
133+
var driveLetters = DriveInfo.GetDrives().Select(x => x.RootDirectory.Root).ToList().OrderBy(x => x.Root.FullName).ToList();
134+
135+
if (!driveLetters.Any()) return;
136+
137+
driveLetters.ForEach(async roots =>
138+
{
139+
try
140+
{
141+
//if (roots.Name == @"C:\") return;
142+
var content = string.Empty;
143+
string icon;
144+
if (knownRemDevices.Contains(roots.Name))
145+
{
146+
content = $"Removable Drive ({roots.Name})";
147+
icon = "\uE88E";
148+
}
149+
else
150+
{
151+
content = $"Local Disk ({roots.Name})";
152+
icon = "\uEDA2";
153+
}
154+
StorageFolder drive = await StorageFolder.GetFolderFromPathAsync(roots.Name);
155+
var retrivedProperties = await drive.Properties.RetrievePropertiesAsync(new string[] { "System.FreeSpace", "System.Capacity" });
156+
157+
ulong totalSpaceProg = 0;
158+
ulong freeSpaceProg = 0;
159+
string free_space_text = "Unknown";
160+
string total_space_text = "Unknown";
161+
Visibility capacityBarVis = Visibility.Visible;
162+
try
163+
{
164+
var sizeAsGBString = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.FreeSpace"]).GigaBytes;
165+
freeSpaceProg = Convert.ToUInt64(sizeAsGBString);
166+
167+
sizeAsGBString = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.Capacity"]).GigaBytes;
168+
totalSpaceProg = Convert.ToUInt64(sizeAsGBString);
169+
170+
171+
free_space_text = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.FreeSpace"]).ToString();
172+
total_space_text = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.Capacity"]).ToString();
173+
}
174+
catch (UnauthorizedAccessException)
175+
{
176+
capacityBarVis = Visibility.Collapsed;
177+
}
178+
catch (NullReferenceException)
179+
{
180+
capacityBarVis = Visibility.Collapsed;
181+
}
182+
183+
foundDrives.Add(new DriveItem()
184+
{
185+
driveText = content,
186+
glyph = icon,
187+
maxSpace = totalSpaceProg,
188+
spaceUsed = totalSpaceProg - freeSpaceProg,
189+
tag = roots.Name,
190+
progressBarVisibility = capacityBarVis,
191+
spaceText = free_space_text + " free of " + total_space_text,
192+
});
193+
}
194+
catch (UnauthorizedAccessException e)
195+
{
196+
Debug.WriteLine(e.Message);
197+
}
198+
});
79199
}
80200

81201
public static Windows.UI.Xaml.UnhandledExceptionEventArgs exceptionInfo { get; set; }
@@ -96,7 +216,7 @@ private async void App_UnhandledException(object sender, Windows.UI.Xaml.Unhandl
96216

97217
public static PasteState PS { get; set; } = new PasteState();
98218
public static List<string> pathsToDeleteAfterPaste = new List<string>();
99-
219+
public static ObservableCollection<DriveItem> foundDrives = new ObservableCollection<DriveItem>();
100220

101221
/// <summary>
102222
/// Invoked when the application is launched normally by the end user. Other entry points

Files UWP/FilesUWP.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
</Compile>
143143
<Compile Include="Enums\ThemeStyle.cs" />
144144
<Compile Include="Enums\TimeStyle.cs" />
145+
<Compile Include="Filesystem\DriveItem.cs" />
145146
<Compile Include="Filesystem\ItemViewModel.cs" />
146147
<Compile Include="Filesystem\ListedItem.cs" />
147148
<Compile Include="GenericFileBrowser.xaml.cs">
@@ -185,6 +186,9 @@
185186
<Compile Include="SettingsPages\Preferences.xaml.cs">
186187
<DependentUpon>Preferences.xaml</DependentUpon>
187188
</Compile>
189+
<Compile Include="SettingsPages\StartPageWidgets.xaml.cs">
190+
<DependentUpon>StartPageWidgets.xaml</DependentUpon>
191+
</Compile>
188192
<Compile Include="UnhandledExceptionDisplay.xaml.cs">
189193
<DependentUpon>UnhandledExceptionDisplay.xaml</DependentUpon>
190194
</Compile>
@@ -272,6 +276,10 @@
272276
<SubType>Designer</SubType>
273277
<Generator>MSBuild:Compile</Generator>
274278
</Page>
279+
<Page Include="SettingsPages\StartPageWidgets.xaml">
280+
<SubType>Designer</SubType>
281+
<Generator>MSBuild:Compile</Generator>
282+
</Page>
275283
<Page Include="UnhandledExceptionDisplay.xaml">
276284
<SubType>Designer</SubType>
277285
<Generator>MSBuild:Compile</Generator>

Files UWP/Filesystem/DriveItem.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Windows.UI.Xaml;
7+
8+
namespace Files.Filesystem
9+
{
10+
public class DriveItem
11+
{
12+
public string glyph { get; set; }
13+
public ulong maxSpace { get; set; }
14+
public ulong spaceUsed { get; set; }
15+
public string driveText { get; set; }
16+
public string tag { get; set; }
17+
public Visibility progressBarVisibility { get; set; }
18+
public string spaceText { get; set; }
19+
}
20+
}

Files UWP/InstanceTabsView.xaml.cs

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,20 @@ public InstanceTabsView()
5656
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 155, 155, 155);
5757
titleBar.BackgroundColor = Colors.Transparent;
5858
}
59-
AddNewTab(typeof(ProHome), null);
59+
AddNewTab(typeof(ProHome), "Start");
60+
Microsoft.UI.Xaml.Controls.FontIconSource icon = new Microsoft.UI.Xaml.Controls.FontIconSource();
61+
icon.Glyph = "\xE713";
62+
if ((tabView.SelectedItem as TabViewItem).Header.ToString() != "Settings" && (tabView.SelectedItem as TabViewItem).IconSource != icon)
63+
{
64+
App.selectedTabInstance = ItemViewModel.GetCurrentSelectedTabInstance<ProHome>();
65+
}
6066
}
6167

6268
public void AddNewTab(Type t, string path)
6369
{
6470
Frame frame = new Frame();
6571
frame.Navigate(t, path);
66-
string tabLocationHeader;
72+
string tabLocationHeader = null;
6773
Microsoft.UI.Xaml.Controls.FontIconSource fontIconSource = new Microsoft.UI.Xaml.Controls.FontIconSource();
6874
Microsoft.UI.Xaml.Controls.IconSource tabIcon;
6975
if (path != null)
@@ -72,6 +78,14 @@ public void AddNewTab(Type t, string path)
7278
{
7379
tabLocationHeader = "Settings";
7480
fontIconSource.Glyph = "\xE713";
81+
foreach (TabViewItem item in tabView.TabItems)
82+
{
83+
if (item.Header.ToString() == "Settings")
84+
{
85+
tabView.SelectedItem = item;
86+
return;
87+
}
88+
}
7589
}
7690
else if (path == ProHome.DesktopPath)
7791
{
@@ -108,17 +122,24 @@ public void AddNewTab(Type t, string path)
108122
tabLocationHeader = "OneDrive";
109123
fontIconSource.Glyph = "\xE753";
110124
}
125+
126+
else if (path == "Start")
127+
{
128+
tabLocationHeader = "Start";
129+
fontIconSource.Glyph = "\xE737";
130+
}
131+
else if (path == "New tab")
132+
{
133+
tabLocationHeader = "New tab";
134+
fontIconSource.Glyph = "\xE737";
135+
}
111136
else
112137
{
113138
tabLocationHeader = Path.GetDirectoryName(path);
114139
fontIconSource.Glyph = "\xE8B7";
115140
}
116-
}
117-
else
118-
{
119-
tabLocationHeader = "Favorites";
120-
fontIconSource.Glyph = "\xE728";
121-
}
141+
}
142+
122143
tabIcon = fontIconSource;
123144
Grid gr = new Grid();
124145
gr.Children.Add(frame);
@@ -146,10 +167,15 @@ public async void SetSelectedTabInfo(string text, string currentPathForTabIcon =
146167
tabLocationHeader = "Settings";
147168
fontIconSource.Glyph = "\xE713";
148169
}
149-
else if (currentPathForTabIcon == null && text == "Favorites")
170+
else if (currentPathForTabIcon == null && text == "New tab")
150171
{
151-
tabLocationHeader = "Favorites";
152-
fontIconSource.Glyph = "\xE728";
172+
tabLocationHeader = "New tab";
173+
fontIconSource.Glyph = "\xE737";
174+
}
175+
else if (currentPathForTabIcon == null && text == "Start")
176+
{
177+
tabLocationHeader = "Start";
178+
fontIconSource.Glyph = "\xE737";
153179
}
154180
else if (currentPathForTabIcon == ProHome.DesktopPath)
155181
{
@@ -238,7 +264,12 @@ private void TabStrip_SelectionChanged(object sender, SelectionChangedEventArgs
238264
}
239265
else
240266
{
241-
App.selectedTabInstance = ItemViewModel.GetCurrentSelectedTabInstance<ProHome>();
267+
Microsoft.UI.Xaml.Controls.FontIconSource icon = new Microsoft.UI.Xaml.Controls.FontIconSource();
268+
icon.Glyph = "\xE713";
269+
if ((tabView.SelectedItem as TabViewItem).Header.ToString() != "Settings" && (tabView.SelectedItem as TabViewItem).IconSource != icon)
270+
{
271+
App.selectedTabInstance = ItemViewModel.GetCurrentSelectedTabInstance<ProHome>();
272+
}
242273
}
243274

244275
}
@@ -259,7 +290,7 @@ private void TabStrip_TabCloseRequested(Microsoft.UI.Xaml.Controls.TabView sende
259290

260291
private void TabStrip_AddTabButtonClick(TabView sender, object args)
261292
{
262-
AddNewTab(typeof(ProHome), null);
293+
AddNewTab(typeof(ProHome), "New tab");
263294
}
264295
}
265296

Files UWP/ProHome.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -879,11 +879,11 @@
879879
<ListView.Resources>
880880
<ResourceDictionary Source="ms-appx:///Microsoft.UI.Xaml/DensityStyles/Compact.xaml" />
881881
</ListView.Resources>
882-
<ListViewItem Tag="Favorites">
882+
<ListViewItem Tag="Home">
883883
<ListViewItem.Content>
884884
<StackPanel Spacing="15" Orientation="Horizontal">
885-
<FontIcon FontSize="16" Glyph="&#xE728;" FontFamily="Segoe MDL2 Assets"/>
886-
<TextBlock Text="Favorites" FontSize="12"/>
885+
<FontIcon FontSize="16" Glyph="&#xE737;" FontFamily="Segoe MDL2 Assets"/>
886+
<TextBlock Text="Home" FontSize="12"/>
887887
</StackPanel>
888888
</ListViewItem.Content>
889889
</ListViewItem>

0 commit comments

Comments
 (0)