diff --git a/GitUI/CommandsDialogs/FormBrowse.cs b/GitUI/CommandsDialogs/FormBrowse.cs index 6bb833c4e14..092ba0fdfc0 100644 --- a/GitUI/CommandsDialogs/FormBrowse.cs +++ b/GitUI/CommandsDialogs/FormBrowse.cs @@ -399,7 +399,7 @@ protected override void OnLoad(EventArgs e) RevisionGrid.Load(); _filterBranchHelper.InitToolStripBranchFilter(); - RevisionGrid.Focus(); + ActiveControl = RevisionGrid; RevisionGrid.IndexWatcher.Reset(); RevisionGrid.IndexWatcher.Changed += (_, args) => @@ -1524,6 +1524,11 @@ private void CommitInfoTabControl_SelectedIndexChanged(object sender, EventArgs ThreadHelper.JoinableTaskFactory.RunAsync(() => FillGpgInfoAsync()); FillBuildReport(); FillTerminalTab(); + if (CommitInfoTabControl.SelectedTab == DiffTabPage) + { + // workaround to avoid focusing the "filter files" combobox + revisionDiff.SwitchFocus(alreadyContainedFocus: false); + } } private void ChangelogToolStripMenuItemClick(object sender, EventArgs e) @@ -2035,8 +2040,8 @@ internal enum Command GitGitK = 2, FocusRevisionGrid = 3, FocusCommitInfo = 4, - FocusFileTree = 5, - FocusDiff = 6, + FocusDiff = 5, + FocusFileTree = 6, Commit = 7, AddNotes = 8, FindFileInSelectedCommit = 9, @@ -2056,6 +2061,8 @@ internal enum Command EditFile = 22, OpenAsTempFile = 23, OpenAsTempFileWith = 24, + FocusBranchTree = 25, + FocusGitConsole = 26 } internal Keys GetShortcutKeys(Command cmd) @@ -2098,10 +2105,12 @@ protected override bool ExecuteCommand(int cmd) case Command.GitBash: Module.RunBash(); break; case Command.GitGui: Module.RunGui(); break; case Command.GitGitK: Module.RunGitK(); break; + case Command.FocusBranchTree: FocusBranchTree(); break; case Command.FocusRevisionGrid: RevisionGrid.Focus(); break; - case Command.FocusCommitInfo: CommitInfoTabControl.SelectedTab = CommitInfoTabPage; break; - case Command.FocusFileTree: CommitInfoTabControl.SelectedTab = TreeTabPage; fileTree.Focus(); break; - case Command.FocusDiff: CommitInfoTabControl.SelectedTab = DiffTabPage; revisionDiff.Focus(); break; + case Command.FocusCommitInfo: FocusCommitInfo(); break; + case Command.FocusDiff: FocusTabOf(revisionDiff, (c, alreadyContainedFocus) => c.SwitchFocus(alreadyContainedFocus)); break; + case Command.FocusFileTree: FocusTabOf(fileTree, (c, alreadyContainedFocus) => c.SwitchFocus(alreadyContainedFocus)); break; + case Command.FocusGitConsole: FocusGitConsole(); break; case Command.FocusFilter: FocusFilter(); break; case Command.Commit: CommitToolStripMenuItemClick(null, null); break; case Command.AddNotes: AddNotes(); break; @@ -2124,6 +2133,50 @@ protected override bool ExecuteCommand(int cmd) return true; + void FocusBranchTree() + { + if (!MainSplitContainer.Panel1Collapsed) + { + repoObjectsTree.Focus(); + } + } + + void FocusCommitInfo() + { + if (AppSettings.CommitInfoPosition == CommitInfoPosition.BelowList) + { + CommitInfoTabControl.SelectedTab = CommitInfoTabPage; + } + + RevisionInfo.Focus(); + } + + void FocusTabOf(T containerControl, Action switchFocus) where T : ContainerControl + { + var tabPage = containerControl.Parent as TabPage; + if (CommitInfoTabControl.TabPages.IndexOf(tabPage) >= 0) + { + bool alreadyContainedFocus = containerControl.ContainsFocus; + + if (CommitInfoTabControl.SelectedTab != tabPage) + { + CommitInfoTabControl.SelectedTab = tabPage; + } + + switchFocus(containerControl, alreadyContainedFocus); + } + } + + void FocusGitConsole() + { + FillTerminalTab(); + var tabPageCaption = _consoleTabCaption.Text; + if (CommitInfoTabControl.TabPages.ContainsKey(tabPageCaption)) + { + CommitInfoTabControl.SelectedTab = CommitInfoTabControl.TabPages[tabPageCaption]; + } + } + void OpenWithDifftool() { if (revisionDiff.Visible) diff --git a/GitUI/CommandsDialogs/RevisionDiffControl.cs b/GitUI/CommandsDialogs/RevisionDiffControl.cs index f70d2337273..5e4e2ae020c 100644 --- a/GitUI/CommandsDialogs/RevisionDiffControl.cs +++ b/GitUI/CommandsDialogs/RevisionDiffControl.cs @@ -172,8 +172,6 @@ protected override void OnRuntimeLoad() DiffText.Font = AppSettings.FixedWidthFont; ReloadHotkeys(); - GotFocus += (s, e1) => DiffFiles.Focus(); - base.OnRuntimeLoad(); } @@ -885,5 +883,17 @@ private void diffSubmoduleSummaryMenuItem_Click(object sender, EventArgs e) frm.ShowDialog(this); } } + + public void SwitchFocus(bool alreadyContainedFocus) + { + if (alreadyContainedFocus && DiffFiles.Focused) + { + DiffText.Focus(); + } + else + { + DiffFiles.Focus(); + } + } } } diff --git a/GitUI/CommandsDialogs/RevisionFileTreeControl.cs b/GitUI/CommandsDialogs/RevisionFileTreeControl.cs index 062b561293c..fc87cf41ebb 100644 --- a/GitUI/CommandsDialogs/RevisionFileTreeControl.cs +++ b/GitUI/CommandsDialogs/RevisionFileTreeControl.cs @@ -288,8 +288,6 @@ protected override void OnRuntimeLoad() ReloadHotkeys(); - GotFocus += (s, e1) => tvGitTree.Focus(); - base.OnRuntimeLoad(); } @@ -770,5 +768,17 @@ private void tvGitTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs tvGitTree.SelectedNode = e.Node; } } + + public void SwitchFocus(bool alreadyContainedFocus) + { + if (alreadyContainedFocus && tvGitTree.Focused) + { + FileText.Focus(); + } + else + { + tvGitTree.Focus(); + } + } } } diff --git a/GitUI/Hotkey/HotkeySettingsManager.cs b/GitUI/Hotkey/HotkeySettingsManager.cs index 5f1f27414c7..a1a879b9e11 100644 --- a/GitUI/Hotkey/HotkeySettingsManager.cs +++ b/GitUI/Hotkey/HotkeySettingsManager.cs @@ -243,49 +243,69 @@ public static HotkeySettings[] CreateDefaultSettings() FormCommit.HotkeySettingsName, Hk(FormCommit.Command.AddToGitIgnore, Keys.None), Hk(FormCommit.Command.DeleteSelectedFiles, Keys.Delete), + Hk(FormCommit.Command.EditFile, EditFileHotkey), Hk(FormCommit.Command.FocusUnstagedFiles, Keys.Control | Keys.D1), Hk(FormCommit.Command.FocusSelectedDiff, Keys.Control | Keys.D2), Hk(FormCommit.Command.FocusStagedFiles, Keys.Control | Keys.D3), Hk(FormCommit.Command.FocusCommitMessage, Keys.Control | Keys.D4), + Hk(FormCommit.Command.OpenFile, OpenFileHotkey), + Hk(FormCommit.Command.OpenFileWith, OpenFileWithHotkey), + Hk(FormCommit.Command.OpenWithDifftool, OpenWithDifftoolHotkey), Hk(FormCommit.Command.ResetSelectedFiles, Keys.R), Hk(FormCommit.Command.StageSelectedFile, Keys.S), Hk(FormCommit.Command.UnStageSelectedFile, Keys.U), Hk(FormCommit.Command.ShowHistory, ShowHistoryHotkey), - Hk(FormCommit.Command.ToggleSelectionFilter, Keys.Control | Keys.F), Hk(FormCommit.Command.StageAll, Keys.Control | Keys.S), - Hk(FormCommit.Command.OpenWithDifftool, OpenWithDifftoolHotkey), - Hk(FormCommit.Command.OpenFile, OpenFileHotkey), - Hk(FormCommit.Command.OpenFileWith, OpenFileWithHotkey), - Hk(FormCommit.Command.EditFile, EditFileHotkey)), + Hk(FormCommit.Command.ToggleSelectionFilter, Keys.Control | Keys.F)), new HotkeySettings( FormBrowse.HotkeySettingsName, - Hk(FormBrowse.Command.GitBash, Keys.Control | Keys.G), - Hk(FormBrowse.Command.GitGui, Keys.None), - Hk(FormBrowse.Command.GitGitK, Keys.None), + Hk(FormBrowse.Command.AddNotes, Keys.Control | Keys.Shift | Keys.N), + Hk(FormBrowse.Command.CheckoutBranch, Keys.Control | Keys.Decimal), + Hk(FormBrowse.Command.CloseRepository, Keys.Control | Keys.W), + Hk(FormBrowse.Command.Commit, Keys.Control | Keys.Space), + Hk(FormBrowse.Command.EditFile, EditFileHotkey), + Hk(FormBrowse.Command.FindFileInSelectedCommit, Keys.Control | Keys.Shift | Keys.F), + Hk(FormBrowse.Command.FocusBranchTree, Keys.Control | Keys.D0), Hk(FormBrowse.Command.FocusRevisionGrid, Keys.Control | Keys.D1), Hk(FormBrowse.Command.FocusCommitInfo, Keys.Control | Keys.D2), - Hk(FormBrowse.Command.FocusFileTree, Keys.Control | Keys.D3), - Hk(FormBrowse.Command.FocusDiff, Keys.Control | Keys.D4), + Hk(FormBrowse.Command.FocusDiff, Keys.Control | Keys.D3), + Hk(FormBrowse.Command.FocusFileTree, Keys.Control | Keys.D4), + Hk(FormBrowse.Command.FocusGitConsole, Keys.Control | Keys.D5), Hk(FormBrowse.Command.FocusFilter, Keys.Control | Keys.E), - Hk(FormBrowse.Command.Commit, Keys.Control | Keys.Space), - Hk(FormBrowse.Command.AddNotes, Keys.Control | Keys.Shift | Keys.N), - Hk(FormBrowse.Command.FindFileInSelectedCommit, Keys.Control | Keys.Shift | Keys.F), - Hk(FormBrowse.Command.CheckoutBranch, Keys.Control | Keys.Decimal), + Hk(FormBrowse.Command.GitBash, Keys.Control | Keys.G), + Hk(FormBrowse.Command.GitGui, Keys.None), + Hk(FormBrowse.Command.GitGitK, Keys.None), + Hk(FormBrowse.Command.OpenAsTempFile, OpenAsTempFileHotkey), + Hk(FormBrowse.Command.OpenAsTempFileWith, OpenAsTempFileWithHotkey), + Hk(FormBrowse.Command.OpenSettings, Keys.Control | Keys.Oemcomma), + Hk(FormBrowse.Command.OpenWithDifftool, OpenWithDifftoolHotkey), Hk(FormBrowse.Command.QuickFetch, Keys.Control | Keys.Shift | Keys.Down), Hk(FormBrowse.Command.QuickPull, Keys.Control | Keys.Shift | Keys.P), Hk(FormBrowse.Command.QuickPush, Keys.Control | Keys.Shift | Keys.Up), Hk(FormBrowse.Command.Stash, Keys.Control | Keys.Alt | Keys.Up), Hk(FormBrowse.Command.StashPop, Keys.Control | Keys.Alt | Keys.Down), - Hk(FormBrowse.Command.CloseRepository, Keys.Control | Keys.W), - Hk(FormBrowse.Command.OpenSettings, Keys.Control | Keys.Oemcomma), - Hk(FormBrowse.Command.OpenWithDifftool, OpenWithDifftoolHotkey), - Hk(FormBrowse.Command.ToggleBranchTreePanel, Keys.Control | Keys.Alt | Keys.C), - Hk(FormBrowse.Command.EditFile, EditFileHotkey), - Hk(FormBrowse.Command.OpenAsTempFile, OpenAsTempFileHotkey), - Hk(FormBrowse.Command.OpenAsTempFileWith, OpenAsTempFileWithHotkey)), + Hk(FormBrowse.Command.ToggleBranchTreePanel, Keys.Control | Keys.Alt | Keys.C)), new HotkeySettings( RevisionGridControl.HotkeySettingsName, + Hk(RevisionGridControl.Commands.CompareSelectedCommits, Keys.None), + Hk(RevisionGridControl.Commands.CompareToBase, Keys.Control | Keys.R), + Hk(RevisionGridControl.Commands.CompareToBranch, Keys.None), + Hk(RevisionGridControl.Commands.CompareToCurrentBranch, Keys.None), + Hk(RevisionGridControl.Commands.CompareToWorkingDirectory, Keys.Control | Keys.D), + Hk(RevisionGridControl.Commands.CreateFixupCommit, Keys.Control | Keys.X), + Hk(RevisionGridControl.Commands.GoToCommit, Keys.Control | Keys.Shift | Keys.G), + Hk(RevisionGridControl.Commands.GoToParent, Keys.Control | Keys.P), + Hk(RevisionGridControl.Commands.GoToChild, Keys.Control | Keys.N), + Hk(RevisionGridControl.Commands.NextQuickSearch, Keys.Alt | Keys.Down), + Hk(RevisionGridControl.Commands.PrevQuickSearch, Keys.Alt | Keys.Up), Hk(RevisionGridControl.Commands.RevisionFilter, Keys.Control | Keys.F), + Hk(RevisionGridControl.Commands.SelectCurrentRevision, Keys.Control | Keys.Shift | Keys.C), + Hk(RevisionGridControl.Commands.SelectAsBaseToCompare, Keys.Control | Keys.L), + Hk(RevisionGridControl.Commands.ShowAllBranches, Keys.Control | Keys.Shift | Keys.A), + Hk(RevisionGridControl.Commands.ShowCurrentBranchOnly, Keys.Control | Keys.Shift | Keys.U), + Hk(RevisionGridControl.Commands.ShowFilteredBranches, Keys.Control | Keys.Shift | Keys.T), + Hk(RevisionGridControl.Commands.ShowFirstParent, Keys.Control | Keys.Shift | Keys.S), + Hk(RevisionGridControl.Commands.ShowRemoteBranches, Keys.Control | Keys.Shift | Keys.R), Hk(RevisionGridControl.Commands.ToggleRevisionGraph, Keys.None), Hk(RevisionGridControl.Commands.ToggleAuthorDateCommitDate, Keys.None), Hk(RevisionGridControl.Commands.ToggleOrderRevisionsByDate, Keys.None), @@ -294,25 +314,7 @@ public static HotkeySettings[] CreateDefaultSettings() Hk(RevisionGridControl.Commands.ToggleShowGitNotes, Keys.None), Hk(RevisionGridControl.Commands.ToggleShowMergeCommits, Keys.Control | Keys.Shift | Keys.M), Hk(RevisionGridControl.Commands.ToggleShowTags, Keys.Control | Keys.Alt | Keys.T), - Hk(RevisionGridControl.Commands.ShowAllBranches, Keys.Control | Keys.Shift | Keys.A), - Hk(RevisionGridControl.Commands.ShowCurrentBranchOnly, Keys.Control | Keys.Shift | Keys.U), - Hk(RevisionGridControl.Commands.ShowFilteredBranches, Keys.Control | Keys.Shift | Keys.T), - Hk(RevisionGridControl.Commands.ShowRemoteBranches, Keys.Control | Keys.Shift | Keys.R), - Hk(RevisionGridControl.Commands.ShowFirstParent, Keys.Control | Keys.Shift | Keys.S), - Hk(RevisionGridControl.Commands.GoToParent, Keys.Control | Keys.P), - Hk(RevisionGridControl.Commands.GoToChild, Keys.Control | Keys.N), - Hk(RevisionGridControl.Commands.ToggleHighlightSelectedBranch, Keys.Control | Keys.Shift | Keys.B), - Hk(RevisionGridControl.Commands.NextQuickSearch, Keys.Alt | Keys.Down), - Hk(RevisionGridControl.Commands.PrevQuickSearch, Keys.Alt | Keys.Up), - Hk(RevisionGridControl.Commands.SelectCurrentRevision, Keys.Control | Keys.Shift | Keys.C), - Hk(RevisionGridControl.Commands.SelectAsBaseToCompare, Keys.Control | Keys.L), - Hk(RevisionGridControl.Commands.CompareToBase, Keys.Control | Keys.R), - Hk(RevisionGridControl.Commands.GoToCommit, Keys.Control | Keys.Shift | Keys.G), - Hk(RevisionGridControl.Commands.CreateFixupCommit, Keys.Control | Keys.X), - Hk(RevisionGridControl.Commands.CompareToWorkingDirectory, Keys.Control | Keys.D), - Hk(RevisionGridControl.Commands.CompareToCurrentBranch, Keys.None), - Hk(RevisionGridControl.Commands.CompareToBranch, Keys.None), - Hk(RevisionGridControl.Commands.CompareSelectedCommits, Keys.None)), + Hk(RevisionGridControl.Commands.ToggleHighlightSelectedBranch, Keys.Control | Keys.Shift | Keys.B)), new HotkeySettings( FileViewer.HotkeySettingsName, Hk(FileViewer.Commands.Find, Keys.Control | Keys.F), @@ -321,10 +323,10 @@ public static HotkeySettings[] CreateDefaultSettings() Hk(FileViewer.Commands.GoToLine, Keys.Control | Keys.G), Hk(FileViewer.Commands.IncreaseNumberOfVisibleLines, Keys.None), Hk(FileViewer.Commands.DecreaseNumberOfVisibleLines, Keys.None), - Hk(FileViewer.Commands.ShowEntireFile, Keys.None), - Hk(FileViewer.Commands.TreatFileAsText, Keys.None), Hk(FileViewer.Commands.NextChange, Keys.Alt | Keys.Down), - Hk(FileViewer.Commands.PreviousChange, Keys.Alt | Keys.Up)), + Hk(FileViewer.Commands.PreviousChange, Keys.Alt | Keys.Up), + Hk(FileViewer.Commands.ShowEntireFile, Keys.None), + Hk(FileViewer.Commands.TreatFileAsText, Keys.None)), new HotkeySettings( FormResolveConflicts.HotkeySettingsName, Hk(FormResolveConflicts.Commands.ChooseBase, Keys.B), @@ -334,19 +336,19 @@ public static HotkeySettings[] CreateDefaultSettings() Hk(FormResolveConflicts.Commands.Rescan, Keys.F5)), new HotkeySettings( RevisionDiffControl.HotkeySettingsName, - Hk(RevisionDiffControl.Command.DeleteSelectedFiles, Keys.Delete), - Hk(RevisionDiffControl.Command.ShowHistory, ShowHistoryHotkey), Hk(RevisionDiffControl.Command.Blame, BlameHotkey), + Hk(RevisionDiffControl.Command.DeleteSelectedFiles, Keys.Delete), + Hk(RevisionDiffControl.Command.EditFile, EditFileHotkey), Hk(RevisionDiffControl.Command.OpenWithDifftool, OpenWithDifftoolHotkey), - Hk(RevisionDiffControl.Command.EditFile, EditFileHotkey)), + Hk(RevisionDiffControl.Command.ShowHistory, ShowHistoryHotkey)), new HotkeySettings( RevisionFileTreeControl.HotkeySettingsName, - Hk(RevisionFileTreeControl.Command.ShowHistory, ShowHistoryHotkey), Hk(RevisionFileTreeControl.Command.Blame, BlameHotkey), - Hk(RevisionFileTreeControl.Command.OpenWithDifftool, OpenWithDifftoolHotkey), + Hk(RevisionFileTreeControl.Command.EditFile, EditFileHotkey), Hk(RevisionFileTreeControl.Command.OpenAsTempFile, OpenAsTempFileHotkey), Hk(RevisionFileTreeControl.Command.OpenAsTempFileWith, OpenAsTempFileWithHotkey), - Hk(RevisionFileTreeControl.Command.EditFile, EditFileHotkey)), + Hk(RevisionFileTreeControl.Command.OpenWithDifftool, OpenWithDifftoolHotkey), + Hk(RevisionFileTreeControl.Command.ShowHistory, ShowHistoryHotkey)), new HotkeySettings( FormSettings.HotkeySettingsName, LoadScriptHotkeys())