Examples window: Improve key handling etc. Issue #40036, patch by dbannon.

This commit is contained in:
Juha 2022-12-10 18:59:35 +02:00
parent b3fd61e107
commit 3f4356f2bc
2 changed files with 45 additions and 39 deletions

View File

@ -1,11 +1,12 @@
object FormLazExam: TFormLazExam
Left = 457
Left = 789
Height = 400
Top = 318
Top = 304
Width = 781
Caption = 'Prototype Lazarus Examples Window'
ClientHeight = 400
ClientWidth = 781
KeyPreview = True
OnCreate = FormCreate
OnDestroy = FormDestroy
OnKeyDown = FormKeyDown
@ -20,7 +21,7 @@ object FormLazExam: TFormLazExam
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = CheckGroupCategory
Left = 5
Height = 151
Height = 154
Top = 157
Width = 771
Anchors = [akTop, akLeft, akRight, akBottom]
@ -30,7 +31,6 @@ object FormLazExam: TFormLazExam
Lines.Strings = (
'Memo1'
)
OnKeyDown = FormKeyDown
ParentShowHint = False
ReadOnly = True
ScrollBars = ssAutoVertical
@ -78,8 +78,8 @@ object FormLazExam: TFormLazExam
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ButtonOpen
Left = 5
Height = 23
Top = 313
Height = 20
Top = 316
Width = 771
Anchors = [akLeft, akRight, akBottom]
AutoFill = True
@ -120,8 +120,8 @@ object FormLazExam: TFormLazExam
end
object StatusBar1: TStatusBar
Left = 0
Height = 23
Top = 377
Height = 21
Top = 379
Width = 781
Panels = <>
end
@ -130,10 +130,10 @@ object FormLazExam: TFormLazExam
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ButtonOpen
AnchorSideBottom.Side = asrBottom
Left = 64
Height = 31
Left = 5
Height = 33
Top = 341
Width = 89
Width = 76
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Left = 5
@ -147,10 +147,10 @@ object FormLazExam: TFormLazExam
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ButtonOpen
AnchorSideBottom.Side = asrBottom
Left = 266
Height = 31
Left = 226
Height = 33
Top = 341
Width = 54
Width = 45
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Left = 5
@ -164,10 +164,10 @@ object FormLazExam: TFormLazExam
AnchorSideLeft.Side = asrBottom
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = StatusBar1
Left = 5
Height = 31
Left = 86
Height = 33
Top = 341
Width = 54
Width = 46
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Left = 5
@ -182,10 +182,10 @@ object FormLazExam: TFormLazExam
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ButtonOpen
AnchorSideBottom.Side = asrBottom
Left = 158
Height = 31
Left = 137
Height = 33
Top = 341
Width = 103
Width = 84
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Left = 5
@ -199,7 +199,7 @@ object FormLazExam: TFormLazExam
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 5
Height = 29
Height = 31
Hint = 'Searches for Keywords'
Top = 5
Width = 771

View File

@ -141,6 +141,7 @@ begin
KeyList := TStringList.Create;
BuildSearchList(KeyList, EditSearch.Text);
end;
ListView1.BeginUpdate;
try
if Ex.GetListData(Proj, Cat, Path, KeyW, True, KeyList) then begin
NewLVItem(Proj, Path, KeyW, Cat);
@ -153,6 +154,7 @@ begin
finally
KeyList.Free;
Screen.Cursor := crDefault;
ListView1.EndUpdate;
end;
ButtonOpen.Enabled := false;
ButtonDownLoad.enabled := false;
@ -201,25 +203,26 @@ end;
procedure TFormLazExam.ListView1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then begin
Key := 0;
// Its possible we tabbed into ListView without "selecting" a row.
if ListView1.ItemIndex < 0 then // I don't think this can happen anymore ?
if Key = VK_RETURN then begin
Key := 0;
// Its possible we tabbed into ListView without "selecting" a row.
if ListView1.ItemIndex < 0 then // I don't think this can happen anymore ?
if ListView1.Items.count > 0 then
ListView1.ItemIndex := 0 // Force select first item, its half highlite ??
else exit;
ListView1DblClick(Sender);
end
else if Key = VK_ESCAPE then
ModalResult := mrClose;
ListView1.ItemIndex := 0 // Force select first item, its half highlite ??
else
Exit;
ListView1DblClick(Sender);
end
else if not (Key in [VK_TAB, VK_ESCAPE, VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN]) then
EditSearch.SetFocus;
end;
// --------------------- B U T T O N S -----------------------------------------
procedure TFormLazExam.ButtonOpenClick(Sender: TObject);
begin
if LastListViewIndex < 0 then exit;
ListView1.ItemIndex:= LastListViewIndex;
if LastListViewIndex < 0 then exit;
ListView1.ItemIndex:= LastListViewIndex;
if GetProjectFile(Ex.ExampleWorkingDir() + ListView1.Selected.Caption, True) // Sets ProjectToOpen on success
and ProjectToOpen.IsEmpty then
showmessage(rsExNoProjectFile)
@ -419,13 +422,16 @@ end;
procedure TFormLazExam.EditSearchKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then begin
key := 0;
if ListView1.items.Count > 0 then
if Key in [VK_RETURN, VK_DOWN] then begin
Key := 0;
if ListView1.items.Count > 0 then begin
ListView1.SetFocus;
end
else if Key = VK_ESCAPE then
ModalResult := mrClose;
if Key = VK_DOWN then begin // Is this logic for VK_DOWN good?
ListView1.Selected := ListView1.Items[0];
ListView1.ItemFocused := ListView1.Items[0];
end;
end;
end;
end;
procedure TFormLazExam.PrimeCatFilter();