| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- unit BCLeaLCDDisplay_Editor;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, PropEdits, ComponentEditors,
- BCLeaLCDDisplay;
- type
- TBCLeaLCDDisplayCharDefsPropertyEditor = 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 BCLeaLCDDisplay: TBCLeaLCDDisplay;
- end;
- TBCLeaLCDDisplayComponentEditor = class(TComponentEditor)
- private
- procedure EditLines;
- public
- procedure Edit; override;
- procedure ExecuteVerb(Index: integer); override;
- function GetVerb(Index: integer): string; override;
- function GetVerbCount: integer; override;
- function BCLeaLCDDisplay: TBCLeaLCDDisplay;
- end;
- procedure EditCharDefs(ABCLeaLCDDisplay: TBCLeaLCDDisplay);
- implementation
- uses
- Controls, StdCtrls, Dialogs, ButtonPanel, Forms,
- BCLeaLCDDisplay_EditorForm;
- { Opens the char def editor. }
- procedure EditCharDefs(ABCLeaLCDDisplay: TBCLeaLCDDisplay);
- var
- F: TBCLeaLCDCharDefsEditor;
- begin
- F := TBCLeaLCDCharDefsEditor.Create(nil);
- try
- F.Position := poScreenCenter;
- F.BCLeaLCDDisplay := TBCLeaLCDDisplay(ABCLeaLCDDisplay);
- F.ShowModal; // Cancel has been handled by the editor form.
- finally
- F.Free;
- end;
- end;
- { Loads the char defs of the specified BCLeaLCDDisplay from an xml file. }
- procedure LoadCharDefsFromFile(ABCLeaLCDDisplay: TBCLeaLCDDisplay);
- var
- dlg: TOpenDialog;
- begin
- dlg := TOpenDialog.Create(nil);
- try
- dlg.FileName := '';
- dlg.Filter := 'XML files (*.xml)|*.xml';
- if dlg.Execute then
- begin
- ABCLeaLCDDisplay.CharDefs.LoadFromFile(dlg.FileName);
- ABCLeaLCDDisplay.Invalidate;
- end;
- finally
- dlg.Free;
- end;
- end;
- { Saves the chardefs of the specified BCLeaLCDDisplay to an xml file. }
- procedure SaveCharDefsToFile(ABCLeaLCDDisplay: TBCLeaLCDDisplay);
- var
- dlg: TOpenDialog;
- begin
- dlg := TSaveDialog.Create(nil);
- try
- dlg.FileName := '';
- dlg.Filter := 'XML files (*.xml)|*.xml';
- if dlg.Execute then
- ABCLeaLCDDisplay.CharDefs.SaveToFile(dlg.FileName);
- finally
- dlg.Free;
- end;
- end;
- { TBCLeaLCDDisplayCharDefsPropertyEditor }
- { Opens the chardefs editor. }
- procedure TBCLeaLCDDisplayCharDefsPropertyEditor.Edit;
- begin
- EditCharDefs(BCLeaLCDDisplay);
- end;
- { Executes the routines assigned to the CharDefs context menu }
- procedure TBCLeaLCDDisplayCharDefsPropertyEditor.ExecuteVerb(Index: integer);
- begin
- case Index of
- 0: Edit;
- 1: LoadCharDefsFromFile(BCLeaLCDDisplay);
- 2: SaveCharDefsToFile(BCLeaLCDDisplay);
- end;
- end;
- { The property editor should open the CharDefs editor. }
- function TBCLeaLCDDisplayCharDefsPropertyEditor.GetAttributes: TPropertyAttributes;
- begin
- Result := inherited GetAttributes + [paDialog];
- end;
- { Determines how many items will be added to the CharDefs context menu. }
- function TBCLeaLCDDisplayCharDefsPropertyEditor.GetVerbCount: integer;
- begin
- Result := 3;
- end;
- { Determines the menu item text for CharDefs context menu. }
- function TBCLeaLCDDisplayCharDefsPropertyEditor.GetVerb(Index: integer): string;
- begin
- case Index of
- 0: Result := 'Edit...';
- 1: Result := 'Load from file...';
- 2: Result := 'Save to file...';
- end;
- end;
- function TBCLeaLCDDisplayCharDefsPropertyEditor.BCLeaLCDDisplay: TBCLeaLCDDisplay;
- begin
- Result := TBCLeaLCDDisplay(GetComponent(0));
- end;
- { TBCLeaLCDDisplayComponentEditor }
- procedure TBCLeaLCDDisplayComponentEditor.Edit;
- begin
- ExecuteVerb(0);
- end;
- procedure TBCLeaLCDDisplayComponentEditor.EditLines;
- var
- F: TForm;
- Memo: TMemo;
- begin
- F := TForm.CreateNew(nil);
- try
- F.Caption := 'Edit BCLeaLCDDisplay text';
- F.Position := poScreenCenter;
- F.Width := 300;
- F.Height := 200;
- Memo := TMemo.Create(F);
- with Memo do
- begin
- Align := alClient;
- BorderSpacing.Around := 8;
- Parent := F;
- Lines.Assign(BCLeaLCDDisplay.Lines);
- end;
- with TButtonPanel.Create(F) do
- begin
- ShowButtons := [pbOK, pbCancel];
- Parent := F;
- end;
- if F.ShowModal = mrOk then
- begin
- BCLeaLCDDisplay.Lines.Assign(Memo.Lines);
- BCLeaLCDDisplay.Invalidate;
- end;
- finally
- F.Free;
- end;
- end;
- procedure TBCLeaLCDDisplayComponentEditor.ExecuteVerb(Index: integer);
- begin
- case Index of
- 0: EditLines;
- 1: EditCharDefs(BCLeaLCDDisplay);
- 2: LoadCharDefsFromFile(BCLeaLCDDisplay);
- 3: SaveCharDefsToFile(BCLeaLCDDisplay);
- end;
- end;
- { Determines how many items will be added to the BCLeaLCDDisplay context menu. }
- function TBCLeaLCDDisplayComponentEditor.GetVerbCount: integer;
- begin
- Result := 4;
- end;
- { Determines the menu item text for BCLeaLCDDisplay context menu. }
- function TBCLeaLCDDisplayComponentEditor.GetVerb(Index: integer): string;
- begin
- case Index of
- 0: Result := 'Lines text...';
- 1: Result := 'Edit character defs...';
- 2: Result := 'Load character defs from file...';
- 3: Result := 'Save character defs to file...';
- end;
- end;
- function TBCLeaLCDDisplayComponentEditor.BCLeaLCDDisplay: TBCLeaLCDDisplay;
- begin
- Result := TBCLeaLCDDisplay(GetComponent);
- end;
- end.
|