From 744e8016fa70c0acd6386455d696507ab9586c99 Mon Sep 17 00:00:00 2001 From: matty <10895809+murrty@users.noreply.github.com> Date: Sat, 24 Oct 2020 22:08:57 -0500 Subject: [PATCH] Better form handling for exiting, etc. --- frmDownloader.Designer.cs | 2 ++ frmMain.cs | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/frmDownloader.Designer.cs b/frmDownloader.Designer.cs index 4272e1b..f196295 100644 --- a/frmDownloader.Designer.cs +++ b/frmDownloader.Designer.cs @@ -231,6 +231,7 @@ private void InitializeComponent() { // btnOpenFolder // this.btnOpenFolder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnOpenFolder.DropDownContextMenu = this.cmThreadActions; this.btnOpenFolder.FlatStyle = System.Windows.Forms.FlatStyle.System; this.btnOpenFolder.Location = new System.Drawing.Point(300, 285); this.btnOpenFolder.Name = "btnOpenFolder"; @@ -299,6 +300,7 @@ private void InitializeComponent() { this.Controls.Add(this.lbFileCountSeparator); this.MinimumSize = new System.Drawing.Size(500, 350); this.Name = "frmDownloader"; + this.Opacity = 0D; this.Text = "unknown chan download"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmDownloader_FormClosing); this.ResumeLayout(false); diff --git a/frmMain.cs b/frmMain.cs index 4ad6909..06ecc88 100644 --- a/frmMain.cs +++ b/frmMain.cs @@ -67,7 +67,7 @@ public void SetItemStatus(string URL, string Status) { int ItemIndex = ThreadURLs.IndexOf(URL); lvThreads.Items[ItemIndex].SubItems[0].Text = Status; } - public bool AddNewThread(string URL) { + public bool AddNewThread(string URL, bool IsHidden = false) { if (Chans.SupportedChan(URL)) { if (ThreadURLs.Contains(URL)) { int ThreadURLIndex = ThreadURLs.IndexOf(URL); @@ -103,6 +103,10 @@ public bool AddNewThread(string URL) { newThread.StartDownload(); ThreadDownloadForms.Add(newThread); newThread.Show(); + if (IsHidden) { + newThread.Hide(); + } + newThread.Opacity = 100; return true; } } @@ -157,20 +161,22 @@ public bool TryExiting() { private void frmMain_Load(object sender, EventArgs e) { if (General.Default.SaveQueueOnExit && !Program.IsDebug) { string[] ThreadArray = Chans.LoadThreads(); - if (ThreadArray.Length > 0) { + if (ThreadArray != null && ThreadArray.Length > 0) { for (int ThreadArrayIndex = 0; ThreadArrayIndex < ThreadArray.Length; ThreadArrayIndex++) { - AddNewThread(ThreadArray[ThreadArrayIndex]); + AddNewThread(ThreadArray[ThreadArrayIndex], true); } } } if (General.Default.ShowTrayIcon) { niTray.Visible = true; } + niTray.ContextMenu = cmTray; } private void frmMain_FormClosing(object sender, FormClosingEventArgs e) { if (General.Default.MinimizeInsteadOfExiting) { + this.Hide(); + niTray.Visible = true; e.Cancel = true; - return; } if (!TryExiting()) { @@ -201,7 +207,7 @@ private void cmItems_Popup(object sender, EventArgs e) { } } private void niTray_MouseDoubleClick(object sender, MouseEventArgs e) { - if (this.Visible == false) { + if (!this.Visible) { this.Show(); this.Activate(); if (!General.Default.ShowTrayIcon) {