Skip to content

Commit

Permalink
Split pull button in 2 buttons (fetch and pull)
Browse files Browse the repository at this point in the history
* One for fetch operations,
* One for rebase operations,

With there own default operation setting.

Improvement over gitextensions#3923

# Conflicts:
#	GitUI/CommandsDialogs/FormBrowse.Designer.cs
#	GitUI/CommandsDialogs/FormBrowse.cs
  • Loading branch information
pmiossec committed Nov 7, 2021
1 parent ec51f01 commit 2084c83
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 86 deletions.
9 changes: 9 additions & 0 deletions GitCommands/Settings/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,15 @@ public enum PullAction
Default
}

/// <summary>
/// Gets or sets the default fetch action that is performed by the toolbar icon when it is clicked on.
/// </summary>
public static PullAction DefaultFetchAction
{
get => GetEnum("DefaultFetchAction", PullAction.Fetch);
set => SetEnum("DefaultFetchAction", value);
}

/// <summary>
/// Gets or sets the default pull action that is performed by the toolbar icon when it is clicked on.
/// </summary>
Expand Down
186 changes: 136 additions & 50 deletions GitUI/CommandsDialogs/FormBrowse.Designer.cs

Large diffs are not rendered by default.

74 changes: 53 additions & 21 deletions GitUI/CommandsDialogs/FormBrowse.InitMenusAndToolbars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private void InitMenusAndToolbars(string? revFilter, string? pathFilter)
translateToolStripMenuItem,
recoverLostObjectsToolStripMenuItem,
branchSelect,
toolStripButtonFetch,
toolStripButtonPull,
pullToolStripMenuItem,
pullToolStripMenuItem1,
Expand Down Expand Up @@ -70,8 +71,9 @@ private void InitMenusAndToolbars(string? revFilter, string? pathFilter)

UpdateCommitButtonAndGetBrush(status: null, AppSettings.ShowGitStatusInBrowseToolbar);

FillNextFetchActionAsDefaultToolStripMenuItems();
FillNextPullActionAsDefaultToolStripMenuItems();
RefreshDefaultPullAction();
RefreshDefaultActions();

FillUserShells(defaultShell: BashShell.ShellName);

Expand Down Expand Up @@ -144,9 +146,32 @@ void WorkaroundToolbarLocationBug()
}
}

private void FillNextFetchActionAsDefaultToolStripMenuItems()
{
FillNextActionAsDefaultToolStripMenuItems(toolStripButtonFetch, setDefaultFetchButtonActionToolStripMenuItem,
(object sender, EventArgs eventArgs) =>
{
var clickedMenuItem = (ToolStripMenuItem)sender;
AppSettings.DefaultFetchAction = (AppSettings.PullAction)clickedMenuItem.Tag;
RefreshDefaultFetchAction();
});
}

private void FillNextPullActionAsDefaultToolStripMenuItems()
{
var setDefaultPullActionDropDown = (ToolStripDropDownMenu)setDefaultPullButtonActionToolStripMenuItem.DropDown;
FillNextActionAsDefaultToolStripMenuItems(toolStripButtonPull, setDefaultPullButtonActionToolStripMenuItem,
(object sender, EventArgs eventArgs) =>
{
var clickedMenuItem = (ToolStripMenuItem)sender;
AppSettings.DefaultPullAction = (AppSettings.PullAction)clickedMenuItem.Tag;
RefreshDefaultPullAction();
});
}

private void FillNextActionAsDefaultToolStripMenuItems(ToolStripSplitButton buttonActionToolStripMenuItem,
ToolStripMenuItem defaultButtonActionToolStripMenuItem, EventHandler setDefaultPullActionMenuItemClick)
{
var setDefaultPullActionDropDown = (ToolStripDropDownMenu)defaultButtonActionToolStripMenuItem.DropDown;

// Show both Check and Image margins in a menu
setDefaultPullActionDropDown.ShowImageMargin = true;
Expand All @@ -161,7 +186,7 @@ private void FillNextPullActionAsDefaultToolStripMenuItems()
}
};

