using System;
using System.Collections.Generic;
using System.IO;
namespace SourceGit {
///
/// User's preference settings. Serialized to
///
public class Preference {
///
/// Tools setting.
///
public class ToolSetting {
///
/// Git executable file path.
///
public string GitExecutable { get; set; }
///
/// Default clone directory.
///
public string GitDefaultCloneDir { get; set; }
///
/// Selected merge tool.
///
public int MergeTool { get; set; } = 0;
///
/// Executable file path for merge tool.
///
public string MergeExecutable { get; set; } = "--";
}
///
/// File's display mode.
///
public enum FilesDisplayMode {
Tree,
List,
Grid,
}
///
/// Settings for UI.
///
public class UISetting {
///
/// Use light theme?
///
public bool UseLightTheme { get; set; }
///
/// Main window width
///
public double WindowWidth { get; set; }
///
/// Main window height
///
public double WindowHeight { get; set; }
///
/// Move commit viewer from bottom to right
///
public bool MoveCommitViewerRight { get; set; }
///
/// File's display mode in unstaged view.
///
public FilesDisplayMode UnstageFileDisplayMode { get; set; }
///
/// File's display mode in staged view.
///
public FilesDisplayMode StagedFileDisplayMode { get; set; }
///
/// Use DataGrid instead of TreeView in changes view.
///
public bool UseListInChanges { get; set; }
///
/// Use combined instead of side-by-side mode in diff viewer.
///
public bool UseCombinedDiff { get; set; }
}
///
/// Group(Virtual folder) for watched repositories.
///
public class Group {
///
/// Unique ID of this group.
///
public string Id { get; set; }
///
/// Display name.
///
public string Name { get; set; }
///
/// Parent ID.
///
public string ParentId { get; set; }
///
/// Cache UI IsExpended status.
///
public bool IsExpended { get; set; }
}
#region SAVED_DATAS
///
/// Check for updates.
///
public bool CheckUpdate { get; set; } = true;
///
/// Settings for executables.
///
public ToolSetting Tools { get; set; } = new ToolSetting();
///
/// Use light color theme.
///
public UISetting UI { get; set; } = new UISetting();
#endregion
#region SETTING_REPOS
///
/// Groups for repositories.
///
public List Groups { get; set; } = new List();
///
/// Watched repositories.
///
public List Repositories { get; set; } = new List();
#endregion
#region METHODS_ON_GROUP
///
/// Add new group(virtual folder).
///
/// Display name.
/// Parent group ID.
/// Added group instance.
public Group AddGroup(string name, string parentId) {
var group = new Group() {
Name = name,
Id = Guid.NewGuid().ToString(),
ParentId = parentId,
IsExpended = false,
};
Groups.Add(group);
Groups.Sort((l, r) => l.Name.CompareTo(r.Name));
return group;
}
///
/// Find group by ID.
///
/// Unique ID
/// Founded group's instance.
public Group FindGroup(string id) {
foreach (var group in Groups) {
if (group.Id == id) return group;
}
return null;
}
///
/// Rename group.
///
/// Unique ID
/// New name.
public void RenameGroup(string id, string newName) {
foreach (var group in Groups) {
if (group.Id == id) {
group.Name = newName;
break;
}
}
Groups.Sort((l, r) => l.Name.CompareTo(r.Name));
}
///
/// Remove a group.
///
/// Unique ID
public void RemoveGroup(string id) {
int removedIdx = -1;
for (int i = 0; i < Groups.Count; i++) {
if (Groups[i].Id == id) {
removedIdx = i;
break;
}
}
if (removedIdx >= 0) Groups.RemoveAt(removedIdx);
}
#endregion
#region METHODS_ON_REPOS
///
/// Add repository.
///
/// Local storage path.
/// Group's ID
/// Added repository instance.
public Git.Repository AddRepository(string path, string groupId) {
var repo = FindRepository(path);
if (repo != null) return repo;
var dir = new DirectoryInfo(path);
repo = new Git.Repository() {
Path = dir.FullName,
Name = dir.Name,
GroupId = groupId,
LastOpenTime = 0,
};
Repositories.Add(repo);
Repositories.Sort((l, r) => l.Name.CompareTo(r.Name));
return repo;
}
///
/// Find repository by path.
///
/// Local storage path.
/// Founded repository instance.
public Git.Repository FindRepository(string path) {
var dir = new DirectoryInfo(path);
foreach (var repo in Repositories) {
if (repo.Path == dir.FullName) return repo;
}
return null;
}
///
/// Change a repository's display name in RepositoryManager.
///
/// Local storage path.
/// New name
public void RenameRepository(string path, string newName) {
var repo = FindRepository(path);
if (repo == null) return;
repo.Name = newName;
Repositories.Sort((l, r) => l.Name.CompareTo(r.Name));
}
///
/// Remove a repository in RepositoryManager.
///
/// Local storage path.
public void RemoveRepository(string path) {
var dir = new DirectoryInfo(path);
var removedIdx = -1;
for (int i = 0; i < Repositories.Count; i++) {
if (Repositories[i].Path == dir.FullName) {
removedIdx = i;
break;
}
}
if (removedIdx >= 0) Repositories.RemoveAt(removedIdx);
}
#endregion
}
}