enhance: reduce the times calling Save() (#436)

This commit is contained in:
leo 2024-09-02 14:14:52 +08:00
parent 9fe8ffcea9
commit 931831431b
No known key found for this signature in database
4 changed files with 18 additions and 13 deletions

View file

@ -27,7 +27,7 @@ namespace SourceGit.ViewModels
Name = _name,
IsRepository = false,
IsExpanded = false,
}, _parent);
}, _parent, true);
Welcome.Instance.Refresh();
return null;

View file

@ -18,7 +18,7 @@ namespace SourceGit.ViewModels
public override Task<bool> Sure()
{
Preference.Instance.RemoveNode(_node);
Preference.Instance.RemoveNode(_node, true);
Welcome.Instance.Refresh();
return null;
}

View file

@ -343,7 +343,7 @@ namespace SourceGit.ViewModels
return true;
}
public void AddNode(RepositoryNode node, RepositoryNode to = null)
public void AddNode(RepositoryNode node, RepositoryNode to, bool save)
{
var collection = to == null ? RepositoryNodes : to.SubNodes;
collection.Add(node);
@ -355,7 +355,8 @@ namespace SourceGit.ViewModels
return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
});
Save();
if (save)
Save();
}
public RepositoryNode FindNode(string id)
@ -376,32 +377,36 @@ namespace SourceGit.ViewModels
IsRepository = true,
};
AddNode(node, parent);
AddNode(node, parent, true);
}
else if (shouldMoveNode)
{
MoveNode(node, parent);
MoveNode(node, parent, true);
}
return node;
}
public void MoveNode(RepositoryNode node, RepositoryNode to = null)
public void MoveNode(RepositoryNode node, RepositoryNode to, bool save)
{
if (to == null && RepositoryNodes.Contains(node))
return;
if (to != null && to.SubNodes.Contains(node))
return;
RemoveNode(node);
AddNode(node, to);
Save();
RemoveNode(node, false);
AddNode(node, to, false);
if (save)
Save();
}
public void RemoveNode(RepositoryNode node)
public void RemoveNode(RepositoryNode node, bool save)
{
RemoveNodeRecursive(node, RepositoryNodes);
Save();
if (save)
Save();
}
public void SortByRenamedNode(RepositoryNode node)

View file

@ -139,7 +139,7 @@ namespace SourceGit.ViewModels
public void MoveNode(RepositoryNode from, RepositoryNode to)
{
Preference.Instance.MoveNode(from, to);
Preference.Instance.MoveNode(from, to, true);
Refresh();
}