var setDefaultPullActionDropDownItems = toolStripButtonPull.DropDownItems
var setDefaultPullActionDropDownItems = buttonActionToolStripMenuItem.DropDownItems
.OfType<ToolStripMenuItem>()
.Where(tsmi => tsmi.Tag is AppSettings.PullAction)
.Select(tsmi =>
Expand All @@ -175,19 +200,12 @@ private void FillNextPullActionAsDefaultToolStripMenuItems()
Tag = tsmi.Tag
};
tsi.Click += SetDefaultPullActionMenuItemClick;
tsi.Click += setDefaultPullActionMenuItemClick;
return tsi;
});

setDefaultPullActionDropDown.Items.AddRange(setDefaultPullActionDropDownItems.ToArray());

void SetDefaultPullActionMenuItemClick(object sender, EventArgs eventArgs)
{
var clickedMenuItem = (ToolStripMenuItem)sender;
AppSettings.DefaultPullAction = (AppSettings.PullAction)clickedMenuItem.Tag;
RefreshDefaultPullAction();
}
}

private void FillUserShells(string defaultShell)
Expand Down Expand Up @@ -239,36 +257,50 @@ private void FillUserShells(string defaultShell)
gitBashToolStripMenuItem.Tag = _shellProvider.GetShell(BashShell.ShellName);
}

private void RefreshDefaultActions()
{
RefreshDefaultFetchAction();
RefreshDefaultPullAction();
}

private void RefreshDefaultFetchAction()
{
RefreshDefaultAction(setDefaultFetchButtonActionToolStripMenuItem, AppSettings.DefaultFetchAction);
}

private void RefreshDefaultPullAction()
{
if (setDefaultPullButtonActionToolStripMenuItem is null)
RefreshDefaultAction(setDefaultPullButtonActionToolStripMenuItem, AppSettings.DefaultPullAction);
}

private void RefreshDefaultAction(ToolStripMenuItem? toolStripMenuItem, AppSettings.PullAction defaultPullAction)
{
if (toolStripMenuItem is null)
{
// We may get called while instantiating the form
return;
}

var defaultPullAction = AppSettings.DefaultPullAction;

foreach (ToolStripMenuItem menuItem in setDefaultPullButtonActionToolStripMenuItem.DropDown.Items)
foreach (ToolStripMenuItem menuItem in toolStripMenuItem.DropDown.Items)
{
menuItem.Checked = (AppSettings.PullAction)menuItem.Tag == defaultPullAction;
}

switch (defaultPullAction)
{
case AppSettings.PullAction.Fetch:
toolStripButtonPull.Image = Images.PullFetch.AdaptLightness();
toolStripButtonPull.ToolTipText = _pullFetch.Text;
toolStripButtonFetch.Image = Images.PullFetch.AdaptLightness();
toolStripButtonFetch.ToolTipText = _pullFetch.Text;
break;

case AppSettings.PullAction.FetchAll:
toolStripButtonPull.Image = Images.PullFetchAll.AdaptLightness();
toolStripButtonPull.ToolTipText = _pullFetchAll.Text;
toolStripButtonFetch.Image = Images.PullFetchAll.AdaptLightness();
toolStripButtonFetch.ToolTipText = _pullFetchAll.Text;
break;

case AppSettings.PullAction.FetchPruneAll:
toolStripButtonPull.Image = Images.PullFetchPruneAll.AdaptLightness();
toolStripButtonPull.ToolTipText = _pullFetchPruneAll.Text;
toolStripButtonFetch.Image = Images.PullFetchPruneAll.AdaptLightness();
toolStripButtonFetch.ToolTipText = _pullFetchPruneAll.Text;
break;

case AppSettings.PullAction.Merge:
Expand Down
19 changes: 15 additions & 4 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ protected override void OnActivated(EventArgs e)
Handle,
new WindowsThumbnailToolbarButtons(
new WindowsThumbnailToolbarButton(toolStripButtonCommit.Text, toolStripButtonCommit.Image, CommitToolStripMenuItemClick),
new WindowsThumbnailToolbarButton(toolStripButtonPush.Text, toolStripButtonPush.Image, PushToolStripMenuItemClick),
new WindowsThumbnailToolbarButton(toolStripButtonPull.Text, toolStripButtonPull.Image, PullToolStripMenuItemClick)));
new WindowsThumbnailToolbarButton(toolStripButtonFetch.Text, toolStripButtonFetch.Image, fetchToolStripMenuItem_Click),
new WindowsThumbnailToolbarButton(toolStripButtonPull.Text, toolStripButtonPull.Image, PullToolStripMenuItemClick),
new WindowsThumbnailToolbarButton(toolStripButtonPush.Text, toolStripButtonPush.Image, PushToolStripMenuItemClick)));
}

