Skip to content

Commit

Permalink
Revert ability for move and show/hide toolbars
Browse files Browse the repository at this point in the history
Due to discovered layout and placement instability of toolbars
reverting most of the functionality added in gitextensions#8572.

Closes gitextensions#8680
  • Loading branch information
RussKie committed Jan 3, 2021
1 parent b304774 commit 136169e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 99 deletions.
75 changes: 1 addition & 74 deletions GitUI/CommandsDialogs/BrowseDialog/FormBrowseMenus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,11 @@ internal class FormBrowseMenus : ITranslate, IDisposable
/// </summary>
private readonly ToolStrip _mainMenuStrip;

/// <summary>
/// The context menu that be shown to allow toggle visibilty of toolbars in <see cref="FormBrowse"/>.
/// </summary>
private readonly ContextMenuStrip _toolStripContextMenu = new ContextMenuStrip();

private List<MenuCommand> _navigateMenuCommands;
private List<MenuCommand> _viewMenuCommands;

private ToolStripMenuItem _navigateToolStripMenuItem;
private ToolStripMenuItem _viewToolStripMenuItem;
private ToolStripMenuItem _toolbarsMenuItem;

// we have to remember which items we registered with the menucommands because other
// location (RevisionGrid) can register items too!
Expand All @@ -44,8 +38,6 @@ public FormBrowseMenus(ToolStrip menuStrip)

CreateMenuItems();
Translate();

_toolStripContextMenu.Opening += (s, e) => RefreshToolbarsMenuItemCheckedState(_toolStripContextMenu.Items);
}

public void Dispose()
Expand All @@ -60,7 +52,6 @@ protected virtual void Dispose(bool disposing)
{
_navigateToolStripMenuItem.Dispose();
_viewToolStripMenuItem.Dispose();
_toolbarsMenuItem.Dispose();
}
}

Expand All @@ -79,43 +70,6 @@ public virtual void TranslateItems(ITranslation translation)
TranslationUtils.TranslateItemsFromList("FormBrowse", translation, GetAdditionalMainMenuItemsForTranslation());
}

/// <summary>
/// Creates menu items for each toolbar supplied in <paramref name="toolStrips"/>. These menus will
/// be surfaced in <see cref="_mainMenuStrip"/>, and <see cref="_toolStripContextMenu"/>,
/// and will allow to toggle visibility of the toolbars.
/// </summary>
/// <param name="toolStrips">The list of toobars to toggle visibility for.</param>
public void CreateToolbarsMenus(params ToolStripEx[] toolStrips)
{
Debug.Assert(_toolbarsMenuItem != null, "Toolbars menu item must be already created.");

foreach (ToolStrip toolStrip in toolStrips)
{
Debug.Assert(!string.IsNullOrEmpty(toolStrip.Text), "Toolstrip must specify its name via Text property.");

_toolStripContextMenu.Items.Add(CreateItem(toolStrip));
_toolbarsMenuItem.DropDownItems.Add(CreateItem(toolStrip));
}

static ToolStripItem CreateItem(ToolStrip senderToolStrip)
{
var toolStripItem = new ToolStripMenuItem(senderToolStrip.Text)
{
Checked = senderToolStrip.Visible,
CheckOnClick = true,
Tag = senderToolStrip
};
toolStripItem.Click += (s, e) =>
{
senderToolStrip.Visible = !senderToolStrip.Visible;
};

return toolStripItem;
}
}

public void ShowToolStripContextMenu(Point point) => _toolStripContextMenu.Show(point);

