From 54a236a1129229f25b99872e3ede338f273f123d Mon Sep 17 00:00:00 2001 From: Andreia Gaita Date: Thu, 11 Dec 2014 13:55:44 +0100 Subject: [PATCH] Fix browsing/monitoring non-git directories Update view model when selecting an empty/non-git directory so that UI refreshes correctly. Make sure the observable for the git directory creation event gets disposed after getting one event, so that FileSystemWatchers listening for creation events don't accumulate if the directory is created more than once. --- SeeGitApp/Extensions/ModelExtensions.cs | 2 +- SeeGitApp/ViewModels/MainWindowViewModel.cs | 28 ++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/SeeGitApp/Extensions/ModelExtensions.cs b/SeeGitApp/Extensions/ModelExtensions.cs index 3b2f8e9..f1000f7 100644 --- a/SeeGitApp/Extensions/ModelExtensions.cs +++ b/SeeGitApp/Extensions/ModelExtensions.cs @@ -64,7 +64,7 @@ public static IObservable CreateGitRepositoryCreationObserv e => e.ChangeType == WatcherChangeTypes.Created && e.FullPath.Equals(expectedGitDirectory, StringComparison.OrdinalIgnoreCase)) - .Throttle(TimeSpan.FromSeconds(1)); + .Take(1); } public static IObservable CreateGitRepositoryChangesObservable(string path) diff --git a/SeeGitApp/ViewModels/MainWindowViewModel.cs b/SeeGitApp/ViewModels/MainWindowViewModel.cs index 8b83a03..5c68e0c 100644 --- a/SeeGitApp/ViewModels/MainWindowViewModel.cs +++ b/SeeGitApp/ViewModels/MainWindowViewModel.cs @@ -57,25 +57,21 @@ private set public void MonitorRepository(string repositoryWorkingPath) { if (repositoryWorkingPath == null) return; - - string gitPath = ModelExtensions.GetGitRepositoryPath(repositoryWorkingPath); - if (!Directory.Exists(gitPath)) - { - MonitorForRepositoryCreation(repositoryWorkingPath); - return; - } - RepositoryPath = repositoryWorkingPath; + string gitPath = ModelExtensions.GetGitRepositoryPath(repositoryWorkingPath); _graphBuilder = _graphBuilderThunk(gitPath); RepositoryPath = Directory.GetParent(gitPath).FullName; - Graph = _graphBuilder.Graph(); + var graph = _graphBuilder.Graph(); - if (_graph.VertexCount > 1) - _graph.LayoutAlgorithmType = "EfficientSugiyama"; - Graph = Graph; + if (graph.VertexCount > 1) + graph.LayoutAlgorithmType = "EfficientSugiyama"; + Graph = graph; - MonitorForRepositoryChanges(gitPath); + if (!Directory.Exists(gitPath)) + MonitorForRepositoryCreation(RepositoryPath); + else + MonitorForRepositoryChanges(gitPath); } private void MonitorForRepositoryCreation(string repositoryWorkingPath) @@ -92,7 +88,11 @@ private void MonitorForRepositoryChanges(string gitRepositoryPath) public void Refresh() { - Graph = _graphBuilder.Graph(); + string gitPath = ModelExtensions.GetGitRepositoryPath(RepositoryPath); + if (!Directory.Exists(gitPath)) + MonitorRepository(RepositoryPath); + else + Graph = _graphBuilder.Graph(); } public bool ToggleSettings()