Skip to content

Commit

Permalink
Merge pull request gitextensions#8520 from pmiossec/form_push_manage_…
Browse files Browse the repository at this point in the history
…selection

FormPush: Add context menu to easily manage multiple push selection
  • Loading branch information
RussKie committed Oct 9, 2020
2 parents 19f3a34 + d8d2268 commit 545d6b2
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 1 deletion.
40 changes: 40 additions & 0 deletions GitUI/CommandsDialogs/FormPush.Designer.cs

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

59 changes: 58 additions & 1 deletion GitUI/CommandsDialogs/FormPush.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -43,7 +44,7 @@ public partial class FormPush : GitModuleForm
private readonly IConfigFileRemoteSettingsManager _remotesManager;

public bool ErrorOccurred { get; private set; }

private int _pushColumnIndex;
#region Translation
private readonly TranslationString _branchNewForRemote =
new TranslationString("The branch you are about to push seems to be a new branch for the remote." +
Expand Down Expand Up @@ -155,6 +156,14 @@ void Init()
{
ShowOptions_LinkClicked(null, null);
}

// Save the value because later the value for all the columns will be at '0'
_pushColumnIndex = PushColumn.Index;

PushColumn.HeaderCell.ContextMenuStrip = menuPushSelection;

// Handle left button click to also open the context menu
BranchGrid.ColumnHeaderMouseClick += BranchGrid_ColumnHeaderMouseClick;
}
}

Expand Down Expand Up @@ -1197,5 +1206,53 @@ private void ForceWithLeaseCheckedChanged(object sender, EventArgs e)
ForcePushBranches.Checked = false;
}
}

private void BranchGrid_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex == _pushColumnIndex && e.Button == MouseButtons.Left)
{
var locationWhereToOpenContextMenu = BranchGrid.PointToScreen(BranchGrid.Location)
+ new Size(BranchGrid.GetCellDisplayRectangle(_pushColumnIndex, -1, true).Location)
+ new Size(e.Location);
menuPushSelection.Show(locationWhereToOpenContextMenu);
}
}

private void unselectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
SetBranchesPushCheckboxesState(_ => false);
}

private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
SetBranchesPushCheckboxesState(_ => true);
}

private void selectTrackedToolStripMenuItem_Click(object sender, EventArgs e)
{
SetBranchesPushCheckboxesState(row =>
{
// Check if the branch is tracked (i.e. not new)
var isNewAtRemote = row.Cells[NewColumn.Name] as DataGridViewTextBoxCell;
return isNewAtRemote != null && isNewAtRemote.Value.ToString() == Strings.No;
});
}

private void SetBranchesPushCheckboxesState(Func<DataGridViewRow, bool> willPush)
{
// Necessary to end the edit mode of the Cell.
BranchGrid.EndEdit();

foreach (DataGridViewRow row in BranchGrid.Rows)
{
var pushCheckBox = row.Cells[PushColumn.Name] as DataGridViewCheckBoxCell;
if (pushCheckBox == null || !pushCheckBox.Visible)
{
continue;
}

pushCheckBox.Value = willPush(row);
}
}
}
}
21 changes: 21 additions & 0 deletions GitUI/CommandsDialogs/FormPush.resx
Expand Up @@ -138,4 +138,25 @@
<metadata name="DeleteColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="LocalColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="RemoteColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="NewColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="PushColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ForceColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="DeleteColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="menuPushSelection.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>114, 17</value>
</metadata>
</root>
12 changes: 12 additions & 0 deletions GitUI/Translation/English.xlf
Expand Up @@ -5469,6 +5469,18 @@ Would you like to do it now?</source>
<source>to</source>
<target />
</trans-unit>
<trans-unit id="selectAllToolStripMenuItem.Text">
<source>Select all</source>
<target />
</trans-unit>
<trans-unit id="selectTrackedToolStripMenuItem.Text">
<source>Select tracked</source>
<target />
</trans-unit>
<trans-unit id="unselectAllToolStripMenuItem.Text">
<source>Unselect all</source>
<target />
</trans-unit>
</body>
</file>
<file datatype="plaintext" original="FormPuttyError" source-language="en">
Expand Down

0 comments on commit 545d6b2

Please sign in to comment.