📄 optionsdialog.pas
字号:
Function TMySynEdit.iCanUndo: Boolean;
Begin
If Not HexView Then
Result := CanUndo
Else Result := HexEdit.CanUndo;
End;
Function TMySynEdit.SelAvail: Boolean;
Begin
If Not HexView Then
Result := Inherited SelAvail
Else Result := HexEdit.SelCount > 0;
End;
Function TMySynEdit.iCanPaste: Boolean;
Begin
If Not HexView Then
Result := CanPaste
Else Result := (ClipBoard.HasFormat(CF_TEXT)) And (Not HexEdit.ReadOnlyView);
End;
Procedure TMySynEdit.CopyToClipboard;
Var
pct: Integer;
pPC: PChar;
Begin
If Not HexView Then
Inherited CopyToClipboard
Else With HexEdit Do Begin
pCT := SelCount;
pPC := BufferFromFile(Min(SelStart, SelEnd), pCT);
SetCBText(pPC, pCT);
FreeMem(pPC, pCT);
End;
End;
Procedure TMySynEdit.CutToClipboard;
Begin
If Not HexView Then
Inherited CutToClipboard
Else With HexEdit Do Begin
CopyToClipboard;
DeleteSelection;
End;
End;
Procedure TMySynEdit.PasteFromClipboard;
Var
s: String;
BT: Integer;
Begin
If Not HexView Then
Inherited PasteFromClipboard
Else Begin
s := ClipBoard.AsText;
HexEdit.ReplaceSelection(ConvertHexToBin(@s[1], @s[1], Length(s), False, bt), bt);
End;
End;
Procedure TMySynEdit.SetFocus;
Begin
If FHexView Then
HexEdit.SetFocus
Else
Inherited SetFocus;
End;
Procedure TMySynEdit.SetHexView(Const Value: Boolean);
Begin
FHexView := Value;
If FHexView Then Begin
If Modified Or (HexEdit.DataSize <= 0) Then
SaveToHexEdit;
End
Else Begin
If HexEdit.Modified Or (Lines.Text = #$0D#$0A) Then Begin
LoadFromHexEdit;
End;
End; //if-else
HexEdit.Visible := FHexView;
Visible := Not FHexView;
If NeedSetFocus Then
SetFocus;
End;
Function TMySynEdit.GetCollaspePrmpt(LineNo: Integer; Var CollapseID: Integer): Boolean;
Var
s, t: String;
i: Integer;
Begin
I := Length(sCollaspePrmpt);
S := Copy(Lines[LineNo - 1], 1, I);
Result := S = sCollaspePrmpt;
If Result Then Begin
S := Copy(Lines[LineNo - 1], I + 1, Length(Lines[LineNo - 1]));
t := '';
I := 1;
While (s[I] <> ':') And (I <= Length(s)) Do Begin
t := t + s[I];
Inc(I);
End;
CollapseID := StrToInt(t);
End;
End;
Procedure TMySynEdit.CreateCollaspeMark(LineNo, CollapseID, idMark: Integer);
Var
Mark: TSynEditMark;
Begin
Mark := TSynEditMark.Create(Self);
With Mark Do Begin
Line := LineNo;
Column := CollapseID;
ImageIndex := idMark;
//IsBookmark := False; // this is read only
Visible := True;
InternalImage := (BookMarkOptions.BookMarkImages = Nil);
End;
Marks.Place(Mark);
End;
Procedure TMySynEdit.NextCollaspe;
Var
s: String;
LineNo, I: Integer;
Begin
//if CollaspeList.Count <= 0 then exit;
I := Length(sCollaspePrmpt);
LineNo := CaretY + 1;
While LineNo <= Lines.Count Do Begin
S := Copy(Lines[LineNo - 1], 1, I);
If (S = sCollaspePrmpt) Or (S = sExpandPrmpt) Then Begin
CaretY := LineNo;
Exit;
End;
Inc(LineNo);
End; //while
End;
Procedure TMySynEdit.PrevCollaspe;
Var
s: String;
LineNo, I: Integer;
Begin
//if CollaspeList.Count <= 0 then exit;
I := Length(sCollaspePrmpt);
LineNo := CaretY - 1;
While LineNo >= 1 Do Begin
S := Copy(Lines[LineNo - 1], 1, I);
If (S = sCollaspePrmpt) Or (S = sExpandPrmpt) Then Begin
CaretY := LineNo;
Exit;
End;
Dec(LineNo);
End; //while
End;
Function TMySynEdit.DeleteCollapse(AID: Integer): Boolean;
Var
strs: TmyStrings;
Begin
strs := FindCollaspeList(AID);
Result := strs <> Nil;
If Result Then Begin
CollaspeList.Remove(Strs);
Strs.Free;
End;
End;
Function TMySynEdit.FindCollaspeList(Const AID: Integer): TmyStrings;
Var
I: Integer;
Begin
Result := Nil;
For I := 0 To CollaspeList.Count - 1 Do Begin
If TmyStrings(CollaspeList[I]).ID = AID Then Begin
Result := TmyStrings(CollaspeList[I]);
Break;
End;
End;
End;
Procedure TMySynEdit.ExpandAll;
Var
I: Integer;
Begin
If CollaspeList.Count <= 0 Then Exit;
For I := 1 To Lines.Count Do Begin
ExpandText(I);
End; //for
If CollaspeList.Count > 0 Then //error
ClearCollaspeList;
MaxID := 0;
End;
Procedure TMySynEdit.CollaspeAll;
Var
I: Integer;
Begin
I := 1;
While I <= Lines.Count Do Begin
CollaspeText(I, 0, '');
Inc(I);
End; //for
End;
Procedure TMySynEdit.ExpandText(Const LineNo: Integer);
Var
s: String;
ID: Integer;
strs: TmyStrings;
//cap, prmpt: PChar;
Begin
Marks.ClearLine(LineNo);
//I := Length(sCollaspePrmpt);
//S := Copy(Lines[LineNo-1], 1, I);
If GetCollaspePrmpt(LineNo, ID) {S = sCollaspePrmpt} Then Begin
//S := Copy(Lines[LineNo-1], I+1, Length(Lines[LineNo-1]));
//t := '';
//I := 1;
{While (s[I] <> ':') and (I <= Length(s)) do
begin
t := t+ s[I];
inc(I);
end;}
//Delete(s, 1, Length(t)+1); //del 'xx:'
//ShowMessage(t+':'+s);
S := Copy(Lines[LineNo - 1], Length(sCollaspePrmpt) + Length(IntToStr(ID)) + 2,
Length(Lines[LineNo - 1])); //Copy Linecount:desc
//ID := StrToInt(t);
Strs := FindCollaspeList(ID);
BlockBegin := Point(1, LineNo);
BlockEnd := Point(Length(Lines[LineNo - 1]) + 1, LineNo);
If Assigned(Strs) Then Begin
s := sExpandPrmpt + S;
//Lines.Delete(LineNo-1);
//Lines.Insert(LineNo-1, Strs.Text);
s := s + #13#10 + Strs.Text;
Delete(S, Length(S) - 1, 2);
SelText := s;
CollaspeList.Remove(Strs);
Strs.Free;
CreateCollaspeMark(LineNo, 1, idExpandPic);
End Else Begin
//cap := PChar(dlgOption.Tran.TMsg(sExpandErrPrompt));
//prmpt := PChar(dlgOption.Tran.TMsg(sExpandErrCaption));
If Application.MessageBox(PChar(dlgOption.Tran.TMsg(sExpandErrPrompt))
, PChar(dlgOption.Tran.TMsg(sExpandErrCaption)), MB_YESNO) = IdYes Then
SelText := '';
//Lines.Delete(LineNo-1);
End;
End;
If CollaspeList.Count <= 0 Then MaxID := 0;
End;
Procedure TMySynEdit.CollaspeText(LineNo: Integer; Count: Integer; Desc: String);
Var
s, t: String;
I, iCount: Integer;
strs: TmyStrings;
//P: TPoint;
Begin
I := Length(sExpandPrmpt);
S := Copy(Lines[LineNo - 1], 1, I);
If S = sExpandPrmpt Then Begin
S := Copy(Lines[LineNo - 1], I + 1, Length(Lines[LineNo - 1]));
CaretY := LineNo;
CommandProcessor(ecDeleteLine, #0, Nil);
//Lines.Delete(LineNo-1);
t := '';
I := 1;
If s[I] = ':' Then Inc(I);
While (s[I] <> ':') And (I <= Length(s)) Do Begin
t := t + s[I];
Inc(I);
End;
iCount := StrToInt(t);
If Desc = '' Then Desc := Copy(S, I + 1, Length(S));
//if (Count = 1) or (Count = 0) then
Count := iCount;
//else dec(Count);
//Inc(LineNo);
//ShowMessage(IntToStr(Count));
End
Else If Count = 0 Then Exit;
If (Length(Lines[LineNo - 1]) = 0) And (Count = 1) Then Exit;
BlockBegin := Point(1, LineNo);
BlockEnd := Point(Length(Lines[LineNo + Count - 2]) + 1, LineNo + Count - 1);
Strs := TmyStrings.Create;
//for I := LineNo - 1 to LineNo + Count - 2 do
Strs.Text := SelText;
//if Strs[Strs.Count-1]='' then Strs.Delete(Strs.Count-1);
Strs.ID := MaxID;
Inc(MaxID);
CollaspeList.Add(Strs);
//for I := LineNo - 1 to LineNo + Count - 2 do
//Lines.Delete(I);
//SelText := '';
SelText := sCollaspePrmpt + IntToStr(Strs.ID) + ':' + IntToStr(Count) + ':' + Desc;
Marks.ClearLine(CaretY);
CreateCollaspeMark(CaretY, Strs.ID, idCollaspePic);
//Inc(LineNo, Count - 1);
//LineNo := LineNo + Count-1;
End;
Procedure TMySynEdit.SaveCollaspeList;
Var
myIniFile: String;
//INI: TFileStream;
Ini: TIniFile;
I, J: Integer;
//s: string;
Begin
myIniFile := ChangeFileExt(FileName, myINIExt);
If FileExists(myIniFile) Then DeleteFile(myIniFile);
If CollaspeList.Count <= 0 Then Exit;
//INI := TFileStream.Create(myIniFile, fmCreate);
Ini := TIniFile.Create(myIniFile);
Try
//s := '['+secCollaspe+']'+#13#10;
//INI.Write(s[1], Length(s));
//s := 'Total=' + IntToStr(CollaspeList.Count)+#13#10;
//INI.Write(s[1], Length(s));
Ini.WriteInteger(secCollaspe, 'Total', CollaspeList.Count);
//for I := 0 to CollaspeList.Count - 1 do with TmyStrings(CollaspeList[I]) do
//begin
//s := 'ID'+ IntToStr(I) + '=' + IntToStr(ID)+#13#10;
//INI.Write(s[1], Length(s));
//INI.WriteInteger(secCollaspe, 'ID'+ IntToStr(I), ID);
//end;
For I := 0 To CollaspeList.Count - 1 Do With TmyStrings(CollaspeList[I]) Do Begin
//s := '['+secCollaspe+IntToStr(I)+']'+#13#10;
//INI.Write(s[1], Length(s));
//s := Text;
//INI.Write(s[1], Length(s));
Ini.WriteInteger(secCollaspe + IntToStr(I), 'ID', ID);
Ini.WriteInteger(secCollaspe + IntToStr(I), 'Count', Count);
For J := 0 To Count - 1 Do
Ini.WriteString(secCollaspe + IntToStr(I), 'L' + IntToStr(J), '''' + Strings[J] + '''');
//if no "'" then the INIFile Class will trim spaces!!
End; //for
Finally
Ini.Free;
End;
End;
Procedure TMySynEdit.LoadCollaspeList;
Var
myIniFile: String;
Ini: TIniFile;
I, J, Total, Count: Integer;
s: TmyStrings;
Begin
myIniFile := ChangeFileExt(FileName, myINIExt);
ClearCollaspeList;
If FileExists(myIniFile) Then Begin
Ini := TIniFile.Create(myIniFile);
Try
Total := Ini.ReadInteger(secCollaspe, 'Total', 0);
For I := 0 To Total - 1 Do Begin
s := TmyStrings.Create;
S.ID := Ini.ReadInteger(secCollaspe + IntToStr(I), 'ID', 0);
If MaxID < S.ID Then MaxID := S.ID + 1;
Count := Ini.ReadInteger(secCollaspe + IntToStr(I), 'Count', 0);
For J := 0 To Count - 1 Do
//INI.ReadSectionValues(secCollaspe + IntToStr(I), S);
S.Add(Ini.ReadString(secCollaspe + IntToStr(I), 'L' + IntToStr(J), ''));
CollaspeList.Add(S);
End; //for
Finally
Ini.Free;
End;
I := 1;
While I <= Lines.Count Do Begin
If GetCollaspePrmpt(I, J) Then Begin
CreateCollaspeMark(I, J, idCollaspePic);
End;
Inc(I);
End; //while
End;
End;
Procedure TMySynEdit.ClearCollaspeList;
Begin
While CollaspeList.Count > 0 Do Begin
TmyStrings(CollaspeList[CollaspeList.Count - 1]).Free;
CollaspeList.Delete(CollaspeList.Count - 1);
End;
End;
Procedure TMySynEdit.SaveToHexEdit;
Begin
HexEdit.AsText := Lines.Text;
End;
Procedure TMySynEdit.LoadFromHexEdit;
Begin
Lines.Text := HexEdit.AsText;
Lines.Delete(0);
End;
procedure TMySynEdit.PaintGutter(AClip: TRect; FirstLine,
LastLine: integer);
var
LH, X, Y: integer;
ImgIndex: integer;
begin
inherited;
if FShowCurrentLine then with EditorDataModule do
begin
X := 14;
LH := LineHeight;
Y := (LH - ilGutterGlyphs.Height) div 2
+ LH * (FirstLine - TopLine);
while FirstLine <= LastLine do begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -