呵,动作真快,下面一些建议提供参考:
1. 行号和Symbol的字体可以设置,还有颜色。默认的“宋体”不好看
2. 行号的代码的TCnEditorGutter.Width可根据行号宽度进行动态调整
3. 单击TCnEditorGutter可以设置或取消书签
4. SymbolList过滤还是只过滤以输入的单词打头好些,太多眼花
以下是我的前段时间写的的一些代码片段:
// 画行号
procedure TGutterPanel.DrawLineNumber;
var
i: Integer;
Number: string;
R: TRect;
EditView: IOTAEditView;
TopRow: Integer;
BottomRow: Integer;
CurrentRow: Integer;
begin
EditView := CnOtaGetTopMostEditView;
if not Assigned(EditView) then Exit;
TopRow:= EditView.TopRow;
BottomRow:= EditView.BottomRow;
CurrentRow:= EditView.CursorPos.Line;
with FLineControl do
begin
Refresh;
Canvas.Brush.Style:= bsClear;
Canvas.Font:= Self.Font;
// 根据字串的宽度动态调整Gutter的宽度
Self.Width:= FLineControl.Canvas.TextWidth(IntToStr(BottomRow))+3;
for i:= TopRow to BottomRow do
begin
if (i=CurrentRow) and Assigned(FEditCursor) then
begin
// 画一个当前行的图标代替
Canvas.Draw((Width - FEditCursor.Width) div 2 ,
(i-TopRow)* FLineHeight, FEditCursor);
end
else
begin
Number:= IntToStr(i);
R:= Rect(0, (i-TopRow)* FLineHeight, Width-3, (i-TopRow)* FLineHeight+FLineHeight);
DrawText(Canvas.Handle, PChar(Number), Length(Number), R, DT_RIGHT);
end;
end;
// 画一条垂直线
Canvas.Pen.Color:= VLineColor;
Canvas.MoveTo(Width-1, 0);
Canvas.LineTo(Width-1, Height);
end;
end;
// 单击Gutter Panel设置或取消书签
procedure TGutterPanel.LineControltMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Row: Integer;
EditView: IOTAEditView;
ID: Integer;
EditPos, SavePos: TOTAEditPos;
function GetBlankBookmarkID: Integer;
var
i: Integer;
begin
Result:= 0;
for i:=0 to 9 do
if EditView.BookmarkPos[i ].Line = 0 then
begin
Result:= i;
Exit;
end;
end;
function FindBookmark(Row: Integer): Integer;
var
i: Integer;
begin
Result:= -1;
for i:=0 to 9 do
if EditView.BookmarkPos[i ].Line=Row then
begin
Result:= i;
Exit;
end;
end;
begin
if Button = mbLeft then
begin
EditView := CnOtaGetTopMostEditView;
if Assigned(EditView) then
begin
Row:= EditView.TopRow + Y div FLineHeight;
SavePos:= EditView.CursorPos;
EditPos:= EditView.CursorPos;
EditPos.Line:= Row;
EditView.CursorPos:= EditPos;
ID:= FindBookmark(Row);
if ID=-1 then ID:= GetBlankBookmarkID;
EditView.BookmarkToggle(ID);
EditView.CursorPos:= SavePos;
EditView.Paint;
end;
end;
end;
|