@ -1,4 +1,7 @@
@@ -1,4 +1,7 @@
#region Usings
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
#region Usings
using System ;
using System.Collections.Generic ;
@ -32,8 +35,10 @@ namespace ICSharpCode.Data.Core.UI.Windows
@@ -32,8 +35,10 @@ namespace ICSharpCode.Data.Core.UI.Windows
DependencyProperty . Register ( "IsReadyForNextStep" , typeof ( bool ) , typeof ( WizardWindowInnards ) , new FrameworkPropertyMetadata ( false , IsReadyForNextStep_Changed ) ) ;
private WizardWindow _ wizardWindow = null ;
private ObservableCollection < WizardUserControl > _ wizardUserControls = new ObservableCollection < WizardUserControl > ( ) ;
private WizardErrorUserControl _ wizardErrorUserControl = null ;
private WizardUserControl _ currentWizardUserControl = null ;
private int _ currentIndex = 0 ;
private int _ previousIndex = 0 ;
#endregion
@ -47,6 +52,15 @@ namespace ICSharpCode.Data.Core.UI.Windows
@@ -47,6 +52,15 @@ namespace ICSharpCode.Data.Core.UI.Windows
get { return _ wizardUserControls ; }
}
/// <summary>
/// Gets or sets the current WizardWindows' user control for displaying errors.
/// </summary>
public WizardErrorUserControl WizardErrorUserControl
{
get { return _ wizardErrorUserControl ; }
set { _ wizardErrorUserControl = value ; }
}
/// <summary>
/// Returns the current WizardUserControls index of the WizardWindow.
/// </summary>
@ -55,6 +69,7 @@ namespace ICSharpCode.Data.Core.UI.Windows
@@ -55,6 +69,7 @@ namespace ICSharpCode.Data.Core.UI.Windows
get { return _ currentIndex ; }
protected set
{
_ previousIndex = _ currentIndex ;
_ currentIndex = value ;
_ currentWizardUserControl = null ;
OnPropertyChanged ( "CurrentIndex" ) ;
@ -73,10 +88,28 @@ namespace ICSharpCode.Data.Core.UI.Windows
@@ -73,10 +88,28 @@ namespace ICSharpCode.Data.Core.UI.Windows
return _ currentWizardUserControl ;
else
{
_ currentWizardUserControl = _ wizardUserControls . FirstOrDefault ( wuc = > wuc . Index = = _ currentIndex ) ;
BindingBase binding = new Binding ( "IsReadyForNextStep" ) { Source = _ currentWizardUserControl } ;
SetBinding ( WizardWindowInnards . IsReadyForNextStepProperty , binding ) ;
ToggleEnabledButtons ( ) ;
if ( _ currentIndex = = - 1 )
{
_ currentWizardUserControl = _ wizardErrorUserControl ;
}
else
{
_ currentWizardUserControl = _ wizardUserControls . FirstOrDefault ( wuc = > wuc . Index = = _ currentIndex ) ;
BindingBase binding = new Binding ( "IsReadyForNextStep" ) { Source = _ currentWizardUserControl } ;
SetBinding ( WizardWindowInnards . IsReadyForNextStepProperty , binding ) ;
}
if ( _ currentWizardUserControl ! = null )
{
if ( _ currentIndex ! = - 1 & & _ currentIndex - 1 = = _ previousIndex )
_ currentWizardUserControl . Activate ( true ) ;
else
_ currentWizardUserControl . Activate ( false ) ;
ToggleEnabledButtons ( ) ;
}
return _ currentWizardUserControl ;
}
}
@ -106,7 +139,7 @@ namespace ICSharpCode.Data.Core.UI.Windows
@@ -106,7 +139,7 @@ namespace ICSharpCode.Data.Core.UI.Windows
if ( ! IsInitialized )
return ;
if ( C urrentIndex = = 0 )
if ( _ c urrentIndex = = 0 )
{
btnPrevious . IsEnabled = false ;
}
@ -115,7 +148,7 @@ namespace ICSharpCode.Data.Core.UI.Windows
@@ -115,7 +148,7 @@ namespace ICSharpCode.Data.Core.UI.Windows
btnPrevious . IsEnabled = true ;
}
if ( C urrentIndex = = _ wizardUserControls . Count - 1 )
if ( _ currentIndex = = - 1 | | _ c urrentIndex = = _ wizardUserControls . Count - 1 )
{
btnNext . IsEnabled = false ;
}
@ -134,8 +167,6 @@ namespace ICSharpCode.Data.Core.UI.Windows
@@ -134,8 +167,6 @@ namespace ICSharpCode.Data.Core.UI.Windows
}
else
btnFinish . IsEnabled = false ;
CurrentWizardUserControl . OnActivate ( ) ;
}
#endregion
@ -157,6 +188,10 @@ namespace ICSharpCode.Data.Core.UI.Windows
@@ -157,6 +188,10 @@ namespace ICSharpCode.Data.Core.UI.Windows
{
if ( CurrentIndex = = 0 )
return ;
else if ( CurrentIndex = = - 1 )
{
CurrentIndex = _ wizardErrorUserControl . PreviousIndex ;
}
else
{
CurrentIndex - - ;
@ -175,7 +210,25 @@ namespace ICSharpCode.Data.Core.UI.Windows
@@ -175,7 +210,25 @@ namespace ICSharpCode.Data.Core.UI.Windows
private void btnFinish_Click ( object sender , RoutedEventArgs e )
{
_ wizardWindow . OnFinished ( ) ;
try
{
_ wizardWindow . OnFinished ( ) ;
}
catch ( Exception ex )
{
if ( _ wizardErrorUserControl ! = null )
{
_ wizardErrorUserControl . Exception = ex ;
_ wizardErrorUserControl . PreviousIndex = _ currentIndex ;
CurrentIndex = - 1 ;
return ;
}
else
{
throw ex ;
}
}
_ wizardWindow . DialogResult = true ;
_ wizardWindow . Close ( ) ;