Win positioned, Beginner listed first, keypress triggers sort, Enter same as dbl click

This commit is contained in:
David Bannon 2022-05-02 09:35:30 +10:00 committed by Maxim Ganetsky
parent 5efb577ae9
commit 1dbfe9f875
4 changed files with 101 additions and 68 deletions

View File

@ -46,6 +46,7 @@ resourcestring
rsExampleKeyWords = 'Keywords'; // "
rsExSearchingForExamples = 'Searching for Examples ...';
rsFailedToCopyFilesTo = 'Failed to copy files to'; // Followed by a dir were we, apparently, cannot write
rsGroupHint = 'Double click to invert';
// These are ObjectInspector set but I believe I cannot get OI literals i18n in a Package ??
rsExampleOpen = 'Open'; // Button Caption

View File

@ -196,8 +196,7 @@ uses LCLProc,
lazfileutils, fileutil,
jsonscanner, // these are the FPC JSON tools
base64,
laz2_DOM, laz2_XMLRead // just to get LazarusDirectory, remove if we find a better way !
{, IDEOptionsIntf} ;
laz2_DOM, laz2_XMLRead; // just to get LazarusDirectory, remove if we find a better way !
const
LastUpDate = 'LastUpDate'; // Name of JSON item were we store last update date
@ -304,6 +303,11 @@ end;
// T E X A M P L E D A T A
// =============================================================================
// Address of this function is passed to a list sort call. We sort on category, Beginners at top
function CategorySorter( Item1: Pointer; Item2: Pointer) : Integer;
begin
result := CompareStr(PExRec(Item1)^.Category, PExRec(Item2)^.Category);
end;
function TExampleData.Count: integer;
begin
@ -541,6 +545,7 @@ begin
ScanLocalTree(ExamplesHome, True); // Get, eg, any OPM Examples
end;
end;
ExList.Sort(@CategorySorter);
// if ExList.Count = 0 then begin
// debugln('TExampleData.LoadExData - found examples = ' + inttostr(ExList.Count));
// debugln('Lazarus Dir (ie source tree) = ' + GetLazDir());

View File

@ -1,15 +1,15 @@
object FormLazExam: TFormLazExam
Left = 55
Height = 500
Top = 143
Width = 976
Left = 88
Height = 400
Top = 155
Width = 781
Caption = 'Prototype Lazarus Examples Window'
ClientHeight = 500
ClientWidth = 976
DesignTimePPI = 120
ClientHeight = 400
ClientWidth = 781
OnCreate = FormCreate
OnDestroy = FormDestroy
OnShow = FormShow
LCLVersion = '2.3.0.0'
object Memo1: TMemo
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Splitter2
@ -17,14 +17,14 @@ object FormLazExam: TFormLazExam
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = CheckGroupCategory
Left = 6
Height = 202
Top = 197
Width = 964
Left = 5
Height = 151
Top = 157
Width = 771
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 6
BorderSpacing.Right = 6
BorderSpacing.Bottom = 6
BorderSpacing.Left = 5
BorderSpacing.Right = 5
BorderSpacing.Bottom = 5
Lines.Strings = (
'Memo1'
)
@ -32,6 +32,7 @@ object FormLazExam: TFormLazExam
ReadOnly = True
ScrollBars = ssAutoVertical
TabOrder = 1
TabStop = False
end
object ListView1: TListView
AnchorSideLeft.Control = Owner
@ -39,22 +40,22 @@ object FormLazExam: TFormLazExam
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Splitter2
Left = 6
Height = 139
Left = 5
Height = 110
Hint = 'Click for Info, Double Click to download'
Top = 46
Width = 964
Top = 37
Width = 771
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Around = 6
BorderSpacing.Around = 5
Columns = <
item
Width = 10
Width = 8
end
item
Width = 10
Width = 8
end
item
Width = 10
Width = 740
end>
ParentShowHint = False
ReadOnly = True
@ -62,6 +63,7 @@ object FormLazExam: TFormLazExam
TabOrder = 0
OnClick = ListView1Click
OnDblClick = ListView1DblClick
OnKeyDown = ListView1KeyDown
OnSelectItem = ListView1SelectItem
end
object CheckGroupCategory: TCheckGroup
@ -69,16 +71,16 @@ object FormLazExam: TFormLazExam
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ButtonOpen
Left = 6
Height = 24
Top = 405
Width = 964
Left = 5
Height = 23
Top = 313
Width = 771
Anchors = [akLeft, akRight, akBottom]
AutoFill = True
AutoSize = True
BorderSpacing.Left = 6
BorderSpacing.Right = 6
BorderSpacing.Bottom = 6
BorderSpacing.Left = 5
BorderSpacing.Right = 5
BorderSpacing.Bottom = 5
Caption = 'Category'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
@ -91,6 +93,8 @@ object FormLazExam: TFormLazExam
Columns = 2
OnDblClick = CheckGroupCategoryDblClick
OnItemClick = CheckGroupCategoryItemClick
ParentShowHint = False
ShowHint = True
TabOrder = 2
end
object Splitter2: TSplitter
@ -101,18 +105,18 @@ object FormLazExam: TFormLazExam
AnchorSideBottom.Control = Memo1
Cursor = crVSplit
Left = 0
Height = 6
Top = 191
Width = 976
Height = 5
Top = 152
Width = 781
Align = alNone
Anchors = [akLeft, akRight]
ResizeAnchor = akTop
end
object StatusBar1: TStatusBar
Left = 0
Height = 29
Top = 471
Width = 976
Height = 23
Top = 377
Width = 781
Panels = <>
end
object ButtonDownload: TButton
@ -121,13 +125,13 @@ object FormLazExam: TFormLazExam
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ButtonOpen
AnchorSideBottom.Side = asrBottom
Left = 74
Height = 30
Top = 435
Width = 95
Left = 64
Height = 31
Top = 341
Width = 89
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Left = 6
BorderSpacing.Left = 5
Caption = 'Download'
OnClick = ButtonDownloadClick
TabOrder = 5
@ -138,13 +142,13 @@ object FormLazExam: TFormLazExam
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ButtonOpen
AnchorSideBottom.Side = asrBottom
Left = 283
Height = 30
Top = 435
Width = 62
Left = 266
Height = 31
Top = 341
Width = 54
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Left = 6
BorderSpacing.Left = 5
Caption = 'Close'
OnClick = ButtonCloseClick
TabOrder = 6
@ -153,14 +157,14 @@ object FormLazExam: TFormLazExam
AnchorSideLeft.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = StatusBar1
Left = 6
Height = 30
Top = 435
Width = 62
Left = 5
Height = 31
Top = 341
Width = 54
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Left = 6
BorderSpacing.Bottom = 6
BorderSpacing.Left = 5
BorderSpacing.Bottom = 5
Caption = 'Open'
OnClick = ButtonOpenClick
TabOrder = 7
@ -171,13 +175,13 @@ object FormLazExam: TFormLazExam
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ButtonOpen
AnchorSideBottom.Side = asrBottom
Left = 175
Height = 30
Top = 435
Width = 102
Left = 158
Height = 31
Top = 341
Width = 103
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Left = 6
BorderSpacing.Left = 5
Caption = 'ButtonView'
OnClick = ButtonViewClick
TabOrder = 8
@ -187,15 +191,16 @@ object FormLazExam: TFormLazExam
AnchorSideTop.Control = Owner
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 6
Height = 28
Left = 5
Height = 29
Hint = 'Searches for Keywords'
Top = 6
Width = 964
Top = 5
Width = 771
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 6
BorderSpacing.Top = 6
BorderSpacing.Right = 6
BorderSpacing.Left = 5
BorderSpacing.Top = 5
BorderSpacing.Right = 5
OnChange = EditSearchChange
OnExit = EditSearchExit
OnKeyUp = EditSearchKeyUp
ParentShowHint = False

