// This file is dedicated to init logic for FormBrowse menus and toolbars private void InitMenusAndToolbars(string?revFilter, string?pathFilter) { commandsToolStripMenuItem.DropDownOpening += CommandsToolStripMenuItem_DropDownOpening; toolPanel.TopToolStripPanel.MouseClick += (s, e) => { if (e.Button == MouseButtons.Right) { _formBrowseMenus.ShowToolStripContextMenu(Cursor.Position); } }; new ToolStripItem[] { translateToolStripMenuItem, recoverLostObjectsToolStripMenuItem, branchSelect, toolStripButtonPull, pullToolStripMenuItem, pullToolStripMenuItem1, mergeToolStripMenuItem, rebaseToolStripMenuItem1, fetchToolStripMenuItem, fetchAllToolStripMenuItem, fetchPruneAllToolStripMenuItem, toolStripButtonPush, pushToolStripMenuItem, branchToolStripMenuItem, }.ForEach(ColorHelper.AdaptImageLightness); if (!EnvUtils.RunningOnWindows()) { toolStripSeparator6.Visible = false; PuTTYToolStripMenuItem.Visible = false; } pullToolStripMenuItem1.Tag = AppSettings.PullAction.None; mergeToolStripMenuItem.Tag = AppSettings.PullAction.Merge; rebaseToolStripMenuItem1.Tag = AppSettings.PullAction.Rebase; fetchToolStripMenuItem.Tag = AppSettings.PullAction.Fetch; fetchAllToolStripMenuItem.Tag = AppSettings.PullAction.FetchAll; fetchPruneAllToolStripMenuItem.Tag = AppSettings.PullAction.FetchPruneAll; Color toolForeColor = SystemColors.WindowText; BackColor = SystemColors.Window; ForeColor = toolForeColor; mainMenuStrip.ForeColor = toolForeColor; InitToolStripStyles(toolForeColor, Color.Transparent); UpdateCommitButtonAndGetBrush(status: null, AppSettings.ShowGitStatusInBrowseToolbar); FillNextPullActionAsDefaultToolStripMenuItems(); RefreshDefaultPullAction(); FillUserShells(defaultShell: BashShell.ShellName); WorkaroundToolbarLocationBug(); if (!string.IsNullOrWhiteSpace(revFilter)) { ToolStripFilters.SetRevisionFilter(revFilter); } if (!string.IsNullOrWhiteSpace(pathFilter)) { SetPathFilter(pathFilter); } return; void InitToolStripStyles(Color toolForeColor, Color toolBackColor) { toolPanel.TopToolStripPanel.BackColor = toolBackColor; toolPanel.TopToolStripPanel.ForeColor = toolForeColor; mainMenuStrip.BackColor = toolBackColor; ToolStripMain.BackColor = toolBackColor; ToolStripMain.ForeColor = toolForeColor; ToolStripFilters.BackColor = toolBackColor; ToolStripFilters.ForeColor = toolForeColor; ToolStripFilters.InitToolStripStyles(toolForeColor, toolBackColor); ToolStripScripts.BackColor = toolBackColor; ToolStripScripts.ForeColor = toolForeColor; } 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 all toolbars on the same row foreach (ToolStrip toolStrip in toolStrips) { Debug.Assert(toolStrip.Top == 0, $"{toolStrip.Name} must be placed on the 1st row"); } // 4. Assert the correct order of toolbars for (int i = toolStrips.Length - 1; i > 0; i--) { Debug.Assert(toolStrips[i].Left < toolStrips[i - 1].Left, $"{toolStrips[i - 1].Name} must be placed before {toolStrips[i].Name}"); } #endif } }
// This file is dedicated to init logic for FormBrowse revisiong grid control private void InitRevisionGrid(ObjectId?selectedId, ObjectId?firstId) { RevisionGrid.IndexWatcher.Changed += (_, args) => { bool indexChanged = args.IsIndexChanged; this.InvokeAsync( () => { RefreshButton.Image = indexChanged && AppSettings.UseFastChecks && Module.IsValidGitWorkingDir() ? Images.ReloadRevisionsDirty : Images.ReloadRevisions; }) .FileAndForget(); }; RevisionGrid.MenuCommands.MenuChanged += (sender, e) => _formBrowseMenus.OnMenuCommandsPropertyChanged(); RevisionGrid.PathFilterChanged += revisionGrid_PathFilterChanged; RevisionGrid.RefFilterOptionsChanged += (sender, e) => { if (e.RefFilterOptions.HasFlag(RefFilterOptions.All | RefFilterOptions.Boundary)) { // This means show all branches ToolStripFilters.ClearFilters(); AppSettings.BranchFilterEnabled = AppSettings.ShowCurrentBranchOnly = false; } }; RevisionGrid.RevisionGraphLoaded += (sender, e) => { if (sender is null || MainSplitContainer.Panel1Collapsed) { // - the event is either not originated from the revision grid, or // - the left panel is hidden return; } // Apply filtering when: // 1. don't show reflogs, and // 2. one of the following // a) show the current branch only, or // b) filter on specific branch bool isFiltering = !AppSettings.ShowReflogReferences && (AppSettings.ShowCurrentBranchOnly || AppSettings.BranchFilterEnabled); repoObjectsTree.ToggleFilterMode(isFiltering); }; RevisionGrid.SelectionChanged += (sender, e) => { _selectedRevisionUpdatedTargets = UpdateTargets.None; RefreshSelection(); }; RevisionGrid.ToggledBetweenArtificialAndHeadCommits += (s, e) => { if (!revisionDiff.Visible) { CommitInfoTabControl.SelectedTab = DiffTabPage; } if (revisionDiff.Visible) { // force focus of file list revisionDiff.SwitchFocus(alreadyContainedFocus: false); } }; RevisionGrid.SelectedId = selectedId; RevisionGrid.FirstId = firstId; }