Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class ChangesetTreeView : Subview
[SerializeField] private List<GitCommitTarget> entryCommitTargets = new List<GitCommitTarget>();
[SerializeField] private List<string> foldedTreeEntries = new List<string>();
[NonSerialized] private FileTreeNode tree;
[NonSerialized] private Action<FileTreeNode> stateChangeCallback;

public override void OnGUI()
{
Expand Down Expand Up @@ -153,15 +152,15 @@ public void UpdateEntries(IList<GitStatusEntry> newEntries)

// Build tree structure

tree = new FileTreeNode(FileSystemHelpers.FindCommonPath(entries.Select(e => e.Path)), stateChangeCallback);
tree = new FileTreeNode(FileSystemHelpers.FindCommonPath(entries.Select(e => e.Path)));
tree.RepositoryPath = tree.Path;
for (var index = 0; index < entries.Count; index++)
{
var entryPath = entries[index].Path.ToNPath();
if (entryPath.IsChildOf(tree.Path))
entryPath = entryPath.RelativeTo(tree.Path.ToNPath());

var node = new FileTreeNode(entryPath, stateChangeCallback) { Target = entryCommitTargets[index] };
var node = new FileTreeNode(entryPath) { Target = entryCommitTargets[index] };
if (!string.IsNullOrEmpty(entries[index].ProjectPath))
{
node.Icon = AssetDatabase.GetCachedIcon(entries[index].ProjectPath);
Expand Down Expand Up @@ -209,7 +208,7 @@ private void BuildTree(FileTreeNode parent, FileTreeNode node)
if (!found)
{
var p = parent.RepositoryPath.ToNPath().Combine(root);
BuildTree(parent.Add(new FileTreeNode(root, stateChangeCallback) { RepositoryPath = p }), node);
BuildTree(parent.Add(new FileTreeNode(root) { RepositoryPath = p }), node);
}
}
else if (nodePath.ExtensionWithDot == ".meta")
Expand Down Expand Up @@ -259,25 +258,7 @@ private void TreeNode(FileTreeNode node)
}
if (EditorGUI.EndChangeCheck())
{
var filesAdded = new List<string>();
var filesRemoved = new List<string>();
stateChangeCallback = new Action<FileTreeNode>(s =>
{
if (s.State == CommitState.None)
filesRemoved.Add(s.Path);
else
filesAdded.Add(s.Path);
});
node.State = toggled ? CommitState.All : CommitState.None;
if (filesAdded.Count > 0)
GitClient.Add(filesAdded);
if (filesRemoved.Count > 0)
GitClient.Remove(filesAdded);
if (filesAdded.Count > 0|| filesRemoved.Count > 0)
{
GitClient.Status();
}
// we might need to run git status after these calls
}
}

Expand Down Expand Up @@ -421,7 +402,6 @@ private enum CommitState

private class FileTreeNode
{
private readonly Action<FileTreeNode> stateChangeCallback;
private List<FileTreeNode> children;
private string path;
private CommitState state;
Expand All @@ -432,15 +412,8 @@ private class FileTreeNode
public string RepositoryPath;
public GitCommitTarget Target { get; set; }

public FileTreeNode(Action<FileTreeNode> stateChangeCallback)
{
this.stateChangeCallback = stateChangeCallback;
children = new List<FileTreeNode>();
}

public FileTreeNode(string path, Action<FileTreeNode> stateChangeCallback)
public FileTreeNode(string path)
{
this.stateChangeCallback = stateChangeCallback;
this.path = path ?? "";
Label = this.path;
children = new List<FileTreeNode>();
Expand Down Expand Up @@ -514,7 +487,6 @@ public CommitState State
}

state = value;
stateChangeCallback.SafeInvoke(this);

if (children == null)
{
Expand Down