From d1c568d1f8454d34ed45cd742998d91bd99049a8 Mon Sep 17 00:00:00 2001 From: cgz Date: Fri, 11 Mar 2016 16:45:47 +0800 Subject: [PATCH] NightMode --- MarkDownEditor.Setup/Product.wxs | 35 ++++++++----- MarkDownEditor/App.config | 3 ++ MarkDownEditor/MarkDownEditor.csproj | 14 +++--- MarkDownEditor/Model/DocumentExporter.cs | 2 +- MarkDownEditor/Properties/AssemblyInfo.cs | 4 +- .../Properties/Resources.Designer.cs | 13 ++++- MarkDownEditor/Properties/Resources.resx | 7 ++- .../Properties/Resources.zh-CN.resx | 7 ++- .../Properties/Settings.Designer.cs | 12 +++++ MarkDownEditor/Properties/Settings.settings | 3 ++ MarkDownEditor/View/MainWindow.xaml | 8 +-- MarkDownEditor/View/SettingsControl.xaml | 11 ++-- MarkDownEditor/View/StatusBarControl.xaml | 2 +- MarkDownEditor/ViewModel/AboutViewModel.cs | 2 +- MarkDownEditor/ViewModel/MainViewModel.cs | 50 +++++++++++++------ MarkDownEditor/ViewModel/SettingsViewModel.cs | 25 ++++++++++ MarkDownEditor/css/{ => Dark}/Retro.css | 0 MarkDownEditor/css/{ => Light}/Air.css | 0 MarkDownEditor/css/{ => Light}/Default.css | 0 .../css/{ => Light}/Github_andyferra.css | 0 MarkDownEditor/css/{ => Light}/Modest.css | 0 MarkDownEditor/css/{ => Light}/Simonlc.css | 0 MarkDownEditor/css/{ => Light}/Splendor.css | 0 Readme.md | 3 +- 24 files changed, 146 insertions(+), 55 deletions(-) rename MarkDownEditor/css/{ => Dark}/Retro.css (100%) rename MarkDownEditor/css/{ => Light}/Air.css (100%) rename MarkDownEditor/css/{ => Light}/Default.css (100%) rename MarkDownEditor/css/{ => Light}/Github_andyferra.css (100%) rename MarkDownEditor/css/{ => Light}/Modest.css (100%) rename MarkDownEditor/css/{ => Light}/Simonlc.css (100%) rename MarkDownEditor/css/{ => Light}/Splendor.css (100%) diff --git a/MarkDownEditor.Setup/Product.wxs b/MarkDownEditor.Setup/Product.wxs index 06c920a..3e055bc 100644 --- a/MarkDownEditor.Setup/Product.wxs +++ b/MarkDownEditor.Setup/Product.wxs @@ -2,8 +2,8 @@ - - + + @@ -13,7 +13,8 @@ - + + @@ -53,7 +54,10 @@ - + + + + @@ -164,15 +168,20 @@ - - - - - - - - - + + + + + + + + + + + + + + diff --git a/MarkDownEditor/App.config b/MarkDownEditor/App.config index b878cd7..287298f 100644 --- a/MarkDownEditor/App.config +++ b/MarkDownEditor/App.config @@ -61,6 +61,9 @@ + + False + diff --git a/MarkDownEditor/MarkDownEditor.csproj b/MarkDownEditor/MarkDownEditor.csproj index 82c93f5..e75627d 100644 --- a/MarkDownEditor/MarkDownEditor.csproj +++ b/MarkDownEditor/MarkDownEditor.csproj @@ -289,25 +289,25 @@ - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest diff --git a/MarkDownEditor/Model/DocumentExporter.cs b/MarkDownEditor/Model/DocumentExporter.cs index bc3f01a..dfc8892 100644 --- a/MarkDownEditor/Model/DocumentExporter.cs +++ b/MarkDownEditor/Model/DocumentExporter.cs @@ -59,7 +59,7 @@ public void Export(string markdownType, string sourceCodePath, string cssFile, s var tmpFile = Path.GetTempFileName(); if (cssFile!=null) { - StreamReader sr = new StreamReader($"css/{cssFile}"); + StreamReader sr = new StreamReader(cssFile); var cssContent = sr.ReadToEnd(); sr.Close(); StreamWriter sw = new StreamWriter(tmpFile); diff --git a/MarkDownEditor/Properties/AssemblyInfo.cs b/MarkDownEditor/Properties/AssemblyInfo.cs index c8b42bc..93b9020 100644 --- a/MarkDownEditor/Properties/AssemblyInfo.cs +++ b/MarkDownEditor/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.3.4.0")] -[assembly: AssemblyFileVersion("0.3.4.0")] +[assembly: AssemblyVersion("0.3.5.0")] +[assembly: AssemblyFileVersion("0.3.5.0")] diff --git a/MarkDownEditor/Properties/Resources.Designer.cs b/MarkDownEditor/Properties/Resources.Designer.cs index edaf0ca..de53918 100644 --- a/MarkDownEditor/Properties/Resources.Designer.cs +++ b/MarkDownEditor/Properties/Resources.Designer.cs @@ -717,6 +717,15 @@ public static string NewVersionIsReleased { } } + /// + /// Looks up a localized string similar to Night Mode. + /// + public static string NightMode { + get { + return ResourceManager.GetString("NightMode", resourceCulture); + } + } + /// /// Looks up a localized string similar to No CSS. /// @@ -1348,7 +1357,7 @@ public static string Uploading { } /// - /// Looks up a localized string similar to Upload Local Image To Imgur(Outside Mainland China). + /// Looks up a localized string similar to Upload Local Image To Imgur(Outside PRC). /// public static string UploadLocalImage2IMGUR { get { @@ -1357,7 +1366,7 @@ public static string UploadLocalImage2IMGUR { } /// - /// Looks up a localized string similar to Upload Local Image To Qiniu(Mainland China). + /// Looks up a localized string similar to Upload Local Image To Qiniu(PRC). /// public static string UploadLocalImage2Qiniu { get { diff --git a/MarkDownEditor/Properties/Resources.resx b/MarkDownEditor/Properties/Resources.resx index f033828..40f7be4 100644 --- a/MarkDownEditor/Properties/Resources.resx +++ b/MarkDownEditor/Properties/Resources.resx @@ -457,7 +457,7 @@ Uploading - Upload Local Image To Imgur(Outside Mainland China) + Upload Local Image To Imgur(Outside PRC) Find @@ -547,7 +547,7 @@ Images - Upload Local Image To Qiniu(Mainland China) + Upload Local Image To Qiniu(PRC) Editor @@ -567,4 +567,7 @@ Warning + + Night Mode + \ No newline at end of file diff --git a/MarkDownEditor/Properties/Resources.zh-CN.resx b/MarkDownEditor/Properties/Resources.zh-CN.resx index cfad4b7..2372e68 100644 --- a/MarkDownEditor/Properties/Resources.zh-CN.resx +++ b/MarkDownEditor/Properties/Resources.zh-CN.resx @@ -457,7 +457,7 @@ 正在上传 - 上传本地图片至Imgur(非中国大陆地区) + 上传本地图片至Imgur(国内无法上传) 查找 @@ -547,7 +547,7 @@ 图片影像 - 上传本地图片至七牛(中国大陆地区) + 上传本地图片至七牛 编辑器 @@ -567,4 +567,7 @@ 警告 + + 夜间模式 + \ No newline at end of file diff --git a/MarkDownEditor/Properties/Settings.Designer.cs b/MarkDownEditor/Properties/Settings.Designer.cs index 3563a7d..15943a2 100644 --- a/MarkDownEditor/Properties/Settings.Designer.cs +++ b/MarkDownEditor/Properties/Settings.Designer.cs @@ -232,5 +232,17 @@ public string LastLatestVersion { this["LastLatestVersion"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool NightMode { + get { + return ((bool)(this["NightMode"])); + } + set { + this["NightMode"] = value; + } + } } } diff --git a/MarkDownEditor/Properties/Settings.settings b/MarkDownEditor/Properties/Settings.settings index ad1ddba..9a0dd16 100644 --- a/MarkDownEditor/Properties/Settings.settings +++ b/MarkDownEditor/Properties/Settings.settings @@ -56,5 +56,8 @@ + + False + \ No newline at end of file diff --git a/MarkDownEditor/View/MainWindow.xaml b/MarkDownEditor/View/MainWindow.xaml index 0d440ee..ebb3bcb 100644 --- a/MarkDownEditor/View/MainWindow.xaml +++ b/MarkDownEditor/View/MainWindow.xaml @@ -59,7 +59,7 @@ - + @@ -99,7 +99,9 @@ - + diff --git a/MarkDownEditor/View/SettingsControl.xaml b/MarkDownEditor/View/SettingsControl.xaml index 4717605..c06f7e6 100644 --- a/MarkDownEditor/View/SettingsControl.xaml +++ b/MarkDownEditor/View/SettingsControl.xaml @@ -30,7 +30,7 @@ - @@ -38,9 +38,10 @@ + - @@ -74,7 +75,7 @@ - @@ -92,7 +93,7 @@ - + @@ -116,7 +117,7 @@ - diff --git a/MarkDownEditor/View/StatusBarControl.xaml b/MarkDownEditor/View/StatusBarControl.xaml index e1be7f9..53551ce 100644 --- a/MarkDownEditor/View/StatusBarControl.xaml +++ b/MarkDownEditor/View/StatusBarControl.xaml @@ -28,7 +28,7 @@ - diff --git a/MarkDownEditor/ViewModel/AboutViewModel.cs b/MarkDownEditor/ViewModel/AboutViewModel.cs index 771723e..a8890f5 100644 --- a/MarkDownEditor/ViewModel/AboutViewModel.cs +++ b/MarkDownEditor/ViewModel/AboutViewModel.cs @@ -41,7 +41,7 @@ public class AboutViewModel : ViewModelBase /// public AboutViewModel() { - CheckForUpdate(); + //CheckForUpdate(); } public override void Cleanup() diff --git a/MarkDownEditor/ViewModel/MainViewModel.cs b/MarkDownEditor/ViewModel/MainViewModel.cs index 220d59c..0c55b2c 100644 --- a/MarkDownEditor/ViewModel/MainViewModel.cs +++ b/MarkDownEditor/ViewModel/MainViewModel.cs @@ -51,15 +51,8 @@ public MainViewModel() { Directory.SetCurrentDirectory(AppDomain.CurrentDomain.SetupInformation.ApplicationBase); - ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.GetAccent(Properties.Settings.Default.DefaultAccent), ThemeManager.DetectAppStyle(Application.Current).Item1); + UpdateCSSFiles(); - var css = Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "css"), "*.css") - .Select(s=>Path.GetFileName(s)).ToList(); - css.Insert(0, Properties.Resources.NoCSS); - css.Add(Properties.Resources.AddCustomCSS); - CssFiles = css; - - CurrentCssFileIndex = 2; CurrentMarkdownTypeText = Properties.Settings.Default.MarkdownProcessor; Qiniu.Conf.Config.ACCESS_KEY = SecretKey.QiniuConfig.AccessKey; @@ -402,9 +395,10 @@ await DialogCoordinator.Instance.ShowMessageAsync(context, { await Task.Run(()=> { - DocumentExporter.Export(Name, MarkDownType[context.CurrentMarkdownTypeText], - context.CurrentCssFileIndex == 0 || context.CurrentCssFileIndex == CssFiles.Count-1 ? - null : CssFiles[context.CurrentCssFileIndex], SourceCodePath, dlg.FileName); + bool isNightMode = ViewModelLocator.Main.SettingsViewModel.IsNightMode; + var cssFilePath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "css", isNightMode ? "Dark" : "Light", ViewModelLocator.Main.CurrentCssFiles[ViewModelLocator.Main.CurrentCssFileIndex]); + + DocumentExporter.Export(Name, MarkDownType[context.CurrentMarkdownTypeText], cssFilePath, SourceCodePath, dlg.FileName); }); await progress.CloseAsync(); var ret = await DialogCoordinator.Instance.ShowMessageAsync(context, @@ -467,10 +461,12 @@ public string CurrentMarkdownTypeText } } - public static List CssFiles { get; private set; } + public static List LightCssFiles { get; private set; } + public static List DarkCssFiles { get; private set; } + public List CurrentCssFiles => SettingsViewModel.IsNightMode ? DarkCssFiles : LightCssFiles; private int currentCssFileIndex; - public int CurrentCssFileIndex + public int CurrentCssFileIndex { get { return currentCssFileIndex; } set @@ -482,7 +478,7 @@ public int CurrentCssFileIndex RaisePropertyChanged("CurrentCssFileIndex"); UpdatePreview(); - if (value == CssFiles.Count - 1) + if (value == (SettingsViewModel.IsNightMode?DarkCssFiles:LightCssFiles).Count - 1) { ShowCustomCSSMessage(); } @@ -1175,6 +1171,25 @@ await DialogCoordinator.Instance.ShowMessageAsync(this, Properties.Resources.Err }); #endregion + public void UpdateCSSFiles() + { + var lightCSS = Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "css", "Light"), "*.css") + .Select(s => Path.GetFileName(s)).ToList(); + lightCSS.Insert(0, Properties.Resources.NoCSS); + lightCSS.Add(Properties.Resources.AddCustomCSS); + LightCssFiles = lightCSS; + + var darkCSS = Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "css", "Dark"), "*.css") + .Select(s => Path.GetFileName(s)).ToList(); + darkCSS.Insert(0, Properties.Resources.NoCSS); + darkCSS.Add(Properties.Resources.AddCustomCSS); + DarkCssFiles = darkCSS; + + RaisePropertyChanged("CurrentCssFiles"); + CurrentCssFileIndex = SettingsViewModel.IsNightMode? 1: 2; + + } + private async void LoadDefaultDocument() { var args = Environment.GetCommandLineArgs(); @@ -1237,7 +1252,12 @@ private void UpdatePreview() sw.Write(SourceCode.Text); sw.Close(); - DocumentExporter.Export("Html", MarkDownType[CurrentMarkdownTypeText], CurrentCssFileIndex==0|| CurrentCssFileIndex== CssFiles.Count-1? null:CssFiles[CurrentCssFileIndex], markdownSourceTempPath, previewSourceTempPath); + bool isNightMode = SettingsViewModel.IsNightMode; + var cssFilePath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "css", isNightMode?"Dark":"Light", CurrentCssFiles[CurrentCssFileIndex]); + DocumentExporter.Export("Html", + MarkDownType[CurrentMarkdownTypeText], + CurrentCssFileIndex==0|| CurrentCssFileIndex== CurrentCssFiles.Count-1? null: cssFilePath, + markdownSourceTempPath, previewSourceTempPath); ShouldReload = !ShouldReload; } diff --git a/MarkDownEditor/ViewModel/SettingsViewModel.cs b/MarkDownEditor/ViewModel/SettingsViewModel.cs index 8e1c3d0..f2d7150 100644 --- a/MarkDownEditor/ViewModel/SettingsViewModel.cs +++ b/MarkDownEditor/ViewModel/SettingsViewModel.cs @@ -40,6 +40,9 @@ public class SettingsViewModel : ViewModelBase /// public SettingsViewModel() { + ThemeManager.ChangeAppStyle(Application.Current, + ThemeManager.GetAccent(Properties.Settings.Default.DefaultAccent), + ThemeManager.GetAppTheme(isNightMode ? "BaseDark" : "BaseLight")); } public override void Cleanup() @@ -82,6 +85,28 @@ public CultureInfo CultureInfo public List AllLanguages => App.AllLanguages; + private bool isNightMode = Properties.Settings.Default.NightMode; + public bool IsNightMode + { + get { return isNightMode; } + set + { + if (isNightMode == value) + return; + isNightMode = value; + Properties.Settings.Default.NightMode = value; + Properties.Settings.Default.Save(); + + var theme = ThemeManager.DetectAppStyle(Application.Current); + var appTheme = ThemeManager.GetAppTheme(isNightMode?"BaseDark":"BaseLight"); + ThemeManager.ChangeAppStyle(Application.Current, theme.Item2, appTheme); + + ViewModelLocator.Main.UpdateCSSFiles(); + + RaisePropertyChanged("IsNightMode"); + } + } + public class AccentItem { public string Name { get; set; } diff --git a/MarkDownEditor/css/Retro.css b/MarkDownEditor/css/Dark/Retro.css similarity index 100% rename from MarkDownEditor/css/Retro.css rename to MarkDownEditor/css/Dark/Retro.css diff --git a/MarkDownEditor/css/Air.css b/MarkDownEditor/css/Light/Air.css similarity index 100% rename from MarkDownEditor/css/Air.css rename to MarkDownEditor/css/Light/Air.css diff --git a/MarkDownEditor/css/Default.css b/MarkDownEditor/css/Light/Default.css similarity index 100% rename from MarkDownEditor/css/Default.css rename to MarkDownEditor/css/Light/Default.css diff --git a/MarkDownEditor/css/Github_andyferra.css b/MarkDownEditor/css/Light/Github_andyferra.css similarity index 100% rename from MarkDownEditor/css/Github_andyferra.css rename to MarkDownEditor/css/Light/Github_andyferra.css diff --git a/MarkDownEditor/css/Modest.css b/MarkDownEditor/css/Light/Modest.css similarity index 100% rename from MarkDownEditor/css/Modest.css rename to MarkDownEditor/css/Light/Modest.css diff --git a/MarkDownEditor/css/Simonlc.css b/MarkDownEditor/css/Light/Simonlc.css similarity index 100% rename from MarkDownEditor/css/Simonlc.css rename to MarkDownEditor/css/Light/Simonlc.css diff --git a/MarkDownEditor/css/Splendor.css b/MarkDownEditor/css/Light/Splendor.css similarity index 100% rename from MarkDownEditor/css/Splendor.css rename to MarkDownEditor/css/Light/Splendor.css diff --git a/Readme.md b/Readme.md index b133c7d..787b3d7 100644 --- a/Readme.md +++ b/Readme.md @@ -42,7 +42,8 @@ The editor has the following `features`: - Modern(Metro) Style App - Code highlighting - Support of English & 简体中文 -- Switching the accent color of theme +- Switching the color theme +- Night Mode - Editing Mode & Reading Mode - Full Screen support - ......