this.InvokeAsync(OnActivate).FileAndForget();
Expand Down Expand Up @@ -503,7 +504,7 @@ protected override void OnClosed(EventArgs e)
protected override void OnUICommandsChanged(GitUICommandsChangedEventArgs e)
{
var oldCommands = e.OldCommands;
RefreshDefaultPullAction();
RefreshDefaultActions();

if (oldCommands is not null)
{
Expand Down Expand Up @@ -1392,7 +1393,7 @@ private void OnShowSettingsClick(object sender, EventArgs e)

_gitStatusMonitor.Active = NeedsGitStatusMonitor() && Module.IsValidGitWorkingDir();

RefreshDefaultPullAction();
RefreshDefaultActions();
}

private void TagToolStripMenuItemClick(object sender, EventArgs e)
Expand Down Expand Up @@ -2401,6 +2402,16 @@ private void pullToolStripMenuItem1_Click(object sender, EventArgs e)
DoPull(pullAction: AppSettings.FormPullAction, isSilent: false);
}

private void ToolStripButtonFetchClick(object sender, EventArgs e)
{
DoPull(pullAction: AppSettings.DefaultFetchAction, isSilent: true);
}

private void ToolStripButtonFetch_DropDownOpened(object sender, EventArgs e)
{
ToolStripFilters.PreventToolStripSplitButtonClosing(sender as ToolStripSplitButton);
}

private void mergeToolStripMenuItem_Click(object sender, EventArgs e)
{
DoPull(pullAction: AppSettings.PullAction.Merge, isSilent: true);
Expand Down
2 changes: 1 addition & 1 deletion GitUI/GitUICommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,7 @@ private static void UpdateSettingsBasedOnArguments(IReadOnlyDictionary<string, s

if (arguments.ContainsKey("fetch"))
{
AppSettings.DefaultPullAction = AppSettings.PullAction.Fetch;
AppSettings.DefaultFetchAction = AppSettings.PullAction.Fetch;
}

if (arguments.ContainsKey("autostash"))
Expand Down
8 changes: 8 additions & 0 deletions GitUI/Translation/English.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -3042,6 +3042,10 @@ Do you want to continue?</source>
<source>&amp;Solve merge conflicts...</source>
<target />
</trans-unit>
<trans-unit id="setDefaultFetchButtonActionToolStripMenuItem.Text">
<source>Set default Fetch button action</source>
<target />
</trans-unit>
<trans-unit id="setDefaultPullButtonActionToolStripMenuItem.Text">
<source>Set &amp;default Pull button action</source>
<target />
Expand Down Expand Up @@ -3094,6 +3098,10 @@ Do you want to continue?</source>
<source>Commit</source>
<target />
</trans-unit>
<trans-unit id="toolStripButtonFetch.Text">
<source>Fetch</source>
<target />
</trans-unit>
<trans-unit id="toolStripButtonLevelUp.ToolTipText">
<source>Submodules</source>
<target />
Expand Down
25 changes: 17 additions & 8 deletions GitUI/WindowsJumpListManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public sealed class WindowsJumpListManager : IWindowsJumpListManager
private readonly IRepositoryDescriptionProvider _repositoryDescriptionProvider;
private ThumbnailToolBarButton? _commitButton;
private ThumbnailToolBarButton? _pushButton;
private ThumbnailToolBarButton? _fetchButton;
private ThumbnailToolBarButton? _pullButton;
private string? _deferredAddToRecent;
private bool ToolbarButtonsCreated => _commitButton is not null;
Expand Down Expand Up @@ -69,6 +70,7 @@ private void Dispose(bool disposing)
_commitButton?.Dispose();
_pushButton?.Dispose();
_pullButton?.Dispose();
_fetchButton?.Dispose();
}
}

