1+ using System ;
2+ using System . ComponentModel . Composition ;
3+ using System . Reactive . Linq ;
4+ using GitHub . Exports ;
5+ using GitHub . Info ;
6+ using GitHub . Services ;
7+ using GitHub . UI ;
8+ using ReactiveUI ;
9+
10+ namespace GitHub . ViewModels
11+ {
12+ /// <summary>
13+ /// The view model for the "Sign in to GitHub" view in the GitHub pane.
14+ /// </summary>
15+ [ ExportViewModel ( ViewType = UIViewType . LoggedOut ) ]
16+ [ PartCreationPolicy ( CreationPolicy . NonShared ) ]
17+ public class LoggedOutViewModel : BaseViewModel , ILoggedOutViewModel
18+ {
19+ IUIProvider uiProvider ;
20+ IVisualStudioBrowser browser ;
21+
22+ /// <summary>
23+ /// Initializes a new instance of the <see cref="LoggedOutViewModel"/> class.
24+ /// </summary>
25+ [ ImportingConstructor ]
26+ public LoggedOutViewModel ( IUIProvider uiProvider , IVisualStudioBrowser browser )
27+ {
28+ this . uiProvider = uiProvider ;
29+ this . browser = browser ;
30+ SignIn = ReactiveCommand . Create ( ) ;
31+ SignIn . Subscribe ( _ => OnSignIn ( ) ) ;
32+ Register = ReactiveCommand . Create ( ) ;
33+ Register . Subscribe ( _ => OnRegister ( ) ) ;
34+ }
35+
36+ /// <inheritdoc/>
37+ public IReactiveCommand < object > SignIn { get ; }
38+
39+ /// <inheritdoc/>
40+ public IReactiveCommand < object > Register { get ; }
41+
42+ /// <summary>
43+ /// Called when the <see cref="SignIn"/> command is executed.
44+ /// </summary>
45+ void OnSignIn ( )
46+ {
47+ // Show the Sign In dialog. We don't need to listen to the outcome of this: the parent
48+ // GitHubPaneViewModel will listen to RepositoryHosts.IsLoggedInToAnyHost and close
49+ // this view when the user logs in.
50+ uiProvider . SetupUI ( UIControllerFlow . Authentication , null ) ;
51+ uiProvider . RunUI ( ) ;
52+ }
53+
54+ /// <summary>
55+ /// Called when the <see cref="Register"/> command is executed.
56+ /// </summary>
57+ void OnRegister ( )
58+ {
59+ browser . OpenUrl ( GitHubUrls . Pricing ) ;
60+ }
61+ }
62+ }
0 commit comments