refactor: add repository

This commit is contained in:
leo 2025-01-11 11:28:37 +08:00
parent 52fba29613
commit 275a52eb5c
No known key found for this signature in database
6 changed files with 12 additions and 13 deletions

View file

@ -129,8 +129,7 @@ namespace SourceGit.ViewModels
CallUIThread(() => CallUIThread(() =>
{ {
var normalizedPath = path.Replace("\\", "/"); var node = Preference.Instance.FindOrAddNodeByRepositoryPath(path, null, true);
var node = Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, null, true);
var launcher = App.GetLauncer(); var launcher = App.GetLauncer();
var page = null as LauncherPage; var page = null as LauncherPage;
foreach (var one in launcher.Pages) foreach (var one in launcher.Pages)

View file

@ -38,8 +38,7 @@ namespace SourceGit.ViewModels
CallUIThread(() => CallUIThread(() =>
{ {
var normalizedPath = _targetPath.Replace("\\", "/"); Preference.Instance.FindOrAddNodeByRepositoryPath(_targetPath, _parentNode, true);
Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, _parentNode, true);
Welcome.Instance.Refresh(); Welcome.Instance.Refresh();
}); });

View file

@ -103,8 +103,7 @@ namespace SourceGit.ViewModels
} }
else else
{ {
var normalized = test.StdOut.Trim().Replace("\\", "/"); var node = pref.FindOrAddNodeByRepositoryPath(test.StdOut.Trim(), null, false);
var node = pref.FindOrAddNodeByRepositoryPath(normalized, null, false);
Welcome.Instance.Refresh(); Welcome.Instance.Refresh();
OpenRepositoryInTab(node, null); OpenRepositoryInTab(node, null);
} }

View file

@ -405,13 +405,17 @@ namespace SourceGit.ViewModels
public RepositoryNode FindOrAddNodeByRepositoryPath(string repo, RepositoryNode parent, bool shouldMoveNode) public RepositoryNode FindOrAddNodeByRepositoryPath(string repo, RepositoryNode parent, bool shouldMoveNode)
{ {
var node = FindNodeRecursive(repo, RepositoryNodes); var normalized = repo.Replace('\\', '/');
if (normalized.EndsWith("/"))
normalized = normalized.TrimEnd('/');
var node = FindNodeRecursive(normalized, RepositoryNodes);
if (node == null) if (node == null)
{ {
node = new RepositoryNode() node = new RepositoryNode()
{ {
Id = repo, Id = normalized,
Name = Path.GetFileName(repo), Name = Path.GetFileName(normalized),
Bookmark = 0, Bookmark = 0,
IsRepository = true, IsRepository = true,
}; };

View file

@ -307,8 +307,7 @@ namespace SourceGit.Views
return; return;
} }
var normalizedPath = test.StdOut.Trim().Replace("\\", "/"); var node = ViewModels.Preference.Instance.FindOrAddNodeByRepositoryPath(test.StdOut.Trim(), parent, true);
var node = ViewModels.Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, parent, true);
ViewModels.Welcome.Instance.Refresh(); ViewModels.Welcome.Instance.Refresh();
var launcher = this.FindAncestorOfType<Launcher>()?.DataContext as ViewModels.Launcher; var launcher = this.FindAncestorOfType<Launcher>()?.DataContext as ViewModels.Launcher;

View file

@ -63,8 +63,7 @@ namespace SourceGit.Views
return; return;
} }
var normalizedPath = test.StdOut.Trim().Replace("\\", "/"); var node = ViewModels.Preference.Instance.FindOrAddNodeByRepositoryPath(test.StdOut.Trim(), parent, false);
var node = ViewModels.Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, parent, false);
ViewModels.Welcome.Instance.Refresh(); ViewModels.Welcome.Instance.Refresh();
var launcher = this.FindAncestorOfType<Launcher>()?.DataContext as ViewModels.Launcher; var launcher = this.FindAncestorOfType<Launcher>()?.DataContext as ViewModels.Launcher;