diff --git a/src/ViewModels/Clone.cs b/src/ViewModels/Clone.cs index d17028607..3a2bef1a0 100644 --- a/src/ViewModels/Clone.cs +++ b/src/ViewModels/Clone.cs @@ -113,11 +113,12 @@ public override Task Sure() CallUIThread(() => { - var repo = Preference.AddRepository(path, Path.Combine(path, ".git")); var node = new RepositoryNode() { - Id = repo.FullPath, - Name = Path.GetFileName(repo.FullPath), + Id = path, + FullPath = path, + Name = Path.GetFileName(path), + GitDir = Path.Combine(path, ".git"), Bookmark = 0, IsRepository = true, }; diff --git a/src/ViewModels/Init.cs b/src/ViewModels/Init.cs index 5f1e846e2..46c241f77 100644 --- a/src/ViewModels/Init.cs +++ b/src/ViewModels/Init.cs @@ -31,11 +31,12 @@ public override Task Sure() CallUIThread(() => { - var repo = Preference.AddRepository(_targetPath, gitDir); var node = new RepositoryNode() { - Id = repo.FullPath, - Name = Path.GetFileName(repo.FullPath), + Id = _targetPath, + FullPath = _targetPath, + Name = Path.GetFileName(_targetPath), + GitDir = gitDir, Bookmark = 0, IsRepository = true, }; diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index cf4883287..d8f6d8da5 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Text.Json; using System.Text.Json.Serialization; @@ -267,11 +268,25 @@ public string ExternalMergeToolDiffCmd set => SetProperty(ref _externalMergeToolDiffCmd, value); } - public List Repositories + [JsonIgnore] + public IEnumerable Repositories { - get; - set; - } = new List(); + get + { + var result = new Collection(); + foreach (var m in RepositoryNodes) + { + result.Add(new Repository() + { + FullPath = m.Id, + GitDir = Path.GetFullPath(Path.Combine(m.Id, ".git")), + Filters = m.Filters, + CommitMessages = m.CommitMessages + }); + } + return result; + } + } public AvaloniaList RepositoryNodes { @@ -376,19 +391,22 @@ public static Repository AddRepository(string rootDir, string gitDir) { var normalized = rootDir.Replace('\\', '/'); var repo = FindRepository(normalized); + if (repo == null) + { + var node = new RepositoryNode() + { + Id = normalized, + Name = Path.GetFileName(normalized), + IsRepository = true + }; + _instance.RepositoryNodes.Add(node); + } + + repo = FindRepository(normalized); if (repo != null) { repo.GitDir = gitDir; - return repo; } - - repo = new Repository() - { - FullPath = normalized, - GitDir = gitDir - }; - - _instance.Repositories.Add(repo); return repo; } diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 73a500b52..fe025bea9 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -1305,11 +1305,12 @@ public ContextMenu CreateContextMenuForSubmodule(string submodule) { var root = Path.GetFullPath(Path.Combine(_fullpath, submodule)); var gitDir = new Commands.QueryGitDir(root).Result(); - var repo = Preference.AddRepository(root, gitDir); var node = new RepositoryNode() { - Id = repo.FullPath, - Name = Path.GetFileName(repo.FullPath), + Id = root, + FullPath = root, + Name = Path.GetFileName(root), + GitDir = gitDir, Bookmark = 0, IsRepository = true, }; diff --git a/src/ViewModels/RepositoryNode.cs b/src/ViewModels/RepositoryNode.cs index b0b6e73ed..739f23286 100644 --- a/src/ViewModels/RepositoryNode.cs +++ b/src/ViewModels/RepositoryNode.cs @@ -17,6 +17,29 @@ public string Id SetProperty(ref _id, normalized); } } + + public string FullPath + { + get => _fullpath; + set + { + if (value != null) + { + var normalized = value.Replace('\\', '/'); + SetProperty(ref _fullpath, normalized); + } + else + { + SetProperty(ref _fullpath, null); + } + } + } + + public string GitDir + { + get => _gitDir; + set => SetProperty(ref _gitDir, value); + } public string Name { @@ -55,6 +78,18 @@ public AvaloniaList SubNodes set => SetProperty(ref _subNodes, value); } + public AvaloniaList Filters + { + get; + set; + } = new AvaloniaList(); + + public AvaloniaList CommitMessages + { + get; + set; + } = new AvaloniaList(); + public void Edit() { if (PopupHost.CanCreatePopup()) @@ -89,6 +124,8 @@ public void Delete() private string _id = string.Empty; private string _name = string.Empty; + private string _gitDir = string.Empty; + private string _fullpath = string.Empty; private bool _isRepository = false; private int _bookmark = 0; private bool _isExpanded = false; diff --git a/src/Views/Welcome.axaml.cs b/src/Views/Welcome.axaml.cs index 53ef2b5a6..e165fc7a9 100644 --- a/src/Views/Welcome.axaml.cs +++ b/src/Views/Welcome.axaml.cs @@ -256,11 +256,12 @@ private Task OpenOrInitRepository(string path, ViewModels.RepositoryNode parent var gitDir = new Commands.QueryGitDir(root).Result(); Dispatcher.UIThread.Invoke(() => { - var repo = ViewModels.Preference.AddRepository(root, gitDir); var node = new ViewModels.RepositoryNode() { - Id = repo.FullPath, - Name = Path.GetFileName(repo.FullPath), + Id = root, + FullPath = root, + Name = Path.GetFileName(root), + GitDir = gitDir, Bookmark = 0, IsRepository = true, };