Skip to content

Commit 54a236a

Browse files
committed
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.
1 parent 7261668 commit 54a236a

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

SeeGitApp/Extensions/ModelExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static IObservable<FileSystemEventArgs> CreateGitRepositoryCreationObserv
6464
e =>
6565
e.ChangeType == WatcherChangeTypes.Created &&
6666
e.FullPath.Equals(expectedGitDirectory, StringComparison.OrdinalIgnoreCase))
67-
.Throttle(TimeSpan.FromSeconds(1));
67+
.Take(1);
6868
}
6969

7070
public static IObservable<FileSystemEventArgs> CreateGitRepositoryChangesObservable(string path)

SeeGitApp/ViewModels/MainWindowViewModel.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,21 @@ private set
5757
public void MonitorRepository(string repositoryWorkingPath)
5858
{
5959
if (repositoryWorkingPath == null) return;
60-
61-
string gitPath = ModelExtensions.GetGitRepositoryPath(repositoryWorkingPath);
62-
if (!Directory.Exists(gitPath))
63-
{
64-
MonitorForRepositoryCreation(repositoryWorkingPath);
65-
return;
66-
}
6760

68-
RepositoryPath = repositoryWorkingPath;
61+
string gitPath = ModelExtensions.GetGitRepositoryPath(repositoryWorkingPath);
6962

7063
_graphBuilder = _graphBuilderThunk(gitPath);
7164
RepositoryPath = Directory.GetParent(gitPath).FullName;
72-
Graph = _graphBuilder.Graph();
65+
var graph = _graphBuilder.Graph();
7366

74-
if (_graph.VertexCount > 1)
75-
_graph.LayoutAlgorithmType = "EfficientSugiyama";
76-
Graph = Graph;
67+
if (graph.VertexCount > 1)
68+
graph.LayoutAlgorithmType = "EfficientSugiyama";
69+
Graph = graph;
7770

78-
MonitorForRepositoryChanges(gitPath);
71+
if (!Directory.Exists(gitPath))
72+
MonitorForRepositoryCreation(RepositoryPath);
73+
else
74+
MonitorForRepositoryChanges(gitPath);
7975
}
8076

8177
private void MonitorForRepositoryCreation(string repositoryWorkingPath)
@@ -92,7 +88,11 @@ private void MonitorForRepositoryChanges(string gitRepositoryPath)
9288

9389
public void Refresh()
9490
{
95-
Graph = _graphBuilder.Graph();
91+
string gitPath = ModelExtensions.GetGitRepositoryPath(RepositoryPath);
92+
if (!Directory.Exists(gitPath))
93+
MonitorRepository(RepositoryPath);
94+
else
95+
Graph = _graphBuilder.Graph();
9696
}
9797

9898
public bool ToggleSettings()

0 commit comments

Comments
 (0)