From 30a4c3f9b5a410826f3966a905f3c449d13e5f7c Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 5 Nov 2019 22:00:38 +0200 Subject: [PATCH] Resolved #41 Save file and close it, without closing the app --- Crypto Notepad/MainForm.Designer.cs | 32 +++++++++++++------ Crypto Notepad/MainForm.cs | 20 ++++++++++++ .../Properties/Resources.Designer.cs | 10 ++++++ Crypto Notepad/Properties/Resources.resx | 29 +++++++++++++---- 4 files changed, 74 insertions(+), 17 deletions(-) diff --git a/Crypto Notepad/MainForm.Designer.cs b/Crypto Notepad/MainForm.Designer.cs index 0f54ad4..848b9e5 100644 --- a/Crypto Notepad/MainForm.Designer.cs +++ b/Crypto Notepad/MainForm.Designer.cs @@ -37,6 +37,7 @@ public void InitializeComponent() this.mainMenuSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.saveMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.saveAsMainMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.saveCloseFileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.mainMenuSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.openFileLocationMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.deleteFileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); @@ -172,6 +173,7 @@ public void InitializeComponent() this.mainMenuSeparator1, this.saveMainMenu, this.saveAsMainMenu, + this.saveCloseFileMainMenu, this.mainMenuSeparator2, this.openFileLocationMainMenu, this.deleteFileMainMenu, @@ -187,7 +189,7 @@ public void InitializeComponent() // this.newMainMenu.Name = "newMainMenu"; this.newMainMenu.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N))); - this.newMainMenu.Size = new System.Drawing.Size(195, 22); + this.newMainMenu.Size = new System.Drawing.Size(232, 22); this.newMainMenu.Text = "New"; this.newMainMenu.Click += new System.EventHandler(this.NewMainMenu_Click); // @@ -195,20 +197,20 @@ public void InitializeComponent() // this.openMainMenu.Name = "openMainMenu"; this.openMainMenu.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O))); - this.openMainMenu.Size = new System.Drawing.Size(195, 22); + this.openMainMenu.Size = new System.Drawing.Size(232, 22); this.openMainMenu.Text = "Open..."; this.openMainMenu.Click += new System.EventHandler(this.OpenMainMenu_Click); // // mainMenuSeparator1 // this.mainMenuSeparator1.Name = "mainMenuSeparator1"; - this.mainMenuSeparator1.Size = new System.Drawing.Size(192, 6); + this.mainMenuSeparator1.Size = new System.Drawing.Size(229, 6); // // saveMainMenu // this.saveMainMenu.Name = "saveMainMenu"; this.saveMainMenu.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); - this.saveMainMenu.Size = new System.Drawing.Size(195, 22); + this.saveMainMenu.Size = new System.Drawing.Size(232, 22); this.saveMainMenu.Text = "Save"; this.saveMainMenu.Click += new System.EventHandler(this.SaveMainMenu_Click); // @@ -217,39 +219,48 @@ public void InitializeComponent() this.saveAsMainMenu.Name = "saveAsMainMenu"; this.saveAsMainMenu.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift) | System.Windows.Forms.Keys.S))); - this.saveAsMainMenu.Size = new System.Drawing.Size(195, 22); + this.saveAsMainMenu.Size = new System.Drawing.Size(232, 22); this.saveAsMainMenu.Text = "Save As..."; this.saveAsMainMenu.Click += new System.EventHandler(this.SaveAsMainMenu_Click); // + // saveCloseFileMainMenu + // + this.saveCloseFileMainMenu.Name = "saveCloseFileMainMenu"; + this.saveCloseFileMainMenu.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.Shift) + | System.Windows.Forms.Keys.S))); + this.saveCloseFileMainMenu.Size = new System.Drawing.Size(232, 22); + this.saveCloseFileMainMenu.Text = "Save && Close File"; + this.saveCloseFileMainMenu.Click += new System.EventHandler(this.SaveCloseFileMainMenu_Click); + // // mainMenuSeparator2 // this.mainMenuSeparator2.Name = "mainMenuSeparator2"; - this.mainMenuSeparator2.Size = new System.Drawing.Size(192, 6); + this.mainMenuSeparator2.Size = new System.Drawing.Size(229, 6); // // openFileLocationMainMenu // this.openFileLocationMainMenu.Name = "openFileLocationMainMenu"; - this.openFileLocationMainMenu.Size = new System.Drawing.Size(195, 22); + this.openFileLocationMainMenu.Size = new System.Drawing.Size(232, 22); this.openFileLocationMainMenu.Text = "Open File Location"; this.openFileLocationMainMenu.Click += new System.EventHandler(this.OpenFileLocationMainMenu_Click); // // deleteFileMainMenu // this.deleteFileMainMenu.Name = "deleteFileMainMenu"; - this.deleteFileMainMenu.Size = new System.Drawing.Size(195, 22); + this.deleteFileMainMenu.Size = new System.Drawing.Size(232, 22); this.deleteFileMainMenu.Text = "Delete File"; this.deleteFileMainMenu.Click += new System.EventHandler(this.DeleteFileToolStripMenuItem_Click); // // mainMenuSeparator3 // this.mainMenuSeparator3.Name = "mainMenuSeparator3"; - this.mainMenuSeparator3.Size = new System.Drawing.Size(192, 6); + this.mainMenuSeparator3.Size = new System.Drawing.Size(229, 6); // // exitMainMenu // this.exitMainMenu.Name = "exitMainMenu"; this.exitMainMenu.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Q))); - this.exitMainMenu.Size = new System.Drawing.Size(195, 22); + this.exitMainMenu.Size = new System.Drawing.Size(232, 22); this.exitMainMenu.Text = "Exit"; this.exitMainMenu.Click += new System.EventHandler(this.ExitMainMenu_Click); // @@ -1327,5 +1338,6 @@ public void InitializeComponent() private System.Windows.Forms.ToolStripStatusLabel statusPanelModifiedLabel; private System.Windows.Forms.ToolStripStatusLabel statusPanelSizeLabel; private System.Windows.Forms.Timer statusPanelTimer; + private System.Windows.Forms.ToolStripMenuItem saveCloseFileMainMenu; } } diff --git a/Crypto Notepad/MainForm.cs b/Crypto Notepad/MainForm.cs index 31068db..b76e11e 100644 --- a/Crypto Notepad/MainForm.cs +++ b/Crypto Notepad/MainForm.cs @@ -625,6 +625,7 @@ public void MenuIcons(bool menuIcons) checkForUpdatesMainMenu.Image = Resources.upload_cloud; aboutMainMenu.Image = Resources.information; alwaysOnTopMainMenu.Image = Resources.applications_blue; + saveCloseFileMainMenu.Image = Resources.disk__minus; } else { @@ -1104,6 +1105,23 @@ private void SaveAsMainMenu_Click(object sender, EventArgs e) StatusPanelFileInfo(); } + private async void SaveCloseFileMainMenu_Click(object sender, EventArgs e) + { + using (StreamWriter writer = new StreamWriter(filePath)) + { + writer.Write(AES.Encrypt(richTextBox.Text, PublicVar.encryptionKey.Get(), null, settings.HashAlgorithm, Convert.ToInt32(settings.PasswordIterations), Convert.ToInt32(settings.KeySize))); + writer.Close(); + } + PublicVar.encryptionKey.Set(null); + richTextBox.Clear(); + PublicVar.openFileName = ""; + filePath = ""; + Text = PublicVar.appName; + statusPanelModifiedLabel.Text = "Modified"; + statusPanelModifiedLabel.ToolTipText = null; + statusPanelSizeLabel.Text = "Size"; + } + private void OpenFileLocationMainMenu_Click(object sender, EventArgs e) { Process.Start("explorer.exe", @"/select, " + filePath); @@ -1147,11 +1165,13 @@ private void FileMainMenu_DropDownOpened(object sender, EventArgs e) { openFileLocationMainMenu.Enabled = false; deleteFileMainMenu.Enabled = false; + saveCloseFileMainMenu.Enabled = false; } else { openFileLocationMainMenu.Enabled = true; deleteFileMainMenu.Enabled = true; + saveCloseFileMainMenu.Enabled = true; } } /*File*/ diff --git a/Crypto Notepad/Properties/Resources.Designer.cs b/Crypto Notepad/Properties/Resources.Designer.cs index 728d8d6..ee48d2b 100644 --- a/Crypto Notepad/Properties/Resources.Designer.cs +++ b/Crypto Notepad/Properties/Resources.Designer.cs @@ -130,6 +130,16 @@ internal static System.Drawing.Bitmap cross_button { } } + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap disk__minus { + get { + object obj = ResourceManager.GetObject("disk__minus", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Поиск локализованного ресурса типа System.Drawing.Bitmap. /// diff --git a/Crypto Notepad/Properties/Resources.resx b/Crypto Notepad/Properties/Resources.resx index d75d08f..563549b 100644 --- a/Crypto Notepad/Properties/Resources.resx +++ b/Crypto Notepad/Properties/Resources.resx @@ -1014,15 +1014,30 @@ + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAABl0RVh0U29m + dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAFSSURBVDhPpdPBKwRhGMfx92j/AVquLkoODg5ikz1I + SltqS0kkTnLCYR0oaU8upA2rjVJSkr0hamUlXmSVtkSZtpnMNHa3mcwYM37muTt411Pf46ee5/AwAP+K + daTUsF/ajwtGJsxCSSU9deGU47lvLNx6mL9yMJu1MZP5wOSJifEjA0PHBiKnJkJnFhovPxG8+ULw3C6T + ZW2rBT6WfsfogY6RfQ3De28Y3JUxsFNA//Yrolsv6Es9IZLMo3ftET2JB3Sv3KNr+Q410xlOJ3D/loqG + LGtfl7nneXBdVygyZFlrQuKO48C2baHIkGUtS8/csiyYpikUGbKseTHPDcNAsVgUigxZ1hTP8VKpBE3T + hCJDljXMXXNd1yHLslBkyLL6WJarqgpJkoQiQ5bVTRxyWklRFKHIkGVVnbGNQHSTVxJZ5k/Ar9qvVjAy + gV9f9O+B/QDSyg0U5iAfSgAAAABJRU5ErkJggg== + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAABUklEQVQ4T6XTwSsEYRjH8fdo - /wFari5KDg4OYpM9SEpbaktJJE5ywmEdKGlPLqQNq41SUpK9IWplJV5klbZEmbaZzDR2t5nMGDN+5rk7 - eNdT3+OnnufwMAD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