A lightweight and syntax hilighted UNICODE editor.
一個小巧、語法加亮、使用UNICODE編碼的程式碼編輯器。
TCodeEdit is a component of my lysee project for editing pascal and lysee codes, and it is easy to be extended to fit other developing languages. On the whole, TCodeEdit is small, siuse, languages. On the whole, TCodeEdit is small, siuse, languages. I put it in here open source.
TCodeEdit起初是為我的Lysee專案開發的Pascal/Lysee程式碼編輯器,後來發現可以輕鬆的擴充它用於編輯其他程式語言。整體上, TCodeEdit具有小巧、簡單、易用的特點,對其他程式設計師也許也有用處,因此我把它放在這裡,開放原始碼供大家使用。
TCodeEdit is in development and lack of some helpful functions.
TCodeEdit還在開發完善中,除了基本的語法加亮編輯功能,其他一些輔助功能還有待添加:
TCodeEdit was release under the MIT license. Just use it as you will.
TCodeEdit使用MIT許可,可以放心使用.
Maybe has just completed 60%, so current version is 0.6.0.
也許剛完成60%,所以版本暫定為0.6.0.
Get TCodeEdit and add it to your Lazarus/Delphi project.
下載TCodeEdit後加入你的開發專案。
Use codeedit.pas in your form unit and declare class field to hold TCodeEdit
將codeedit.pas加入需要使用TCodeEdit的視窗單元並宣告類別成員變數。
uses codeedit;
type
TMainForm = class (TForm)
private
FEdit: TCodeEdit ;
procedure EditStatus (Sender: TObject);
end ;
Palce a TCodeEdit at where you want by calling PlaceACodeEdit().
呼叫PlaceACodeEdit函數把TCodeEdit放在需要的位置。
procedure TMainForm.FormCreate (Sender: TObject);
begin
FEdit := PlaceACodeEdit(Self);
FEdit.OnStatus := @EditStatus;
end ;
Reponds OnStatus event to display editor status and enable/disable menu or buttons.
回應OnStatus事件顯示編輯器狀態,修改相關選單、按鈕等元件的屬性。
procedure TMainForm.EditStatus (Sender: TObject);
begin
EditUndoMenu.Enabled := (FEdit.Undos.Last <> nil );
EditRedoMenu.Enabled := (FEdit.Redos.Last <> nil );
EditCutMenu.Enabled := FEdit.Selection.Selected;
EditCopyMenu.Enabled := FEdit.Selection.Selected;
EditPasteMenu.Enabled := HasTextFormat;
StatusBar.Panels[ 0 ].Text := Format( ' %d, %d ' , [FEdit.Caret.LineIndex + 1 , FEdit.Caret.TextIndex]);
if FEdit.Modified then
StatusBar.Panels[ 1 ].Text := ' Changed ' else
StatusBar.Panels[ 1 ].Text := ' ' ;
StatusBar.Panels[ 2 ].Text := FEdit.Syntax.Language;
end ;
How to open a file.
如何開啟文件。
procedure TMainForm.FileOpenMenuClick (Sender: TObject);
begin
CloseDialogs;
if OpenDialog.Execute then
FEdit.Lines.LoadFromFile(OpenDialog.FileName);
end ;
Base on file extension, TCodeEdit will choose prefered language syntax automatically.
開啟檔案後, TCodeEdit會根據檔案後綴自動選擇相符的語法加亮類別。
How to use syntax class manually.
如何手動設定語法加亮類別。
FEdit.Syntax.SyntaxClass := TPascalSyntax;
FEdit.Syntax.SyntaxClass := FindSyntax( ' Pascal ' );
FEdit.Syntax.SyntaxClass := FindSyntaxByFileExt( ' .pas ' );
FEdit.Syntax.SyntaxClass := FindFileSyntax( ' ~/editor/frmmain.pas ' );