Skip to content

Commit 1e62021

Browse files
Merge into Main
2 parents aca6998 + 4e806de commit 1e62021

27 files changed

+2247
-2253
lines changed

src/Files.App/App.xaml.cs

Lines changed: 406 additions & 409 deletions
Large diffs are not rendered by default.

src/Files.App/DataModels/TerminalFileModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
34
using System.Linq;
45
using System.Text.Json.Serialization;
56

@@ -14,7 +15,7 @@ public class TerminalFileModel
1415
public string DefaultTerminalName { get; set; }
1516

1617
[JsonPropertyName("terminals")]
17-
public List<Terminal> Terminals { get; set; } = new List<Terminal>();
18+
public ObservableCollection<Terminal> Terminals { get; set; } = new ObservableCollection<Terminal>();
1819

1920
public Terminal GetDefaultTerminal()
2021
{
Lines changed: 155 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,167 @@
11
using Files.App.Extensions;
2+
using Microsoft.UI.Xaml;
3+
using Microsoft.UI.Xaml.Markup;
24
using System;
35
using System.Collections.Generic;
46
using System.Diagnostics;
57
using System.IO;
68
using System.Linq;
79
using System.Threading.Tasks;
810
using Windows.Storage;
9-
using Microsoft.UI.Xaml;
10-
using Microsoft.UI.Xaml.Markup;
1111

1212
namespace Files.App.Helpers
1313
{
14-
public class ExternalResourcesHelper
15-
{
16-
public List<AppTheme> Themes = new List<AppTheme>()
17-
{
18-
new AppTheme
19-
{
20-
Name = "Default".GetLocalizedResource(),
21-
},
22-
};
23-
24-
public StorageFolder ThemeFolder { get; set; }
25-
public StorageFolder ImportedThemesFolder { get; set; }
26-
27-
public string CurrentThemeResources { get; set; }
28-
29-
public async Task LoadSelectedTheme()
30-
{
31-
string bundledThemesPath = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "Files.App", "Themes");
32-
ThemeFolder = await StorageFolder.GetFolderFromPathAsync(bundledThemesPath);
33-
ImportedThemesFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Themes", CreationCollisionOption.OpenIfExists);
34-
35-
if (App.AppSettings.SelectedTheme.Path != null)
36-
{
37-
await TryLoadThemeAsync(App.AppSettings.SelectedTheme);
38-
}
39-
}
40-
41-
public async Task LoadOtherThemesAsync()
42-
{
43-
try
44-
{
45-
await AddThemesAsync(ThemeFolder);
46-
await AddThemesAsync(ImportedThemesFolder);
47-
}
48-
catch (Exception)
49-
{
50-
Debug.WriteLine($"Error loading themes");
51-
}
52-
}
53-
54-
private async Task AddThemesAsync(StorageFolder folder)
55-
{
56-
foreach (var file in (await folder.GetFilesAsync()).Where(x => x.FileType == ".xaml"))
57-
{
58-
if(!Themes.Exists(t => t.AbsolutePath == file.Path))
59-
{
60-
Themes.Add(new AppTheme()
61-
{
62-
Name = file.Name.Replace(".xaml", "", StringComparison.Ordinal),
63-
Path = file.Name,
64-
AbsolutePath = file.Path,
65-
});
66-
}
67-
}
68-
}
69-
70-
public async Task<bool> TryLoadThemeAsync(AppTheme theme)
71-
{
72-
try
73-
{
74-
var xaml = await TryLoadResourceDictionary(theme);
75-
if (xaml != null)
76-
{
77-
App.Current.Resources.MergedDictionaries.Add(xaml);
78-
return true;
79-
}
80-
return false;
81-
}
82-
catch (Exception ex)
83-
{
84-
App.Logger.Warn(ex, $"Error loading theme: {theme?.Path}");
85-
return false;
86-
}
87-
}
88-
89-
public async Task<ResourceDictionary> TryLoadResourceDictionary(AppTheme theme)
90-
{
91-
StorageFile file;
92-
if (theme?.Path == null)
93-
{
94-
return null;
95-
}
96-
97-
if (theme.AbsolutePath.Contains(ImportedThemesFolder.Path))
98-
{
99-
file = await ImportedThemesFolder.GetFileAsync(theme.Path);
100-
theme.IsImportedTheme = true;
101-
}
102-
else
103-
{
104-
file = await ThemeFolder.GetFileAsync(theme.Path);
105-
theme.IsImportedTheme = false;
106-
}
107-
108-
var code = await FileIO.ReadTextAsync(file);
109-
var xaml = XamlReader.Load(code) as ResourceDictionary;
110-
xaml.Add("CustomThemeID", theme.Key);
111-
return xaml;
112-
}
113-
114-
public async Task UpdateTheme(AppTheme OldTheme, AppTheme NewTheme)
115-
{
116-
if (OldTheme.Path != null)
117-
{
118-
RemoveTheme(OldTheme);
119-
}
120-
121-
if (NewTheme.Path != null)
122-
{
123-
await TryLoadThemeAsync(NewTheme);
124-
}
125-
}
126-
127-
public bool RemoveTheme(AppTheme theme)
128-
{
129-
try
130-
{
131-
App.Current.Resources.MergedDictionaries.Remove(App.Current.Resources.MergedDictionaries.FirstOrDefault(x => x.TryGetValue("CustomThemeID", out var key) && (key as string) == theme.Key));
132-
return true;
133-
}
134-
catch (Exception)
135-
{
136-
return false;
137-
}
138-
}
139-
}
140-
141-
public class AppTheme
142-
{
143-
public string Name { get; set; }
144-
public string Path { get; set; }
145-
public string AbsolutePath { get; set; }
146-
public string Key => $"{Name}";
147-
public bool IsImportedTheme { get; set; }
148-
}
14+
public class ExternalResourcesHelper
15+
{
16+
public List<AppTheme> Themes = new List<AppTheme>()
17+
{
18+
new AppTheme
19+
{
20+
Name = "Default".GetLocalizedResource(),
21+
},
22+
};
23+
24+
public StorageFolder ThemeFolder { get; set; }
25+
public StorageFolder ImportedThemesFolder { get; set; }
26+
27+
public string CurrentThemeResources { get; set; }
28+
29+
public async Task LoadSelectedTheme()
30+
{
31+
string bundledThemesPath = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "Files.App", "Themes");
32+
ThemeFolder = await StorageFolder.GetFolderFromPathAsync(bundledThemesPath);
33+
ImportedThemesFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Themes", CreationCollisionOption.OpenIfExists);
34+
35+
if (App.AppSettings.SelectedTheme.Path != null)
36+
{
37+
await TryLoadThemeAsync(App.AppSettings.SelectedTheme);
38+
}
39+
}
40+
41+
/// <summary>
42+
/// Overrides xaml resources with custom values
43+
/// </summary>
44+
/// <param name="UseCompactSpacing"></param>
45+
public void OverrideAppResources(bool UseCompactSpacing)
46+
{
47+
if (UseCompactSpacing)
48+
{
49+
Application.Current.Resources["ListItemHeight"] = 28;
50+
Application.Current.Resources["NavigationViewItemOnLeftMinHeight"] = 24;
51+
}
52+
else
53+
{
54+
Application.Current.Resources["ListItemHeight"] = 36;
55+
Application.Current.Resources["NavigationViewItemOnLeftMinHeight"] = 32;
56+
}
57+
}
58+
59+
public async Task LoadOtherThemesAsync()
60+
{
61+
try
62+
{
63+
await AddThemesAsync(ThemeFolder);
64+
await AddThemesAsync(ImportedThemesFolder);
65+
}
66+
catch (Exception)
67+
{
68+
Debug.WriteLine($"Error loading themes");
69+
}
70+
}
71+
72+
private async Task AddThemesAsync(StorageFolder folder)
73+
{
74+
foreach (var file in (await folder.GetFilesAsync()).Where(x => x.FileType == ".xaml"))
75+
{
76+
if (!Themes.Exists(t => t.AbsolutePath == file.Path))
77+
{
78+
Themes.Add(new AppTheme()
79+
{
80+
Name = file.Name.Replace(".xaml", "", StringComparison.Ordinal),
81+
Path = file.Name,
82+
AbsolutePath = file.Path,
83+
});
84+
}
85+
}
86+
}
87+
88+
public async Task<bool> TryLoadThemeAsync(AppTheme theme)
89+
{
90+
try
91+
{
92+
var xaml = await TryLoadResourceDictionary(theme);
93+
if (xaml != null)
94+
{
95+
App.Current.Resources.MergedDictionaries.Add(xaml);
96+
return true;
97+
}
98+
return false;
99+
}
100+
catch (Exception ex)
101+
{
102+
App.Logger.Warn(ex, $"Error loading theme: {theme?.Path}");
103+
return false;
104+
}
105+
}
106+
107+
public async Task<ResourceDictionary> TryLoadResourceDictionary(AppTheme theme)
108+
{
109+
StorageFile file;
110+
if (theme?.Path == null)
111+
{
112+
return null;
113+
}
114+
115+
if (theme.AbsolutePath.Contains(ImportedThemesFolder.Path))
116+
{
117+
file = await ImportedThemesFolder.GetFileAsync(theme.Path);
118+
theme.IsImportedTheme = true;
119+
}
120+
else
121+
{
122+
file = await ThemeFolder.GetFileAsync(theme.Path);
123+
theme.IsImportedTheme = false;
124+
}
125+
126+
var code = await FileIO.ReadTextAsync(file);
127+
var xaml = XamlReader.Load(code) as ResourceDictionary;
128+
xaml.Add("CustomThemeID", theme.Key);
129+
return xaml;
130+
}
131+
132+
public async Task UpdateTheme(AppTheme OldTheme, AppTheme NewTheme)
133+
{
134+
if (OldTheme.Path != null)
135+
{
136+
RemoveTheme(OldTheme);
137+
}
138+
139+
if (NewTheme.Path != null)
140+
{
141+
await TryLoadThemeAsync(NewTheme);
142+
}
143+
}
144+
145+
public bool RemoveTheme(AppTheme theme)
146+
{
147+
try
148+
{
149+
App.Current.Resources.MergedDictionaries.Remove(App.Current.Resources.MergedDictionaries.FirstOrDefault(x => x.TryGetValue("CustomThemeID", out var key) && (key as string) == theme.Key));
150+
return true;
151+
}
152+
catch (Exception)
153+
{
154+
return false;
155+
}
156+
}
157+
}
158+
159+
public class AppTheme
160+
{
161+
public string Name { get; set; }
162+
public string Path { get; set; }
163+
public string AbsolutePath { get; set; }
164+
public string Key => $"{Name}";
165+
public bool IsImportedTheme { get; set; }
166+
}
149167
}

0 commit comments

Comments
 (0)