Browse Source

Implemented AsynchronousWaitDialog.ShowWaitDialogForAsyncOperation() API.

pull/326/merge
Andreas Weizel 12 years ago
parent
commit
6c6a55d0b7
  1. 9
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormsDesigner/CSharpDesignerLoader.cs
  2. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs
  3. 10
      src/Main/Base/Project/Src/Editor/Commands/FindReferencesCommand.cs
  4. 101
      src/Main/Base/Project/Src/Gui/Dialogs/AsynchronousWaitDialog.cs

9
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormsDesigner/CSharpDesignerLoader.cs

@ -30,6 +30,7 @@ using ICSharpCode.NRefactory.CSharp.Resolver; @@ -30,6 +30,7 @@ using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Refactoring;
using Microsoft.CSharp;
using CSharpBinding.Parser;
@ -239,14 +240,18 @@ namespace CSharpBinding.FormsDesigner @@ -239,14 +240,18 @@ namespace CSharpBinding.FormsDesigner
controlSymbol = designerClass.GetFields(f => f.Name == oldName, GetMemberOptions.IgnoreInheritedMembers)
.SingleOrDefault();
if (controlSymbol != null) {
FindReferenceService.RenameSymbol(controlSymbol, newName, new DummyProgressMonitor())
AsynchronousWaitDialog.ShowWaitDialogForAsyncOperation(
"${res:SharpDevelop.Refactoring.Rename}",
progressMonitor =>
FindReferenceService.RenameSymbol(controlSymbol, newName, progressMonitor)
.ObserveOnUIThread()
.Subscribe(error => SD.MessageService.ShowError(error.Message), // onNext
ex => SD.MessageService.ShowException(ex), // onError
// onCompleted - force refresh of the DesignerCodeFile's parse info, because the code generator
// seems to work with an outdated version, when the document is saved.
() => SD.ParserService.Parse(new FileName(context.DesignerCodeFileDocument.FileName), context.DesignerCodeFileDocument)
);
)
);
}
}

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs

@ -234,7 +234,10 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -234,7 +234,10 @@ namespace ICSharpCode.WpfDesign.AddIn
ISymbol controlSymbol = designerClass.GetFields(f => f.Name == propertyGridView.PropertyGrid.OldName, GetMemberOptions.IgnoreInheritedMembers)
.SingleOrDefault();
if (controlSymbol != null) {
FindReferenceService.RenameSymbol(controlSymbol, propertyGridView.PropertyGrid.Name, new DummyProgressMonitor())
AsynchronousWaitDialog.ShowWaitDialogForAsyncOperation(
"${res:SharpDevelop.Refactoring.Rename}",
progressMonitor =>
FindReferenceService.RenameSymbol(controlSymbol, propertyGridView.PropertyGrid.Name, progressMonitor)
.ObserveOnUIThread()
.Subscribe(error => SD.MessageService.ShowError(error.Message), // onNext
ex => SD.MessageService.ShowException(ex), // onError
@ -244,7 +247,8 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -244,7 +247,8 @@ namespace ICSharpCode.WpfDesign.AddIn
SD.ParserService.ParseAsync(fileName).FireAndForget();
}
}
);
)
);
}
}

10
src/Main/Base/Project/Src/Editor/Commands/FindReferencesCommand.cs

@ -65,10 +65,14 @@ namespace ICSharpCode.SharpDevelop.Editor.Commands @@ -65,10 +65,14 @@ namespace ICSharpCode.SharpDevelop.Editor.Commands
NewSymbolName = entity.Name
};
if ((bool) renameDialog.ShowDialog()) {
using (IProgressMonitor progressMonitor = AsynchronousWaitDialog.ShowWaitDialog("${res:SharpDevelop.Refactoring.Rename}"))
// using (IProgressMonitor progressMonitor = AsynchronousWaitDialog.ShowWaitDialog("${res:SharpDevelop.Refactoring.Rename}"))
AsynchronousWaitDialog.ShowWaitDialogForAsyncOperation(
"${res:SharpDevelop.Refactoring.Rename}",
progressMonitor =>
FindReferenceService.RenameSymbol(entity, renameDialog.NewSymbolName, progressMonitor)
.ObserveOnUIThread()
.Subscribe(error => SD.MessageService.ShowError(error.Message), ex => SD.MessageService.ShowException(ex), () => {});
.ObserveOnUIThread()
.Subscribe(error => SD.MessageService.ShowError(error.Message), ex => SD.MessageService.ShowException(ex), () => {}));
}
}
}

101
src/Main/Base/Project/Src/Gui/Dialogs/AsynchronousWaitDialog.cs

