📄 mainedit.pas
字号:
End;
Procedure TfrmJediEdit.FileOpenExecute(Sender: TObject);
Var
I: Integer;
Begin
If (CurrentEditor <> Nil) And (CurrentEditor.FileName <> '') Then OpenFileDialog.InitialDir := ExtractFilePath(CurrentEditor.FileName);
If OpenFileDialog.Execute Then Begin
For I := 0 To OpenFileDialog.Files.Count - 1 Do OpenFile(OpenFileDialog.Files[I]);
End;
End;
Procedure TfrmJediEdit.StatusChangeEvent(Sender: TObject; Changes: TSynStatusChanges);
Begin
With Sender As TMySynEdit Do Begin
If CaretY <> OldCaretY Then Begin
If Assigned((Sender As TMySynEdit).OnSpecialLineColors) Then Begin
InvalidateLine(OldCaretY);
OldCaretY := CaretY;
InvalidateLine(OldCaretY);
End;
End;
With StatusBar Do Begin
//Panels[stLinePanel]: 'Line:Column'
Panels[stLinePanel].Text := Format('%0:6d:%1:3d', [CaretY, CaretX]);
//Panels[stTotalLinePanel]: 'Total Lines'
Panels[stTotalLinePanel].Text := Format('%6d', [Lines.Count]);
//Panels[stInsertPanel]: 'Insert/Overwrite'
If InsertMode Then Panels[stInsertPanel].Text := tran.TMsg(sInsertMode)
Else Panels[stInsertPanel].Text := tran.TMsg(sOverwriteMode);
End;
End;
End;
Procedure TfrmJediEdit.FileSaveExecute(Sender: TObject);
Begin
SaveFile(CurrentEditor);
End;
Function TfrmJediEdit.CurrentEditor: TMySynEdit;
Begin
Result := Nil;
If PageControl.PageCount > 0 Then Result := Editor[PageControl.ActivePage.PageIndex];
End;
Procedure TfrmJediEdit.FileSaveAsExecute(Sender: TObject);
Begin
SaveAsFile(CurrentEditor);
End;
Procedure TfrmJediEdit.EditCopyExecute(Sender: TObject);
Begin
CurrentEditor.CopyToClipboard;
End;
Procedure TfrmJediEdit.EditCutExecute(Sender: TObject);
Begin
CurrentEditor.CutToClipboard;
End;
Procedure TfrmJediEdit.EditPasteExecute(Sender: TObject);
Begin
CurrentEditor.PasteFromClipboard;
End;
Function TfrmJediEdit.GetEditor(Index: Integer): TMySynEdit;
Var
I: Integer;
Begin
Result := Nil;
For I := 0 To PageControl.Pages[Index].ControlCount - 1 Do Begin
If PageControl.Pages[Index].Controls[I] Is TMySynEdit Then Begin
Result := PageControl.Pages[Index].Controls[I] As TMySynEdit;
Break;
End;
End;
End;
Function TfrmJediEdit.GetEditorCount: Integer;
Begin
Result := PageControl.PageCount;
End;
Procedure TfrmJediEdit.FileCloseExecute(Sender: TObject);
Begin
If CloseFile(CurrentEditor) = MrCancel Then Exit;
PageControl.ActivePage.Free;
If PageControl.PageCount = 0 Then Begin
Caption := Application.Title;
cbxHighlighter.Enabled := False;
tbHighlighter.Enabled := False;
End Else PageControlChange(Self);
End;
Procedure TfrmJediEdit.FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
Begin
CanClose := PromptSave;
If CanClose Then EditorDataModule.StoreSettings(ExtractFilePath(Application.ExeName) + GetDefaultIniName);
{$IFDEF debug}
SendDebug('FormClose Query Over');
{$ENDIF}
End;
Procedure TfrmJediEdit.PageControlChange(Sender: TObject);
Var
Idx: Integer;
// s: String;
Edit: TMySynEdit;
Begin
Edit := CurrentEditor;
If Assigned(Edit) Then Begin
If Edit.FileName <> '' Then Caption := Application.Title + ' : [' + Edit.FileName + ']'
Else Caption := Application.Title + ' : [' + PageControl.ActivePage.Caption + ']';
Idx := 0;
If Assigned(Edit.Highlighter) Then Begin
Idx := cbxHighlighter.Items.IndexOf(Edit.Highlighter.LanguageName);
If (Idx < 0) Then Idx := 0;
If Edit.HighLighter = EditorDataModule.PythonSyn1 Then EditorDataModule.PythonBehaviour1.Editor := Edit
Else EditorDataModule.PythonBehaviour1.Editor := Nil;
End;
cbxHighlighter.ItemIndex := Idx;
StatusChangeEvent(Edit, []);
End;
End;
Procedure TfrmJediEdit.cbxHighlighterChange(Sender: TObject);
Var
s: String;
Begin
If CurrentEditor <> Nil Then Begin
With cbxHighlighter Do Begin
CurrentEditor.Highlighter := Items.Objects[ItemIndex] As TSynCustomHighlighter;
If CurrentEditor.Highlighter = EditorDataModule.PythonSyn1 Then EditorDataModule.PythonBehaviour1.Editor := CurrentEditor
Else EditorDataModule.PythonBehaviour1.Editor := Nil;
s := GetTemplateFileName(Items[ItemIndex]);
If FileExists(s) Then EditorDataModule.AutoComplete1.AutoCompleteList.LoadFromFile(s);
End;
CurrentEditor.SetFocus;
End;
End;
Procedure TfrmJediEdit.DropFilesEvent(Sender: TObject; X, Y: Integer; Files: TStrings);
Var
I: Integer;
Begin
For I := 0 To Files.Count - 1 Do OpenFile(Files[I]);
End;
Procedure TfrmJediEdit.EditSelectAllExecute(Sender: TObject);
Begin
CurrentEditor.SelectAll;
End;
Procedure TfrmJediEdit.EditUndoExecute(Sender: TObject);
Begin
CurrentEditor.Undo;
End;
Procedure TfrmJediEdit.EditRedoExecute(Sender: TObject);
Begin
CurrentEditor.Redo;
End;
Procedure TfrmJediEdit.EditFindExecute(Sender: TObject);
Const
cHexChars = '0123456789abcdef';
Var
OldBlockBegin: TPoint;
OldBlockEnd: TPoint;
PStr, pTMP: String;
pCT, pCT1: Integer;
Begin
With CurrentEditor Do Begin
If HexView Then Begin
If HexEdit.DataSize < 1 Then Exit;
FindPos := -1;
FindICase := False;
If FindBuf <> Nil Then Begin
FreeMem(FindBuf);
FindBuf := Nil;
End;
If Not InputQuery(tran.TMsg(sFindHexCaption), tran.TMsg(sFindHexPrompt), FindHexStr) Then Exit;
// make a search string
If FindHexStr = '' Then Exit;
PStr := '';
If UpCase(FindHexStr[1]) = 'T' Then Begin
PStr := Copy(FindHexStr, 2, Maxint);
pCT1 := Length(PStr);
End Else Begin
pTMP := AnsiLowerCase(FindHexStr); // calculate Data from input
For pCT := Length(pTMP) Downto 1 Do Begin
If Pos(pTMP[pCT], cHexChars) = 0 Then Delete(pTMP, pCT, 1);
End;
While (Length(pTMP) Mod 2) <> 0 Do pTMP := '0' + pTMP;
If pTMP = '' Then Exit;
PStr := '';
pCT1 := Length(pTMP) Div 2;
For pCT := 0 To (Length(pTMP) Div 2) - 1 Do PStr := PStr + Char((Pos(pTMP[pCt * 2 + 1], cHexChars) - 1) * 16 + (Pos(pTMP[pCt * 2 + 2], cHexChars) - 1));
End;
If pCT1 = 0 Then Exit;
GetMem(FindBuf, pCT1);
Try
If FindHexStr[1] = 'T' Then FindICase := True;
FindLen := pCT1;
Move(PStr[1], FindBuf^, pCt1);
FindPos := HexEdit.Find(FindBuf, FindLen, HexEdit.GetCursorPos, HexEdit.DataSize - 1, FindICase, UpCase(FindHexStr[1]) = 'T');
If FindPos = -1 Then ShowMessage(tran.TMsg(sNotFound))
Else Begin
HexEdit.SelStart := FindPos + FindLen - 1;
HexEdit.SelEnd := FindPos;
End;
Finally
End;
End Else Begin
SelectionMode := smNormal;
DlgFind := TDlgFind.Create(Nil);
Try
If Length(SelText) > 1 Then DlgFind.cbFindText.Text := SelText
Else Begin
OldBlockBegin := BlockBegin;
OldBlockEnd := BlockEnd;
SetSelWord;
DlgFind.cbFindText.Text := SelText;
BlockBegin := OldBlockBegin;
BlockEnd := OldBlockEnd;
End;
If dlgFind.ShowModal = MrOk Then Begin
FindHexStr := dlgFind.cbFindText.Text;
SearchOptions := [];
If dlgFind.cbMatchCase.Checked Then Include(SearchOptions, ssoMatchCase);
If dlgFind.cbWholeWord.Checked Then Include(SearchOptions, ssoWholeWord);
If dlgFind.rbBackward.Checked Then Include(SearchOptions, ssoBackwards);
If dlgFind.rbSelectedOnly.Checked Then Include(SearchOptions, ssoSelectedOnly);
If dlgFind.rbEntireScope.Checked Then Include(SearchOptions, ssoEntireScope);
If SearchReplace(dlgFind.cbFindText.Text, '', SearchOptions) = 0 Then ShowMessage(tran.TMsg(sNotFound));
End;
Finally
DlgFind.Free;
End;
End;
End;
End;
Procedure TfrmJediEdit.ReplaceTextEvent(Sender: TObject; Const ASearch,
AReplace: String; Line, Column: Integer; Var Action: TSynReplaceAction);
Begin
Case dlgReplacePrompt.ShowModal Of
MrOk: Action := raReplace;
MrCancel: Action := raCancel;
MrYesToAll: Action := raReplaceAll;
MrIgnore: Action := raSkip;
End;
End;
Procedure TfrmJediEdit.EditReplaceExecute(Sender: TObject);
Var
OldBlockBegin: TPoint;
OldBlockEnd: TPoint;
Result: Integer;
Begin
dlgReplace := TdlgReplace.Create(Nil);
With CurrentEditor Do Try
If Length(SelText) > 1 Then dlgReplace.cbFindText.Text := SelText
Else Begin
OldBlockBegin := BlockBegin;
OldBlockEnd := BlockEnd;
SetSelWord;
dlgReplace.cbFindText.Text := SelText;
BlockBegin := OldBlockBegin;
BlockEnd := OldBlockEnd;
End;
//dlgReplace.cbFindText.Text := SelText;
Result := dlgReplace.ShowModal;
With dlgReplace Do If (Result = MrOk) Or (Result = MrYesToAll) Then Begin
SearchOptions := [ssoReplace];
If cbMatchCase.Checked Then Include(SearchOptions, ssoMatchCase);
If cbWholeWord.Checked Then Include(SearchOptions, ssoWholeWord);
If rbBackward.Checked Then Include(SearchOptions, ssoBackwards);
If rbSelectedOnly.Checked Then Include(SearchOptions, ssoSelectedOnly);
If rbEntireScope.Checked Then Include(SearchOptions, ssoEntireScope);
If cbPrompt.Checked Then Include(SearchOptions, ssoPrompt);
If Result = MrYesToAll Then Include(SearchOptions, ssoReplaceAll);
If SearchReplace(cbFindText.Text, cbReplaceText.Text, SearchOptions) = 0 Then ShowMessage(tran.TMsg(sNotFound));
End;
Finally
dlgReplace.Free;
End;
End;
Procedure TfrmJediEdit.EditFindNextExecute(Sender: TObject);
Begin
With CurrentEditor Do Begin
If HexView Then Begin
If HexEdit.DataSize < 1 Then Exit;
If FindPos = HexEdit.SelEnd Then Inc(FindPos, 1);
FindPos := HexEdit.Find(FindBuf, FindLen, FindPos, HexEdit.DataSize - 1, FindICase, False);
If FindPos = -1 Then ShowMessage(tran.TMsg(sNotFound))
Else Begin
HexEdit.SelStart := FindPos + FindLen - 1;
HexEdit.SelEnd := FindPos;
End;
End Else Begin
SelectionMode := smNormal;
Exclude(SearchOptions, ssoEntireScope);
Exclude(SearchOptions, ssoReplace);
If (SelText <> '') And (Length(SelText) > 1) Then Begin
If (BlockBegin.Y > BlockEnd.Y)
Or ((BlockBegin.Y = BlockEnd.Y) And (BlockBegin.X > BlockEnd.X)) Then Begin
CaretXY := BlockBegin;
End;
FindHexStr := SelText;
End;
If SearchReplace(FindHexStr, '', SearchOptions) = 0 Then ShowMessage(tran.TMsg(sNotFound));
End;
End;
End;
{The basic code contained in the next two procedures,
which works with the DPR code to allow file association
and open doubleclicked file in the running instance of app
was written by Andrius Adamonis}
Procedure TfrmJediEdit.DefaultHandler(Var Message);
Var
S: String;
Begin
With TMessage(Message) Do Begin
If Integer(Msg) = WM_FINDINSTANCE Then Result := MyUniqueConst
Else If Msg = WM_OPENEDITOR Then Begin
SetLength(S, MAX_PATH);
GlobalGetAtomName(WPARAM, PChar(S), MAX_PATH);
SetLength(S, StrLen(PChar(S)));
ShowApplication;
Try
OpenFile(S);
PageControlChange(Nil);
Except
On E: Exception Do Raise Exception.Create('Error opening ' + S + ' - ' + E.Message);
End;
End Else Inherited DefaultHandler(Message);
End;
End;
Function TfrmJediEdit.PromptSave: Boolean;
Var
I: Integer;
Begin
Result := True;
For I := 0 To EditorCount - 1 Do Begin
If CloseFile(Editor[I]) = MrCancel Then Begin
Result := False;
Break;
End;
End;
End;
Procedure TfrmJediEdit.ShowApplication;
Begin
If IsIconic(Application.Handle) Then Application.Restore
Else Begin
Application.Minimize;
Application.Restore;
// ShowWindow(Handle, SW_SHOW);
// Application.BringToFront;
End;
End;
// Check up to the first 8k to see if there are any nonprintable chars
Function IsFileHex(Const AFileName: String): Boolean;
Var
FileStream: TFileStream;
Buffer: Array[0..8191] Of Byte;
CharCount, i: Integer;
Begin
Result := False;
FileStream := Nil;
Try
FileStream := TFileStream.Create(AFileName, FmOpenRead Or FmShareDenyNone);
CharCount := FileStream.Read(Buffer, SizeOf(Buffer));
For i := Low(Buffer) To CharCount - 1 Do If Buffer[i] < 6 Then Begin
// if there are nonprintable chars, then stop
Result := True;
Break;
End;
Finally
FileStream.Free;
End;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -