Skip to content

Commit 6ac7d6d

Browse files
ferrariofilippoyaira2
authored andcommitted
Added file picker
1 parent 1f965d8 commit 6ac7d6d

File tree

4 files changed

+61
-8
lines changed

4 files changed

+61
-8
lines changed

src/Files.App/Actions/Open/OpenInIDEAction.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
4848
private void DevSettings_PropertyChanged(object? sender, PropertyChangedEventArgs e)
4949
{
5050
if (e.PropertyName == nameof(IDevToolsSettingsService.IDEPath))
51+
{
5152
OnPropertyChanged(nameof(IsExecutable));
53+
}
54+
else if (e.PropertyName == nameof(IDevToolsSettingsService.FriendlyIDEName))
55+
{
56+
OnPropertyChanged(nameof(Label));
57+
OnPropertyChanged(nameof(Description));
58+
}
5259
}
5360
}
5461
}

src/Files.App/Actions/Open/OpenRepoInIDEAction.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
4545
private void DevSettings_PropertyChanged(object? sender, PropertyChangedEventArgs e)
4646
{
4747
if (e.PropertyName == nameof(IDevToolsSettingsService.IDEPath))
48+
{
4849
OnPropertyChanged(nameof(IsExecutable));
50+
}
51+
else if (e.PropertyName == nameof(IDevToolsSettingsService.FriendlyIDEName))
52+
{
53+
OnPropertyChanged(nameof(Label));
54+
OnPropertyChanged(nameof(Description));
55+
}
4956
}
5057
}
5158
}

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

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public sealed partial class DevToolsViewModel : ObservableObject
99
{
1010
protected readonly IFileTagsSettingsService FileTagsSettingsService = Ioc.Default.GetRequiredService<IFileTagsSettingsService>();
1111
protected readonly IDevToolsSettingsService DevToolsSettingsService = Ioc.Default.GetRequiredService<IDevToolsSettingsService>();
12+
private readonly ICommonDialogService CommonDialogService = Ioc.Default.GetRequiredService<ICommonDialogService>();
1213

1314
public Dictionary<OpenInIDEOption, string> OpenInIDEOptions { get; private set; } = [];
1415
public ICommand RemoveCredentialsCommand { get; }
@@ -37,21 +38,42 @@ public bool IsEditingIDEConfig
3738
public bool CanSaveIDEChanges
3839
{
3940
get => _CanSaveIDEChanges;
40-
set => SetProperty(ref _CanSaveIDEChanges, value);
41+
set => SetProperty(ref _CanSaveIDEChanges, value);
42+
}
43+
44+
private bool _IsFriendlyNameValid;
45+
public bool IsFriendlyNameValid
46+
{
47+
get => _IsFriendlyNameValid;
48+
set => SetProperty(ref _IsFriendlyNameValid, value);
4149
}
4250

4351
private string _IDEPath;
4452
public string IDEPath
4553
{
4654
get => _IDEPath;
47-
set => SetProperty(ref _IDEPath, value);
55+
set
56+
{
57+
if (SetProperty(ref _IDEPath, value))
58+
CanSaveIDEChanges = IsFriendlyNameValid && !string.IsNullOrWhiteSpace(IDEPath);
59+
}
4860
}
4961

5062
private string _IDEFriendlyName;
5163
public string IDEFriendlyName
5264
{
5365
get => _IDEFriendlyName;
54-
set => SetProperty(ref _IDEFriendlyName, value);
66+
set
67+
{
68+
if (SetProperty(ref _IDEFriendlyName, value))
69+
{
70+
IsFriendlyNameValid =
71+
!string.IsNullOrEmpty(value) &&
72+
!value.Contains('\"') &&
73+
!value.Contains('\'');
74+
CanSaveIDEChanges = IsFriendlyNameValid && !string.IsNullOrWhiteSpace(IDEPath);
75+
}
76+
}
5577
}
5678

5779
public DevToolsViewModel()
@@ -63,6 +85,8 @@ public DevToolsViewModel()
6385

6486
IDEPath = DevToolsSettingsService.IDEPath;
6587
IDEFriendlyName = DevToolsSettingsService.FriendlyIDEName;
88+
IsFriendlyNameValid = true;
89+
CanSaveIDEChanges = false;
6690

6791
IsLogoutEnabled = GitHelpers.GetSavedCredentials() != string.Empty;
6892

@@ -112,6 +136,8 @@ private void DoCancelIDEChanges()
112136
private void DoSaveIDEChanges()
113137
{
114138
IsEditingIDEConfig = false;
139+
IsFriendlyNameValid = true;
140+
CanSaveIDEChanges = false;
115141
DevToolsSettingsService.IDEPath = IDEPath;
116142
DevToolsSettingsService.FriendlyIDEName = IDEFriendlyName;
117143
}
@@ -123,7 +149,15 @@ private void DoStartEditingIDE()
123149

124150
private void DoOpenFilePickerForIDE()
125151
{
126-
152+
var result = CommonDialogService.Open_FileOpenDialog(
153+
MainWindow.Instance.WindowHandle,
154+
false,
155+
[ "*.exe;*.bat;*.cmd;*.ahk" ],
156+
Environment.SpecialFolder.ProgramFiles,
157+
out var filePath
158+
);
159+
160+
IDEPath = filePath;
127161
}
128162
}
129163
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@
7676
Text="{helpers:ResourceString Name=DefaultIDE}"
7777
TextTrimming="CharacterEllipsis" />
7878

