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

View File

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