Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 3d2b580

Browse files
committed
Consolidate PathError into PathWarning
There was an issue with PathError appearing at the top. When the error appeared, the repository list would move down causing a different repository to be selected. This would clause flickering between two repositories. This commit consolidates PathError into PathWarning (which appears above the path which is being validated). This avoids the flicker and puts the warning next to the text box which it applies to. The logic to block clone or open when there is a file in the way has been moved to the commands' `canExecute` observable.
1 parent 527b1d1 commit 3d2b580

File tree

4 files changed

+10
-34
lines changed

4 files changed

+10
-34
lines changed

src/GitHub.App/SampleData/Dialog/Clone/RepositoryCloneViewModelDesigner.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public RepositoryCloneViewModelDesigner()
1616
}
1717

1818
public string Path { get; set; }
19-
public string PathError { get; set; }
2019
public string PathWarning { get; set; }
2120
public int SelectedTabIndex { get; set; }
2221
public string Title => null;

src/GitHub.App/ViewModels/Dialog/Clone/RepositoryCloneViewModel.cs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class RepositoryCloneViewModel : ViewModelBase, IRepositoryCloneViewModel
2929
readonly IReadOnlyList<IRepositoryCloneTabViewModel> tabs;
3030
string path;
3131
IRepositoryModel previousRepository;
32-
ObservableAsPropertyHelper<string> pathError;
3332
ObservableAsPropertyHelper<string> pathWarning;
3433
int selectedTabIndex;
3534

@@ -63,25 +62,19 @@ public RepositoryCloneViewModel(
6362
Path = service.DefaultClonePath;
6463
repository.Subscribe(x => UpdatePath(x));
6564

66-
pathError = Observable.CombineLatest(
67-
repository,
68-
this.WhenAnyValue(x => x.Path),
69-
ValidatePathError)
70-
.ToProperty(this, x => x.PathError);
71-
7265
pathWarning = Observable.CombineLatest(
7366
repository,
7467
this.WhenAnyValue(x => x.Path),
7568
ValidatePathWarning)
7669
.ToProperty(this, x => x.PathWarning);
7770

7871
var canClone = Observable.CombineLatest(
79-
repository, this.WhenAnyValue(x => x.Path), this.WhenAnyValue(x => x.PathError),
80-
(repo, path, error) => repo != null && error == null && !service.DestinationDirectoryExists(path));
72+
repository, this.WhenAnyValue(x => x.Path),
73+
(repo, path) => repo != null && !service.DestinationFileExists(path) && !service.DestinationDirectoryExists(path));
8174

8275
var canOpen = Observable.CombineLatest(
83-
repository, this.WhenAnyValue(x => x.Path), this.WhenAnyValue(x => x.PathError),
84-
(repo, path, error) => repo != null && error == null && service.DestinationDirectoryExists(path));
76+
repository, this.WhenAnyValue(x => x.Path),
77+
(repo, path) => repo != null && !service.DestinationFileExists(path) && service.DestinationDirectoryExists(path));
8578

8679
Browse = ReactiveCommand.Create().OnExecuteCompleted(_ => BrowseForDirectory());
8780
Clone = ReactiveCommand.CreateAsyncObservable(
@@ -102,8 +95,6 @@ public string Path
10295
set => this.RaiseAndSetIfChanged(ref path, value);
10396
}
10497

105-
public string PathError => pathError.Value;
106-
10798
public string PathWarning => pathWarning.Value;
10899

109100
public int SelectedTabIndex
@@ -247,22 +238,15 @@ string FindDirWithout(string dir, string match, int levels)
247238
}
248239
}
249240

250-
string ValidatePathError(IRepositoryModel repository, string path)
251-
{
252-
if (repository != null)
253-
{
254-
return service.DestinationFileExists(path) ?
255-
Resources.DestinationAlreadyExists :
256-
null;
257-
}
258-
259-
return null;
260-
}
261-
262241
string ValidatePathWarning(IRepositoryModel repositoryModel, string path)
263242
{
264243
if (repositoryModel != null)
265244
{
245+
if (service.DestinationFileExists(path))
246+
{
247+
return Resources.DestinationAlreadyExists;
248+
}
249+
266250
if (service.DestinationDirectoryExists(path))
267251
{
268252
using (var repository = gitService.GetRepository(path))

src/GitHub.Exports.Reactive/ViewModels/Dialog/Clone/IRepositoryCloneViewModel.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace GitHub.ViewModels.Dialog.Clone
66
{
77
/// <summary>
8-
/// ViewModel for the the Clone Repository dialog
8+
/// ViewModel for the Clone Repository dialog
99
/// </summary>
1010
public interface IRepositoryCloneViewModel : IDialogContentViewModel, IConnectionInitializedViewModel
1111
{
@@ -29,11 +29,6 @@ public interface IRepositoryCloneViewModel : IDialogContentViewModel, IConnectio
2929
/// </summary>
3030
string Path { get; set; }
3131

32-
/// <summary>
33-
/// Gets an error message that explains why <see cref="Path"/> is not valid.
34-
/// </summary>
35-
string PathError { get; }
36-
3732
/// <summary>
3833
/// Gets a warning message that explains why <see cref="Path"/> is suspect.
3934
/// </summary>

src/GitHub.VisualStudio/Views/Dialog/Clone/RepositoryCloneView.xaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
</UserControl.Resources>
2222

2323
<DockPanel>
24-
<ghfvs:InfoPanel Message="{Binding PathError}"/>
25-
2624
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom" HorizontalAlignment="Center">
2725
<ghfvs:OcticonCircleButton
2826
Margin="12"

0 commit comments

Comments
 (0)