style<Repository>: normalize repository's path

This commit is contained in:
leo 2024-03-01 13:40:12 +08:00
parent 1c005983c7
commit e3a7abe776
7 changed files with 26 additions and 19 deletions

View file

@ -66,17 +66,15 @@ namespace SourceGit {
public static void RaiseException(string context, string message) {
if (Current is App app && app._notificationReceiver != null) {
var ctx = context.Replace('\\', '/');
var notice = new Models.Notification() { IsError = true, Message = message };
app._notificationReceiver.OnReceiveNotification(ctx, notice);
app._notificationReceiver.OnReceiveNotification(context, notice);
}
}
public static void SendNotification(string context, string message) {
if (Current is App app && app._notificationReceiver != null) {
var ctx = context.Replace('\\', '/');
var notice = new Models.Notification() { IsError = false, Message = message };
app._notificationReceiver.OnReceiveNotification(ctx, notice);
app._notificationReceiver.OnReceiveNotification(context, notice);
}
}

View file

@ -89,8 +89,8 @@ namespace SourceGit.ViewModels {
CallUIThread(() => {
var repo = Preference.AddRepository(path, Path.Combine(path, ".git"));
var node = new RepositoryNode() {
Id = path,
Name = Path.GetFileName(path),
Id = repo.FullPath,
Name = Path.GetFileName(repo.FullPath),
Bookmark = 0,
IsRepository = true,
};

View file

@ -25,8 +25,8 @@ namespace SourceGit.ViewModels {
CallUIThread(() => {
var repo = Preference.AddRepository(_targetPath, gitDir);
var node = new RepositoryNode() {
Id = _targetPath,
Name = Path.GetFileName(_targetPath),
Id = repo.FullPath,
Name = Path.GetFileName(repo.FullPath),
Bookmark = 0,
IsRepository = true,
};

View file

@ -209,23 +209,22 @@ namespace SourceGit.ViewModels {
}
public static Repository FindRepository(string path) {
var dir = new DirectoryInfo(path);
foreach (var repo in _instance.Repositories) {
if (repo.FullPath == dir.FullName) return repo;
if (repo.FullPath == path) return repo;
}
return null;
}
public static Repository AddRepository(string rootDir, string gitDir) {
var repo = FindRepository(rootDir);
var normalized = rootDir.Replace('\\', '/');
var repo = FindRepository(normalized);
if (repo != null) {
repo.GitDir = gitDir;
return repo;
}
var dir = new DirectoryInfo(rootDir);
repo = new Repository() {
FullPath = dir.FullName,
FullPath = normalized,
GitDir = gitDir
};

View file

@ -12,7 +12,14 @@ namespace SourceGit.ViewModels {
public class Repository : ObservableObject, Models.IRepository {
public string FullPath {
get => _fullpath;
set => SetProperty(ref _fullpath, value);
set {
if (value != null) {
var normalized = value.Replace('\\', '/');
SetProperty(ref _fullpath, normalized);
} else {
SetProperty(ref _fullpath, null);
}
}
}
public string GitDir {
@ -1009,8 +1016,8 @@ namespace SourceGit.ViewModels {
var gitDir = new Commands.QueryGitDir(root).Result();
var repo = Preference.AddRepository(root, gitDir);
var node = new RepositoryNode() {
Id = root,
Name = Path.GetFileName(root),
Id = repo.FullPath,
Name = Path.GetFileName(repo.FullPath),
Bookmark = 0,
IsRepository = true,
};

View file

@ -6,7 +6,10 @@ namespace SourceGit.ViewModels {
public class RepositoryNode : ObservableObject {
public string Id {
get => _id;
set => SetProperty(ref _id, value);
set {
var normalized = value.Replace('\\', '/');
SetProperty(ref _id, normalized);
}
}
public string Name {

View file

@ -192,8 +192,8 @@ namespace SourceGit.Views {
Dispatcher.UIThread.Invoke(() => {
var repo = ViewModels.Preference.AddRepository(root, gitDir);
var node = new ViewModels.RepositoryNode() {
Id = root,
Name = Path.GetFileName(root),
Id = repo.FullPath,
Name = Path.GetFileName(repo.FullPath),
Bookmark = 0,
IsRepository = true,
};