View File

@ -25,7 +25,6 @@ Notes -
David Bannon, Feb 2022
}
{$mode objfpc}{$H+}
{x$define EXTESTMODE}
{X$define ONLINE_EXAMPLES}
@ -53,6 +52,7 @@ type
EditSearch: TEdit;
ListView1: TListView;
Memo1: TMemo;
Panel1: TPanel;
Splitter2: TSplitter;
StatusBar1: TStatusBar;
procedure ButtonCloseClick(Sender: TObject);
@ -61,6 +61,7 @@ type
procedure ButtonViewClick(Sender: TObject);
procedure CheckGroupCategoryDblClick(Sender: TObject);
procedure CheckGroupCategoryItemClick(Sender: TObject; Index: integer);
procedure EditSearchChange(Sender: TObject);
procedure EditSearchExit(Sender: TObject);
procedure EditSearchKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormCreate(Sender: TObject);
@ -68,6 +69,8 @@ type
procedure FormShow(Sender: TObject);
procedure ListView1Click(Sender: TObject);
procedure ListView1DblClick(Sender: TObject);
procedure ListView1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
private
procedure BuildSearchList(SL: TStringList; const Term: AnsiString);
@ -182,6 +185,15 @@ begin
ButtonOpenClick(self);
end;
procedure TFormLazExam.ListView1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = vk_return then begin
Key := 0;
ListView1DblClick(Sender);
end;
end;
// --------------------- B U T T O N S -----------------------------------------
procedure TFormLazExam.ButtonOpenClick(Sender: TObject);
@ -267,6 +279,7 @@ var
begin
for i := 0 to CheckGroupCategory.Items.Count -1 do
CheckGroupCategory.Checked[i] := not CheckGroupCategory.Checked[i];
CheckGroupCategoryItemClick(Sender, 0);
end;
procedure TFormLazExam.CheckGroupCategoryItemClick(Sender: TObject; Index: integer);
@ -278,6 +291,7 @@ begin
LoadUpListView();
end;
// ---------------------- Setting Project to Open ------------------------------
function TFormLazExam.GetProjectFile(const APath : string; WriteProjectToOpen : boolean = false) : boolean;
@ -378,6 +392,12 @@ begin
LoadUpListView();
end;
procedure TFormLazExam.EditSearchChange(Sender: TObject);
begin
if (EditSearch.Text <> '') and (EditSearch.Text <> rsExSearchPrompt) then
KeyWordSearch();
end;
procedure TFormLazExam.EditSearchKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
// Must do this here to stop LCL from selecting the text on VK_RETURN
@ -419,6 +439,7 @@ begin
ListView1.Column[2].Visible := false;
ListView1.ReadOnly := True;
EditSearch.text := rsExSearchPrompt;
CheckGroupCategory.Hint := rsGroupHint;
Ex := nil;
// These are ObjectInspector set but I believe I cannot get OI literals set in a Package ??
ButtonClose.Caption := rsExampleClose;
@ -445,6 +466,9 @@ var
i : integer;
begin
Memo1.clear;
Top := Screen.Height div 10;
Height := Screen.Height * 7 div 10;
ListView1.Height:= Screen.Height * 3 div 10;
if Ex <> Nil then Ex.Free;
StatusBar1.SimpleText := rsExSearchingForExamples;
Ex := TExampleData.Create();
@ -470,8 +494,6 @@ begin
if EditSearch.Text <> rsExSearchPrompt then
KeyWordSearch()
else EditSearch.SetFocus;
end;
{ Must add a FormClose event