Skip to content

Commit

Permalink
Merge pull request #54 from TorisanKitsune/Fix-Settings
Browse files Browse the repository at this point in the history
Fix settings
  • Loading branch information
mkromis committed Dec 2, 2019
2 parents 600e10b + 91e8b74 commit ab29de6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
27 changes: 19 additions & 8 deletions Modules/MinoriEditorShell/Platforms/Wpf/Core/MesWpfSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,23 @@ public override void LoadPlugins(IMvxPluginManager pluginManager)
return container;
}

protected override void InitializeLastChance()
/// <summary>
/// Used to ensure plugins are loaded.
/// </summary>
/// <returns>returns base manager</returns>
protected override IMvxPluginManager CreatePluginManager()
{
base.InitializeLastChance();
IMvxPluginManager manager = base.CreatePluginManager();
manager.EnsurePluginLoaded<MvvmCross.Plugin.Messenger.Plugin>();
return manager;
}

/// <summary>
/// Sets up initial connected types and setup
/// </summary>
public override void InitializePrimary()
{
base.InitializePrimary();

// register necessary interfaces
Mvx.IoCProvider.LazyConstructAndRegisterSingleton<IMesManager, MesManagerViewModel>();
Expand All @@ -94,17 +108,13 @@ protected override void InitializeLastChance()

// Register themes
Mvx.IoCProvider.LazyConstructAndRegisterSingleton<IMesThemeManager, MesThemeManager>();
}

public override void InitializePrimary()
{
base.InitializePrimary();

// try to setup culture info
String code = Properties.Settings.Default.LanguageCode;

if (!String.IsNullOrWhiteSpace(code))
{
var culture = CultureInfo.GetCultureInfo(code);
CultureInfo culture = CultureInfo.GetCultureInfo(code);
// If code == "en", force to use default resource (Resources.resx)
// See PO #243
#warning fix translator depends
Expand All @@ -114,6 +124,7 @@ public override void InitializePrimary()
Thread.CurrentThread.CurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public Boolean SetCurrentTheme(String name, Boolean applySetting)

if (applySetting)
{
Properties.Settings.Default.ThemeName = CurrentTheme.Name;
Properties.Settings.Default.ThemeName = CurrentTheme.GetType().Name;
Properties.Settings.Default.Save();
}

return true;
Expand Down
20 changes: 18 additions & 2 deletions Modules/MinoriEditorShell/Platforms/Wpf/Views/MesWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using MinoriEditorShell.Services;
using MvvmCross;
using MvvmCross.Binding.BindingContext;
using MvvmCross.Core;
using MvvmCross.Platforms.Wpf.Views;
using MvvmCross.ViewModels;
using System;
Expand Down Expand Up @@ -87,11 +88,26 @@ private void MesWindow_Unloaded(Object sender, RoutedEventArgs e)
ViewModel?.ViewDestroy();
}

/// <summary>
/// Load inital settings if possible
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MesWindow_Loaded(Object sender, RoutedEventArgs e)
{
// Set theme
String blueTheme = "MesBlueTheme";

// Get main theme property if possible
String themeName = Properties.Settings.Default.ThemeName;
if (String.IsNullOrEmpty(themeName)) themeName = blueTheme;

// Set theme from name
IMesThemeManager manager = Mvx.IoCProvider.Resolve<IMesThemeManager>();
IMesTheme theme = manager.Themes.Single(x => x is MesBlueTheme);
IMesTheme theme = manager.Themes.FirstOrDefault(x => x.GetType().Name == themeName);

// Set to defualt if missing or error
if (theme == null) theme = manager.Themes.First(x => x.GetType().Name == themeName);

manager.SetCurrentTheme(theme.Name);

ViewModel?.ViewAppearing();
Expand Down

0 comments on commit ab29de6

Please sign in to comment.