79+
<TextBlock
80+
Grid.Column="1"
81+
VerticalAlignment="Center"
82+
FontWeight="SemiBold"
83+
Text="{x:Bind ViewModel.IDEFriendlyName, Mode=TwoWay}"
84+
Visibility="{x:Bind ViewModel.IsEditingIDEConfig, Converter={StaticResource InvertedBoolVisibilityConverter}, Mode=OneWay}" />
85+
7986
<StackPanel
8087
Grid.Column="1"
8188
Orientation="Horizontal"
@@ -85,8 +92,7 @@
8592
x:Name="IDEFriendlyNameTextBox"
8693
Width="200"
8794
VerticalAlignment="Center"
88-
Text="{x:Bind ViewModel.IDEFriendlyName, Mode=TwoWay}"
89-
Visibility="{x:Bind ViewModel.IsEditingIDEConfig, Converter={StaticResource BoolVisibilityConverter}, Mode=OneWay}">
95+
Text="{x:Bind ViewModel.IDEFriendlyName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
9096
<TextBox.Resources>
9197
<SolidColorBrush x:Key="TextControlBackgroundFocused" Color="{ThemeResource SolidBackgroundFillColorSecondary}" />
9298
</TextBox.Resources>
@@ -96,7 +102,6 @@
96102
x:Name="PickIDEExe"
97103
Grid.Column="1"
98104
Command="{x:Bind ViewModel.OpenFilePickerForIDECommand, Mode=OneWay}"
99-
CommandParameter="{x:Bind XamlRoot, Mode=OneWay}"
100105
Content="{helpers:ResourceString Name=Browse}" />
101106
</StackPanel>
102107

@@ -124,7 +129,7 @@
124129
ColumnSpacing="8"
125130
CornerRadius="4"
126131
ToolTipService.ToolTip="{helpers:ResourceString Name=ErrorInputEmpty}"
127-
Visibility="{x:Bind ViewModel.CanSaveIDEChanges, Mode=OneWay, Converter={StaticResource InvertedBoolVisibilityConverter}}">
132+
Visibility="{x:Bind ViewModel.IsFriendlyNameValid, Mode=OneWay, Converter={StaticResource InvertedBoolVisibilityConverter}}">
128133
<Grid.ColumnDefinitions>
129134
<ColumnDefinition Width="Auto" />
130135
<ColumnDefinition Width="Auto" />

0 commit comments

Comments
 (0)