Skip to content

Commit

Permalink
gitextensions#5347 Hotkeys for focusing areas of Browse window
Browse files Browse the repository at this point in the history
  • Loading branch information
mstv committed Sep 7, 2018
1 parent 56f720d commit 7430e9e
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 59 deletions.
65 changes: 59 additions & 6 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -2056,6 +2061,8 @@ internal enum Command
EditFile = 22,
OpenAsTempFile = 23,
OpenAsTempFileWith = 24,
FocusBranchTree = 25,
FocusGitConsole = 26
}

internal Keys GetShortcutKeys(Command cmd)
Expand Down Expand Up @@ -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;
Expand All @@ -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>(T containerControl, Action<T, bool> 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)
Expand Down
14 changes: 12 additions & 2 deletions GitUI/CommandsDialogs/RevisionDiffControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ protected override void OnRuntimeLoad()
DiffText.Font = AppSettings.FixedWidthFont;
ReloadHotkeys();

GotFocus += (s, e1) => DiffFiles.Focus();

base.OnRuntimeLoad();
}

Expand Down Expand Up @@ -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();
}
}
}
}
14 changes: 12 additions & 2 deletions GitUI/CommandsDialogs/RevisionFileTreeControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ protected override void OnRuntimeLoad()

ReloadHotkeys();

GotFocus += (s, e1) => tvGitTree.Focus();

base.OnRuntimeLoad();
}

Expand Down Expand Up @@ -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();
}
}
}
}
100 changes: 51 additions & 49 deletions GitUI/Hotkey/HotkeySettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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())
Expand Down

0 comments on commit 7430e9e

Please sign in to comment.