Skip to content

Commit

Permalink
设置功能基本完善
Browse files Browse the repository at this point in the history
  • Loading branch information
zsh2401 committed Sep 11, 2018
1 parent d7a34b4 commit 41e4418
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 64 deletions.
2 changes: 1 addition & 1 deletion AutumnBox.GUI/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<value>NULL</value>
</setting>
<setting name="Theme" serializeAs="String">
<value>秋-AutumnBox</value>
<value>Autumn</value>
</setting>
<setting name="NotifyOnFinish" serializeAs="String">
<value>True</value>
Expand Down
3 changes: 2 additions & 1 deletion AutumnBox.GUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
\* =============================================================================*/
using AutumnBox.GUI.Properties;
using AutumnBox.GUI.Util;
using AutumnBox.GUI.Util.Custom;
using AutumnBox.GUI.Util.I18N;
using AutumnBox.Support.Log;
using System.Windows;
Expand All @@ -36,10 +37,10 @@ public App() : base()
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Current = this;
#if !DEBUG
this.DispatcherUnhandledException += FatalHandler.Current_DispatcherUnhandledException;
#endif
ThemeManager.Instance.ApplyBySetting();
if (Settings.Default.IsFirstLaunch)
{
Logger.Info(this, "is first launch");
Expand Down
2 changes: 1 addition & 1 deletion AutumnBox.GUI/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion AutumnBox.GUI/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Value Profile="(Default)">NULL</Value>
</Setting>
<Setting Name="Theme" Type="System.String" Scope="User">
<Value Profile="(Default)">秋-AutumnBox</Value>
<Value Profile="(Default)">Autumn</Value>
</Setting>
<Setting Name="NotifyOnFinish" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
Expand Down
2 changes: 2 additions & 0 deletions AutumnBox.GUI/Resources/Languages/en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
<s:String x:Key="UpdateWindowBtnSkipVersion">Skip this version</s:String>

<!--PanelSettings-->
<s:String x:Key="PanelSettingsInterface">Interface</s:String>
<s:String x:Key="PanelSettingsOther">Other</s:String>
<s:String x:Key="PanelSettingsLanguage">Language</s:String>
<s:String x:Key="PanelSettingsDebug">Debug</s:String>
<s:String x:Key="PanelSettingsSendToDesktop">Create shortcut</s:String>
Expand Down
5 changes: 4 additions & 1 deletion AutumnBox.GUI/Resources/Languages/zh-CN.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
<s:String x:Key="UpdateWindowBtnSkipVersion">跳过此版本</s:String>

<!--PanelSettings-->
<s:String x:Key="PanelSettingsInterface">界面</s:String>
<s:String x:Key="PanelSettingsFinishedSound">功能完成音效</s:String>
<s:String x:Key="PanelSettingsOther">其它</s:String>
<s:String x:Key="PanelSettingsLanguage">语言</s:String>
<s:String x:Key="PanelSettingsDebug">调试</s:String>
<s:String x:Key="PanelSettingsDebug">调试</s:String>
<s:String x:Key="PanelSettingsSendToDesktop">创建快捷方式</s:String>
<s:String x:Key="PanelSettingsCreateDebugWindow">显示调试窗口</s:String>
<s:String x:Key="PanelSettingsLaunchDebugWindowOnNextLaunch">在下次启动时显示调试窗口</s:String>
Expand Down
2 changes: 1 addition & 1 deletion AutumnBox.GUI/Util/Custom/ITheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace AutumnBox.GUI.Util.Custom
{
interface ITheme
{
string ThemeName { get; }
string Name { get; }
ResourceDictionary Resource { get; }
}
}
30 changes: 15 additions & 15 deletions AutumnBox.GUI/Util/Custom/ThemeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ThemeManager : IThemeManager
private const int INDEX_OF_THEME = 2;
private const string FILE_PATH = "pack://application:,,,/AutumnBox.GUI;component/Resources/Themes/";
private const string THEME_NAME_KEY = "ThemeName";
public static ThemeManager Instance { get; private set; }
public static IThemeManager Instance { get; private set; }
static ThemeManager()
{
Instance = new ThemeManager();
Expand All @@ -26,21 +26,15 @@ static ThemeManager()

public ITheme Current
{
get => current;
get => GetCurrentTheme();
set
{
current = value ?? throw new ArgumentNullException();
Apply(current);
Apply(value);
}
}
private ITheme current;

private List<ITheme> themes;
private ThemeManager()
{
Load();
}
private void Load()
{
themes = new List<ITheme>() {
ThemeImpl.LoadFrom("Autumn.xaml"),
Expand All @@ -50,23 +44,30 @@ private void Load()
public void ApplyBySetting()
{
var settingTheme = Settings.Default.Theme;
var findingResult = themes.Find(_the => _the.ThemeName == settingTheme);
var findingResult = themes.Find(_the => _the.Name == settingTheme);
Current = findingResult;
}

private ITheme GetCurrentTheme()
{
var currentThemeName = App.Current.Resources[THEME_NAME_KEY].ToString();
return themes.Find((t) =>
{
return t.Name == currentThemeName;
});
}
private void Apply(ITheme theme)
{
if (theme == null)
if (Current.Equals(theme))
{
return;
}
App.Current.Resources.MergedDictionaries[INDEX_OF_THEME] = theme.Resource;
current = theme;
}

private class ThemeImpl : ITheme
{
public string ThemeName => Resource[THEME_NAME_KEY].ToString();
public string Name => Resource[THEME_NAME_KEY].ToString();

public ResourceDictionary Resource { get; private set; }

Expand All @@ -81,10 +82,9 @@ public static ThemeImpl LoadFrom(string filename)
}
private class RandomTheme : ITheme
{
public string ThemeName => "Random-随机";
public string Name => "Random-随机";

public ResourceDictionary Resource => throw new NotImplementedException();
private ResourceDictionary current;
public void Random() { }
}
}
Expand Down
15 changes: 12 additions & 3 deletions AutumnBox.GUI/Util/I18N/LanguageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ public ILanguage Current
{
get
{
return current;
return GetCurrent();
}
set
{
Apply(value);
}
}
private ILanguage current;

public IEnumerable<ILanguage> Languages => languages;
private List<Language> languages;
Expand All @@ -64,10 +63,20 @@ private void AllLoad()
return _l.LanCode == App.Current.Resources["LanguageCode"].ToString();
});
}
private ILanguage GetCurrent() {
var code = App.Current.Resources[LANG_CODE_KEY].ToString();
return languages.Find((t) =>
{
return t.LanCode == code;
});
}
private void Apply(ILanguage lang)
{
if (Current.Equals(lang))
{
return;
}
App.Current.Resources.MergedDictionaries[INDEX_OF_LANG] = lang.Resource;
current = lang;
Settings.Default.Language = lang.LanCode;
Settings.Default.Save();
LanguageChanged?.Invoke(this, new EventArgs());
Expand Down
52 changes: 35 additions & 17 deletions AutumnBox.GUI/View/DialogContent/ContentSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,47 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
FontFamily="{DynamicResource AutumnBox.Font}"
mc:Ignorable="d" Height="255.547" Width="422.631">
mc:Ignorable="d" Height="294.047" Width="262.131">
<StackPanel>
<Grid>
<TextBlock HorizontalAlignment="Left" Margin="5" Text="In other words,please be true" FontSize="15"/>
<Button Style="{DynamicResource MaterialDesignFlatButton}" Margin="5" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" VerticalAlignment="Top" HorizontalAlignment="Right" Content="{DynamicResource btnClose}"/>

</Grid>
<StackPanel Margin="15" Orientation="Vertical">
<StackPanel Margin="5" Orientation="Horizontal">
<TextBlock Margin="0,0,15,0" VerticalAlignment="Center" Text="{DynamicResource PanelSettingsLanguage}"/>
<ComboBox ItemsSource="{Binding Languages}" DisplayMemberPath="{Binding DisplayMemberPath}" SelectedItem="{Binding SelectedItem}" Width="170"/>
</StackPanel>
<StackPanel Margin="5" Orientation="Horizontal">
<TextBlock Margin="0,0,15,0" VerticalAlignment="Center" Text="{DynamicResource PanelSettingsDebug}"/>
<StackPanel>
<Button Command="{Binding ShowDebugWindow}" FontSize="12" Margin="0,5" Style="{DynamicResource MaterialDesignRaisedButton}" Content="{DynamicResource PanelSettingsCreateDebugWindow}"/>
<CheckBox IsChecked="{Binding DebugOnNext}" Content="{DynamicResource PanelSettingsLaunchDebugWindowOnNextLaunch}"/>
<materialDesign:Card Margin="0,0,0,5">
<StackPanel Margin="5">
<TextBlock Text="{DynamicResource PanelSettingsInterface}" Margin="0,0,0,5"/>
<Label Height="1" Background="LightGray"/>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,15,0" VerticalAlignment="Center" Text="{DynamicResource Theme}"/>
<ComboBox ItemsSource="{Binding Themes}" DisplayMemberPath="{Binding ThemeDisplayMemberPath}" SelectedItem="{Binding SelectedTheme}" Width="170"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,15,0" VerticalAlignment="Center" Text="{DynamicResource PanelSettingsLanguage}"/>
<ComboBox ItemsSource="{Binding Languages}" DisplayMemberPath="{Binding LanguageDisplayMemberPath}" SelectedItem="{Binding SelectedLanguage}" Width="170"/>
</StackPanel>
</StackPanel>
<StackPanel Margin="5" Orientation="Horizontal">
<TextBlock Text="Other"/>
<Button Command="{Binding SendToDesktop}" FontSize="12" Margin="5" Style="{DynamicResource MaterialDesignRaisedButton}" Content="{DynamicResource PanelSettingsSendToDesktop}"/>
</materialDesign:Card>

<materialDesign:Card Margin="0,0,0,5">
<StackPanel Margin="5">
<TextBlock Text="{DynamicResource PanelSettingsDebug}" Margin="0,0,0,5"/>
<Label Height="1" Background="LightGray"/>
<Button Command="{Binding ShowDebugWindow}" FontSize="12" Style="{DynamicResource MaterialDesignFlatButton}" Content="{DynamicResource PanelSettingsCreateDebugWindow}"/>
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<ToggleButton Style="{DynamicResource MaterialDesignSwitchToggleButton}" IsChecked="{Binding DebugOnNext}" ToolTip="{DynamicResource PanelSettingsLaunchDebugWindowOnNextLaunch}"/>
<TextBlock Margin="5,0,0,0" Text="{DynamicResource PanelSettingsLaunchDebugWindowOnNextLaunch}"/>
</StackPanel>

</StackPanel>
</StackPanel>
</materialDesign:Card>

<materialDesign:Card Margin="0,0,0,5">
<StackPanel Margin="5" Orientation="Vertical">
<TextBlock Margin="0,0,0,5" Text="{DynamicResource PanelSettingsOther}"/>
<Label Height="1" Background="LightGray"/>
<Button Command="{Binding SendToDesktop}" FontSize="12" Margin="5" Style="{DynamicResource MaterialDesignFlatButton}" Content="{DynamicResource PanelSettingsSendToDesktop}"/>
</StackPanel>
</materialDesign:Card>
<Button Style="{DynamicResource MaterialDesignFlatButton}" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Content="{DynamicResource btnClose}"/>
</StackPanel>

</UserControl>
38 changes: 15 additions & 23 deletions AutumnBox.GUI/ViewModel/VMSettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*************************************************/
using AutumnBox.GUI.MVVM;
using AutumnBox.GUI.Properties;
using AutumnBox.GUI.Util.Custom;
using AutumnBox.GUI.Util.I18N;
using AutumnBox.GUI.Util.OS;
using AutumnBox.GUI.View.Windows;
Expand All @@ -22,26 +23,28 @@ class VMSettingsDialog : ViewModelBase
#region MVVM
public IEnumerable<ILanguage> Languages
{
get => _langs;
get => LanguageManager.Instance.Languages;
}
public ILanguage SelectedLanguage
{
get => LanguageManager.Instance.Current;
set
{
_langs = value;
LanguageManager.Instance.Current = value;
RaisePropertyChanged();
}
}
private IEnumerable<ILanguage> _langs;

public ILanguage SelectedItem
public IEnumerable<ITheme> Themes { get => ThemeManager.Instance.Themes; }
public ITheme SelectedTheme
{
get => _selectedItem;
set
get => ThemeManager.Instance.Current; set
{
_selectedItem = value;
ApplyLanguage();
ThemeManager.Instance.Current = value;
RaisePropertyChanged();
}
}
private ILanguage _selectedItem;


public bool DebugOnNext
{
Expand All @@ -59,12 +62,12 @@ public bool DebugOnNext
public ICommand SendToDesktop { get; private set; }

public ICommand ShowDebugWindow { get; private set; }
public string DisplayMemberPath { get; set; } = nameof(ILanguage.LangName);

public string ThemeDisplayMemberPath { get; set; } = nameof(ITheme.Name);
public string LanguageDisplayMemberPath { get; set; } = nameof(ILanguage.LangName);
#endregion
public VMSettingsDialog()
{
Languages = LanguageManager.Instance.Languages;
SelectedItem = LanguageManager.Instance.Current;
SendToDesktop = new MVVMCommand((_) =>
{
ShortcutHelper.CreateShortcutOnDesktop("AutumnBox", System.Environment.CurrentDirectory + "/AutumnBox.GUI.exe", "The AutumnBox-Dream of us");
Expand All @@ -74,16 +77,5 @@ public VMSettingsDialog()
new LogWindow().Show();
});
}
private void ApplyLanguage()
{
if (SelectedItem.Equals(LanguageManager.Instance.Current))
{
return;
}
else
{
LanguageManager.Instance.Current = SelectedItem;
}
}
}
}

0 comments on commit 41e4418

Please sign in to comment.