Skip to content

Commit ddb0035

Browse files
Thomas1664yaira2
andauthored
Show dialog to restart app after language changed (#1856)
Co-authored-by: Yair Aichenbaum <[email protected]>
1 parent c3fd0bd commit ddb0035

File tree

9 files changed

+149
-17
lines changed

9 files changed

+149
-17
lines changed

Files/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ private void OnSuspending(object sender, SuspendingEventArgs e)
423423
deferral.Complete();
424424
}
425425

426-
private void SaveSessionTabs() // Enumerates through all tabs and gets the Path property and saves it to AppSettings.LastSessionPages
426+
public static void SaveSessionTabs() // Enumerates through all tabs and gets the Path property and saves it to AppSettings.LastSessionPages
427427
{
428428
AppSettings.LastSessionPages = MainPage.AppInstances.DefaultIfEmpty().Select(tab => tab != null ? tab.Path ?? ResourceController.GetTranslation("NewTab") : ResourceController.GetTranslation("NewTab")).ToArray();
429429
}

Files/Dialogs/RestartDialog.xaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<UserControl
2+
x:Class="Files.Dialogs.RestartDialog"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
8+
mc:Ignorable="d"
9+
d:DesignHeight="300"
10+
d:DesignWidth="400">
11+
12+
<UserControl.Resources>
13+
<DataTemplate x:Key="RestartDialogTemplate">
14+
<UserControl>
15+
<Grid x:Name="RootGrid">
16+
<Grid.RowDefinitions>
17+
<RowDefinition />
18+
<RowDefinition Height="Auto" />
19+
</Grid.RowDefinitions>
20+
21+
<Grid.ColumnDefinitions>
22+
<ColumnDefinition Width="*" />
23+
<ColumnDefinition Width="Auto" />
24+
</Grid.ColumnDefinitions>
25+
26+
<TextBlock
27+
x:Name="TextBlock"
28+
x:Uid="RestartNotificationText"
29+
Grid.RowSpan="2"
30+
TextWrapping="WrapWholeWords"
31+
VerticalAlignment="Center" />
32+
33+
<StackPanel
34+
x:Name="ButtonsStackPanel"
35+
Grid.RowSpan="2"
36+
Grid.Column="1"
37+
Margin="20,0,0,0"
38+
Orientation="Horizontal"
39+
VerticalAlignment="Center">
40+
41+
<Button
42+
x:Name="YesButton"
43+
x:Uid="ButtonYes"
44+
Width="70"
45+
Height="30"
46+
Click="YesButton_Click" />
47+
48+
<Button
49+
x:Name="NoButton"
50+
x:Uid="ButtonNo"
51+
Width="70"
52+
Height="30"
53+
Margin="10,0,0,0"
54+
Click="NoButton_Click" />
55+
</StackPanel>
56+
</Grid>
57+
</UserControl>
58+
</DataTemplate>
59+
</UserControl.Resources>
60+
61+
<controls:InAppNotification
62+
x:Name="RestartNotification"
63+
ContentTemplate="{StaticResource RestartDialogTemplate}" />
64+
</UserControl>

Files/Dialogs/RestartDialog.xaml.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Diagnostics;
3+
using Windows.System;
4+
using Windows.UI.Xaml;
5+
using Windows.UI.Xaml.Controls;
6+
7+
namespace Files.Dialogs
8+
{
9+
public sealed partial class RestartDialog : UserControl
10+
{
11+
public RestartDialog()
12+
{
13+
this.InitializeComponent();
14+
}
15+
16+
public void Show()
17+
{
18+
RestartNotification.Show(10000);
19+
}
20+
21+
public void Dismiss()
22+
{
23+
RestartNotification.Dismiss();
24+
}
25+
26+
private async void YesButton_Click(object sender, RoutedEventArgs e)
27+
{
28+
App.AppSettings.ResumeAfterRestart = true;
29+
App.SaveSessionTabs();
30+
await Launcher.LaunchUriAsync(new Uri("files-uwp://home/page="));
31+
Process.GetCurrentProcess().Kill();
32+
}
33+
34+
private void NoButton_Click(object sender, RoutedEventArgs e)
35+
{
36+
RestartNotification.Dismiss();
37+
}
38+
}
39+
}

Files/Files.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@
169169
<Compile Include="Dialogs\ConfirmDeleteDialog.xaml.cs">
170170
<DependentUpon>ConfirmDeleteDialog.xaml</DependentUpon>
171171
</Compile>
172+
<Compile Include="Dialogs\RestartDialog.xaml.cs">
173+
<DependentUpon>RestartDialog.xaml</DependentUpon>
174+
</Compile>
172175
<Compile Include="Filesystem\CloudDriveSyncStatus.cs" />
173176
<Compile Include="Filesystem\StorageFileHelpers\StorageFileExtensions.cs" />
174177
<Compile Include="Filesystem\StorageFileHelpers\IStorageItemWithPath.cs" />
@@ -447,6 +450,10 @@
447450
<Generator>MSBuild:Compile</Generator>
448451
<SubType>Designer</SubType>
449452
</Page>
453+
<Page Include="Dialogs\RestartDialog.xaml">
454+
<SubType>Designer</SubType>
455+
<Generator>MSBuild:Compile</Generator>
456+
</Page>
450457
<Page Include="ResourceDictionaries\PropertiesStyles.xaml">
451458
<SubType>Designer</SubType>
452459
<Generator>MSBuild:Compile</Generator>

