Skip to content

Commit 2a07de8

Browse files
committed
Support customization of common locations from Preferences
1 parent 8880587 commit 2a07de8

File tree

4 files changed

+121
-8
lines changed

4 files changed

+121
-8
lines changed

Files UWP/ProHome.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ public ProHome()
8989
Ribbon.Translation += new System.Numerics.Vector3(0, 0, 4);
9090
}
9191

92+
// Overwrite paths for common locations if Custom Locations setting is enabled
93+
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
94+
if (localSettings.Values["customLocationsSetting"].Equals(true))
95+
{
96+
DesktopPath = localSettings.Values["DesktopLocation"].ToString();
97+
DownloadsPath = localSettings.Values["DownloadsLocation"].ToString();
98+
DocumentsPath = localSettings.Values["DocumentsLocation"].ToString();
99+
PicturesPath = localSettings.Values["PicturesLocation"].ToString();
100+
MusicPath = localSettings.Values["MusicLocation"].ToString();
101+
VideosPath = localSettings.Values["VideosLocation"].ToString();
102+
}
92103

93104
}
94105

Files UWP/SettingsPages/Preferences.xaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
<Grid Name="CustomLibraries">
1515
<StackPanel Orientation="Vertical">
1616
<TextBlock FontSize="20" Text="Custom Locations"/>
17-
<TextBlock Text="Replaces common locations with those of your choice"/>
17+
<TextBlock Text="Replaces common locations with those of your choice. You'll need to restart Files after saving your settings or disabling custom locations."/>
1818
<ToggleSwitch IsEnabled="True" Toggled="ToggleSwitch_Toggled" Name="CustomLocationToggle" VerticalAlignment="Top"/>
19+
<Grid Margin="0, 0, 0, 12.5">
20+
<TextBlock Text="Desktop" VerticalAlignment="Center" Margin="0,0,25,0" HorizontalAlignment="Left"/>
21+
<TextBox Name="DesktopL" PlaceholderText="Custom Desktop Location" HorizontalAlignment="Left" Margin="125,0,0,0" Width="500" />
22+
</Grid>
1923
<Grid Margin="0, 0, 0, 12.5">
2024
<TextBlock Text="Downloads" VerticalAlignment="Center" Margin="0,0,25,0" HorizontalAlignment="Left"/>
2125
<TextBox Name="DownloadsL" PlaceholderText="Custom Downloads Location" HorizontalAlignment="Left" Margin="125,0,0,0" Width="500" />
@@ -38,7 +42,10 @@
3842
</Grid>
3943
<StackPanel Orientation="Horizontal">
4044
<Button Content="Save Locations" Name="SaveCustomL" HorizontalAlignment="Left" Click="SaveCustomL_Click" />
41-
<FontIcon Glyph="&#xE73E;" Name="SuccessMark" Margin="25,0,0,0"/>
45+
<StackPanel Name="SuccessMark" Orientation="Horizontal" Spacing="15">
46+
<FontIcon Glyph="&#xE73E;" Margin="25,0,0,0"/>
47+
<TextBlock VerticalAlignment="Center" Text="Restart the app for these changes to take effect."/>
48+
</StackPanel>
4249
</StackPanel>
4350
</StackPanel>
4451
</Grid>

