mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 04:34:59 +00:00
style: add .editorconfig for code formatting. see issu #25
This commit is contained in:
parent
a8eeea4f78
commit
18aaa0a143
225 changed files with 7781 additions and 3911 deletions
|
@ -1,43 +1,58 @@
|
|||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SourceGit.ViewModels {
|
||||
public class FileTreeNode : ObservableObject {
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class FileTreeNode : ObservableObject
|
||||
{
|
||||
public string FullPath { get; set; } = string.Empty;
|
||||
public bool IsFolder { get; set; } = false;
|
||||
public object Backend { get; set; } = null;
|
||||
public List<FileTreeNode> Children { get; set; } = new List<FileTreeNode>();
|
||||
|
||||
public bool IsExpanded {
|
||||
public bool IsExpanded
|
||||
{
|
||||
get => _isExpanded;
|
||||
set => SetProperty(ref _isExpanded, value);
|
||||
}
|
||||
|
||||
public static List<FileTreeNode> Build(List<Models.Change> changes) {
|
||||
public static List<FileTreeNode> Build(List<Models.Change> changes)
|
||||
{
|
||||
var nodes = new List<FileTreeNode>();
|
||||
var folders = new Dictionary<string, FileTreeNode>();
|
||||
var expanded = changes.Count <= 50;
|
||||
|
||||
foreach (var c in changes) {
|
||||
foreach (var c in changes)
|
||||
{
|
||||
var sepIdx = c.Path.IndexOf('/', StringComparison.Ordinal);
|
||||
if (sepIdx == -1) {
|
||||
nodes.Add(new FileTreeNode() {
|
||||
if (sepIdx == -1)
|
||||
{
|
||||
nodes.Add(new FileTreeNode()
|
||||
{
|
||||
FullPath = c.Path,
|
||||
Backend = c,
|
||||
IsFolder = false,
|
||||
IsExpanded = false
|
||||
});
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
FileTreeNode lastFolder = null;
|
||||
var start = 0;
|
||||
|
||||
while (sepIdx != -1) {
|
||||
while (sepIdx != -1)
|
||||
{
|
||||
var folder = c.Path.Substring(0, sepIdx);
|
||||
if (folders.ContainsKey(folder)) {
|
||||
if (folders.ContainsKey(folder))
|
||||
{
|
||||
lastFolder = folders[folder];
|
||||
} else if (lastFolder == null) {
|
||||
lastFolder = new FileTreeNode() {
|
||||
}
|
||||
else if (lastFolder == null)
|
||||
{
|
||||
lastFolder = new FileTreeNode()
|
||||
{
|
||||
FullPath = folder,
|
||||
Backend = null,
|
||||
IsFolder = true,
|
||||
|
@ -45,8 +60,11 @@ namespace SourceGit.ViewModels {
|
|||
};
|
||||
nodes.Add(lastFolder);
|
||||
folders.Add(folder, lastFolder);
|
||||
} else {
|
||||
var cur = new FileTreeNode() {
|
||||
}
|
||||
else
|
||||
{
|
||||
var cur = new FileTreeNode()
|
||||
{
|
||||
FullPath = folder,
|
||||
Backend = null,
|
||||
IsFolder = true,
|
||||
|
@ -61,7 +79,8 @@ namespace SourceGit.ViewModels {
|
|||
sepIdx = c.Path.IndexOf('/', start);
|
||||
}
|
||||
|
||||
lastFolder.Children.Add(new FileTreeNode() {
|
||||
lastFolder.Children.Add(new FileTreeNode()
|
||||
{
|
||||
FullPath = c.Path,
|
||||
Backend = c,
|
||||
IsFolder = false,
|
||||
|
@ -75,30 +94,41 @@ namespace SourceGit.ViewModels {
|
|||
return nodes;
|
||||
}
|
||||
|
||||
public static List<FileTreeNode> Build(List<Models.Object> files) {
|
||||
public static List<FileTreeNode> Build(List<Models.Object> files)
|
||||
{
|
||||
var nodes = new List<FileTreeNode>();
|
||||
var folders = new Dictionary<string, FileTreeNode>();
|
||||
var expanded = files.Count <= 50;
|
||||
|
||||
foreach (var f in files) {
|
||||
foreach (var f in files)
|
||||
{
|
||||
var sepIdx = f.Path.IndexOf('/', StringComparison.Ordinal);
|
||||
if (sepIdx == -1) {
|
||||
nodes.Add(new FileTreeNode() {
|
||||
if (sepIdx == -1)
|
||||
{
|
||||
nodes.Add(new FileTreeNode()
|
||||
{
|
||||
FullPath = f.Path,
|
||||
Backend = f,
|
||||
IsFolder = false,
|
||||
IsExpanded = false
|
||||
});
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
FileTreeNode lastFolder = null;
|
||||
var start = 0;
|
||||
|
||||
while (sepIdx != -1) {
|
||||
while (sepIdx != -1)
|
||||
{
|
||||
var folder = f.Path.Substring(0, sepIdx);
|
||||
if (folders.ContainsKey(folder)) {
|
||||
if (folders.ContainsKey(folder))
|
||||
{
|
||||
lastFolder = folders[folder];
|
||||
} else if (lastFolder == null) {
|
||||
lastFolder = new FileTreeNode() {
|
||||
}
|
||||
else if (lastFolder == null)
|
||||
{
|
||||
lastFolder = new FileTreeNode()
|
||||
{
|
||||
FullPath = folder,
|
||||
Backend = null,
|
||||
IsFolder = true,
|
||||
|
@ -106,8 +136,11 @@ namespace SourceGit.ViewModels {
|
|||
};
|
||||
nodes.Add(lastFolder);
|
||||
folders.Add(folder, lastFolder);
|
||||
} else {
|
||||
var cur = new FileTreeNode() {
|
||||
}
|
||||
else
|
||||
{
|
||||
var cur = new FileTreeNode()
|
||||
{
|
||||
FullPath = folder,
|
||||
Backend = null,
|
||||
IsFolder = true,
|
||||
|
@ -122,7 +155,8 @@ namespace SourceGit.ViewModels {
|
|||
sepIdx = f.Path.IndexOf('/', start);
|
||||
}
|
||||
|
||||
lastFolder.Children.Add(new FileTreeNode() {
|
||||
lastFolder.Children.Add(new FileTreeNode()
|
||||
{
|
||||
FullPath = f.Path,
|
||||
Backend = f,
|
||||
IsFolder = false,
|
||||
|
@ -136,13 +170,17 @@ namespace SourceGit.ViewModels {
|
|||
return nodes;
|
||||
}
|
||||
|
||||
public static FileTreeNode SelectByPath(List<FileTreeNode> nodes, string path) {
|
||||
foreach (var node in nodes) {
|
||||
public static FileTreeNode SelectByPath(List<FileTreeNode> nodes, string path)
|
||||
{
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
if (node.FullPath == path) return node;
|
||||
|
||||
if (node.IsFolder && path.StartsWith(node.FullPath + "/", StringComparison.Ordinal)) {
|
||||
|
||||
if (node.IsFolder && path.StartsWith(node.FullPath + "/", StringComparison.Ordinal))
|
||||
{
|
||||
var foundInChildren = SelectByPath(node.Children, path);
|
||||
if (foundInChildren != null) {
|
||||
if (foundInChildren != null)
|
||||
{
|
||||
node.IsExpanded = true;
|
||||
}
|
||||
return foundInChildren;
|
||||
|
@ -152,20 +190,26 @@ namespace SourceGit.ViewModels {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static void Sort(List<FileTreeNode> nodes) {
|
||||
nodes.Sort((l, r) => {
|
||||
if (l.IsFolder == r.IsFolder) {
|
||||
private static void Sort(List<FileTreeNode> nodes)
|
||||
{
|
||||
nodes.Sort((l, r) =>
|
||||
{
|
||||
if (l.IsFolder == r.IsFolder)
|
||||
{
|
||||
return l.FullPath.CompareTo(r.FullPath);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return l.IsFolder ? -1 : 1;
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var node in nodes) {
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
if (node.Children.Count > 1) Sort(node.Children);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isExpanded = true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue