You've already forked lazarus-ccr
193 lines
4.5 KiB
ObjectPascal
193 lines
4.5 KiB
ObjectPascal
![]() |
unit indlcddisplay_editor;
|
||
|
|
||
|
{$mode objfpc}{$H+}
|
||
|
|
||
|
interface
|
||
|
|
||
|
uses lazlogger,
|
||
|
Classes, SysUtils, PropEdits, ComponentEditors,
|
||
|
indLCDDisplay;
|
||
|
|
||
|
type
|
||
|
TLCDDisplayCharDefsPropertyEditor = class(TPersistentPropertyEditor)
|
||
|
public
|
||
|
procedure Edit; override;
|
||
|
procedure ExecuteVerb(Index: Integer); override;
|
||
|
function GetAttributes: TPropertyAttributes; override;
|
||
|
function GetVerb(Index: Integer): string; override;
|
||
|
function GetVerbCount: Integer; override;
|
||
|
function LCDDisplay: TLCDDisplay;
|
||
|
end;
|
||
|
|
||
|
TLCDDisplayComponentEditor = class(TDefaultComponentEditor)
|
||
|
public
|
||
|
procedure EditLines;
|
||
|
procedure ExecuteVerb(Index: Integer);
|
||
|
function GetVerb(Index: Integer): string; override;
|
||
|
function GetVerbCount: Integer; override;
|
||
|
function LCDDisplay: TLCDDisplay;
|
||
|
end;
|
||
|
|
||
|
procedure EditCharDefs(ALCDDisplay: TLCDDisplay);
|
||
|
|
||
|
implementation
|
||
|
|
||
|
uses
|
||
|
Dialogs, indLCDDisplay_EditorForm;
|
||
|
|
||
|
{ Opens the char def editor. }
|
||
|
procedure EditCharDefs(ALCDDisplay: TLCDDisplay);
|
||
|
var
|
||
|
F: TLCDCharDefsEditor;
|
||
|
begin
|
||
|
F := TLCDCharDefsEditor.Create(nil);
|
||
|
try
|
||
|
F.LCDDisplay := TLCDDisplay(ALCDDisplay);
|
||
|
F.ShowModal; // Cancel has been handled by the editor form.
|
||
|
finally
|
||
|
F.Free;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
{ Loads the char defs of the specified LCDDisplay from an xml file. }
|
||
|
procedure LoadCharDefsFromFile(ALCDDisplay: TLCDDisplay);
|
||
|
var
|
||
|
dlg: TOpenDialog;
|
||
|
begin
|
||
|
dlg := TOpenDialog.Create(nil);
|
||
|
try
|
||
|
dlg.FileName := '';
|
||
|
dlg.Filter := 'XML files (*.xml)|*.xml';
|
||
|
if dlg.Execute then
|
||
|
begin
|
||
|
ALCDDisplay.CharDefs.LoadFromFile(dlg.FileName);
|
||
|
ALCDDisplay.Invalidate;
|
||
|
end;
|
||
|
finally
|
||
|
dlg.Free;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
{ Saves the chardefs of the specified LCDDisplay to an xml file. }
|
||
|
procedure SaveCharDefsToFile(ALCDDisplay: TLCDDisplay);
|
||
|
var
|
||
|
dlg: TOpenDialog;
|
||
|
begin
|
||
|
dlg := TSaveDialog.Create(nil);
|
||
|
try
|
||
|
dlg.FileName := '';
|
||
|
dlg.Filter := 'XML files (*.xml)|*.xml';
|
||
|
if dlg.Execute then
|
||
|
ALCDDisplay.CharDefs.SaveToFile(dlg.FileName);
|
||
|
finally
|
||
|
dlg.Free;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
|
||
|
{ TLCDDisplayCharDefsPropertyEditor }
|
||
|
|
||
|
{ Opens the chardefs editor. }
|
||
|
procedure TLCDDisplayCharDefsPropertyEditor.Edit;
|
||
|
begin
|
||
|
EditCharDefs(LCDDisplay);
|
||
|
end;
|
||
|
|
||
|
{ Executes the routines assigned to the CharDefs context menu }
|
||
|
procedure TLCDDisplayCharDefsPropertyEditor.ExecuteVerb(Index: Integer);
|
||
|
begin
|
||
|
case Index of
|
||
|
0: Edit;
|
||
|
1: LoadCharDefsFromFile(LCDDisplay);
|
||
|
2: SaveCharDefsToFile(LCDDisplay);
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
{ The property editor should open the CharDefs editor. }
|
||
|
function TLCDDisplayCharDefsPropertyEditor.GetAttributes: TPropertyAttributes;
|
||
|
begin
|
||
|
Result := inherited GetAttributes + [paDialog];
|
||
|
end;
|
||
|
|
||
|
{ Determines how many items will be added to the CharDefs context menu. }
|
||
|
function TLCDDisplayCharDefsPropertyEditor.GetVerbCount: Integer;
|
||
|
begin
|
||
|
Result := 3;
|
||
|
end;
|
||
|
|
||
|
{ Determines the menu item text for CharDefs context menu. }
|
||
|
function TLCDDisplayCharDefsPropertyEditor.GetVerb(Index: Integer): string;
|
||
|
begin
|
||
|
case Index of
|
||
|
0: Result := 'Edit...';
|
||
|
1: Result := 'Load from file...';
|
||
|
2: Result := 'Save to file...';
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
function TLCDDisplayCharDefsPropertyEditor.LCDDisplay: TLCDDisplay;
|
||
|
begin
|
||
|
Result := TLCDDisplay(GetComponent(0));
|
||
|
end;
|
||
|
|
||
|
{ TLCDDisplayComponentEditor }
|
||
|
|
||
|
procedure TLCDDisplayComponentEditor.EditLines;
|
||
|
begin
|
||
|
{
|
||
|
F := TStringsPropEditorForm.Create(nil);
|
||
|
dlg :=
|
||
|
Old := TStrings(GetObjectValue);
|
||
|
TheDialog := CreateDlg(Old);
|
||
|
try
|
||
|
if (TheDialog.ShowModal = mrOK) then begin
|
||
|
New := TheDialog.ListBox.Items;
|
||
|
AssignItems(Old, TheDialog.ListBox.Items);
|
||
|
SetPtrValue(New);
|
||
|
end;
|
||
|
finally
|
||
|
TheDialog.Free;
|
||
|
end;
|
||
|
}
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplayComponentEditor.ExecuteVerb(Index: Integer);
|
||
|
begin
|
||
|
if LCDDisplay = nil then
|
||
|
DebugLn('LCDDisplay = nil')
|
||
|
else
|
||
|
DebugLn(LCDDisplay.ClassName);
|
||
|
|
||
|
case Index of
|
||
|
0: EditLines;
|
||
|
1: EditCharDefs(LCDDisplay);
|
||
|
2: LoadCharDefsFromFile(LCDDisplay);
|
||
|
3: SaveCharDefsToFile(LCDDisplay);
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
{ Determines how many items will be added to the LCDDisplay context menu. }
|
||
|
function TLCDDisplayComponentEditor.GetVerbCount: Integer;
|
||
|
begin
|
||
|
Result := 4;
|
||
|
end;
|
||
|
|
||
|
{ Determines the menu item text for LCDDisplay context menu. }
|
||
|
function TLCDDisplayComponentEditor.GetVerb(Index: Integer): string;
|
||
|
begin
|
||
|
case Index of
|
||
|
0: Result := 'Text...';
|
||
|
1: Result := 'Edit character defs...';
|
||
|
2: Result := 'Load character defs from file...';
|
||
|
3: Result := 'Save character defs to file...';
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
function TLCDDisplayComponentEditor.LCDDisplay: TLCDDisplay;
|
||
|
begin
|
||
|
Result := TLCDDisplay(GetComponent);
|
||
|
end;
|
||
|
|
||
|
end.
|
||
|
|