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 @@ -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 @@ -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 @@ -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;
}

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

@ -19,6 +19,12 @@ namespace SearchAndReplace @@ -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 @@ -40,13 +46,15 @@ namespace SearchAndReplace
/// </summary>
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;
/// <summary>
/// Shows a wait dialog.
@ -92,6 +100,7 @@ namespace SearchAndReplace @@ -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 @@ -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 @@ -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 @@ -237,7 +254,7 @@ namespace SearchAndReplace
public bool IsCancelled {
get {
return false;
return cancelled;
}
}
}

Loading…
Cancel
Save