@@ -44,8 +44,11 @@ public MainWindowViewModel()
4444
4545 OptionsCommand = ReactiveCommand . CreateFromTask ( ShowOptions ) ;
4646
47- ConnectFTPCommand = ReactiveCommand . CreateFromTask ( ConnectFTP ) ;
48- DisconnectFTPCommand = ReactiveCommand . CreateFromTask ( DisconnectFTP ) ;
47+ var canConnect = this . WhenAnyValue ( vm => vm . IsConnected ) . Select ( isConnected => ! isConnected ) ;
48+ var canDisconnect = this . WhenAnyValue ( vm => vm . IsConnected ) ;
49+
50+ ConnectFTPCommand = ReactiveCommand . CreateFromTask ( ConnectFTP , canConnect ) ;
51+ DisconnectFTPCommand = ReactiveCommand . CreateFromTask ( DisconnectFTP , canDisconnect ) ;
4952
5053 LeftFileViewModel = new FilesPaneViewModel ( this , OnFocusChanged ) ;
5154 RightFileViewModel = new FilesPaneViewModel ( this , OnFocusChanged ) ;
@@ -64,6 +67,13 @@ public MainWindowViewModel()
6467 _progress = new Progress < int > ( Progress_Show ) ;
6568 }
6669
70+ private bool _isConnected ;
71+ public bool IsConnected
72+ {
73+ get => _isConnected ;
74+ set => this . RaiseAndSetIfChanged ( ref _isConnected , value ) ;
75+ }
76+
6777 private void SetLanguage ( )
6878 {
6979 var cultureName = OptionsModel . Instance . Language ;
@@ -569,12 +579,14 @@ public async Task ConnectFTP()
569579 if ( result != null )
570580 {
571581 await RightFileViewModel . ConnectFTP ( result . FtpName , result . IsAnonymous , result . UserName , result . Password ) ;
582+ IsConnected = true ;
572583 }
573584 }
574585
575586 public async Task DisconnectFTP ( )
576587 {
577588 await RightFileViewModel . DisconnectFTP ( ) ;
589+ IsConnected = false ;
578590 }
579591
580592 public async Task ShowOptions ( )
0 commit comments