Skip to content

Commit

Permalink
Refactor how are handled boolean git settings
Browse files Browse the repository at this point in the history
  • Loading branch information
pmiossec committed Aug 3, 2022
1 parent 5f97338 commit 4f359c4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
using Microsoft;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft;

namespace GitUI.CommandsDialogs.SettingsDialog.Pages
{
public partial class GitConfigAdvancedSettingsPage : ConfigFileSettingsPage
{
private readonly Dictionary<string, CheckBox> _gitSettings = new();

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);
}

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

protected override void SettingsToPage()
{
Validates.NotNull(CurrentSettings);
checkBoxPullRebase.Checked = CurrentSettings.GetValue("pull.rebase") == "true";
checkBoxFetchPrune.Checked = CurrentSettings.GetValue("fetch.prune") == "true";
checkBoxRebaseAutostash.Checked = CurrentSettings.GetValue("rebase.autoStash") == "true";
checkBoxRebaseAutosquash.Checked = CurrentSettings.GetValue("rebase.autosquash") == "true";
foreach (KeyValuePair<string, CheckBox> gitSetting in _gitSettings)
{
gitSetting.Value.Checked = CurrentSettings.GetValue(gitSetting.Key) == "true";
}
}

protected override void PageToSettings()
{
Validates.NotNull(CurrentSettings);
CurrentSettings.SetValue("pull.rebase", checkBoxPullRebase.Checked ? "true" : "false");
CurrentSettings.SetValue("fetch.prune", checkBoxFetchPrune.Checked ? "true" : "false");
CurrentSettings.SetValue("rebase.autoStash", checkBoxRebaseAutostash.Checked ? "true" : "false");
CurrentSettings.SetValue("rebase.autosquash", checkBoxRebaseAutosquash.Checked ? "true" : "false");
foreach (KeyValuePair<string, CheckBox> gitSetting in _gitSettings)
{
CurrentSettings.SetValue(gitSetting.Key, gitSetting.Value.Checked ? "true" : "false");
}
}
}
}
4 changes: 4 additions & 0 deletions GitUI/Translation/English.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8029,6 +8029,10 @@ Context menu for additional operations</source>
<source>Rebase local branch when pulling (instead of merge)</source>
<target />
</trans-unit>
<trans-unit id="checkBoxRebaseAutosquash.Text">
<source>Automatically squash commits when doing an interactive rebase</source>
<target />
</trans-unit>
<trans-unit id="checkBoxRebaseAutostash.Text">
<source>Automatically stash before doing a rebase</source>
<target />
Expand Down

0 comments on commit 4f359c4

Please sign in to comment.