-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
bclealcddisplay_editor.pas
211 lines (183 loc) · 5.14 KB
/
bclealcddisplay_editor.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
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.