Skip to content

Commit d0ac233

Browse files
committed
Work properly with new settings-vm
1 parent 7a90114 commit d0ac233

File tree

6 files changed

+116
-83
lines changed

6 files changed

+116
-83
lines changed

Files/Filesystem/ItemViewModel.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,25 +557,25 @@ public async void RapidAddItemsToCollectionAsync(string path)
557557
switch (Universal.path)
558558
{
559559
case "Desktop":
560-
Universal.path = App.DesktopPath;
560+
Universal.path = App.AppSettings.DesktopPath;
561561
break;
562562
case "Downloads":
563-
Universal.path = App.DownloadsPath;
563+
Universal.path = App.AppSettings.DownloadsPath;
564564
break;
565565
case "Documents":
566-
Universal.path = App.DocumentsPath;
566+
Universal.path = App.AppSettings.DocumentsPath;
567567
break;
568568
case "Pictures":
569-
Universal.path = App.PicturesPath;
569+
Universal.path = App.AppSettings.PicturesPath;
570570
break;
571571
case "Music":
572-
Universal.path = App.MusicPath;
572+
Universal.path = App.AppSettings.MusicPath;
573573
break;
574574
case "Videos":
575-
Universal.path = App.VideosPath;
575+
Universal.path = App.AppSettings.VideosPath;
576576
break;
577577
case "OneDrive":
578-
Universal.path = App.OneDrivePath;
578+
Universal.path = App.AppSettings.OneDrivePath;
579579
break;
580580
}
581581
ObservableCollection<PartialStorageItem> partialFiles = null;

Files/Interacts/Interaction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public async void OpenDirectoryInTerminal(object sender, RoutedEventArgs e)
100100

101101
if (localSettings.Values["terminal_id"] != null) terminalId = (int)localSettings.Values["terminal_id"];
102102

103-
var terminal = App.Terminals.Single(p => p.Id == terminalId);
103+
var terminal = App.AppSettings.Terminals.Single(p => p.Id == terminalId);
104104

105105
localSettings.Values["Application"] = terminal.Path;
106106
localSettings.Values["Arguments"] = String.Format(terminal.arguments, currentInstance.instanceViewModel.Universal.path);

Files/SettingsPages/Personalization.xaml.cs

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -10,85 +10,85 @@
1010

