Skip to content

Commit

Permalink
Maybe a little more clearer using a record type
Browse files Browse the repository at this point in the history
  • Loading branch information
pmiossec committed Aug 3, 2022
1 parent 4f359c4 commit 370a82a
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@ namespace GitUI.CommandsDialogs.SettingsDialog.Pages
{
public partial class GitConfigAdvancedSettingsPage : ConfigFileSettingsPage
{
private readonly Dictionary<string, CheckBox> _gitSettings = new();
private record GitSettingUiMapping(string GitSettingKey, CheckBox MappedCheckbox);
private readonly List<GitSettingUiMapping> _gitSettings;

public GitConfigAdvancedSettingsPage()
{
InitializeComponent();
Text = "Advanced";
InitializeComplete();
FillGitSettings();
Load += GitConfigAdvancedSettingsPage_Load;
}

private void FillGitSettings()
{
_gitSettings.Add("pull.rebase", checkBoxPullRebase);
_gitSettings.Add("fetch.prune", checkBoxFetchPrune);
_gitSettings.Add("rebase.autoStash", checkBoxRebaseAutostash);
_gitSettings.Add("rebase.autosquash", checkBoxRebaseAutosquash);
_gitSettings = new List<GitSettingUiMapping>
{
new("pull.rebase", checkBoxPullRebase),
new("fetch.prune", checkBoxFetchPrune),
new("rebase.autoStash", checkBoxRebaseAutostash),
new("rebase.autosquash", checkBoxRebaseAutosquash)
};
Load += GitConfigAdvancedSettingsPage_Load;
}

private void GitConfigAdvancedSettingsPage_Load(object? sender, System.EventArgs e)
{
foreach (KeyValuePair<string, CheckBox> gitSetting in _gitSettings)
foreach (var gitSetting in _gitSettings)
{
gitSetting.Value.Text += $" [{gitSetting.Key}]";
gitSetting.MappedCheckbox.Text += $" [{gitSetting.GitSettingKey}]";
}
}

protected override void SettingsToPage()
{
Validates.NotNull(CurrentSettings);
foreach (KeyValuePair<string, CheckBox> gitSetting in _gitSettings)
foreach (var gitSetting in _gitSettings)
{
gitSetting.Value.Checked = CurrentSettings.GetValue(gitSetting.Key) == "true";
gitSetting.MappedCheckbox.Checked = CurrentSettings.GetValue(gitSetting.GitSettingKey) == "true";
}
}

protected override void PageToSettings()
{
Validates.NotNull(CurrentSettings);
foreach (KeyValuePair<string, CheckBox> gitSetting in _gitSettings)
foreach (var gitSetting in _gitSettings)
{
CurrentSettings.SetValue(gitSetting.Key, gitSetting.Value.Checked ? "true" : "false");
CurrentSettings.SetValue(gitSetting.GitSettingKey, gitSetting.MappedCheckbox.Checked ? "true" : "false");
}
}
}
Expand Down

0 comments on commit 370a82a

Please sign in to comment.