mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-26 21:04:59 +00:00
fix: Save different GPGFormat executable files independently
This commit is contained in:
parent
d3d6889e25
commit
8c0ff1f613
3 changed files with 29 additions and 14 deletions
|
@ -2,18 +2,17 @@
|
||||||
|
|
||||||
namespace SourceGit.Models
|
namespace SourceGit.Models
|
||||||
{
|
{
|
||||||
public class GPGFormat(string name, string value, string desc, string program, bool needFindProgram)
|
public class GPGFormat(string name, string value, string desc, string program)
|
||||||
{
|
{
|
||||||
public string Name { get; set; } = name;
|
public string Name { get; set; } = name;
|
||||||
public string Value { get; set; } = value;
|
public string Value { get; set; } = value;
|
||||||
public string Desc { get; set; } = desc;
|
public string Desc { get; set; } = desc;
|
||||||
public string Program { get; set; } = program;
|
public string Program { get; set; } = program;
|
||||||
public bool NeedFindProgram { get; set; } = needFindProgram;
|
|
||||||
|
|
||||||
public static readonly List<GPGFormat> Supported = [
|
public static readonly List<GPGFormat> Supported = [
|
||||||
new GPGFormat("OPENPGP", "openpgp", "DEFAULT", "gpg", true),
|
new GPGFormat("OPENPGP", "openpgp", "DEFAULT", "gpg"),
|
||||||
new GPGFormat("X.509", "x509", "", "gpgsm", true),
|
new GPGFormat("X.509", "x509", "", "gpgsm"),
|
||||||
new GPGFormat("SSH", "ssh", "Requires Git >= 2.34.0", "ssh-keygen", false),
|
new GPGFormat("SSH", "ssh", "Requires Git >= 2.34.0", "ssh-keygen"),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -412,14 +412,12 @@
|
||||||
<TextBlock Grid.Row="1" Grid.Column="0"
|
<TextBlock Grid.Row="1" Grid.Column="0"
|
||||||
Text="{DynamicResource Text.Preference.GPG.Path}"
|
Text="{DynamicResource Text.Preference.GPG.Path}"
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
Margin="0,0,16,0"
|
Margin="0,0,16,0"/>
|
||||||
IsVisible="{Binding #me.GPGFormat.NeedFindProgram}"/>
|
|
||||||
<TextBox Grid.Row="1" Grid.Column="1"
|
<TextBox Grid.Row="1" Grid.Column="1"
|
||||||
Height="28"
|
Height="28"
|
||||||
CornerRadius="3"
|
CornerRadius="3"
|
||||||
Text="{Binding #me.GPGExecutableFile, Mode=TwoWay}"
|
Text="{Binding #me.GPGExecutableFile, Mode=TwoWay}"
|
||||||
Watermark="{DynamicResource Text.Preference.GPG.Path.Placeholder}"
|
Watermark="{DynamicResource Text.Preference.GPG.Path.Placeholder}">
|
||||||
IsVisible="{Binding #me.GPGFormat.NeedFindProgram}">
|
|
||||||
<TextBox.InnerRightContent>
|
<TextBox.InnerRightContent>
|
||||||
<Button Classes="icon_button" Width="30" Height="30" Click="SelectGPGExecutable">
|
<Button Classes="icon_button" Width="30" Height="30" Click="SelectGPGExecutable">
|
||||||
<Path Data="{StaticResource Icons.Folder.Open}" Fill="{DynamicResource Brush.FG1}"/>
|
<Path Data="{StaticResource Icons.Folder.Open}" Fill="{DynamicResource Brush.FG1}"/>
|
||||||
|
|
|
@ -162,14 +162,18 @@ namespace SourceGit.Views
|
||||||
if (config.TryGetValue("gpg.format", out var gpgFormat))
|
if (config.TryGetValue("gpg.format", out var gpgFormat))
|
||||||
GPGFormat = Models.GPGFormat.Supported.Find(x => x.Value == gpgFormat) ?? Models.GPGFormat.Supported[0];
|
GPGFormat = Models.GPGFormat.Supported.Find(x => x.Value == gpgFormat) ?? Models.GPGFormat.Supported[0];
|
||||||
|
|
||||||
if (GPGFormat.Value == "opengpg" && config.TryGetValue("gpg.program", out var opengpg))
|
foreach (var supportedSingleFormat in Models.GPGFormat.Supported)
|
||||||
GPGExecutableFile = opengpg;
|
{
|
||||||
else if (config.TryGetValue($"gpg.{GPGFormat.Value}.program", out var gpgProgram))
|
_gpgExecutableFiles[supportedSingleFormat.Value] = config.GetValueOrDefault($"gpg.{supportedSingleFormat.Value}.program");
|
||||||
GPGExecutableFile = gpgProgram;
|
}
|
||||||
|
if (config.TryGetValue("gpg.program", out var defaultGpgProgram))
|
||||||
|
_gpgExecutableFiles[Models.GPGFormat.Supported[0].Value] = defaultGpgProgram;
|
||||||
|
GPGExecutableFile = _gpgExecutableFiles[GPGFormat.Value];
|
||||||
|
|
||||||
ver = new Commands.Version().Query();
|
ver = new Commands.Version().Query();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.PropertyChanged += PreferencePropertyChanged;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
GitVersion = ver;
|
GitVersion = ver;
|
||||||
}
|
}
|
||||||
|
@ -189,7 +193,7 @@ namespace SourceGit.Views
|
||||||
SetIfChanged(config, "commit.gpgsign", EnableGPGCommitSigning ? "true" : "false");
|
SetIfChanged(config, "commit.gpgsign", EnableGPGCommitSigning ? "true" : "false");
|
||||||
SetIfChanged(config, "tag.gpgsign", EnableGPGTagSigning ? "true" : "false");
|
SetIfChanged(config, "tag.gpgsign", EnableGPGTagSigning ? "true" : "false");
|
||||||
SetIfChanged(config, "gpg.format", GPGFormat.Value);
|
SetIfChanged(config, "gpg.format", GPGFormat.Value);
|
||||||
SetIfChanged(config, $"gpg.{GPGFormat.Value}.program", GPGFormat.Value != "ssh" ? GPGExecutableFile : null);
|
SetIfChanged(config, $"gpg.{GPGFormat.Value}.program", GPGExecutableFile);
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
@ -296,5 +300,19 @@ namespace SourceGit.Views
|
||||||
if (changed)
|
if (changed)
|
||||||
new Commands.Config(null).Set(key, value);
|
new Commands.Config(null).Set(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void PreferencePropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Property == GPGExecutableFileProperty)
|
||||||
|
_gpgExecutableFiles[GPGFormat.Value] = (string)e.NewValue;
|
||||||
|
else if (e.Property == GPGFormatProperty)
|
||||||
|
{
|
||||||
|
var newValue = _gpgExecutableFiles[GPGFormat.Value];
|
||||||
|
if (GPGExecutableFile != newValue)
|
||||||
|
GPGExecutableFile = newValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Dictionary<string, string> _gpgExecutableFiles = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue