From 7a5eed271eb2cf49d85c4493922a4ad61d8a3768 Mon Sep 17 00:00:00 2001 From: Geliy Sokolov Date: Thu, 6 Sep 2018 10:31:39 +1100 Subject: [PATCH] Implements "minimise on close" feature. --- Client/Controls/MainWindow.xaml | 1 + Client/Controls/MainWindow.xaml.cs | 15 +++++++++++++++ Client/Controls/Options.xaml | 1 + Client/Controls/Options.xaml.cs | 1 + Client/MainWindowViewModel.cs | 1 + Client/User.Designer.cs | 13 +++++++++++++ Client/User.settings | 3 +++ Client/app.config | 3 +++ 8 files changed, 38 insertions(+) diff --git a/Client/Controls/MainWindow.xaml b/Client/Controls/MainWindow.xaml index d1f403ff..f86eac95 100644 --- a/Client/Controls/MainWindow.xaml +++ b/Client/Controls/MainWindow.xaml @@ -5,6 +5,7 @@ xmlns:local="clr-namespace:Client" xmlns:convertors="clr-namespace:Client.Converters" Loaded="Window_Loaded" + Closing="Window_Closing" Title="todotxt.net" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" diff --git a/Client/Controls/MainWindow.xaml.cs b/Client/Controls/MainWindow.xaml.cs index 6b8b2639..8898a0c0 100644 --- a/Client/Controls/MainWindow.xaml.cs +++ b/Client/Controls/MainWindow.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.Reflection; using System.Windows; @@ -136,6 +137,20 @@ private void Window_Loaded(object sender, RoutedEventArgs e) DataContext = ViewModel; } + private void Window_Closing(object sender, CancelEventArgs e) + { + if (Application.Current.ShutdownMode == ShutdownMode.OnExplicitShutdown) + { + return; + } + + if (User.Default.MinimiseToSystemTray && User.Default.MinimiseOnClose) + { + e.Cancel = true; + WindowState = WindowState.Minimized; + } + } + #region window location handlers private void Window_LocationChanged(object sender, EventArgs e) { diff --git a/Client/Controls/Options.xaml b/Client/Controls/Options.xaml index 3a979688..389fd473 100644 --- a/Client/Controls/Options.xaml +++ b/Client/Controls/Options.xaml @@ -46,6 +46,7 @@ + diff --git a/Client/Controls/Options.xaml.cs b/Client/Controls/Options.xaml.cs index 2fa0d10c..0fdaa588 100644 --- a/Client/Controls/Options.xaml.cs +++ b/Client/Controls/Options.xaml.cs @@ -33,6 +33,7 @@ public Options(FontInfo taskFont) cbAddCreationDate.IsChecked = User.Default.AddCreationDate; cbDebugOn.IsChecked = User.Default.DebugLoggingOn; cbMinToSysTray.IsChecked = User.Default.MinimiseToSystemTray; + cbMinOnClose.IsChecked = User.Default.MinimiseOnClose; cbRequireCtrlEnter.IsChecked = User.Default.RequireCtrlEnter; cbAllowGrouping.IsChecked = User.Default.AllowGrouping; cbMoveFocusToTaskListAfterAddingNewTask.IsChecked = User.Default.MoveFocusToTaskListAfterAddingNewTask; diff --git a/Client/MainWindowViewModel.cs b/Client/MainWindowViewModel.cs index 272de064..4de48c18 100644 --- a/Client/MainWindowViewModel.cs +++ b/Client/MainWindowViewModel.cs @@ -1493,6 +1493,7 @@ public void ShowOptionsDialog() User.Default.AddCreationDate = o.cbAddCreationDate.IsChecked.Value; User.Default.DebugLoggingOn = o.cbDebugOn.IsChecked.Value; User.Default.MinimiseToSystemTray = o.cbMinToSysTray.IsChecked.Value; + User.Default.MinimiseOnClose = o.cbMinOnClose.IsChecked.Value; User.Default.RequireCtrlEnter = o.cbRequireCtrlEnter.IsChecked.Value; User.Default.AllowGrouping = o.cbAllowGrouping.IsChecked.Value; User.Default.PreserveWhiteSpace = o.cbPreserveWhiteSpace.IsChecked.Value; diff --git a/Client/User.Designer.cs b/Client/User.Designer.cs index 2a93b4da..33b2471c 100644 --- a/Client/User.Designer.cs +++ b/Client/User.Designer.cs @@ -203,6 +203,18 @@ internal sealed partial class User : global::System.Configuration.ApplicationSet } } + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool MinimiseOnClose { + get { + return ((bool)(this["MinimiseOnClose"])); + } + set { + this["MinimiseOnClose"] = value; + } + } + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("False")] @@ -490,6 +502,7 @@ internal sealed partial class User : global::System.Configuration.ApplicationSet this["ShowHidenTasks"] = value; } } + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("True")] diff --git a/Client/User.settings b/Client/User.settings index c6f16d4a..51440d80 100644 --- a/Client/User.settings +++ b/Client/User.settings @@ -47,6 +47,9 @@ False + + False + False diff --git a/Client/app.config b/Client/app.config index da9a2d4d..a5789485 100644 --- a/Client/app.config +++ b/Client/app.config @@ -52,6 +52,9 @@ False + + False + False