From a3f37285fb65e1333321b926128b1a93687fd15d Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 19 Nov 2006 20:31:29 +0000 Subject: [PATCH] Add cancel button to AsynchronousWaitDialog. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2061 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Gui/AsynchronousWaitDialog.Designer.cs | 23 +++++++++++++++---- .../Gui/AsynchronousWaitDialog.cs | 21 +++++++++++++++-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/AsynchronousWaitDialog.Designer.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/AsynchronousWaitDialog.Designer.cs index f48d2ed865..9c3acb3851 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/AsynchronousWaitDialog.Designer.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/AsynchronousWaitDialog.Designer.cs @@ -36,6 +36,7 @@ namespace SearchAndReplace { this.taskLabel = new System.Windows.Forms.Label(); this.progressBar = new System.Windows.Forms.ProgressBar(); + this.cancelButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // // taskLabel @@ -49,19 +50,32 @@ namespace SearchAndReplace // // progressBar // - this.progressBar.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) + this.progressBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.progressBar.Location = new System.Drawing.Point(12, 58); this.progressBar.Name = "progressBar"; - this.progressBar.Size = new System.Drawing.Size(311, 27); + this.progressBar.Size = new System.Drawing.Size(235, 22); this.progressBar.Style = System.Windows.Forms.ProgressBarStyle.Marquee; this.progressBar.TabIndex = 1; // + // cancelButton + // + this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Location = new System.Drawing.Point(253, 58); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(75, 23); + this.cancelButton.TabIndex = 2; + this.cancelButton.Text = "button1"; + this.cancelButton.UseVisualStyleBackColor = true; + this.cancelButton.Click += new System.EventHandler(this.CancelButtonClick); + // // AsynchronousWaitDialogForm // - this.ClientSize = new System.Drawing.Size(336, 97); + this.CancelButton = this.cancelButton; + this.ClientSize = new System.Drawing.Size(336, 87); this.ControlBox = false; + this.Controls.Add(this.cancelButton); this.Controls.Add(this.progressBar); this.Controls.Add(this.taskLabel); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; @@ -70,6 +84,7 @@ namespace SearchAndReplace this.Text = "AsynchronousWaitDialog"; this.ResumeLayout(false); } + internal System.Windows.Forms.Button cancelButton; internal System.Windows.Forms.ProgressBar progressBar; internal System.Windows.Forms.Label taskLabel; } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/AsynchronousWaitDialog.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/AsynchronousWaitDialog.cs index f57bafc5fe..ffd35e1051 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/AsynchronousWaitDialog.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/AsynchronousWaitDialog.cs @@ -19,6 +19,12 @@ namespace SearchAndReplace internal AsynchronousWaitDialogForm() { InitializeComponent(); + cancelButton.Text = ResourceService.GetString("Global.CancelButtonText"); + } + + void CancelButtonClick(object sender, System.EventArgs e) + { + cancelButton.Enabled = false; } } @@ -40,13 +46,15 @@ namespace SearchAndReplace /// public const int ShowWaitDialogDelay = 500; + readonly object lockObject = new object(); bool disposed; AsynchronousWaitDialogForm dlg; - object lockObject = new object(); volatile int totalWork; volatile string titleName; volatile string taskName; volatile int workDone; + volatile bool cancelled; + volatile bool allowCancel; /// /// Shows a wait dialog. @@ -92,6 +100,7 @@ namespace SearchAndReplace return; dlg = new AsynchronousWaitDialogForm(); dlg.Text = StringParser.Parse(titleName); + dlg.cancelButton.Click += delegate { cancelled = true; }; UpdateTask(); dlg.CreateControl(); IntPtr h = dlg.Handle; // force handle creation @@ -171,6 +180,7 @@ namespace SearchAndReplace totalWork = 0; lock (lockObject) { + this.allowCancel = allowCancel; this.totalWork = totalWork; this.taskName = name; if (dlg != null && disposed == false) { @@ -193,6 +203,13 @@ namespace SearchAndReplace int totalWork = this.totalWork; dlg.taskLabel.Text = StringParser.Parse(taskName); + if (allowCancel) { + dlg.cancelButton.Visible = true; + dlg.progressBar.Width = dlg.cancelButton.Left - 8 - dlg.progressBar.Left; + } else { + dlg.cancelButton.Visible = false; + dlg.progressBar.Width = dlg.cancelButton.Right - dlg.progressBar.Left; + } if (totalWork > 0) { if (dlg.progressBar.Value > totalWork) { @@ -237,7 +254,7 @@ namespace SearchAndReplace public bool IsCancelled { get { - return false; + return cancelled; } } }