1111
namespace Files.SettingsPages
1212
{
13-
public sealed partial class Personalization : Page
14-
{
15-
public Personalization()
16-
{
17-
InitializeComponent();
13+
public sealed partial class Personalization : Page
14+
{
15+
public Personalization()
16+
{
17+
InitializeComponent();
1818

19-
//Load Theme Style
20-
var _themeval = Enum.GetValues(typeof(ThemeStyle)).Cast<ThemeStyle>();
21-
ThemeChooser.ItemsSource = _themeval.ToList();
22-
ThemeStyle _selectedTheme = App.AppSettings.ThemeValue;
19+
//Load Theme Style
20+
var _themeval = Enum.GetValues(typeof(ThemeStyle)).Cast<ThemeStyle>();
21+
ThemeChooser.ItemsSource = _themeval.ToList();
22+
ThemeStyle _selectedTheme = App.AppSettings.ThemeValue;
2323

24-
ThemeChooser.SelectedIndex = _themeval.ToList().IndexOf(_selectedTheme);
25-
ThemeChooser.Loaded += (s, e) =>
26-
{
27-
ThemeChooser.SelectionChanged += async (s1, e1) =>
28-
{
29-
switch (e1.AddedItems[0].ToString())
30-
{
31-
case "System":
32-
App.AppSettings.ThemeValue = ThemeStyle.System;
33-
break;
34-
case "Light":
35-
App.AppSettings.ThemeValue = ThemeStyle.Light;
36-
break;
37-
case "Dark":
38-
App.AppSettings.ThemeValue = ThemeStyle.Dark;
39-
break;
40-
}
41-
42-
await RestartReminder.Fade(value: 1.0f, duration: 1500, delay: 0).StartAsync();
43-
await RestartReminder.Fade(value: 0.0f, duration: 1500, delay: 0).StartAsync();
44-
};
45-
};
24+
ThemeChooser.SelectedIndex = _themeval.ToList().IndexOf(_selectedTheme);
25+
ThemeChooser.Loaded += (s, e) =>
26+
{
27+
ThemeChooser.SelectionChanged += async (s1, e1) =>
28+
{
29+
switch (e1.AddedItems[0].ToString())
30+
{
31+
case "System":
32+
App.AppSettings.ThemeValue = ThemeStyle.System;
33+
break;
34+
case "Light":
35+
App.AppSettings.ThemeValue = ThemeStyle.Light;
36+
break;
37+
case "Dark":
38+
App.AppSettings.ThemeValue = ThemeStyle.Dark;
39+
break;
40+
}
41+
42+
//await RestartReminder.Fade(value: 1.0f, duration: 1500, delay: 0).StartAsync();
43+
//await RestartReminder.Fade(value: 0.0f, duration: 1500, delay: 0).StartAsync();
44+
};
45+
};
4646

47-
//Load App Time Style
48-
var _dateformatval = Enum.GetValues(typeof(TimeStyle)).Cast<TimeStyle>();
49-
DateFormatChooser.ItemsSource = _dateformatval.ToList();
47+
//Load App Time Style
48+
var _dateformatval = Enum.GetValues(typeof(TimeStyle)).Cast<TimeStyle>();
49+
DateFormatChooser.ItemsSource = _dateformatval.ToList();
5050

51-
TimeStyle _selectedFormat = App.AppSettings.DisplayedTimeStyle;
52-
DateFormatChooser.SelectedIndex = _dateformatval.ToList().IndexOf(_selectedFormat);
53-
DateFormatChooser.Loaded += (s, e) =>
54-
{
55-
DateFormatChooser.SelectionChanged += async (s1, e1) =>
56-
{
57-
switch (e1.AddedItems[0].ToString())
58-
{
59-
case "Application":
60-
App.AppSettings.DisplayedTimeStyle = TimeStyle.Application;
61-
break;
62-
case "System":
63-
App.AppSettings.DisplayedTimeStyle = TimeStyle.System;
64-
break;
65-
}
51+
TimeStyle _selectedFormat = App.AppSettings.DisplayedTimeStyle;
52+
DateFormatChooser.SelectedIndex = _dateformatval.ToList().IndexOf(_selectedFormat);
53+
DateFormatChooser.Loaded += (s, e) =>
54+
{
55+
DateFormatChooser.SelectionChanged += async (s1, e1) =>
56+
{
57+
switch (e1.AddedItems[0].ToString())
58+
{
59+
case "Application":
60+
App.AppSettings.DisplayedTimeStyle = TimeStyle.Application;
61+
break;
62+
case "System":
63+
App.AppSettings.DisplayedTimeStyle = TimeStyle.System;
64+
break;
65+
}
6666

67-
await TimeFormatReminder.Fade(value: 1.0f, duration: 1500, delay: 0).StartAsync();
68-
await TimeFormatReminder.Fade(value: 0.0f, duration: 1500, delay: 0).StartAsync();
69-
};
70-
};
67+
//await TimeFormatReminder.Fade(value: 1.0f, duration: 1500, delay: 0).StartAsync();
68+
//await TimeFormatReminder.Fade(value: 0.0f, duration: 1500, delay: 0).StartAsync();
69+
};
70+
};
7171

72-
73-
AcrylicSidebarSwitch.IsOn = App.AppSettings.SidebarThemeMode.Equals(SidebarOpacity.Opaque) ? false : true;
72+
73+
AcrylicSidebarSwitch.IsOn = App.AppSettings.SidebarThemeMode.Equals(SidebarOpacity.Opaque) ? false : true;
7474

75-
AcrylicSidebarSwitch.Loaded += (sender, args) =>
76-
{
77-
AcrylicSidebarSwitch.Toggled += (o, eventArgs) =>
78-
{
79-
if (((ToggleSwitch)o).IsOn)
80-
{
81-
App.AppSettings.SidebarThemeMode = SidebarOpacity.AcrylicEnabled;
82-
}
83-
else
84-
{
85-
App.AppSettings.SidebarThemeMode = SidebarOpacity.Opaque;
86-
}
87-
};
88-
};
89-
}
75+
AcrylicSidebarSwitch.Loaded += (sender, args) =>
76+
{
77+
AcrylicSidebarSwitch.Toggled += (o, eventArgs) =>
78+
{
79+
if (((ToggleSwitch)o).IsOn)
80+
{
81+
App.AppSettings.SidebarThemeMode = SidebarOpacity.AcrylicEnabled;
82+
}
83+
else
84+
{
85+
App.AppSettings.SidebarThemeMode = SidebarOpacity.Opaque;
86+
}
87+
};
88+
};
89+
}
9090

91-
}
91+
}
9292

9393

9494
}

