@@ -18,6 +18,7 @@ public sealed partial class DevToolsViewModel : ObservableObject
1818 public ICommand CancelIDEChangesCommand { get ; }
1919 public ICommand SaveIDEChangesCommand { get ; }
2020 public ICommand OpenFilePickerForIDECommand { get ; }
21+ public ICommand TestIDECommand { get ; }
2122
2223 // Enabled when there are saved credentials
2324 private bool _IsLogoutEnabled ;
@@ -34,18 +35,21 @@ public bool IsEditingIDEConfig
3435 set => SetProperty ( ref _IsEditingIDEConfig , value ) ;
3536 }
3637
37- private bool _CanSaveIDEChanges ;
38- public bool CanSaveIDEChanges
38+ public bool CanSaveIDEChanges =>
39+ IsFriendlyNameValid && IsIDEPathValid && _IDEPathTested ;
40+
41+ private bool _IsIDEPathValid ;
42+ public bool IsIDEPathValid
3943 {
40- get => _CanSaveIDEChanges ;
41- set => SetProperty ( ref _CanSaveIDEChanges , value ) ;
44+ get => _IsIDEPathValid ;
45+ set => SetProperty ( ref _IsIDEPathValid , value ) ;
4246 }
4347
4448 private bool _IsFriendlyNameValid ;
4549 public bool IsFriendlyNameValid
4650 {
47- get => _IsFriendlyNameValid ;
48- set => SetProperty ( ref _IsFriendlyNameValid , value ) ;
51+ get => _IsIDEPathValid ;
52+ set => SetProperty ( ref _IsIDEPathValid , value ) ;
4953 }
5054
5155 private string _IDEPath ;
@@ -55,7 +59,13 @@ public string IDEPath
5559 set
5660 {
5761 if ( SetProperty ( ref _IDEPath , value ) )
58- CanSaveIDEChanges = IsFriendlyNameValid && ! string . IsNullOrWhiteSpace ( IDEPath ) ;
62+ {
63+ IsIDEPathValid =
64+ ! string . IsNullOrWhiteSpace ( value ) &&
65+ ! value . Contains ( '\" ' ) &&
66+ ! value . Contains ( '\' ' ) ;
67+ IDEPathTested = false ;
68+ }
5969 }
6070 }
6171
@@ -67,15 +77,23 @@ public string IDEFriendlyName
6777 {
6878 if ( SetProperty ( ref _IDEFriendlyName , value ) )
6979 {
70- IsFriendlyNameValid =
71- ! string . IsNullOrEmpty ( value ) &&
72- ! value . Contains ( '\" ' ) &&
73- ! value . Contains ( '\' ' ) ;
74- CanSaveIDEChanges = IsFriendlyNameValid && ! string . IsNullOrWhiteSpace ( IDEPath ) ;
80+ IsFriendlyNameValid = ! string . IsNullOrEmpty ( value ) ;
81+ OnPropertyChanged ( nameof ( CanSaveIDEChanges ) ) ;
7582 }
7683 }
7784 }
7885
86+ private bool _IDEPathTested = false ;
87+ public bool IDEPathTested
88+ {
89+ get => _IDEPathTested ;
90+ set
91+ {
92+ if ( SetProperty ( ref _IDEPathTested , value ) )
93+ OnPropertyChanged ( nameof ( CanSaveIDEChanges ) ) ;
94+ }
95+ }
96+
7997 public DevToolsViewModel ( )
8098 {
8199 // Open in IDE options
@@ -85,8 +103,8 @@ public DevToolsViewModel()
85103
86104 IDEPath = DevToolsSettingsService . IDEPath ;
87105 IDEFriendlyName = DevToolsSettingsService . FriendlyIDEName ;
106+ IsIDEPathValid = true ;
88107 IsFriendlyNameValid = true ;
89- CanSaveIDEChanges = false ;
90108
91109 IsLogoutEnabled = GitHelpers . GetSavedCredentials ( ) != string . Empty ;
92110
@@ -96,6 +114,7 @@ public DevToolsViewModel()
96114 SaveIDEChangesCommand = new RelayCommand ( DoSaveIDEChanges ) ;
97115 StartEditingIDECommand = new RelayCommand ( DoStartEditingIDE ) ;
98116 OpenFilePickerForIDECommand = new RelayCommand ( DoOpenFilePickerForIDE ) ;
117+ TestIDECommand = new RelayCommand ( DoTestIDE ) ;
99118 }
100119
101120 private string selectedOpenInIDEOption ;
@@ -131,13 +150,15 @@ private void DoCancelIDEChanges()
131150 IsEditingIDEConfig = false ;
132151 IDEPath = DevToolsSettingsService . IDEPath ;
133152 IDEFriendlyName = DevToolsSettingsService . FriendlyIDEName ;
153+ IsIDEPathValid = true ;
154+ IsFriendlyNameValid = true ;
134155 }
135156
136157 private void DoSaveIDEChanges ( )
137158 {
138159 IsEditingIDEConfig = false ;
160+ IsIDEPathValid = true ;
139161 IsFriendlyNameValid = true ;
140- CanSaveIDEChanges = false ;
141162 DevToolsSettingsService . IDEPath = IDEPath ;
142163 DevToolsSettingsService . FriendlyIDEName = IDEFriendlyName ;
143164 }
@@ -149,15 +170,25 @@ private void DoStartEditingIDE()
149170
150171 private void DoOpenFilePickerForIDE ( )
151172 {
152- var result = CommonDialogService . Open_FileOpenDialog (
173+ CommonDialogService . Open_FileOpenDialog (
153174 MainWindow . Instance . WindowHandle ,
154175 false ,
155- [ "*.exe;*.bat;*.cmd;*.ahk" ] ,
176+ [ "*.exe;*.bat;*.cmd;*.ahk" ] ,
156177 Environment . SpecialFolder . ProgramFiles ,
157178 out var filePath
158179 ) ;
159180
160181 IDEPath = filePath ;
161182 }
183+
184+ private async void DoTestIDE ( )
185+ {
186+ IDEPathTested = await Win32Helper . RunPowershellCommandAsync (
187+ $ "& \' { IDEPath } \' ",
188+ PowerShellExecutionOptions . None // PowerShellExecutionOptions.Hidden doesn't work with some IDEs if path is not provided
189+ ) ;
190+
191+ IsIDEPathValid = _IDEPathTested ;
192+ }
162193 }
163194}
0 commit comments