From 4e57eb4fac896148af4e9a990952b7c4c1b60c79 Mon Sep 17 00:00:00 2001 From: juha Date: Sat, 27 Apr 2013 10:13:37 +0000 Subject: [PATCH] IDE: Improvements to keymapping buttons' default state and TabOrder. git-svn-id: trunk@40897 - --- components/ideintf/propedits.pp | 26 ++++++++++++++++++++------ ide/keymapshortcutdlg.lfm | 3 ++- ide/keymapshortcutdlg.pas | 33 ++++++++++++++++++++------------- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/components/ideintf/propedits.pp b/components/ideintf/propedits.pp index 94a649562d..878245f1ee 100644 --- a/components/ideintf/propedits.pp +++ b/components/ideintf/propedits.pp @@ -1454,6 +1454,7 @@ type private FAllowedShifts: TShiftState; FGrabButton: TButton; + FMainOkButton: TCustomButton; FKey: Word; FKeyComboBox: TComboBox; FShiftButtons: TShiftState; @@ -1467,15 +1468,13 @@ type procedure SetShiftState(const AValue: TShiftState); procedure OnGrabButtonClick(Sender: TObject); procedure OnShiftCheckBoxClick(Sender: TObject); - procedure OnGrabFormKeyDown(Sender: TObject; var AKey: Word; - AShift: TShiftState); + procedure OnGrabFormKeyDown(Sender: TObject; var AKey: Word; AShift: TShiftState); procedure OnKeyComboboxEditingDone(Sender: TObject); protected procedure Loaded; override; procedure RealSetText(const Value: TCaption); override; procedure UpdateShiftButons; - procedure Notification(AComponent: TComponent; Operation: TOperation); - override; + procedure Notification(AComponent: TComponent; Operation: TOperation); override; function ShiftToStr(s: TShiftStateEnum): string; public constructor Create(TheOwner: TComponent); override; @@ -1486,6 +1485,7 @@ type property AllowedShifts: TShiftState read FAllowedShifts write SetAllowedShifts; property KeyComboBox: TComboBox read FKeyComboBox; property GrabButton: TButton read FGrabButton; + property MainOkButton: TCustomButton read FMainOkButton write FMainOkButton; property ShiftCheckBox[Shift: TShiftStateEnum]: TCheckBox read GetShiftCheckBox; end; @@ -6437,6 +6437,9 @@ begin FGrabForm.Height:=50; FGrabForm.AutoSize:=true; FGrabForm.ShowModal; + // After getting a key, focus the main form's OK button. User can just click Enter. + if (Key <> VK_UNKNOWN) and Assigned(MainOkButton) then + MainOkButton.SetFocus; FreeAndNil(FGrabForm); end; @@ -6478,8 +6481,7 @@ begin Key:=KeyStringToVKCode(KeyComboBox.Text); end; -function TCustomShortCutGrabBox.GetShiftCheckBox(Shift: TShiftStateEnum - ): TCheckBox; +function TCustomShortCutGrabBox.GetShiftCheckBox(Shift: TShiftStateEnum): TCheckBox; begin Result:=FCheckBoxes[Shift]; end; @@ -6607,6 +6609,7 @@ end; constructor TCustomShortCutGrabBox.Create(TheOwner: TComponent); var i: Integer; + ShSt: TShiftStateEnum; s: String; begin inherited Create(TheOwner); @@ -6648,6 +6651,17 @@ begin ShiftState:=[]; Key:=VK_UNKNOWN; KeyComboBox.Text:=KeyAndShiftStateToKeyString(Key,[]); + + // Fix TabOrders. The controls were created in "wrong" order. + i:=FGrabButton.TabOrder; // GrabButton was created first. + for ShSt:=Low(FCheckBoxes) to High(FCheckBoxes) do begin + if Assigned(FCheckBoxes[ShSt]) then begin + FCheckBoxes[ShSt].TabOrder:=i; + Inc(i); + end; + end; + FKeyComboBox.TabOrder:=i; + FGrabButton.TabOrder:=i+1; end; function TCustomShortCutGrabBox.GetDefaultShiftButtons: TShiftState; diff --git a/ide/keymapshortcutdlg.lfm b/ide/keymapshortcutdlg.lfm index e47dce624d..a16cd18e7c 100644 --- a/ide/keymapshortcutdlg.lfm +++ b/ide/keymapshortcutdlg.lfm @@ -10,7 +10,8 @@ object ShortCutDialog: TShortCutDialog ClientHeight = 260 ClientWidth = 545 OnCreate = FormCreate - LCLVersion = '0.9.31' + OnShow = FormShow + LCLVersion = '1.1' object PrimaryGroupBox: TGroupBox Left = 6 Height = 93 diff --git a/ide/keymapshortcutdlg.pas b/ide/keymapshortcutdlg.pas index f195527f40..a34692f1b8 100644 --- a/ide/keymapshortcutdlg.pas +++ b/ide/keymapshortcutdlg.pas @@ -46,6 +46,7 @@ type SecondaryGroupBox: TGroupBox; procedure CancelButtonClick(Sender: TObject); procedure FormCreate(Sender: TObject); + procedure FormShow(Sender: TObject); procedure OkButtonClick(Sender: TObject); private FKeyCommandRelationList: TKeyCommandRelationList; @@ -83,8 +84,7 @@ type function ShowKeyMappingEditForm(Index: integer; AKeyCommandRelationList: TKeyCommandRelationList): TModalResult; -function ShowKeyMappingGrabForm(out Key: TIDEShortCut; - AllowSequence: boolean = false): TModalResult; +function ShowKeyMappingGrabForm(out Key: TIDEShortCut; AllowSequence: boolean = false): TModalResult; implementation @@ -106,8 +106,7 @@ begin end; end; -function ShowKeyMappingGrabForm(out Key: TIDEShortCut; - AllowSequence: boolean): TModalResult; +function ShowKeyMappingGrabForm(out Key: TIDEShortCut; AllowSequence: boolean): TModalResult; var ShortCutDialog: TShortCutDialog; begin @@ -177,6 +176,11 @@ begin ClearKeys; end; +procedure TShortCutDialog.FormShow(Sender: TObject); +begin + FPrimaryKey1Box.GrabButton.SetFocus; +end; + procedure TShortCutDialog.CancelButtonClick(Sender: TObject); begin IDEDialogLayoutList.SaveLayout(Self); @@ -264,6 +268,18 @@ begin SecondaryGroupBox.Visible:=FShowSecondary; end; +procedure TShortCutDialog.SetShowSequence(const AValue: boolean); +begin + if FShowSequence=AValue then exit; + FShowSequence:=AValue; + FPrimaryKey2Box.Visible:=FShowSequence; + FSecondaryKey2Box.Visible:=FShowSequence; + // With a single key GrabBox focus OK button after keypress. + if not (FShowSecondary or FShowSequence) then + FPrimaryKey1Box.MainOkButton:=BtnPanel.OKButton; + UpdateCaptions; +end; + procedure TShortCutDialog.SetPrimaryShortCut(const AValue: TIDEShortCut); var APrimaryShortCut: TIDEShortCut; @@ -304,15 +320,6 @@ begin SecondaryKey2Box.ShiftState:=AValue.Shift2; end; -procedure TShortCutDialog.SetShowSequence(const AValue: boolean); -begin - if FShowSequence=AValue then exit; - FShowSequence:=AValue; - FPrimaryKey2Box.Visible:=FShowSequence; - FSecondaryKey2Box.Visible:=FShowSequence; - UpdateCaptions; -end; - function TShortCutDialog.ResolveConflicts(Key: TIDEShortCut; Scope: TIDECommandScope): TModalResult; type