@ -66,6 +66,8 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -66,6 +66,8 @@ namespace ICSharpCode.SharpDevelop.Gui
readonly string defaultTaskName;
readonly CancellationTokenSource cancellation;
readonly ProgressCollector collector;
readonly bool runningInOwnThread;
readonly Action<IProgressMonitor> asyncOperation;
readonly SynchronizationHelper synchronizationHelper = new SynchronizationHelper();
AsynchronousWaitDialogForm dlg;
@ -106,8 +108,8 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -106,8 +108,8 @@ namespace ICSharpCode.SharpDevelop.Gui
{
if (titleName == null)
throw new ArgumentNullException("titleName");
AsynchronousWaitDialog h = new AsynchronousWaitDialog(titleName, defaultTaskName, allowCancel);
h.Start();
AsynchronousWaitDialog h = new AsynchronousWaitDialog(titleName, defaultTaskName, allowCancel, null);
h.StartInThread();
return h;
}
@ -121,8 +123,8 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -121,8 +123,8 @@ namespace ICSharpCode.SharpDevelop.Gui
{
if (titleName == null)
throw new ArgumentNullException("titleName");
using (AsynchronousWaitDialog h = new AsynchronousWaitDialog(titleName, defaultTaskName, true)) {
h.Start();
using (AsynchronousWaitDialog h = new AsynchronousWaitDialog(titleName, defaultTaskName, true, null)) {
h.StartInThread();
try {
action(h);
} catch (OperationCanceledException ex) {
@ -133,12 +135,41 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -133,12 +135,41 @@ namespace ICSharpCode.SharpDevelop.Gui
}
}
private AsynchronousWaitDialog(string titleName, string defaultTaskName, bool allowCancel)
/// <summary>
/// Shows a wait dialog that does not support cancelling and waits for an asynchronous operation to end.
/// </summary>
/// <param name="titleName">Title of the wait dialog</param>
/// <param name="asyncOperation">Asynchronous operation to be executed.</param>
public static void ShowWaitDialogForAsyncOperation(string titleName, Action<IProgressMonitor> asyncOperation)
{
ShowWaitDialogForAsyncOperation(titleName, null, asyncOperation);
}
/// <summary>
/// Shows a wait dialog that does not support cancelling and waits for an asynchronous operation to end.
/// </summary>
/// <param name="titleName">Title of the wait dialog</param>
/// <param name="allowCancel">Specifies whether a cancel button should be shown.</param>
/// <param name="defaultTaskName">The default description text, if no named task is active.</param>
/// <param name="asyncOperation">Asynchronous operation to be executed.</param>
/// <returns>AsynchronousWaitDialog object - you can use it to access the wait dialog's properties.
/// To close the wait dialog, call Dispose() on the AsynchronousWaitDialog object</returns>
public static void ShowWaitDialogForAsyncOperation(string titleName, string defaultTaskName, Action<IProgressMonitor> asyncOperation)
{
if (titleName == null)
throw new ArgumentNullException("titleName");
AsynchronousWaitDialog h = new AsynchronousWaitDialog(titleName, defaultTaskName, false, asyncOperation);
h.StartWithAsyncOperation();
}
private AsynchronousWaitDialog(string titleName, string defaultTaskName, bool allowCancel, Action<IProgressMonitor> asyncOperation)
{
this.titleName = StringParser.Parse(titleName);
this.defaultTaskName = StringParser.Parse(defaultTaskName ?? "${res:Global.PleaseWait}");
if (allowCancel)
this.cancellation = new CancellationTokenSource();
this.asyncOperation = asyncOperation;
this.runningInOwnThread = (asyncOperation == null);
this.collector = new ProgressCollector(synchronizationHelper, allowCancel ? cancellation.Token : CancellationToken.None);
}
#endregion
@ -200,7 +231,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -200,7 +231,7 @@ namespace ICSharpCode.SharpDevelop.Gui
/// <summary>
/// Start waiting thread
/// </summary>
internal void Start()
internal void StartInThread()
{
Thread newThread = new Thread(Run);
newThread.Name = "AsynchronousWaitDialog thread";
@ -213,8 +244,43 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -213,8 +244,43 @@ namespace ICSharpCode.SharpDevelop.Gui
void Run()
{
Thread.Sleep(ShowWaitDialogDelay);
if (collector.ProgressMonitorIsDisposed)
if (CreateDialogForm()) {
if (collector.ShowingDialog) {
Application.Run();
} else {
Application.Run(dlg);
}
}
}
#endregion
internal void StartWithAsyncOperation()
{
// Start asynchronous operation
if (asyncOperation == null)
return;
asyncOperation(collector.ProgressMonitor);
// Wait delay before showing dialog
var timer = new System.Windows.Forms.Timer();
timer.Interval = ShowWaitDialogDelay;
timer.Tick += (sender, e) =>
{
timer.Stop();
timer.Dispose();
// Create and show dialog
if (CreateDialogForm())
dlg.ShowDialog();
};
timer.Start();
}
bool CreateDialogForm()
{
if (collector.ProgressMonitorIsDisposed)
return false;
dlg = new AsynchronousWaitDialogForm(cancellation != null);
dlg.Text = titleName;
@ -230,18 +296,13 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -230,18 +296,13 @@ namespace ICSharpCode.SharpDevelop.Gui
// check IsDisposed once again (we might have missed an event while we initialized the dialog):
if (collector.ProgressMonitorIsDisposed) {
dlg.Dispose();
return;
return false;
}
progress_PropertyChanged(null, new System.ComponentModel.PropertyChangedEventArgs("TaskName"));
if (collector.ShowingDialog) {
Application.Run();
} else {
Application.Run(dlg);
}
return true;
}
#endregion
/// <summary>
/// Closes the wait dialog.
@ -249,7 +310,8 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -249,7 +310,8 @@ namespace ICSharpCode.SharpDevelop.Gui
void progress_ProgressMonitorDisposed(object sender, EventArgs e)
{
dlg.Dispose();
Application.ExitThread();
if (runningInOwnThread)
Application.ExitThread();
}
bool reshowTimerRunning = false;
@ -267,8 +329,13 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -267,8 +329,13 @@ namespace ICSharpCode.SharpDevelop.Gui
timer.Tick += delegate {
timer.Dispose();
reshowTimerRunning = false;
if (!collector.ShowingDialog)
dlg.Show();
if (!collector.ShowingDialog) {
if (runningInOwnThread)
dlg.Show();
else
if (!dlg.Visible)
dlg.ShowDialog();
}
};
timer.Start();
}

Loading…
Cancel
Save