2020-07-03 00:24:31 -07:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
|
2020-12-16 19:55:06 -08:00
|
|
|
namespace SourceGit {
|
2020-07-03 00:24:31 -07:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// User's preference settings. Serialized to
|
|
|
|
/// </summary>
|
|
|
|
public class Preference {
|
|
|
|
|
|
|
|
/// <summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
/// Tools setting.
|
2020-07-03 00:24:31 -07:00
|
|
|
/// </summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
public class ToolSetting {
|
2020-07-03 00:24:31 -07:00
|
|
|
/// <summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
/// Git executable file path.
|
2020-07-03 00:24:31 -07:00
|
|
|
/// </summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
public string GitExecutable { get; set; }
|
2020-07-03 00:24:31 -07:00
|
|
|
/// <summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
/// Default clone directory.
|
2020-07-03 00:24:31 -07:00
|
|
|
/// </summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
public string GitDefaultCloneDir { get; set; }
|
2020-07-03 00:24:31 -07:00
|
|
|
/// <summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
/// Selected merge tool.
|
2020-07-03 00:24:31 -07:00
|
|
|
/// </summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
public int MergeTool { get; set; } = 0;
|
2020-07-03 00:24:31 -07:00
|
|
|
/// <summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
/// Executable file path for merge tool.
|
2020-07-03 00:24:31 -07:00
|
|
|
/// </summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
public string MergeExecutable { get; set; } = "--";
|
2020-07-03 00:24:31 -07:00
|
|
|
}
|
|
|
|
|
2020-11-27 02:47:32 -08:00
|
|
|
/// <summary>
|
|
|
|
/// File's display mode.
|
|
|
|
/// </summary>
|
|
|
|
public enum FilesDisplayMode {
|
|
|
|
Tree,
|
|
|
|
List,
|
|
|
|
Grid,
|
|
|
|
}
|
|
|
|
|
2020-07-03 00:24:31 -07:00
|
|
|
/// <summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
/// Settings for UI.
|
2020-07-03 00:24:31 -07:00
|
|
|
/// </summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
public class UISetting {
|
|
|
|
/// <summary>
|
|
|
|
/// Use light theme?
|
|
|
|
/// </summary>
|
|
|
|
public bool UseLightTheme { get; set; }
|
|
|
|
/// <summary>
|
|
|
|
/// Main window width
|
|
|
|
/// </summary>
|
|
|
|
public double WindowWidth { get; set; }
|
|
|
|
/// <summary>
|
|
|
|
/// Main window height
|
|
|
|
/// </summary>
|
|
|
|
public double WindowHeight { get; set; }
|
|
|
|
/// <summary>
|
|
|
|
/// Move commit viewer from bottom to right
|
|
|
|
/// </summary>
|
|
|
|
public bool MoveCommitViewerRight { get; set; }
|
|
|
|
/// <summary>
|
|
|
|
/// File's display mode in unstaged view.
|
|
|
|
/// </summary>
|
|
|
|
public FilesDisplayMode UnstageFileDisplayMode { get; set; }
|
|
|
|
/// <summary>
|
|
|
|
/// File's display mode in staged view.
|
|
|
|
/// </summary>
|
|
|
|
public FilesDisplayMode StagedFileDisplayMode { get; set; }
|
|
|
|
/// <summary>
|
|
|
|
/// Use DataGrid instead of TreeView in changes view.
|
|
|
|
/// </summary>
|
|
|
|
public bool UseListInChanges { get; set; }
|
|
|
|
/// <summary>
|
|
|
|
/// Use combined instead of side-by-side mode in diff viewer.
|
|
|
|
/// </summary>
|
|
|
|
public bool UseCombinedDiff { get; set; }
|
2020-07-03 00:24:31 -07:00
|
|
|
}
|
|
|
|
|
2020-11-30 18:31:46 -08:00
|
|
|
/// <summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
/// Group(Virtual folder) for watched repositories.
|
2020-07-03 00:24:31 -07:00
|
|
|
/// </summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
public class Group {
|
|
|
|
/// <summary>
|
|
|
|
/// Unique ID of this group.
|
|
|
|
/// </summary>
|
|
|
|
public string Id { get; set; }
|
|
|
|
/// <summary>
|
|
|
|
/// Display name.
|
|
|
|
/// </summary>
|
|
|
|
public string Name { get; set; }
|
|
|
|
/// <summary>
|
|
|
|
/// Parent ID.
|
|
|
|
/// </summary>
|
|
|
|
public string ParentId { get; set; }
|
|
|
|
/// <summary>
|
|
|
|
/// Cache UI IsExpended status.
|
|
|
|
/// </summary>
|
|
|
|
public bool IsExpended { get; set; }
|
|
|
|
}
|
2020-07-03 00:24:31 -07:00
|
|
|
|
2020-12-16 19:55:06 -08:00
|
|
|
#region SAVED_DATAS
|
2020-07-03 00:24:31 -07:00
|
|
|
/// <summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
/// Check for updates.
|
2020-07-03 00:24:31 -07:00
|
|
|
/// </summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
public bool CheckUpdate { get; set; } = true;
|
2020-07-03 00:24:31 -07:00
|
|
|
/// <summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
/// Settings for executables.
|
2020-07-03 00:24:31 -07:00
|
|
|
/// </summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
public ToolSetting Tools { get; set; } = new ToolSetting();
|
2020-11-19 23:45:04 -08:00
|
|
|
/// <summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
/// Use light color theme.
|
2020-11-19 23:45:04 -08:00
|
|
|
/// </summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
public UISetting UI { get; set; } = new UISetting();
|
2020-07-03 00:24:31 -07:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region SETTING_REPOS
|
|
|
|
/// <summary>
|
|
|
|
/// Groups for repositories.
|
|
|
|
/// </summary>
|
|
|
|
public List<Group> Groups { get; set; } = new List<Group>();
|
|
|
|
/// <summary>
|
|
|
|
/// Watched repositories.
|
|
|
|
/// </summary>
|
2020-12-16 19:55:06 -08:00
|
|
|
public List<Git.Repository> Repositories { get; set; } = new List<Git.Repository>();
|
2020-07-03 00:24:31 -07:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region METHODS_ON_GROUP
|
|
|
|
/// <summary>
|
|
|
|
/// Add new group(virtual folder).
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">Display name.</param>
|
|
|
|
/// <param name="parentId">Parent group ID.</param>
|
|
|
|
/// <returns>Added group instance.</returns>
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Find group by ID.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id">Unique ID</param>
|
|
|
|
/// <returns>Founded group's instance.</returns>
|
|
|
|
public Group FindGroup(string id) {
|
|
|
|
foreach (var group in Groups) {
|
|
|
|
if (group.Id == id) return group;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Rename group.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id">Unique ID</param>
|
|
|
|
/// <param name="newName">New name.</param>
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Remove a group.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id">Unique ID</param>
|
|
|
|
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
|
|
|
|
/// <summary>
|
|
|
|
/// Add repository.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="path">Local storage path.</param>
|
|
|
|
/// <param name="groupId">Group's ID</param>
|
|
|
|
/// <returns>Added repository instance.</returns>
|
2020-12-16 19:55:06 -08:00
|
|
|
public Git.Repository AddRepository(string path, string groupId) {
|
2020-07-03 00:24:31 -07:00
|
|
|
var repo = FindRepository(path);
|
|
|
|
if (repo != null) return repo;
|
|
|
|
|
|
|
|
var dir = new DirectoryInfo(path);
|
2020-12-16 19:55:06 -08:00
|
|
|
repo = new Git.Repository() {
|
2020-07-03 00:24:31 -07:00
|
|
|
Path = dir.FullName,
|
|
|
|
Name = dir.Name,
|
|
|
|
GroupId = groupId,
|
|
|
|
LastOpenTime = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
Repositories.Add(repo);
|
|
|
|
Repositories.Sort((l, r) => l.Name.CompareTo(r.Name));
|
|
|
|
return repo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Find repository by path.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="path">Local storage path.</param>
|
|
|
|
/// <returns>Founded repository instance.</returns>
|
2020-12-16 19:55:06 -08:00
|
|
|
public Git.Repository FindRepository(string path) {
|
2020-07-03 00:24:31 -07:00
|
|
|
var dir = new DirectoryInfo(path);
|
|
|
|
foreach (var repo in Repositories) {
|
|
|
|
if (repo.Path == dir.FullName) return repo;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Change a repository's display name in RepositoryManager.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="path">Local storage path.</param>
|
|
|
|
/// <param name="newName">New name</param>
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Remove a repository in RepositoryManager.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="path">Local storage path.</param>
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|