From e8e2167c3d60f8e41e92bfc08a5a33700d746ade Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 11 Oct 2019 13:37:05 +0300 Subject: [PATCH] Resolved #35 --- Crypto Notepad/App.config | 6 ++ Crypto Notepad/MainForm.cs | 59 ++++++++++++------- .../Properties/Settings.Designer.cs | 29 ++++++++- Crypto Notepad/Properties/Settings.settings | 8 ++- 4 files changed, 79 insertions(+), 23 deletions(-) diff --git a/Crypto Notepad/App.config b/Crypto Notepad/App.config index b80d966..cf75397 100644 --- a/Crypto Notepad/App.config +++ b/Crypto Notepad/App.config @@ -147,6 +147,12 @@ Solid + + False + + + False + False diff --git a/Crypto Notepad/MainForm.cs b/Crypto Notepad/MainForm.cs index 719a4c8..6854824 100644 --- a/Crypto Notepad/MainForm.cs +++ b/Crypto Notepad/MainForm.cs @@ -604,6 +604,10 @@ private void LoadSettings() toolbarPanel.BorderStyle = BorderStyle.None; } + if (settings.closeToTray | settings.minimizeToTray) + { + trayIcon.Visible = true; + } wordWrapMainMenu.Checked = settings.editorWrap; toolbarPanel.BackColor = settings.toolbarBackColor; @@ -727,21 +731,27 @@ public void Toolbaricons(bool oldIcons) #region Event Handlers - private void MainWindow_Activated(object sender, EventArgs e) + private void MainForm_Resize(object sender, EventArgs e) { - richTextBox.Focus(); - - if (PublicVar.keyChanged) + if (settings.minimizeToTray) { - richTextBox.Modified = true; + if (WindowState == FormWindowState.Minimized) + { + Hide(); + } } - if (PublicVar.encryptionKey.Get() == null) + if (WindowState == FormWindowState.Minimized & settings.autoLock & PublicVar.encryptionKey.Get() != null) { - fileLocationToolbarButton.Enabled = false; - deleteFileToolbarButton.Enabled = false; - changeKeyToolbarButton.Enabled = false; - lockToolbarButton.Enabled = false; + pnlEnterKey.Visible = true; + } + + if (WindowState == FormWindowState.Normal) + { + if (pnlEnterKey.Visible) + { + txtKey.Focus(); + } } else { @@ -755,19 +765,17 @@ private void MainWindow_Activated(object sender, EventArgs e) private void MainWindow_FormClosing(object sender, FormClosingEventArgs e) { - if (WindowState == FormWindowState.Normal) + if (settings.closeToTray) { - settings.windowSize = Size; - settings.windowLocation = Location; - settings.windowState = WindowState; + if (settings.autoLock & PublicVar.encryptionKey.Get() != null) + { + pnlEnterKey.Visible = true; + } + Hide(); + e.Cancel = true; + return; } - if (WindowState == FormWindowState.Maximized) - { - settings.windowState = WindowState; - } - settings.Save(); - SaveConfirm(true); if (preventExit) @@ -1184,7 +1192,11 @@ private void DeleteFileToolStripMenuItem_Click(object sender, EventArgs e) private void ExitMainMenu_Click(object sender, EventArgs e) { - Application.Exit(); + SaveConfirm(true); + if (settings.closeToTray) + { + Environment.Exit(0); + } } private void fileMainMenu_DropDownOpened(object sender, EventArgs e) @@ -1670,6 +1682,11 @@ private void FindNextButton_Click(object sender, EventArgs e) #endregion + SaveConfirm(true); + if (settings.closeToTray) + { + Environment.Exit(0); + } #region Debug Menu private void VariablesMainMenu_Click(object sender, EventArgs e) { diff --git a/Crypto Notepad/Properties/Settings.Designer.cs b/Crypto Notepad/Properties/Settings.Designer.cs index 3d3ea67..19a66c9 100644 --- a/Crypto Notepad/Properties/Settings.Designer.cs +++ b/Crypto Notepad/Properties/Settings.Designer.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // Этот код создан программой. // Исполняемая версия:4.0.30319.42000 @@ -608,6 +608,33 @@ public string mlStyle { this["mlStyle"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool minimizeToTray { + get { + return ((bool)(this["minimizeToTray"])); + } + set { + this["minimizeToTray"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool closeToTray { + get { + return ((bool)(this["closeToTray"])); + } + set { + this["closeToTray"] = value; + } + } + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] diff --git a/Crypto Notepad/Properties/Settings.settings b/Crypto Notepad/Properties/Settings.settings index fda0a3f..5366199 100644 --- a/Crypto Notepad/Properties/Settings.settings +++ b/Crypto Notepad/Properties/Settings.settings @@ -1,4 +1,4 @@ - + @@ -137,6 +137,12 @@ Solid + + False + + + False + False