public void ResetMenuCommandSets()
{
_navigateMenuCommands = null;
Expand Down Expand Up @@ -180,14 +134,6 @@ public void InsertRevisionGridMainMenuItems(ToolStripItem insertAfterMenuItem)
_mainMenuStrip.Items.Insert(_mainMenuStrip.Items.IndexOf(insertAfterMenuItem) + 1, _navigateToolStripMenuItem);
_mainMenuStrip.Items.Insert(_mainMenuStrip.Items.IndexOf(_navigateToolStripMenuItem) + 1, _viewToolStripMenuItem);

// We're a bit lying here - "Toolbars" is not a RevisionGrid menu item,
// however it is the logical place to add it to the "View" menu
if (_toolbarsMenuItem.DropDownItems.Count > 0)
{
_viewToolStripMenuItem.DropDownItems.Add(new ToolStripSeparator());
_viewToolStripMenuItem.DropDownItems.Add(_toolbarsMenuItem);
}

// maybe set check marks on menu items
OnMenuCommandsPropertyChanged();
}
Expand Down Expand Up @@ -218,21 +164,11 @@ private void CreateMenuItems()
Text = "View"
};
}

if (_toolbarsMenuItem is null)
{
_toolbarsMenuItem = new ToolStripMenuItem
{
Name = "toolbarsMenuItem",
Text = "Toolbars",
};
_toolbarsMenuItem.DropDownOpening += (s, e) => RefreshToolbarsMenuItemCheckedState(_toolbarsMenuItem.DropDownItems);
}
}

private IEnumerable<(string name, object item)> GetAdditionalMainMenuItemsForTranslation()
{
foreach (ToolStripMenuItem menuItem in new[] { _navigateToolStripMenuItem, _viewToolStripMenuItem, _toolbarsMenuItem })
foreach (ToolStripMenuItem menuItem in new[] { _navigateToolStripMenuItem, _viewToolStripMenuItem })
{
yield return (menuItem.Name, menuItem);
}
Expand Down Expand Up @@ -304,15 +240,6 @@ private IEnumerable<MenuCommand> GetNavigateAndViewMenuCommands()
throw new ApplicationException("this case is not allowed");
}
}

private void RefreshToolbarsMenuItemCheckedState(ToolStripItemCollection toolStripItems)
{
foreach (ToolStripMenuItem item in toolStripItems)
{
Debug.Assert(item.Tag is ToolStrip, "Toolbars context menu items must reference Toolstrips via Tag property.");
item.Checked = ((ToolStrip)item.Tag).Visible;
}
}
}

internal enum MainMenuItem
Expand Down
2 changes: 2 additions & 0 deletions GitUI/CommandsDialogs/FormBrowse.Designer.cs

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

25 changes: 0 additions & 25 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,6 @@ public FormBrowse([NotNull] GitUICommands commands, string filter, ObjectId sele
mainMenuStrip.BackColor = toolBackColor;
mainMenuStrip.ForeColor = toolForeColor;

toolPanel.TopToolStripPanel.MouseClick += (s, e) =>
{
if (e.Button == MouseButtons.Right)
{
_formBrowseMenus.ShowToolStripContextMenu(Cursor.Position);
}
};

InitToolStripStyles(toolForeColor, toolBackColor);

foreach (var control in this.FindDescendants())
Expand Down Expand Up @@ -615,19 +607,6 @@ protected override void OnApplicationActivated()

protected override void OnLoad(EventArgs e)
{
// Removing the main menu before restoring the toolstrip layouts
// as it *does* randomly change the order of the defined items in the menu
Controls.Remove(mainMenuStrip);

toolPanel.TopToolStripPanel.SuspendLayout();
ToolStripManager.LoadSettings(this, "toolsettings");
toolPanel.TopToolStripPanel.ResumeLayout();

// Add the menu back
Controls.Add(mainMenuStrip);

_formBrowseMenus.CreateToolbarsMenus(ToolStripMain, ToolStripFilters);

HideVariableMainMenuItems();
RefreshSplitViewLayout();
LayoutRevisionInfo();
Expand Down Expand Up @@ -689,10 +668,6 @@ protected override void OnActivated(EventArgs e)

protected override void OnFormClosing(FormClosingEventArgs e)
{
// Remove the main menu to prevent its state being persisted
Controls.Remove(mainMenuStrip);

ToolStripManager.SaveSettings(this, "toolsettings");
SaveApplicationSettings();

foreach (var control in this.FindDescendants())
Expand Down

0 comments on commit 136169e

Please sign in to comment.