Files UWP/SettingsPages/Preferences.xaml.cs

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,31 @@ public Preferences()
2222
if (localSettings.Values["customLocationsSetting"].Equals(true))
2323
{
2424
CustomLocationToggle.IsOn = true;
25+
26+
DesktopL.IsEnabled = true;
27+
DesktopL.Text = localSettings.Values["DesktopLocation"].ToString();
28+
2529
DownloadsL.IsEnabled = true;
30+
DownloadsL.Text = localSettings.Values["DownloadsLocation"].ToString();
31+
2632
DocumentsL.IsEnabled = true;
33+
DocumentsL.Text = localSettings.Values["DocumentsLocation"].ToString();
34+
2735
PictureL.IsEnabled = true;
36+
PictureL.Text = localSettings.Values["PicturesLocation"].ToString();
37+
2838
MusicL.IsEnabled = true;
39+
MusicL.Text = localSettings.Values["MusicLocation"].ToString();
40+
2941
VideosL.IsEnabled = true;
42+
VideosL.Text = localSettings.Values["VideosLocation"].ToString();
43+
3044
SaveCustomL.IsEnabled = true;
3145
}
3246
else
3347
{
3448
CustomLocationToggle.IsOn = false;
49+
DesktopL.IsEnabled = false;
3550
DownloadsL.IsEnabled = false;
3651
DocumentsL.IsEnabled = false;
3752
PictureL.IsEnabled = false;
@@ -43,6 +58,7 @@ public Preferences()
4358
else
4459
{
4560
CustomLocationToggle.IsOn = false;
61+
DesktopL.IsEnabled = false;
4662
DownloadsL.IsEnabled = false;
4763
DocumentsL.IsEnabled = false;
4864
PictureL.IsEnabled = false;
@@ -58,16 +74,38 @@ private void ToggleSwitch_Toggled(object sender, Windows.UI.Xaml.RoutedEventArgs
5874
if ((sender as ToggleSwitch).IsOn)
5975
{
6076
localSettings.Values["customLocationsSetting"] = true;
77+
78+
DesktopL.IsEnabled = true;
79+
localSettings.Values["DesktopLocation"] = ProHome.DesktopPath;
80+
6181
DownloadsL.IsEnabled = true;
82+
localSettings.Values["DownloadsLocation"] = ProHome.DownloadsPath;
83+
6284
DocumentsL.IsEnabled = true;
85+
localSettings.Values["DocumentsLocation"] = ProHome.DocumentsPath;
86+
6387
PictureL.IsEnabled = true;
88+
localSettings.Values["PicturesLocation"] = ProHome.PicturesPath;
89+
6490
MusicL.IsEnabled = true;
91+
localSettings.Values["MusicLocation"] = ProHome.MusicPath;
92+
6593
VideosL.IsEnabled = true;
94+
localSettings.Values["VideosLocation"] = ProHome.VideosPath;
95+
96+
DesktopL.Text = localSettings.Values["DesktopLocation"].ToString();
97+
DownloadsL.Text = localSettings.Values["DownloadsLocation"].ToString();
98+
DocumentsL.Text = localSettings.Values["DocumentsLocation"].ToString();
99+
PictureL.Text = localSettings.Values["PicturesLocation"].ToString();
100+
MusicL.Text = localSettings.Values["MusicLocation"].ToString();
101+
VideosL.Text = localSettings.Values["VideosLocation"].ToString();
102+
66103
SaveCustomL.IsEnabled = true;
67104
}
68105
else
69106
{
70107
localSettings.Values["customLocationsSetting"] = false;
108+
DesktopL.IsEnabled = false;
71109
DownloadsL.IsEnabled = false;
72110
DocumentsL.IsEnabled = false;
73111
PictureL.IsEnabled = false;
@@ -80,12 +118,41 @@ private void ToggleSwitch_Toggled(object sender, Windows.UI.Xaml.RoutedEventArgs
80118
private async void SaveCustomL_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
81119
{
82120
StorageFolder newLocationSetting;
83-
if(DownloadsL.Text != null)
121+
bool isFlawless = true;
122+
123+
if (!string.IsNullOrEmpty(DesktopL.Text))
124+
{
125+
try
126+
{
127+
newLocationSetting = await StorageFolder.GetFolderFromPathAsync(DesktopL.Text);
128+
localSettings.Values["DesktopLocation"] = DesktopL.Text;
129+
DesktopL.BorderBrush = new SolidColorBrush(Colors.Black);
130+
}
131+
catch (UnauthorizedAccessException)
132+
{
133+
await ItemViewModel<Preferences>.GetCurrentSelectedTabInstance<ProHome>().permissionBox.ShowAsync();
134+
return;
135+
}
136+
catch (ArgumentException)
137+
{
138+
DesktopL.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
139+
isFlawless = false;
140+
}
141+
catch (FileNotFoundException)
142+
{
143+
DesktopL.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
144+
isFlawless = false;
145+
}
146+
}
147+
148+
if (!string.IsNullOrEmpty(DownloadsL.Text))
84149
{
85150
try
86151
{
87152
newLocationSetting = await StorageFolder.GetFolderFromPathAsync(DownloadsL.Text);
88153
localSettings.Values["DownloadsLocation"] = DownloadsL.Text;
154+
DownloadsL.BorderBrush = new SolidColorBrush(Colors.Black);
155+
89156
}
90157
catch (UnauthorizedAccessException)
91158
{
@@ -95,19 +162,22 @@ private async void SaveCustomL_Click(object sender, Windows.UI.Xaml.RoutedEventA
95162
catch (ArgumentException)
96163
{
97164
DownloadsL.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
165+
isFlawless = false;
98166
}
99167
catch (FileNotFoundException)
100168
{
101169
DownloadsL.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
170+
isFlawless = false;
102171
}
103172
}
104173

105-
if (DocumentsL.Text != null)
174+
if (!string.IsNullOrEmpty(DocumentsL.Text))
106175
{
107176
try
108177
{
109178
newLocationSetting = await StorageFolder.GetFolderFromPathAsync(DocumentsL.Text);
110179
localSettings.Values["DocumentsLocation"] = DocumentsL.Text;
180+
DocumentsL.BorderBrush = new SolidColorBrush(Colors.Black);
111181
}
112182
catch (UnauthorizedAccessException)
113183
{
@@ -117,19 +187,22 @@ private async void SaveCustomL_Click(object sender, Windows.UI.Xaml.RoutedEventA
117187
catch (ArgumentException)
118188
{
119189
DocumentsL.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
190+
isFlawless = false;
120191
}
121192
catch (FileNotFoundException)
122193
{
123194
DocumentsL.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
195+
isFlawless = false;
124196
}
125197
}
126198

127-
if (PictureL.Text != null)
199+
if (!string.IsNullOrEmpty(PictureL.Text))
128200
{
129201
try
130202
{
131203
newLocationSetting = await StorageFolder.GetFolderFromPathAsync(PictureL.Text);
132204
localSettings.Values["PicturesLocation"] = PictureL.Text;
205+
PictureL.BorderBrush = new SolidColorBrush(Colors.Black);
133206
}
134207
catch (UnauthorizedAccessException)
135208
{
@@ -139,19 +212,22 @@ private async void SaveCustomL_Click(object sender, Windows.UI.Xaml.RoutedEventA
139212
catch (ArgumentException)
140213
{
141214
PictureL.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
215+
isFlawless = false;
142216
}
143217
catch (FileNotFoundException)
144218
{
145219
PictureL.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
220+
isFlawless = false;
146221
}
147222
}
148223

149-
if (MusicL.Text != null)
224+
if (!string.IsNullOrEmpty(MusicL.Text))
150225
{
151226
try
152227
{
153228
newLocationSetting = await StorageFolder.GetFolderFromPathAsync(MusicL.Text);
154229
localSettings.Values["MusicLocation"] = MusicL.Text;
230+
MusicL.BorderBrush = new SolidColorBrush(Colors.Black);
155231
}
156232
catch (UnauthorizedAccessException)
157233
{
@@ -161,19 +237,22 @@ private async void SaveCustomL_Click(object sender, Windows.UI.Xaml.RoutedEventA
161237
catch (ArgumentException)
162238
{
163239
MusicL.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
240+
isFlawless = false;
164241
}
165242
catch (FileNotFoundException)
166243
{
167244
MusicL.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
245+
isFlawless = false;
168246
}
169247
}
170248

171-
if (VideosL.Text != null)
249+
if (!string.IsNullOrEmpty(VideosL.Text))
172250
{
173251
try
174252
{
175253
newLocationSetting = await StorageFolder.GetFolderFromPathAsync(VideosL.Text);
176254
localSettings.Values["VideosLocation"] = VideosL.Text;
255+
VideosL.BorderBrush = new SolidColorBrush(Colors.Black);
177256
}
178257
catch (UnauthorizedAccessException)
179258
{
@@ -183,14 +262,19 @@ private async void SaveCustomL_Click(object sender, Windows.UI.Xaml.RoutedEventA
183262
catch (ArgumentException)
184263
{
185264
VideosL.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
265+
isFlawless = false;
186266
}
187267
catch (FileNotFoundException)
188268
{
189269
VideosL.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
270+
isFlawless = false;
190271
}
191272
}
192273

193-
SuccessMark.Visibility = Windows.UI.Xaml.Visibility.Visible;
274+
if (isFlawless)
275+
{
276+
SuccessMark.Visibility = Windows.UI.Xaml.Visibility.Visible;
277+
}
194278
}
195279
}
196280
}

Files UWP/YourHome.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ public YourHome()
3939
instanceInteraction = new Interaction<YourHome>();
4040
GetCurrentSelectedTabInstance<ProHome>().PathText.Text = "Favorites";
4141

42+
// Overwrite paths for common locations if Custom Locations setting is enabled
43+
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
44+
if (localSettings.Values["customLocationsSetting"].Equals(true))
45+
{
46+
DesktopPath = localSettings.Values["DesktopLocation"].ToString();
47+
DownloadsPath = localSettings.Values["DownloadsLocation"].ToString();
48+
DocumentsPath = localSettings.Values["DocumentsLocation"].ToString();
49+
PicturesPath = localSettings.Values["PicturesLocation"].ToString();
50+
MusicPath = localSettings.Values["MusicLocation"].ToString();
51+
VideosPath = localSettings.Values["VideosLocation"].ToString();
52+
}
4253
}
4354

4455
public T GetCurrentSelectedTabInstance<T>()

0 commit comments

Comments
 (0)