Browse Source

Add cancel button to AsynchronousWaitDialog.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2061 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
a3f37285fb
  1. 23
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/AsynchronousWaitDialog.Designer.cs
  2. 21
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/AsynchronousWaitDialog.cs

23
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/AsynchronousWaitDialog.Designer.cs generated

@ -36,6 +36,7 @@ namespace SearchAndReplace
{ {
this.taskLabel = new System.Windows.Forms.Label(); this.taskLabel = new System.Windows.Forms.Label();
this.progressBar = new System.Windows.Forms.ProgressBar(); this.progressBar = new System.Windows.Forms.ProgressBar();
this.cancelButton = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// taskLabel // taskLabel
@ -49,19 +50,32 @@ namespace SearchAndReplace
// //
// progressBar // progressBar
// //
this.progressBar.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.progressBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.progressBar.Location = new System.Drawing.Point(12, 58); this.progressBar.Location = new System.Drawing.Point(12, 58);
this.progressBar.Name = "progressBar"; 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.Style = System.Windows.Forms.ProgressBarStyle.Marquee;
this.progressBar.TabIndex = 1; 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 // 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.ControlBox = false;
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.progressBar); this.Controls.Add(this.progressBar);
this.Controls.Add(this.taskLabel); this.Controls.Add(this.taskLabel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
@ -70,6 +84,7 @@ namespace SearchAndReplace
this.Text = "AsynchronousWaitDialog"; this.Text = "AsynchronousWaitDialog";
this.ResumeLayout(false); this.ResumeLayout(false);
} }
internal System.Windows.Forms.Button cancelButton;
internal System.Windows.Forms.ProgressBar progressBar; internal System.Windows.Forms.ProgressBar progressBar;
internal System.Windows.Forms.Label taskLabel; internal System.Windows.Forms.Label taskLabel;
} }

21
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/AsynchronousWaitDialog.cs

@ -19,6 +19,12 @@ namespace SearchAndReplace
internal AsynchronousWaitDialogForm() internal AsynchronousWaitDialogForm()
{ {
InitializeComponent(); InitializeComponent();
cancelButton.Text = ResourceService.GetString("Global.CancelButtonText");
}
void CancelButtonClick(object sender, System.EventArgs e)
{
cancelButton.Enabled = false;
} }
} }
@ -40,13 +46,15 @@ namespace SearchAndReplace
/// </summary> /// </summary>
public const int ShowWaitDialogDelay = 500; public const int ShowWaitDialogDelay = 500;
readonly object lockObject = new object();
bool disposed; bool disposed;
AsynchronousWaitDialogForm dlg; AsynchronousWaitDialogForm dlg;
object lockObject = new object();
volatile int totalWork; volatile int totalWork;
volatile string titleName; volatile string titleName;
volatile string taskName; volatile string taskName;
volatile int workDone; volatile int workDone;
volatile bool cancelled;
volatile bool allowCancel;
/// <summary> /// <summary>
/// Shows a wait dialog. /// Shows a wait dialog.
@ -92,6 +100,7 @@ namespace SearchAndReplace
return; return;
dlg = new AsynchronousWaitDialogForm(); dlg = new AsynchronousWaitDialogForm();
dlg.Text = StringParser.Parse(titleName); dlg.Text = StringParser.Parse(titleName);
dlg.cancelButton.Click += delegate { cancelled = true; };
UpdateTask(); UpdateTask();
dlg.CreateControl(); dlg.CreateControl();
IntPtr h = dlg.Handle; // force handle creation IntPtr h = dlg.Handle; // force handle creation
@ -171,6 +180,7 @@ namespace SearchAndReplace
totalWork = 0; totalWork = 0;
lock (lockObject) { lock (lockObject) {
this.allowCancel = allowCancel;
this.totalWork = totalWork; this.totalWork = totalWork;
this.taskName = name; this.taskName = name;
if (dlg != null && disposed == false) { if (dlg != null && disposed == false) {
@ -193,6 +203,13 @@ namespace SearchAndReplace
int totalWork = this.totalWork; int totalWork = this.totalWork;
dlg.taskLabel.Text = StringParser.Parse(taskName); 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 (totalWork > 0) {
if (dlg.progressBar.Value > totalWork) { if (dlg.progressBar.Value > totalWork) {
@ -237,7 +254,7 @@ namespace SearchAndReplace
public bool IsCancelled { public bool IsCancelled {
get { get {
return false; return cancelled;
} }
} }
} }

Loading…
Cancel
Save