📄 lcdanimatoreditor.pas.svn-base
字号:
var F: TLCDAnimatorCodeEditorForm;
C: TPersistent;
i: Integer;
begin
C := GetComponent(0);
F := TLCDAnimatorCodeEditorForm.Create(Application);
F.Caption := 'TLCDAnimator Code Editor - ' + (C as TLCDAnimator).Name;
try
F.CodeStringGrid.RowCount := (C as TLCDAnimator).Code.Count;
{ Load Code lines from TLCDAnimator to CodeStringGrid }
if (C as TLCDAnimator).Code.Count <> 0
then for i := 0 to F.CodeStringGrid.RowCount - 1
do F.CodeStringGrid.Cells[1, i] := (C as TLCDAnimator).Code[i];
if F.ShowModal = mrOk
then begin
(C as TLCDAnimator).Code.Clear;
{ UnLoad Code lines from CodeStringGrid to TLCDAnimator }
if F.CodeStringGrid.RowCount <> 0
then for i := 0 to F.CodeStringGrid.RowCount - 1
do (C as TLCDAnimator).Code.Append(F.CodeStringGrid.Cells[1, i]);
try Designer.Modified; except end;
end;
{ Check if a code synthax error had been detected and update CodeErrorFond prop.}
if F.Tag = 0 then (C as TLCDAnimator).CodeErrorFound := False
else (C as TLCDAnimator).CodeErrorFound := True;
finally
F.Free;
end;
end;
////////////////////////////////////////////////////////////////////////////////
// //
// Begining of the routines for the Form Editor //
// //
////////////////////////////////////////////////////////////////////////////////
procedure TLCDAnimatorCodeEditorForm.FormActivate(Sender: TObject);
begin
CodeStringGrid.ColWidths[0] := 45;
CodeStringGrid.ColWidths[1] := 430;
end;
procedure TLCDAnimatorCodeEditorForm.CodeStringGridSelectCell(
Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
begin
with CodeStringGrid do
begin
Cells[1, Selection.Top] := Trim(Cells[1, Selection.Top]);
Invalidate;
end;
end;
procedure TLCDAnimatorCodeEditorForm.InsertLineClick(Sender: TObject);
var i: Integer;
begin
with CodeStringGrid do
begin
RowCount := RowCount + 1;
for i := RowCount downto Selection.Top + 1
do Cells[1, i] := Cells[1, i - 1];
Cells[1, Selection.Top] := '';
SetFocus;
Perform(WM_Keydown, vk_F2,0);
end;
end;
procedure TLCDAnimatorCodeEditorForm.AddLineClick(Sender: TObject);
var i: Integer;
begin
with CodeStringGrid do
begin
RowCount := RowCount + 1;
for i := RowCount downto Selection.Top + 2
do Cells[1, i] := Cells[1, i - 1];
Perform(WM_Keydown, vk_Down,0);
Cells[1, Selection.Top] := '';
SetFocus;
CodeStringGrid.Perform(WM_Keydown, vk_F2,0);
end;
end;
procedure TLCDAnimatorCodeEditorForm.DeleteLineClick(Sender: TObject);
var i:Integer;
begin
with CodeStringGrid do
begin
for i := Selection.Top to RowCount - 1
do Cells[1, i] := Cells[1, i + 1];
RowCount := RowCount - 1;
// Invalidate;
end;
end;
procedure TLCDAnimatorCodeEditorForm.DeleteAllClick(Sender: TObject);
begin
if MessageDlg('Delete all code lines?', mtConfirmation, [mbOK, mbCancel], 0) = mrOK
then begin
CodeStringGrid.RowCount := 0;
CodeStringGrid.Cells[1, 0] := '';
end;
end;
procedure TLCDAnimatorCodeEditorForm.WordClick(Sender: TObject);
begin
with CodeStringGrid do
begin
SetFocus;
Cells[1, Selection.Top] := Cells[1, Selection.Top] + (Sender as TButton).Caption;
Perform(WM_Keydown, vk_F2,0);
Perform(WM_Keydown, vk_End,0);
end;
end;
function CodeSynthaxAnalysis(var Caption: String): TColor;
var n1, n2, n3: Byte;
begin
CodeSynthaxAnalysis := clRed;
Caption := Trim(Caption);
n1 := NbOfThings(Caption, ';');
n2 := NbOfThings(Caption, '(');
n3 := NbOfThings(Caption, ')');
if Caption = ''
then begin
CodeSynthaxAnalysis := clYellow;
Caption := 'Nul line';
end
else if Copy(Caption, 1, 1) <> '['
then Caption := 'Error of ['
else if Copy(Caption, Length(Caption), 1) <> ']'
then Caption := 'Error of ]'
else if not((n1 = n2) and (n2 = n3))
then begin
if n2 <> n3 then Caption := 'Error of ( )'
else if n1 <> n2 then Caption := 'Error of ;';
end
else begin
CodeSynthaxAnalysis := clLime;
Caption := 'Ok'
end;
end;
procedure TLCDAnimatorCodeEditorForm.CodeStringGridDrawCell(Sender: TObject;
ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var str: String;
begin
if gdFixed in State
then with CodeStringGrid do
begin
str := CodeStringGrid.Cells[1, ARow];
Canvas.Font.Color := CodeSynthaxAnalysis(str);
if not SyntaxAnalysisMenu.Checked
then str := IntToStr(ARow + 1) + ' / ' + IntToStr(RowCount);
Canvas.TextOut((ColWidths[0] - Canvas.TextWidth(str)) div 2, Rect.Top + 2, str);
end;
end;
procedure TLCDAnimatorCodeEditorForm.EditMenuClick(Sender: TObject);
begin
CodeStringGrid.Perform(WM_Keydown, vk_F2,0);
end;
procedure TLCDAnimatorCodeEditorForm.SyntaxAnalysisMenuClick(
Sender: TObject);
begin
SyntaxAnalysisMenu.Checked := not SyntaxAnalysisMenu.Checked;
if SyntaxAnalysisMenu.Checked then CodeStringGrid.ColWidths[0] := 70
else CodeStringGrid.ColWidths[0] := 45;
end;
procedure TLCDAnimatorCodeEditorForm.CodeStringGridDblClick(
Sender: TObject);
var ACol, ARow: Integer;
begin
CodeStringGrid.MouseToCell(Mouse.CursorPos.X - CodeStringGrid.ClientOrigin.X,
Mouse.CursorPos.Y - CodeStringGrid.ClientOrigin.Y, ACol, ARow);
if ACol = 0 then SyntaxAnalysisMenuClick(Sender);
end;
procedure TLCDAnimatorCodeEditorForm.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
var i, NbErr: Integer;
str: String;
tmr: TModalResult;
begin
NbErr := 0;
tmr := mrIgnore;
for i := 0 to CodeStringGrid.RowCount - 1
do begin
str := CodeStringGrid.Cells[1, i];
if CodeSynthaxAnalysis(str) = clRed then Inc(NbErr);
end;
if NbErr <> 0 then tmr := MessageDlg('Code synthax error(s) detected.' + #13 + #10 +
#13 + #10 + 'Close Editor anyway?',
mtWarning, [mbAbort, mbIgnore], 0);
Tag := NbErr;
if tmr = mrIgnore then CanClose := True
else CanClose := False;
end;
////////////////////////////////////////////////////////////////////////////////
// //
// End of the routines for the Form Editor //
// //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// Registration of the context menu and 'Code [...]' in the ObjectInspector.
//
////////////////////////////////////////////////////////////////////////////////
procedure Register;
begin
RegisterComponentEditor(TLCDAnimator,TLCDAnimatorEditor);
RegisterPropertyEditor(TypeInfo(TStrings), TLCDAnimator, 'Code', TLCDAnimatorCodeEditorProperty);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -