@@ -36,6 +36,7 @@ enum Trigger { Cancel = 0, Auth = 1, Create = 2, Clone = 3, Publish = 4, Next, F
36
36
readonly CompositeDisposable disposables = new CompositeDisposable ( ) ;
37
37
readonly StateMachine < UIViewType , Trigger > machine ;
38
38
Subject < UserControl > transition ;
39
+ Subject < bool > completion ;
39
40
UIControllerFlow currentFlow ;
40
41
NotifyCollectionChangedEventHandler connectionAdded ;
41
42
@@ -118,17 +119,10 @@ public UIController(IUIProvider uiProvider, IRepositoryHosts hosts, IExportFacto
118
119
. Permit ( Trigger . Next , UIViewType . End ) ;
119
120
120
121
machine . Configure ( UIViewType . End )
121
- . OnEntry ( ( ) =>
122
- {
123
- uiProvider . RemoveService ( typeof ( IConnection ) ) ;
124
- transition . OnCompleted ( ) ;
125
- } )
122
+ . OnEntryFrom ( Trigger . Cancel , ( ) => End ( false ) )
123
+ . OnEntryFrom ( Trigger . Next , ( ) => End ( true ) )
126
124
. Permit ( Trigger . Next , UIViewType . Finished ) ;
127
125
128
- // it might be useful later to check which triggered
129
- // made us enter here (Cancel or Next) and set a final
130
- // result accordingly, which is why UIViewType.End only
131
- // allows a Next trigger
132
126
machine . Configure ( UIViewType . Finished ) ;
133
127
}
134
128
@@ -142,6 +136,27 @@ public IObservable<UserControl> SelectFlow(UIControllerFlow choice)
142
136
return transition ;
143
137
}
144
138
139
+ /// <summary>
140
+ /// Allows listening to the completion state of the ui flow - whether
141
+ /// it was completed because it was cancelled or whether it succeeded.
142
+ /// </summary>
143
+ /// <returns>true for success, false for cancel</returns>
144
+ public IObservable < bool > ListenToCompletionState ( )
145
+ {
146
+ if ( completion == null )
147
+ completion = new Subject < bool > ( ) ;
148
+ return completion ;
149
+ }
150
+
151
+ void End ( bool success )
152
+ {
153
+ uiProvider . RemoveService ( typeof ( IConnection ) ) ;
154
+ transition . OnCompleted ( ) ;
155
+ completion ? . OnNext ( success ) ;
156
+ completion ? . OnCompleted ( ) ;
157
+ completion = null ;
158
+ }
159
+
145
160
void RunView ( UIViewType viewType )
146
161
{
147
162
var view = CreateViewAndViewModel ( viewType ) ;
@@ -281,6 +296,7 @@ protected virtual void Dispose(bool disposing)
281
296
Debug . WriteLine ( "Disposing ({0})" , GetHashCode ( ) ) ;
282
297
disposables . Dispose ( ) ;
283
298
transition ? . Dispose ( ) ;
299
+ completion ? . Dispose ( ) ;
284
300
if ( connectionAdded != null )
285
301
connectionManager . Connections . CollectionChanged -= connectionAdded ;
286
302
connectionAdded = null ;
0 commit comments