Files/SettingsPages/Preferences.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:datamodels="using:Files.DataModels"
77
xmlns:local="using:Files.SettingsPages"
8+
xmlns:local2="using:Files"
89
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
910
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
1011
mc:Ignorable="d">
@@ -227,7 +228,7 @@
227228
<ComboBox
228229
x:Name="TerminalApplicationsComboBox"
229230
Width="130"
230-
ItemsSource="{x:Bind Terminals}"
231+
ItemsSource="{x:Bind local2:App.AppSettings.Terminals}"
231232
SelectionChanged="TerminalApp_SelectionChanged">
232233
<ComboBox.ItemTemplate>
233234
<DataTemplate x:DataType="datamodels:TerminalModel">

Files/SettingsPages/Preferences.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
9090
{
9191
base.OnNavigatedTo(e);
9292

93-
var terminals = App.Terminals;
93+
var terminals = App.AppSettings.Terminals;
9494

95-
foreach (var terminal in terminals) Terminals.Add(terminal);
95+
foreach (var terminal in terminals) App.AppSettings.Terminals.Add(terminal);
9696

9797
var terminalId = 1;
9898
if (localSettings.Values["terminal_id"] != null) terminalId = (int) localSettings.Values["terminal_id"];
9999

100-
TerminalApplicationsComboBox.SelectedItem = Terminals.Single(p => p.Id == terminalId);
100+
TerminalApplicationsComboBox.SelectedItem = App.AppSettings.Terminals.Single(p => p.Id == terminalId);
101101
}
102102

103103
private void CustomLocationToggle_Toggled(object sender, Windows.UI.Xaml.RoutedEventArgs e)

Files/View Models/SettingsViewModel.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
using Windows.UI.Xaml;
1515
using Windows.UI.Xaml.Controls;
1616
using Files.Filesystem;
17+
using Newtonsoft.Json;
18+
using Files.DataModels;
1719

1820
namespace Files.View_Models
1921
{
@@ -133,6 +135,30 @@ private void DetectApplicationTheme()
133135
}
134136
}
135137

138+
private async void LoadTerminalApps()
139+
{
140+
var localFolder = ApplicationData.Current.LocalFolder;
141+
var localSettingsFolder = await localFolder.CreateFolderAsync("settings", CreationCollisionOption.OpenIfExists);
142+
StorageFile file;
143+
try
144+
{
145+
file = await localSettingsFolder.GetFileAsync("terminal.json");
146+
}
147+
catch (FileNotFoundException ex)
148+
{
149+
var defaultFile = StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/terminal/terminal.json"));
150+
151+
file = await localSettingsFolder.CreateFileAsync("terminal.json");
152+
await FileIO.WriteBufferAsync(file, await FileIO.ReadBufferAsync(await defaultFile));
153+
}
154+
155+
var content = await FileIO.ReadTextAsync(file);
156+
157+
var terminals = JsonConvert.DeserializeObject<TerminalFileModel>(content).Terminals;
158+
159+
Terminals = terminals;
160+
}
161+
136162
private FormFactorMode _FormFactor = FormFactorMode.Regular;
137163
private ThemeStyle _ThemeValue;
138164
private bool _AreLinuxFilesSupported = false;
@@ -145,7 +171,13 @@ private void DetectApplicationTheme()
145171
private string _VideosPath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);
146172
private SidebarOpacity _SidebarThemeMode = SidebarOpacity.Opaque;
147173
private TimeStyle _DisplayedTimeStyle = TimeStyle.Application;
174+
private IList<TerminalModel> _Terminals = null;
148175

176+
public IList<TerminalModel> Terminals
177+
{
178+
get => _Terminals;
179+
set => Set(ref _Terminals, value);
180+
}
149181

150182
public FormFactorMode FormFactor
151183
{

0 commit comments

Comments
 (0)