📄 syneditor.pas
字号:
MinPage := 1;
FromPage := 1;
MaxPage := TSynEditPrint(Data).PageCount;
ToPage := MaxPage;
if SelAvail then
Options := [poPageNums, poWarning, poSelection]
else Options := [poPageNums, poWarning];
If Execute then
begin
TSynEditPrint(Data).Copies := Copies;
case PrintRange of
prAllPages: TSynEditPrint(Data).Print;
prPageNums: TSynEditPrint(Data).PrintRange(FromPage, ToPage);
prSelection:
begin
TSynEditPrint(Data).SelectedOnly := true;
TSynEditPrint(Data).Print;
end;
end;
end else exit;
finally
free;
end;
end;
TSynEditPrint(Data).Print;
end;
procedure ClearMarkers;
var
i : integer;
begin
for i := 0 to 9 do ClearBookMark(I);
end;
procedure DeleteCursorWord;
begin
BeginUndoBlock;
Inherited ExecuteCommand(ecDeleteWord, #0, nil);
Inherited ExecuteCommand(ecDeleteLastWord, #0, nil);
EndUndoBlock;
end;
procedure SelectLine;
begin
BeginUndoBlock;
Inherited ExecuteCommand(ecLineStart, #0, nil);
Inherited ExecuteCommand(ecSelLineEnd, #0, nil);
EndUndoBlock;
end;
procedure SelNextWord;
var
BB, BE : TBufferCoord;
begin
SelStart := SelEnd;
BB := NextWordPos;
IF (BB.Line = BlockEnd.Line) and (BB.Char = BlockEnd.Char) then
exit;
BE := WordEndEx(BB);
SetCaretAndSelection(BB, BB, BE);
IF (Trim(SelText) = '') then
ExecuteCommand(ecSelNextWord, #0, nil);
end;
procedure SelPrevWord;
var
BB, BE : TBufferCoord;
begin
SelEnd := SelStart;
BB := PrevWordPos;
IF (BB.Line = BlockBegin.Line) and (BB.Char = BlockBegin.Char) then
exit;
BE := WordEndEx(BB);
SetCaretAndSelection(BB, BB, BE);
IF (Trim(SelText) = '') then
ExecuteCommand(ecSelPrevWord, #0, nil);
end;
procedure SelNextLine;
begin
if CaretY < Lines.Count then
CaretY := CaretY + 1
else
CaretY := 1;
ExecuteCommand(ecSelectLine, #0, nil);
end;
procedure SelPrevLine;
begin
if CaretY > 1 then
CaretY := CaretY - 1
else
CaretY := Lines.Count;
ExecuteCommand(ecSelectLine, #0, nil);
end;
begin
case command of
// ecGotoLastChange 跳转到上次修改的位置
ecGotoLastChange : CaretXY := FLastChangePos;
// ecUpperCase 转换当前单词或选中文本中的字母为大写字母
ecAutoUpperCase : UpperCase;
// ecLowerCase 转换当前单词或选中文本中的字母为小写字母
ecAutoLowerCase : LowerCase;
// ecToggleCase 切换转换当前单词或选中文本中的字母大小写
ecAutoToggleCase : ToggleCase;
// ecTitleCase 转换当前单词或选中文本中的词首字母大写
ecAutoTitleCase : TitleCase;
// ecPrint 打印本身的内容 传入参数AChar为'1'时显示 TPrintDialog
ecPrint : Print;
// ecClearMarkers 清除所有的书签标记
ecClearMarkers : ClearMarkers;
// ecDeleteCursorWord 删除当前光标单词
ecDeleteCursorWord : DeleteCursorWord;
// ecSelectLine 选中当前一行
ecSelectLine : SelectLine;
// SelNextWord 选择下一个单词
ecSelNextWord : SelNextWord;
// SelPrevWord 选择上一个单词
ecSelPrevWord : SelPrevWord;
// ecSelNextLine 选择下行
ecSelNextLine : SelNextLine;
// ecSelPrevLine 选择上行
ecSelPrevLine : SelPrevLine;
else
inherited;
end;
end;
procedure TCustomSynEditor.ExportDocument(Document: string;
Exporter: TSynCustomExporter; Options: TSynDocumentOptions);
var
Ext : string;
begin
If doDefine in Options then
begin
with TSaveDialog.Create(self) do
begin
try
if Title = '' then
Title := format(sExportDocumentTitle, [document]);
Filter := Exporter.DefaultFilter;
If Execute then Document := Filename else Exit;
finally
free;
end;
end;
end;
if Exporter is TSynExporterHTML then
begin
Ext := LowerCase(ExtractFileExt(Document));
if (Ext <> '.htm') and (Ext <> '.html') then
Document := Document + '.htm';
end;
if Exporter is TSynExporterRTF then
begin
Ext := LowerCase(ExtractFileExt(Document));
if (Ext <> '.rtf') then
Document := Document + '.rtf';
end;
if Exporter is TSynExporterTeX then
begin
Ext := LowerCase(ExtractFileExt(Document));
if (Ext <> '.tex') then
Document := Document + '.tex';
end;
Exporter.Highlighter := Highlighter;
Exporter.Title := Document;
Exporter.Font := Font;
If doSelection In Options then
Exporter.ExportRange(Lines, BlockBegin, BlockEnd)
else Exporter.ExportAll(Lines);
Exporter.SaveToFile(Document);
If doReset In Options then
begin
FDocumentName := Document;
FDocumentState := smsDocument;
Reset;
end;
end;
function TCustomSynEditor.getDocumentFormat: TSynEditFileFormat;
begin
result := TSynEditStringList(Lines).FileFormat;
end;
function TCustomSynEditor.LoadDocument(Document: string;
OpenDialog: TOpenDialog; Options: TSynDocumentOptions): boolean;
var
Stream : TMemoryStream;
Str : String;
begin
result := false;
If doDefine In Options then
begin
with OpenDialog do
begin
if Title = '' then
title := sOpenDocumentTitle;
If Execute then
Document := Filename
else Exit;
end;
end;
Stream := TMemoryStream.Create;
try
Stream.LoadFromFile(document);
try
Stream.Position := 0;
doLoadDocument(Stream, Options);
If doSelection In Options then
begin
SetString(Str, nil, Stream.Size);
Stream.Read(Pointer(Str)^, Stream.Size);
SelText := Str
end else Lines.LoadFromStream(Stream);
TopLine := 1;
except
ShowMessage(Format(sOpenDocumentError, [Document]));
exit;
end;
finally
Stream.Free;
end;
If doReset In Options then
begin
FDocumentName := Document;
FDocumentState := smsDocument;
Reset;
DoOnStatusChange([scAll]);
end;
result := true;
end;
procedure TCustomSynEditor.Reset;
begin
// Marks.Clear;
// UndoList.Clear;
// RedoList.Clear;
Modified := false;
StatusChanged([scall]);
end;
function TCustomSynEditor.SaveDocument(Document: string;
SaveDialog: TSaveDialog; Options: TSynDocumentOptions): boolean;
var
Stream : TMemoryStream;
begin
result := false;
If doDefine In Options then
begin
with SaveDialog do
begin
if Title = '' then
Title := Format(sSaveDocumentTitle, [Document]);
If Execute then Document := FileName else Exit;
end;
end;
Stream := TMemoryStream.Create;
try
If doSelection in Options then
begin
with TStringList.Create do
begin
Text := SelText;
SaveToStream(Stream);
end;
end
else Lines.SaveToStream(Stream);
DoSaveDocument(Stream, Options);
Stream.SaveToFile(Document);
Stream.Free;
except
showMessage(Format(sSaveDocumentError, [Document]));
Stream.Free;
exit;
end;
If doReset In Options then
begin
FDocumentName := Document;
FDocumentState := smsDocument;
Reset;
DoOnStatusChange([scAll]);
end;
result := true;
end;
procedure TCustomSynEditor.SetDocumentFormat(
const Value: TSynEditFileFormat);
begin
If DocumentFormat <> value then
begin
TSynEditStringList(Lines).FileFormat := value;
DoOnStatusChange([scAll]);
end;
end;
procedure TCustomSynEditor.SetDocumentName(const Value: string);
begin
If FDocumentName <> value then
begin
FDocumentName := Value;
DoOnStatusChange([scAll]);
end;
end;
procedure TCustomSynEditor.WMSetFocus(var Msg: TWMSetFocus);
begin
inherited;
FocusSynEditor := self;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -