2024-08-05 03:18:57 -07:00
|
|
|
|
using System.Collections.Generic;
|
2024-08-05 02:34:49 -07:00
|
|
|
|
using Avalonia.Collections;
|
2024-07-24 19:59:06 -07:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
2024-07-24 19:59:06 -07:00
|
|
|
|
public class RepositoryConfigure : ObservableObject
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
|
|
|
|
public string UserName
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string UserEmail
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-02 00:13:27 -07:00
|
|
|
|
public List<string> Remotes
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string DefaultRemote
|
|
|
|
|
{
|
|
|
|
|
get => _repo.Settings.DefaultRemote;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_repo.Settings.DefaultRemote != value)
|
|
|
|
|
{
|
|
|
|
|
_repo.Settings.DefaultRemote = value;
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 09:25:30 -07:00
|
|
|
|
public bool GPGCommitSigningEnabled
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool GPGTagSigningEnabled
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string GPGUserSigningKey
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string HttpProxy
|
|
|
|
|
{
|
2024-07-27 19:11:10 -07:00
|
|
|
|
get => _httpProxy;
|
|
|
|
|
set => SetProperty(ref _httpProxy, value);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-22 18:45:52 -07:00
|
|
|
|
public bool EnableSignOffForCommit
|
|
|
|
|
{
|
|
|
|
|
get => _repo.Settings.EnableSignOffForCommit;
|
|
|
|
|
set => _repo.Settings.EnableSignOffForCommit = value;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-25 19:50:21 -07:00
|
|
|
|
public bool EnableAutoFetch
|
|
|
|
|
{
|
|
|
|
|
get => _repo.Settings.EnableAutoFetch;
|
|
|
|
|
set => _repo.Settings.EnableAutoFetch = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int? AutoFetchInterval
|
|
|
|
|
{
|
|
|
|
|
get => _repo.Settings.AutoFetchInterval;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value is null || value < 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var interval = (int)value;
|
|
|
|
|
if (_repo.Settings.AutoFetchInterval != interval)
|
|
|
|
|
_repo.Settings.AutoFetchInterval = interval;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-15 03:59:35 -07:00
|
|
|
|
public AvaloniaList<Models.CommitTemplate> CommitTemplates
|
|
|
|
|
{
|
|
|
|
|
get => _repo.Settings.CommitTemplates;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Models.CommitTemplate SelectedCommitTemplate
|
|
|
|
|
{
|
|
|
|
|
get => _selectedCommitTemplate;
|
|
|
|
|
set => SetProperty(ref _selectedCommitTemplate, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 03:18:57 -07:00
|
|
|
|
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
|
2024-08-05 02:34:49 -07:00
|
|
|
|
{
|
2024-08-05 03:18:57 -07:00
|
|
|
|
get => _repo.Settings.IssueTrackerRules;
|
2024-08-05 02:34:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 03:18:57 -07:00
|
|
|
|
public Models.IssueTrackerRule SelectedIssueTrackerRule
|
2024-08-05 02:34:49 -07:00
|
|
|
|
{
|
|
|
|
|
get => _selectedIssueTrackerRule;
|
|
|
|
|
set => SetProperty(ref _selectedIssueTrackerRule, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public RepositoryConfigure(Repository repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
|
2024-10-02 00:13:27 -07:00
|
|
|
|
Remotes = new List<string>();
|
|
|
|
|
foreach (var remote in _repo.Remotes)
|
|
|
|
|
Remotes.Add(remote.Name);
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_cached = new Commands.Config(repo.FullPath).ListAll();
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (_cached.TryGetValue("user.name", out var name))
|
|
|
|
|
UserName = name;
|
|
|
|
|
if (_cached.TryGetValue("user.email", out var email))
|
|
|
|
|
UserEmail = email;
|
2024-05-30 09:25:30 -07:00
|
|
|
|
if (_cached.TryGetValue("commit.gpgsign", out var gpgCommitSign))
|
|
|
|
|
GPGCommitSigningEnabled = gpgCommitSign == "true";
|
2024-06-18 19:21:36 -07:00
|
|
|
|
if (_cached.TryGetValue("tag.gpgsign", out var gpgTagSign))
|
2024-05-30 09:25:30 -07:00
|
|
|
|
GPGTagSigningEnabled = gpgTagSign == "true";
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (_cached.TryGetValue("user.signingkey", out var signingKey))
|
|
|
|
|
GPGUserSigningKey = signingKey;
|
|
|
|
|
if (_cached.TryGetValue("http.proxy", out var proxy))
|
|
|
|
|
HttpProxy = proxy;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-27 19:11:10 -07:00
|
|
|
|
public void ClearHttpProxy()
|
|
|
|
|
{
|
|
|
|
|
HttpProxy = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-15 03:59:35 -07:00
|
|
|
|
public void AddCommitTemplate()
|
|
|
|
|
{
|
|
|
|
|
var template = new Models.CommitTemplate() { Name = "New Template" };
|
|
|
|
|
_repo.Settings.CommitTemplates.Add(template);
|
|
|
|
|
SelectedCommitTemplate = template;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveSelectedCommitTemplate()
|
|
|
|
|
{
|
|
|
|
|
if (_selectedCommitTemplate != null)
|
|
|
|
|
_repo.Settings.CommitTemplates.Remove(_selectedCommitTemplate);
|
|
|
|
|
SelectedCommitTemplate = null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 02:34:49 -07:00
|
|
|
|
public void AddSampleGithubIssueTracker()
|
|
|
|
|
{
|
|
|
|
|
foreach (var remote in _repo.Remotes)
|
|
|
|
|
{
|
|
|
|
|
if (remote.URL.Contains("github.com", System.StringComparison.Ordinal))
|
|
|
|
|
{
|
|
|
|
|
if (remote.TryGetVisitURL(out string url))
|
|
|
|
|
{
|
2024-08-05 03:18:57 -07:00
|
|
|
|
SelectedIssueTrackerRule = _repo.Settings.AddGithubIssueTracker(url);
|
2024-08-05 02:34:49 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 03:18:57 -07:00
|
|
|
|
SelectedIssueTrackerRule = _repo.Settings.AddGithubIssueTracker(null);
|
2024-08-05 02:34:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddSampleJiraIssueTracker()
|
|
|
|
|
{
|
2024-08-05 03:18:57 -07:00
|
|
|
|
SelectedIssueTrackerRule = _repo.Settings.AddJiraIssueTracker();
|
2024-08-05 02:34:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void NewIssueTracker()
|
|
|
|
|
{
|
2024-08-05 03:18:57 -07:00
|
|
|
|
SelectedIssueTrackerRule = _repo.Settings.AddNewIssueTracker();
|
2024-08-05 02:34:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveSelectedIssueTracker()
|
|
|
|
|
{
|
2024-08-15 03:59:35 -07:00
|
|
|
|
if (_selectedIssueTrackerRule != null)
|
|
|
|
|
_repo.Settings.RemoveIssueTracker(_selectedIssueTrackerRule);
|
2024-08-05 03:18:57 -07:00
|
|
|
|
SelectedIssueTrackerRule = null;
|
2024-08-05 02:34:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-24 19:59:06 -07:00
|
|
|
|
public void Save()
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-09-13 00:20:52 -07:00
|
|
|
|
SetIfChanged("user.name", UserName, "");
|
|
|
|
|
SetIfChanged("user.email", UserEmail, "");
|
|
|
|
|
SetIfChanged("commit.gpgsign", GPGCommitSigningEnabled ? "true" : "false", "false");
|
|
|
|
|
SetIfChanged("tag.gpgsign", GPGTagSigningEnabled ? "true" : "false", "false");
|
|
|
|
|
SetIfChanged("user.signingkey", GPGUserSigningKey, "");
|
|
|
|
|
SetIfChanged("http.proxy", HttpProxy, "");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-13 00:20:52 -07:00
|
|
|
|
private void SetIfChanged(string key, string value, string defValue)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
bool changed = false;
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (_cached.TryGetValue(key, out var old))
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
changed = old != value;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
2024-09-13 00:20:52 -07:00
|
|
|
|
else if (!string.IsNullOrEmpty(value) && value != defValue)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (changed)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
new Commands.Config(_repo.FullPath).Set(key, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly Repository _repo = null;
|
|
|
|
|
private readonly Dictionary<string, string> _cached = null;
|
2024-07-27 19:11:10 -07:00
|
|
|
|
private string _httpProxy;
|
2024-08-15 03:59:35 -07:00
|
|
|
|
private Models.CommitTemplate _selectedCommitTemplate = null;
|
2024-08-05 03:18:57 -07:00
|
|
|
|
private Models.IssueTrackerRule _selectedIssueTrackerRule = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|