Expand Down Expand Up @@ -128,10 +130,12 @@ public void AddToRecent(string workingDir)
Validates.NotNull(_commitButton);
Validates.NotNull(_pushButton);
Validates.NotNull(_fetchButton);
Validates.NotNull(_pullButton);
_commitButton.Enabled = true;
_pushButton.Enabled = true;
_fetchButton.Enabled = true;
_pullButton.Enabled = true;
}, nameof(AddToRecent));
}
Expand Down Expand Up @@ -188,17 +192,20 @@ public void CreateJumpList(IntPtr windowHandle, WindowsThumbnailToolbarButtons b

void CreateTaskbarButtons(IntPtr handle, WindowsThumbnailToolbarButtons thumbButtons)
{
_commitButton = new ThumbnailToolBarButton(MakeIcon(thumbButtons.Commit.Image, 48, true), thumbButtons.Commit.Text);
_commitButton.Click += thumbButtons.Commit.Click;
_commitButton = CreateThumbnailToolBarButton(thumbButtons.Commit);
_fetchButton = CreateThumbnailToolBarButton(thumbButtons.Fetch);
_pullButton = CreateThumbnailToolBarButton(thumbButtons.Pull);
_pushButton = CreateThumbnailToolBarButton(thumbButtons.Push);

_pushButton = new ThumbnailToolBarButton(MakeIcon(thumbButtons.Push.Image, 48, true), thumbButtons.Push.Text);
_pushButton.Click += thumbButtons.Push.Click;

_pullButton = new ThumbnailToolBarButton(MakeIcon(thumbButtons.Pull.Image, 48, true), thumbButtons.Pull.Text);
_pullButton.Click += thumbButtons.Pull.Click;
ThumbnailToolBarButton CreateThumbnailToolBarButton(WindowsThumbnailToolbarButton button)
{
var thumbnailToolBarButton = new ThumbnailToolBarButton(MakeIcon(button.Image, 48, true), button.Text);
thumbnailToolBarButton.Click += button.Click;
return thumbnailToolBarButton;
}

// Call this method using reflection. This is a workaround to *not* reference WPF libraries, because of how the WindowsAPICodePack was implemented.
TaskbarManager.Instance.ThumbnailToolBars.AddButtons(handle, _commitButton, _pullButton, _pushButton);
TaskbarManager.Instance.ThumbnailToolBars.AddButtons(handle, _commitButton, _fetchButton, _pullButton, _pushButton);
}
}

Expand All @@ -216,10 +223,12 @@ public void DisableThumbnailToolbar()
{
Validates.NotNull(_commitButton);
Validates.NotNull(_pushButton);
Validates.NotNull(_fetchButton);
Validates.NotNull(_pullButton);
_commitButton.Enabled = false;
_pushButton.Enabled = false;
_pullButton.Enabled = false;
_fetchButton.Enabled = false;
}, nameof(DisableThumbnailToolbar));
}

Expand Down
6 changes: 4 additions & 2 deletions GitUI/WindowsThumbnailToolbarButtons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
{
public sealed class WindowsThumbnailToolbarButtons
{
public WindowsThumbnailToolbarButtons(WindowsThumbnailToolbarButton commit, WindowsThumbnailToolbarButton pull, WindowsThumbnailToolbarButton push)
public WindowsThumbnailToolbarButtons(WindowsThumbnailToolbarButton commit, WindowsThumbnailToolbarButton fetch, WindowsThumbnailToolbarButton pull, WindowsThumbnailToolbarButton push)
{
Commit = commit;
Fetch = fetch;
Pull = pull;
Push = push;
}

public WindowsThumbnailToolbarButton Commit { get; }
public WindowsThumbnailToolbarButton Fetch { get; }
public WindowsThumbnailToolbarButton Pull { get; }
public WindowsThumbnailToolbarButton Push { get; }
}
}
}

0 comments on commit 2084c83

Please sign in to comment.