Industrial/TLCDDisplay: Fix component editor not executing context menu items. Add edit lines functionality to component editor.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8313 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-06-18 10:57:37 +00:00
parent edb43d5153
commit d926e02845

View File

@ -1,10 +1,10 @@
unit indlcddisplay_editor; unit indLCDDisplay_Editor;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
interface interface
uses lazlogger, uses
Classes, SysUtils, PropEdits, ComponentEditors, Classes, SysUtils, PropEdits, ComponentEditors,
indLCDDisplay; indLCDDisplay;
@ -19,10 +19,12 @@ type
function LCDDisplay: TLCDDisplay; function LCDDisplay: TLCDDisplay;
end; end;
TLCDDisplayComponentEditor = class(TDefaultComponentEditor) TLCDDisplayComponentEditor = class(TComponentEditor)
private
procedure EditLines;
public public
procedure EditLines; procedure Edit; override;
procedure ExecuteVerb(Index: Integer); procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override; function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override; function GetVerbCount: Integer; override;
function LCDDisplay: TLCDDisplay; function LCDDisplay: TLCDDisplay;
@ -33,7 +35,8 @@ procedure EditCharDefs(ALCDDisplay: TLCDDisplay);
implementation implementation
uses uses
Dialogs, indLCDDisplay_EditorForm; Controls, StdCtrls, Dialogs, ButtonPanel, Forms,
indLCDDisplay_EditorForm;
{ Opens the char def editor. } { Opens the char def editor. }
procedure EditCharDefs(ALCDDisplay: TLCDDisplay); procedure EditCharDefs(ALCDDisplay: TLCDDisplay);
@ -42,6 +45,7 @@ var
begin begin
F := TLCDCharDefsEditor.Create(nil); F := TLCDCharDefsEditor.Create(nil);
try try
F.Position := poScreenCenter;
F.LCDDisplay := TLCDDisplay(ALCDDisplay); F.LCDDisplay := TLCDDisplay(ALCDDisplay);
F.ShowModal; // Cancel has been handled by the editor form. F.ShowModal; // Cancel has been handled by the editor form.
finally finally
@ -130,34 +134,50 @@ begin
Result := TLCDDisplay(GetComponent(0)); Result := TLCDDisplay(GetComponent(0));
end; end;
{ TLCDDisplayComponentEditor } { TLCDDisplayComponentEditor }
procedure TLCDDisplayComponentEditor.EditLines; procedure TLCDDisplayComponentEditor.Edit;
begin begin
{ ExecuteVerb(0);
F := TStringsPropEditorForm.Create(nil); end;
dlg :=
Old := TStrings(GetObjectValue); procedure TLCDDisplayComponentEditor.EditLines;
TheDialog := CreateDlg(Old); var
F: TForm;
Memo: TMemo;
begin
F := TForm.CreateNew(nil);
try try
if (TheDialog.ShowModal = mrOK) then begin F.Caption := 'Edit LCDDisplay text';
New := TheDialog.ListBox.Items; F.Position := poScreenCenter;
AssignItems(Old, TheDialog.ListBox.Items); F.Width := 300;
SetPtrValue(New); F.Height := 200;
Memo := TMemo.Create(F);
with Memo do
begin
Align := alClient;
BorderSpacing.Around := 8;
Parent := F;
Lines.Assign(LCDDisplay.Lines);
end;
with TButtonPanel.Create(F) do
begin
ShowButtons := [pbOK, pbCancel];
Parent := F;
end;
if F.ShowModal = mrOK then
begin
LCDDisplay.Lines.Assign(Memo.Lines);
LCDDisplay.Invalidate;
end; end;
finally finally
TheDialog.Free; F.Free;
end; end;
}
end; end;
procedure TLCDDisplayComponentEditor.ExecuteVerb(Index: Integer); procedure TLCDDisplayComponentEditor.ExecuteVerb(Index: Integer);
begin begin
if LCDDisplay = nil then
DebugLn('LCDDisplay = nil')
else
DebugLn(LCDDisplay.ClassName);
case Index of case Index of
0: EditLines; 0: EditLines;
1: EditCharDefs(LCDDisplay); 1: EditCharDefs(LCDDisplay);
@ -176,7 +196,7 @@ end;
function TLCDDisplayComponentEditor.GetVerb(Index: Integer): string; function TLCDDisplayComponentEditor.GetVerb(Index: Integer): string;
begin begin
case Index of case Index of
0: Result := 'Text...'; 0: Result := 'Lines text...';
1: Result := 'Edit character defs...'; 1: Result := 'Edit character defs...';
2: Result := 'Load character defs from file...'; 2: Result := 'Load character defs from file...';
3: Result := 'Save character defs to file...'; 3: Result := 'Save character defs to file...';