Skip to content

Commit

Permalink
Fix toolbar order (revisited)
Browse files Browse the repository at this point in the history
The designer keeps on wrecking havoc with toolbars. Revisit the toolbar
layout workaround, and add assertions to validate the outcome.
  • Loading branch information
RussKie committed Jan 30, 2021
1 parent 53e88d1 commit f841949
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/FormBrowse.Designer.cs

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

40 changes: 29 additions & 11 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,6 @@ public FormBrowse([NotNull] GitUICommands commands, string filter, ObjectId sele

return;

void WorkaroundToolbarLocationBug()
{
// Layout engine bug (?) which may change the order of toolbars
// if the 1st one becomes longer than the 2nd toolbar's Location.X
// the layout engine will be place the 2nd toolbar first
toolPanel.TopToolStripPanel.Controls.Clear();
toolPanel.TopToolStripPanel.Controls.Add(ToolStripScripts);
toolPanel.TopToolStripPanel.Controls.Add(ToolStripFilters);
toolPanel.TopToolStripPanel.Controls.Add(ToolStripMain);
}

void FocusRevisionDiffFileStatusList()
{
if (!revisionDiff.Visible)
Expand Down Expand Up @@ -511,6 +500,35 @@ Brush UpdateCommitButtonAndGetBrush(IReadOnlyList<GitItemStatus> status, bool sh

return brush;
}

void WorkaroundToolbarLocationBug()
{
// Layout engine bug (?) which may change the order of toolbars
// if the 1st one becomes longer than the 2nd toolbar's Location.X
// the layout engine will be place the 2nd toolbar first

// 1. Clear all toolbars
toolPanel.TopToolStripPanel.Controls.Clear();

// 2. Add all the toolbars back in a reverse order, every added toolbar pushing existing ones to the right
ToolStrip[] toolStrips = new[] { ToolStripScripts, ToolStripFilters, ToolStripMain };
foreach (ToolStrip toolStrip in toolStrips)
{
toolPanel.TopToolStripPanel.Controls.Add(toolStrip);
}

#if DEBUG
// 3. Assert the layout is expected
for (int i = toolStrips.Length - 1; i > 0; i--)
{
// Assert all toolbars on the same row
Debug.Assert(toolStrips[i].Top == 0, "All toolbars must be on the same row");

// Assert the correct order of toolbars
Debug.Assert(toolStrips[i].Left < toolStrips[i - 1].Left, $"{toolStrips[i - 1].Name} must be palced before {toolStrips[i].Name}");
}
#endif
}
}

private void FillNextPullActionAsDefaultToolStripMenuItems()
Expand Down

0 comments on commit f841949

Please sign in to comment.