Skip to content

Commit

Permalink
Add an OnKeyDown() to interpret F5, Enter and Delete keys
Browse files Browse the repository at this point in the history
Refresh the list of branches
Switch workspace to the selected branch
Delete the selected branches

Both actions have a confirmation dialog
  • Loading branch information
SRombautsU committed Dec 7, 2023
1 parent 53d91ca commit 301b4fc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -996,4 +996,44 @@ void SPlasticSourceControlBranchesWidget::OnSourceControlProviderChanged(ISource
}
}

FReply SPlasticSourceControlBranchesWidget::OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent)
{
if (InKeyEvent.GetKey() == EKeys::F5)
{
// Pressing F5 refresh the list of branches
RequestBranchesRefresh();
return FReply::Handled();
}
else if (InKeyEvent.GetKey() == EKeys::Enter)
{
// Pressing Enter switch to the selected branch.
const TArray<FString> SelectedBranches = GetSelectedBranches();
if (SelectedBranches.Num() == 1)
{
const FString& SelectedBranch = SelectedBranches[0];
// Note: this action require a confirmation dialog (while the Delete below already have one in OnDeleteBranchesClicked()).
const FText Message = FText::Format(LOCTEXT("SwitchToBranchDialog", "Switch workspace to branch {0}?"), FText::FromString(SelectedBranch));
const EAppReturnType::Type Choice = FMessageDialog::Open(EAppMsgType::YesNo, Message);
if (Choice == EAppReturnType::Yes)
{

OnSwitchToBranchClicked(SelectedBranch);
}
}
return FReply::Handled();
}
else if (InKeyEvent.GetKey() == EKeys::Delete)
{
// Pressing Delete delete the selected branches
const TArray<FString> SelectedBranches = GetSelectedBranches();
if (SelectedBranches.Num() > 0)
{
OnDeleteBranchesClicked(SelectedBranches);
}
return FReply::Handled();
}

return FReply::Unhandled();
}

#undef LOCTEXT_NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class SPlasticSourceControlBranchesWidget : public SCompoundWidget
return BranchesListView.Get();
}

/** Interpret F5, Enter and Delete keys */
virtual FReply OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent) override;

private:
TSharedPtr<SSearchBox> FileSearchBox;

Expand Down

0 comments on commit 301b4fc

Please sign in to comment.