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(() =>
{
var normalizedPath = path.Replace("\\", "/");
var node = Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, null, true);
var node = Preference.Instance.FindOrAddNodeByRepositoryPath(path, null, true);
var launcher = App.GetLauncer();
var page = null as LauncherPage;
foreach (var one in launcher.Pages)

View file

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

View file

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

View file

@ -405,13 +405,17 @@ namespace SourceGit.ViewModels
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)
{
node = new RepositoryNode()
{
Id = repo,
Name = Path.GetFileName(repo),
Id = normalized,
Name = Path.GetFileName(normalized),
Bookmark = 0,
IsRepository = true,
};

View file

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

View file

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