Files/Strings/en-US/Resources.resw

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,6 @@
813813
<data name="SettingsPreferencesAppLanguage.Text" xml:space="preserve">
814814
<value>App Language</value>
815815
</data>
816-
<data name="SettingsPreferencesAppLanguageRestartRequired.Text" xml:space="preserve">
817-
<value>To see changes, a restart is required</value>
818-
</data>
819816
<data name="TabStripDragAndDropUIOverrideCaption" xml:space="preserve">
820817
<value>Move tab here</value>
821818
</data>
@@ -969,6 +966,15 @@
969966
<data name="SettingsPreferencesContextMenu.Text" xml:space="preserve">
970967
<value>Show all context menu items</value>
971968
</data>
969+
<data name="ButtonNo.Content" xml:space="preserve">
970+
<value>No</value>
971+
</data>
972+
<data name="ButtonYes.Content" xml:space="preserve">
973+
<value>Yes</value>
974+
</data>
975+
<data name="RestartNotificationText.Text" xml:space="preserve">
976+
<value>The application needs to be restarted in order to apply the langague setting, would you like to restart the app?</value>
977+
</data>
972978
<data name="PropertiesDialogCancelButton.Content" xml:space="preserve">
973979
<value>Cancel</value>
974980
</data>

Files/View Models/SettingsViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,12 @@ public bool ContinueLastSessionOnStartUp
472472
set => Set(value);
473473
}
474474

475+
public bool ResumeAfterRestart
476+
{
477+
get => Get(false);
478+
set => Set(value);
479+
}
480+
475481
public string OpenASpecificPageOnStartupPath
476482
{
477483
get => Get("");

Files/Views/MainPage.xaml.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,21 @@ protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
101101
{
102102
try
103103
{
104-
if (App.AppSettings.OpenASpecificPageOnStartup)
104+
if (App.AppSettings.ResumeAfterRestart)
105+
{
106+
App.AppSettings.ResumeAfterRestart = false;
107+
108+
foreach (string path in App.AppSettings.LastSessionPages)
109+
{
110+
await AddNewTab(typeof(ModernShellPage), path);
111+
}
112+
113+
if (!App.AppSettings.ContinueLastSessionOnStartUp)
114+
{
115+
App.AppSettings.LastSessionPages = null;
116+
}
117+
}
118+
else if (App.AppSettings.OpenASpecificPageOnStartup)
105119
{
106120
if (App.AppSettings.PagesOnStartupList != null)
107121
{

Files/Views/SettingsPages/Preferences.xaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
xmlns:datamodels="using:Files.DataModels"
77
xmlns:local="using:Files.SettingsPages"
88
xmlns:local2="using:Files"
9+
xmlns:dialogs="using:Files.Dialogs"
910
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1011
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
1112
mc:Ignorable="d">
@@ -34,14 +35,6 @@
3435
x:Uid="SettingsPreferencesAppLanguage"
3536
FontSize="17"
3637
Text="App Language" />
37-
<TextBlock
38-
x:Name="RestartRequiredPrompt"
39-
x:Uid="SettingsPreferencesAppLanguageRestartRequired"
40-
FontSize="14"
41-
FontStyle="Italic"
42-
Foreground="{ThemeResource SystemErrorTextColor}"
43-
Text="Restart required"
44-
Visibility="Collapsed" />
4538
<ComboBox
4639
x:Name="ComboAppLanguage"
4740
Width="200"
@@ -146,5 +139,7 @@
146139
</StackPanel>
147140
</StackPanel>
148141
</ScrollViewer>
142+
143+
<dialogs:RestartDialog x:Name="RestartDialog"/>
149144
</Grid>
150145
</Page>

Files/Views/SettingsPages/Preferences.xaml.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,18 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
4242

4343
private void ComboAppLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e)
4444
{
45-
if (AppSettings.CurrentLanguage.ID == AppSettings.DefaultLanguage.ID)
45+
var selectedValue = ((sender as ComboBox).SelectedValue as DefaultLanguageModel).ID;
46+
if (AppSettings.CurrentLanguage.ID != selectedValue)
4647
{
47-
RestartRequiredPrompt.Visibility = Visibility.Collapsed;
48+
RestartDialog.Show();
4849
}
4950
else
5051
{
51-
RestartRequiredPrompt.Visibility = Visibility.Visible;
52+
RestartDialog.Dismiss();
5253
}
5354
}
5455

55-
private void EditTerminalApplications_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
56+
private void EditTerminalApplications_Click(object sender, RoutedEventArgs e)
5657
{
5758
LaunchTerminalsConfigFile();
5859
}

0 commit comments

Comments
 (0)