Fix bugs and crashes with exporting template theme

This commit is contained in:
Caeden Statia 2020-02-07 16:56:29 -08:00
parent dd68fa16c1
commit 621880a925
2 changed files with 14 additions and 6 deletions

View file

@ -35,12 +35,15 @@ namespace ModAssistant
//Ignore Themes without the xaml extension and ignore themes with the same names as others.
//If requests are made I can instead make a Theme class that splits the pre-installed themes from
//user-made ones so that one more user-made Light/Dark theme can be added.
if (info.Extension.ToLowerInvariant() == "xaml" && !loadedThemes.ContainsKey(info.Name))
MessageBox.Show(info.Extension);
if (info.Extension.ToLower().Contains("xaml"))
{
ResourceDictionary theme = LoadTheme(info.Name);
string name = info.Name.Split('.').First();
MessageBox.Show(name);
ResourceDictionary theme = LoadTheme(name);
if (theme != null)
{
loadedThemes.Add(info.Name, theme);
loadedThemes.Add(name, theme);
}
}
}
@ -102,8 +105,10 @@ namespace ModAssistant
if (!File.Exists($@"{ThemeDirectory}\\{themeName}.xaml"))
{
//Store a local copy of the theme to prevent exceptions trying to access the saved copy while it's being written to.
ResourceDictionary dictionary = LoadTheme(themeName, true);
loadedThemes.Add(themeName, dictionary);
Options.Instance.ApplicationThemeComboBox.ItemsSource = LoadedThemes;
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;

View file

@ -249,13 +249,16 @@ namespace ModAssistant.Pages
private void ApplicationThemeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Themes.ApplyTheme((sender as ComboBox).SelectedItem.ToString(), this);
if ((sender as ComboBox).SelectedItem == null)
{
Themes.ApplyTheme("Light", this);
MainWindow.Instance.MainText = "Current theme has been removed, reverting to Light...";
}else Themes.ApplyTheme((sender as ComboBox).SelectedItem.ToString(), this);
}
private void ApplicationThemeExportTemplate_Click(object sender, RoutedEventArgs e)
{
Themes.WriteThemeToDisk("Light Pink");
Themes.LoadThemes();
}
private void ApplicationThemeOpenThemesFolder_Click(object sender, RoutedEventArgs e)