Skip to content

Commit 0a0564d

Browse files
ferrariofilippoyaira2
authored andcommitted
Added Test button
1 parent 53e83f1 commit 0a0564d

File tree

3 files changed

+94
-16
lines changed

3 files changed

+94
-16
lines changed

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4049,4 +4049,10 @@
40494049
<data name="PathOrAlias" xml:space="preserve">
40504050
<value>Path or alias</value>
40514051
</data>
4052+
<data name="InvalidPath" xml:space="preserve">
4053+
<value>Invalid path</value>
4054+
</data>
4055+
<data name="Test" xml:space="preserve">
4056+
<value>Test</value>
4057+
</data>
40524058
</root>

src/Files.App/ViewModels/Settings/DevToolsViewModel.cs

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/Files.App/Views/Settings/DevToolsPage.xaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,49 @@
109109
x:Name="PickIDEExe"
110110
Command="{x:Bind ViewModel.OpenFilePickerForIDECommand, Mode=OneWay}"
111111
Content="{helpers:ResourceString Name=Browse}" />
112+
<Button
113+
x:Name="TestIDE"
114+
Command="{x:Bind ViewModel.TestIDECommand, Mode=OneWay}"
115+
Content="{helpers:ResourceString Name=Test}"
116+
IsEnabled="{x:Bind ViewModel.IDEPathTested, Converter={StaticResource BoolNegationConverter}, Mode=OneWay}" />
112117
</StackPanel>
113118

119+
<Grid
120+
x:Name="InvalidPathWarning"
121+
Grid.Column="2"
122+
Padding="12,4"
123+
VerticalAlignment="Stretch"
124+
x:Load="{x:Bind ViewModel.IsEditingIDEConfig, Mode=OneWay}"
125+
Background="{ThemeResource SystemFillColorCriticalBackgroundBrush}"
126+
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
127+
BorderThickness="1"
128+
ColumnSpacing="8"
129+
CornerRadius="4"
130+
ToolTipService.ToolTip="{helpers:ResourceString Name=InvalidLocation}"
131+
Visibility="{x:Bind ViewModel.IsIDEPathValid, Mode=OneWay, Converter={StaticResource InvertedBoolVisibilityConverter}}">
132+
<Grid.ColumnDefinitions>
133+
<ColumnDefinition Width="Auto" />
134+
<ColumnDefinition Width="Auto" />
135+
</Grid.ColumnDefinitions>
136+
<TextBlock
137+
VerticalAlignment="Center"
138+
AutomationProperties.AccessibilityView="Raw"
139+
FontFamily="{ThemeResource SymbolThemeFontFamily}"
140+
FontSize="{StaticResource InfoBarIconFontSize}"
141+
Foreground="{ThemeResource InfoBarErrorSeverityIconBackground}"
142+
Text="{StaticResource InfoBarIconBackgroundGlyph}" />
143+
<TextBlock
144+
VerticalAlignment="Center"
145+
FontFamily="{ThemeResource SymbolThemeFontFamily}"
146+
FontSize="{StaticResource InfoBarIconFontSize}"
147+
Foreground="{ThemeResource InfoBarInformationalSeverityIconForeground}"
148+
Text="{StaticResource InfoBarErrorIconGlyph}" />
149+
<TextBlock
150+
Grid.Column="1"
151+
VerticalAlignment="Center"
152+
Text="{helpers:ResourceString Name=InvalidPath}" />
153+
</Grid>
154+
114155
<TextBlock
115156
x:Name="IDEFriendlyName"
116157
Grid.Row="1"

0 commit comments

Comments
 (0)