Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed changes of PR #3833, suspend/resume redrawn of ToolStripEx when dropdown menu is opened/closed #10260

Merged
merged 5 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions GitUI/CommandsDialogs/FormBrowse.Designer.cs

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

17 changes: 0 additions & 17 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,6 @@ private void WorkingDirDropDownOpening(object sender, EventArgs e)

_NO_TRANSLATE_WorkingDir.DropDownItems.Add(mnuRecentReposSettings);

ToolStripFilters.PreventToolStripSplitButtonClosing((ToolStripSplitButton)sender);
_NO_TRANSLATE_WorkingDir.DropDown.ResumeLayout();
}

Expand Down Expand Up @@ -1935,7 +1934,6 @@ private void CurrentBranchDropDownOpening(object sender, EventArgs e)
branchSelect.DropDownItems.Add(new ToolStripSeparator());
AddBranchesMenuItems();

ToolStripFilters.PreventToolStripSplitButtonClosing(sender as ToolStripSplitButton);
branchSelect.DropDown.ResumeLayout();

void AddCheckoutBranchMenuItem()
Expand Down Expand Up @@ -2567,11 +2565,6 @@ private void SubmoduleToolStripButtonClick(object sender, EventArgs e)
SetWorkingDir(path);
}

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

#region Submodules

private ToolStripItem CreateSubmoduleMenuItem(SubmoduleInfo info, string textFormat = "{0}")
Expand Down Expand Up @@ -2797,11 +2790,6 @@ private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
updateForm.SearchForUpdatesAndShow(Owner, true);
}

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

/// <summary>
/// Adds a tab with console interface to Git over the current working copy. Recreates the terminal on tab activation if user exits the shell.
/// </summary>
Expand Down Expand Up @@ -3059,11 +3047,6 @@ private void manageWorktreeToolStripMenuItem_Click(object sender, EventArgs e)
}
}

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

private void undoLastCommitToolStripMenuItem_Click(object sender, EventArgs e)
{
if (AppSettings.DontConfirmUndoLastCommit || MessageBox.Show(this, _undoLastCommitText.Text, _undoLastCommitCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
Expand Down
8 changes: 8 additions & 0 deletions GitUI/Interops/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ internal static partial class NativeMethods
public const int EM_CHARFROMPOS = 0x00D7;
public const int EM_GETFIRSTVISIBLELINE = 0xCE;

public static readonly IntPtr FALSE = IntPtr.Zero;
public static readonly IntPtr TRUE = new(1);

/// <summary>
/// The WM_NULL message performs no operation. An application sends the WM_NULL message if it wants to post a message that the recipient window will ignore.
/// </summary>
public const int WM_NULL = 0x0000;

/// <summary>
/// The WM_SETREDRAW message is sent to a window to allow changes in that window to be redrawn, or to prevent changes in that window from being redrawn.
/// </summary>
public const int WM_SETREDRAW = 0x000B;

/// <summary>
/// The WM_PAINT message is sent when the system or another application makes a request to paint a portion of an application's window. The message is sent when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage function when the application obtains a WM_PAINT message by using the GetMessage or PeekMessage function.
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion GitUI/UserControls/FilterToolBar.Designer.cs

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

31 changes: 0 additions & 31 deletions GitUI/UserControls/FilterToolBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,6 @@ public void InitToolStripStyles(Color toolForeColor, Color toolBackColor)
tstxtRevisionFilter.ForeColor = toolForeColor;
}

public void PreventToolStripSplitButtonClosing(ToolStripSplitButton? control)
{
if (control is null
|| Parent is not ContainerControl parentContainer)
{
return;
}

control.Tag = parentContainer.FindFocusedControl();
gerhardol marked this conversation as resolved.
Show resolved Hide resolved
control.DropDownClosed += ToolStripSplitButtonDropDownClosed;
}

private void SelectShowBranchesFilterOption(int selectedIndex)
{
if (selectedIndex >= tssbtnShowBranches.DropDownItems.Count)
Expand Down Expand Up @@ -382,20 +370,6 @@ private void revisionFilterBox_CheckedChanged(object sender, System.EventArgs e)
}
}

private static void ToolStripSplitButtonDropDownClosed(object sender, EventArgs e)
{
if (sender is ToolStripSplitButton control)
{
control.DropDownClosed -= ToolStripSplitButtonDropDownClosed;

if (control.Tag is Control controlToFocus)
{
controlToFocus.Focus();
control.Tag = null;
}
}
}

private void tsbtnAdvancedFilter_ButtonClick(object sender, EventArgs e)
{
if (!tsmiResetAllFilters.Enabled)
Expand All @@ -408,11 +382,6 @@ private void tsbtnAdvancedFilter_ButtonClick(object sender, EventArgs e)
}
}

private void tsbtnAdvancedFilter_DropDownOpening(object sender, EventArgs e)
{
PreventToolStripSplitButtonClosing(sender as ToolStripSplitButton);
}

private void tstxtRevisionFilter_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyValue == (char)Keys.Enter)
Expand Down
39 changes: 39 additions & 0 deletions GitUI/UserControls/ToolStripEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,45 @@ public ToolStripEx()
_gripButton = propGrip.GetValue(this) as ToolStripButton;
}

protected override void OnItemAdded(ToolStripItemEventArgs e)
{
base.OnItemAdded(e);

if (e.Item is ToolStripDropDownItem item)
{
item.DropDownOpening += SplitButton_DropDownOpening;
item.DropDownClosed += SplitButton_DropDownClosed;
}
}

protected override void OnItemRemoved(ToolStripItemEventArgs e)
{
if (e.Item is ToolStripDropDownItem item)
{
item.DropDownOpening -= SplitButton_DropDownOpening;
item.DropDownClosed -= SplitButton_DropDownClosed;
}
}

private void SplitButton_DropDownOpening(object? sender, EventArgs e)
{
if (sender is ToolStripDropDownItem item && item.Owner is Control control)
{
// Suspends the control's rendering process.
NativeMethods.SendMessageW(control.Handle, NativeMethods.WM_SETREDRAW, NativeMethods.FALSE, IntPtr.Zero);
}
}

private void SplitButton_DropDownClosed(object? sender, EventArgs e)
{
if (sender is ToolStripDropDownItem item && item.Owner is Control control)
{
// Resumes the control's rendering process and trigger a redraw.
NativeMethods.SendMessageW(control.Handle, NativeMethods.WM_SETREDRAW, NativeMethods.TRUE, IntPtr.Zero);
control.Refresh();
}
}

/// <summary>
/// Gets or sets whether the ToolStripEx honors item clicks when its containing form does
/// not have input focus.
Expand Down