Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/ViewModels/Clone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ public override Task<bool> 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,
};
Expand Down
7 changes: 4 additions & 3 deletions src/ViewModels/Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ public override Task<bool> 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,
};
Expand Down
44 changes: 31 additions & 13 deletions src/ViewModels/Preference.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -267,11 +268,25 @@ public string ExternalMergeToolDiffCmd
set => SetProperty(ref _externalMergeToolDiffCmd, value);
}

public List<Repository> Repositories
[JsonIgnore]
public IEnumerable<Repository> Repositories
{
get;
set;
} = new List<Repository>();
get
{
var result = new Collection<Repository>();
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<RepositoryNode> RepositoryNodes
{
Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 4 additions & 3 deletions src/ViewModels/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
37 changes: 37 additions & 0 deletions src/ViewModels/RepositoryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -55,6 +78,18 @@ public AvaloniaList<RepositoryNode> SubNodes
set => SetProperty(ref _subNodes, value);
}

public AvaloniaList<string> Filters
{
get;
set;
} = new AvaloniaList<string>();

public AvaloniaList<string> CommitMessages
{
get;
set;
} = new AvaloniaList<string>();

public void Edit()
{
if (PopupHost.CanCreatePopup())
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/Views/Welcome.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down