Skip to content

Commit 36511c8

Browse files
authored
Enabled the option to continue where you left off when opening Files UWP (#1779)
1 parent fbb098e commit 36511c8

File tree

7 files changed

+66
-6
lines changed

7 files changed

+66
-6
lines changed

Files/App.xaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Files.Controls;
55
using Files.Filesystem;
66
using Files.Helpers;
7+
using Files.UserControls;
78
using Files.View_Models;
89
using Files.Views;
910
using Microsoft.AppCenter;
@@ -15,6 +16,7 @@
1516
using System;
1617
using System.Collections.Generic;
1718
using System.Diagnostics;
19+
using System.Linq;
1820
using System.Threading.Tasks;
1921
using Windows.ApplicationModel;
2022
using Windows.ApplicationModel.Activation;
@@ -391,6 +393,8 @@ private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
391393
/// <param name="e">Details about the suspend request.</param>
392394
private void OnSuspending(object sender, SuspendingEventArgs e)
393395
{
396+
SaveSessionTabs();
397+
394398
var deferral = e.SuspendingOperation.GetDeferral();
395399
//TODO: Save application state and stop any background activity
396400
if (Connection != null)
@@ -402,6 +406,11 @@ private void OnSuspending(object sender, SuspendingEventArgs e)
402406
deferral.Complete();
403407
}
404408

409+
private void SaveSessionTabs() // Enumerates through all tabs and gets the Path property and saves it to AppSettings.LastSessionPages
410+
{
411+
AppSettings.LastSessionPages = MainPage.AppInstances.Select(x => x.Path ?? ResourceController.GetTranslation("NewTab")).ToArray();
412+
}
413+
405414
// Occurs when an exception is not handled on the UI thread.
406415
private static void OnUnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
407416
{

Files/UserControls/MultitaskingControl/HorizontalMultitaskingControl.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public async void SetSelectedTabInfo(string text, string currentPathForTabIcon)
4141
var selectedTabItem = (MainPage.AppInstances[App.InteractionViewModel.TabStripSelectedIndex] as TabItem);
4242
selectedTabItem.AllowStorageItemDrop = App.CurrentInstance.InstanceViewModel.IsPageTypeNotHome;
4343

44+
(MainPage.AppInstances[App.InteractionViewModel.TabStripSelectedIndex] as TabItem).Path = currentPathForTabIcon;
45+
4446
string tabLocationHeader;
4547
Microsoft.UI.Xaml.Controls.FontIconSource fontIconSource = new Microsoft.UI.Xaml.Controls.FontIconSource();
4648
Microsoft.UI.Xaml.Controls.IconSource tabIcon;

Files/UserControls/MultitaskingControl/TabItem.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ public string Header
1414
set => SetProperty(ref _Header, value);
1515
}
1616

17+
private string _Path;
18+
19+
// Please, remember to update the Path whenever navigating to directory,
20+
// currently the update is done in both methods SetSelectedTabInfo in
21+
// classes HorizontalMultitaskingControl and VerticalTabView
22+
public string Path
23+
{
24+
get => _Path;
25+
set => SetProperty(ref _Path, value);
26+
}
27+
1728
private string _Description = null;
1829

1930
public string Description

Files/UserControls/MultitaskingControl/VerticalTabView.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public async void SetSelectedTabInfo(string text, string currentPathForTabIcon =
3636
var selectedTabItem = (MainPage.AppInstances[App.InteractionViewModel.TabStripSelectedIndex] as TabItem);
3737
selectedTabItem.AllowStorageItemDrop = App.CurrentInstance.InstanceViewModel.IsPageTypeNotHome;
3838

39+
MainPage.AppInstances[App.InteractionViewModel.TabStripSelectedIndex].Path = currentPathForTabIcon;
40+
3941
string tabLocationHeader;
4042
Microsoft.UI.Xaml.Controls.FontIconSource fontIconSource = new Microsoft.UI.Xaml.Controls.FontIconSource();
4143
Microsoft.UI.Xaml.Controls.IconSource tabIcon;

Files/View Models/SettingsViewModel.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.Toolkit.Mvvm.Input;
1111
using Microsoft.Toolkit.Uwp.UI;
1212
using System;
13+
using System.Collections.Generic;
1314
using System.Collections.ObjectModel;
1415
using System.Linq;
1516
using System.Reflection;
@@ -447,6 +448,12 @@ public bool OpenASpecificPageOnStartup
447448
set => Set(value);
448449
}
449450

451+
public bool ContinueLastSessionOnStartUp
452+
{
453+
get => Get(false);
454+
set => Set(value);
455+
}
456+
450457
public string OpenASpecificPageOnStartupPath
451458
{
452459
get => Get("");
@@ -712,5 +719,11 @@ public string[] PagesOnStartupList
712719
get => Get<string[]>(null);
713720
set => Set(value);
714721
}
722+
723+
public string[] LastSessionPages
724+
{
725+
get => Get<string[]>(null);
726+
set => Set(value);
727+
}
715728
}
716729
}

Files/Views/MainPage.xaml.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,37 @@ protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
8484
Clipboard.ContentChanged += Clipboard_ContentChanged;
8585
Clipboard_ContentChanged(null, null);
8686

87-
if (string.IsNullOrEmpty(navArgs) && App.AppSettings.OpenASpecificPageOnStartup)
87+
if (string.IsNullOrEmpty(navArgs))
8888
{
8989
try
9090
{
91-
if (App.AppSettings.PagesOnStartupList != null)
91+
if (App.AppSettings.OpenASpecificPageOnStartup)
9292
{
93-
foreach (string path in App.AppSettings.PagesOnStartupList)
93+
94+
if (App.AppSettings.PagesOnStartupList != null)
95+
{
96+
foreach (string path in App.AppSettings.PagesOnStartupList)
97+
{
98+
await AddNewTab(typeof(ModernShellPage), path);
99+
}
100+
}
101+
else
102+
{
103+
await AddNewTab(typeof(ModernShellPage), ResourceController.GetTranslation("NewTab"));
104+
}
105+
}
106+
else if (App.AppSettings.ContinueLastSessionOnStartUp)
107+
{
108+
if (App.AppSettings.LastSessionPages != null)
109+
{
110+
foreach (string path in App.AppSettings.LastSessionPages)
111+
{
112+
await AddNewTab(typeof(ModernShellPage), path);
113+
}
114+
}
115+
else
94116
{
95-
await AddNewTab(typeof(ModernShellPage), path);
117+
await AddNewTab(typeof(ModernShellPage), ResourceController.GetTranslation("NewTab"));
96118
}
97119
}
98120
else
@@ -231,6 +253,7 @@ public static async Task AddNewTab(Type t, string path, int atIndex = -1)
231253
TabItem tvi = new TabItem()
232254
{
233255
Header = tabLocationHeader,
256+
Path = path,
234257
Content = new Grid()
235258
{
236259
Children =
@@ -380,4 +403,4 @@ private async void AddNewInstanceAccelerator_Invoked(KeyboardAccelerator sender,
380403
args.Handled = true;
381404
}
382405
}
383-
}
406+
}

Files/Views/SettingsPages/OnStartup.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
Content="Continue where you left off"
4848
FontSize="16"
4949
GroupName="StartupPageSettingRadioGroup"
50-
IsEnabled="False" />
50+
IsChecked="{x:Bind AppSettings.ContinueLastSessionOnStartUp, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
5151

5252
<RadioButton
5353
x:Name="OpenSpecificPage"

0 commit comments

Comments
 (0)