diff --git a/cudalister.lpi b/cudalister.lpi index ee51078..aa0bac5 100644 --- a/cudalister.lpi +++ b/cudalister.lpi @@ -90,7 +90,7 @@ - + @@ -125,6 +125,13 @@ + + + + + + + diff --git a/cudalister.lpr b/cudalister.lpr index a7c6518..066bd75 100644 --- a/cudalister.lpr +++ b/cudalister.lpr @@ -170,32 +170,32 @@ function ListSendCommand(ListWin: HWND; end; -function ListSearchTextW(ListWin: HWND; - SearchString: PWideChar; - SearchParameter: integer): integer; stdcall; -var - Form: TfmMain; -begin - Result:= LISTPLUGIN_OK; - Form:= TfmMain(FindControl(ListWin)); - if Assigned(Form) then - Form.DoFind( - (SearchParameter and lcs_findfirst)=0, - (SearchParameter and lcs_backwards)<>0, - (SearchParameter and lcs_matchcase)<>0, - (SearchParameter and lcs_wholewords)<>0, - WideString(SearchString) - ); -end; - -function ListSearchText(ListWin: HWND; - SearchString: PChar; - SearchParameter: integer): integer; stdcall; -begin - Result:= ListSearchTextW(ListWin, - PWideChar(WideString(string(SearchString))), - SearchParameter); -end; +//function ListSearchTextW(ListWin: HWND; +// SearchString: PWideChar; +// SearchParameter: integer): integer; stdcall; +//var +// Form: TfmMain; +//begin +// Result:= LISTPLUGIN_OK; +// Form:= TfmMain(FindControl(ListWin)); +// if Assigned(Form) then +// Form.DoFind( +// (SearchParameter and lcs_findfirst)=0, +// (SearchParameter and lcs_backwards)<>0, +// (SearchParameter and lcs_matchcase)<>0, +// (SearchParameter and lcs_wholewords)<>0, +// WideString(SearchString) +// ); +//end; +// +//function ListSearchText(ListWin: HWND; +// SearchString: PChar; +// SearchParameter: integer): integer; stdcall; +//begin +// Result:= ListSearchTextW(ListWin, +// PWideChar(WideString(string(SearchString))), +// SearchParameter); +//end; exports @@ -206,9 +206,9 @@ function ListSearchText(ListWin: HWND; ListLoadNext, ListLoadNextW, ListCloseWindow, - ListSendCommand, - ListSearchText, - ListSearchTextW; + ListSendCommand; + //ListSearchText, + //ListSearchTextW; begin Application.ShowHint:= false; diff --git a/form_find.lfm b/form_find.lfm new file mode 100644 index 0000000..c750927 --- /dev/null +++ b/form_find.lfm @@ -0,0 +1,157 @@ +object fmFind: TfmFind + Left = 446 + Height = 350 + Top = 397 + Width = 734 + BorderStyle = bsDialog + Caption = 'Find/Replace' + ClientHeight = 350 + ClientWidth = 734 + OnShow = FormShow + Position = poScreenCenter + LCLVersion = '2.2.4.0' + object bFind: TButton + Left = 564 + Height = 38 + Top = 72 + Width = 148 + Caption = 'Find' + ModalResult = 1 + TabOrder = 10 + end + object bCancel: TButton + Left = 564 + Height = 38 + Top = 216 + Width = 148 + Cancel = True + Caption = 'Cancel' + ModalResult = 2 + TabOrder = 15 + end + object Label1: TLabel + Left = 14 + Height = 24 + Top = 12 + Width = 76 + Caption = 'Find what:' + ParentColor = False + end + object edFind: TEdit + Left = 14 + Height = 32 + Top = 48 + Width = 538 + TabOrder = 0 + end + object chkRegex: TCheckBox + Left = 14 + Height = 28 + Top = 192 + Width = 118 + Caption = 'Regex' + OnChange = chkRegexChange + TabOrder = 3 + end + object chkBack: TCheckBox + Left = 14 + Height = 28 + Top = 300 + Width = 100 + Caption = 'Backward' + TabOrder = 6 + end + object chkCase: TCheckBox + Left = 14 + Height = 28 + Top = 228 + Width = 118 + Caption = 'Case sensitive' + TabOrder = 4 + end + object chkWords: TCheckBox + Left = 14 + Height = 28 + Top = 264 + Width = 118 + Caption = 'Whole words only' + TabOrder = 5 + end + object edRep: TEdit + Left = 14 + Height = 32 + Top = 132 + Width = 538 + TabOrder = 2 + end + object chkRep: TCheckBox + Left = 14 + Height = 28 + Top = 96 + Width = 104 + Caption = 'Replace with:' + OnChange = chkRepChange + TabOrder = 1 + end + object bRep: TButton + Left = 564 + Height = 38 + Top = 24 + Width = 148 + Caption = 'Replace' + Default = True + ModalResult = 6 + TabOrder = 11 + end + object bRepAll: TButton + Left = 564 + Height = 38 + Top = 72 + Width = 148 + Caption = 'Replace all' + ModalResult = 10 + TabOrder = 12 + end + object chkFromCaret: TCheckBox + Left = 324 + Height = 28 + Top = 192 + Width = 118 + Caption = 'From caret' + TabOrder = 7 + end + object bCount: TButton + Left = 564 + Height = 38 + Top = 120 + Width = 148 + Caption = 'Count all' + ModalResult = 5 + TabOrder = 13 + end + object chkConfirm: TCheckBox + Left = 324 + Height = 28 + Top = 228 + Width = 100 + Caption = 'Confirm replace' + TabOrder = 8 + end + object bMarkAll: TButton + Left = 564 + Height = 38 + Top = 168 + Width = 148 + Caption = 'Mark all' + ModalResult = 4 + TabOrder = 14 + end + object chkInSel: TCheckBox + Left = 324 + Height = 28 + Top = 264 + Width = 118 + Caption = 'In selection' + TabOrder = 9 + end +end diff --git a/form_find.pas b/form_find.pas new file mode 100644 index 0000000..09bfefd --- /dev/null +++ b/form_find.pas @@ -0,0 +1,93 @@ +unit form_find; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ButtonPanel, + StdCtrls; + +type + + { TfmFind } + + TfmFind = class(TForm) + bCount: TButton; + bMarkAll: TButton; + bFind: TButton; + bCancel: TButton; + bRep: TButton; + bRepAll: TButton; + chkInSel: TCheckBox; + chkFromCaret: TCheckBox; + chkConfirm: TCheckBox; + chkRep: TCheckBox; + chkRegex: TCheckBox; + chkBack: TCheckBox; + chkCase: TCheckBox; + chkWords: TCheckBox; + edFind: TEdit; + edRep: TEdit; + Label1: TLabel; + procedure chkRegexChange(Sender: TObject); + procedure chkRepChange(Sender: TObject); + procedure FormShow(Sender: TObject); + private + procedure Update; reintroduce; + { private declarations } + public + { public declarations } + end; + +var + fmFind: TfmFind; + +implementation + +{$R *.lfm} + +{ TfmFind } + +procedure TfmFind.chkRegexChange(Sender: TObject); +begin + Update; +end; + +procedure TfmFind.chkRepChange(Sender: TObject); +begin + Update; +end; + +procedure TfmFind.FormShow(Sender: TObject); +begin + Update; +end; + +procedure TfmFind.Update; +var + rep: boolean; +begin + rep:= chkRep.Checked; + + chkWords.Enabled:= not chkRegex.Checked; + chkBack.Enabled:= not chkRegex.Checked; + chkConfirm.Enabled:= rep; + edRep.Enabled:= rep; + bFind.Visible:= not rep; + bRep.Visible:= rep; + bRepAll.Visible:= rep; + + if rep then + Caption:= 'Replace' + else + Caption:= 'Find'; + + if rep then + bRep.Default:= true + else + bFind.Default:= true; +end; + +end. + diff --git a/form_main.lfm b/form_main.lfm index 620b429..aa5ed55 100644 --- a/form_main.lfm +++ b/form_main.lfm @@ -1,37 +1,38 @@ object fmMain: TfmMain Left = 47 - Height = 374 + Height = 561 Top = 272 - Width = 652 + Width = 978 BorderStyle = bsNone Caption = 'fmMain' - ClientHeight = 374 - ClientWidth = 652 + ClientHeight = 561 + ClientWidth = 978 + DesignTimePPI = 144 KeyPreview = True OnClose = FormClose OnCreate = FormCreate OnDestroy = FormDestroy PopupMenu = PopupText - LCLVersion = '2.3.0.0' + LCLVersion = '2.2.4.0' object PanelAll: TPanel Left = 0 - Height = 374 + Height = 561 Top = 0 - Width = 652 + Width = 978 Align = alClient BevelOuter = bvNone - ClientHeight = 374 - ClientWidth = 652 + ClientHeight = 561 + ClientWidth = 978 TabOrder = 0 object ed: TATSynEdit Left = 0 - Height = 374 + Height = 561 Top = 0 - Width = 652 + Width = 978 Align = alClient DoubleBuffered = True - Font.Height = -12 - Font.Name = 'Courier New' + Font.Height = -18 + Font.Name = 'MS Shell Dlg' ParentFont = False TabOrder = 0 TabStop = True @@ -53,72 +54,118 @@ object fmMain: TfmMain end end object PopupLexers: TPopupMenu - Left = 172 - Top = 81 + Left = 258 + Top = 122 end object PopupText: TPopupMenu OnPopup = PopupTextPopup - Left = 235 - Top = 81 - object mnuTextSel: TMenuItem - Caption = 'Select all' - OnClick = mnuTextSelClick + Left = 353 + Top = 122 + object mnuTextUndo: TMenuItem + Caption = 'Undo' + ShortCut = 16474 + OnClick = mnuTextUndoClick + end + object mnuTextRedo: TMenuItem + Caption = 'Redo' + ShortCut = 24666 + OnClick = mnuTextRedoClick + end + object MenuItem6: TMenuItem + Caption = '-' + end + object mnuTextCut: TMenuItem + Caption = 'Cu&t' + ShortCut = 16472 + OnClick = mnuTextCutClick end object mnuTextCopy: TMenuItem - Caption = 'Copy' + Caption = '&Copy' + ShortCut = 16451 OnClick = mnuTextCopyClick end object mnuTextPaste: TMenuItem - Caption = 'Paste' + Caption = '&Paste' + ShortCut = 16470 OnClick = mnuTextPasteClick end + object mnuTextDelete: TMenuItem + Caption = '&Delete' + OnClick = mnuTextDeleteClick + end + object MenuItem5: TMenuItem + Caption = '-' + end + object mnuTextSel: TMenuItem + Caption = 'Select &all' + ShortCut = 16449 + OnClick = mnuTextSelClick + end + object MenuItem4: TMenuItem + Caption = '-' + end + object mnuTextUpperCase: TMenuItem + Caption = '&Upper Case' + ShortCut = 16469 + OnClick = mnuTextUpperCaseClick + end + object mnuTextLowerCase: TMenuItem + Caption = '&Lower Case' + ShortCut = 24661 + OnClick = mnuTextLowerCaseClick + end object MenuItem3: TMenuItem Caption = '-' end object mnuTextGoto: TMenuItem - Caption = 'Go to...' + Caption = '&Go to...' + ShortCut = 16455 OnClick = mnuTextGotoClick end object mnuTextReadonly: TMenuItem - Caption = 'Read-only (Ctrl+R)' + Caption = '&Read-only' Checked = True + ShortCut = 16466 OnClick = mnuTextReadonlyClick end object mnuTextSave: TMenuItem - Caption = 'Save' + Caption = '&Save' + ShortCut = 16467 OnClick = mnuTextSaveClick end object MenuItem2: TMenuItem Caption = '-' end object mnuOptions: TMenuItem - Caption = 'Options dialog...' + Caption = '&Options dialog...' OnClick = mnuOptionsClick end object mnuWrap: TMenuItem - Caption = 'Word wrap' + Caption = '&Word wrap' + ShortCut = 16471 OnClick = mnuWrapClick end object mnuFind: TMenuItem - Caption = 'Find...' + Caption = '&Find...' + ShortCut = 16454 OnClick = mnuFindClick end end object PopupEnc: TPopupMenu - Left = 300 - Top = 89 + Left = 450 + Top = 134 end object TimerStatusbar: TTimer Enabled = False Interval = 4000 OnTimer = TimerStatusbarTimer - Left = 379 - Top = 100 + Left = 569 + Top = 150 end object TimerEmpty: TTimer Interval = 150 OnTimer = TimerEmptyTimer - Left = 471 - Top = 112 + Left = 707 + Top = 168 end end diff --git a/form_main.pas b/form_main.pas index 1d45b57..9d07d40 100644 --- a/form_main.pas +++ b/form_main.pas @@ -16,6 +16,7 @@ interface ATSynEdit_Adapter_EControl, ATSynEdit_Commands, ATSynEdit_Finder, + ATSynEdit_Markers, ATSynEdit_Globals, ATSynEdit_CharSizer, ATSynEdit_Keymap, @@ -29,6 +30,7 @@ interface file_proc, proc_themes, form_options, + form_find, FileUtil; const @@ -41,12 +43,21 @@ TfmMain = class(TForm) ed: TATSynEdit; mnuWrap: TMenuItem; mnuFind: TMenuItem; + mnuTextCut: TMenuItem; + mnuTextUndo: TMenuItem; + mnuTextRedo: TMenuItem; mnuTextSave: TMenuItem; mnuTextPaste: TMenuItem; + mnuTextDelete: TMenuItem; mnuTextReadonly: TMenuItem; + mnuTextUpperCase: TMenuItem; + mnuTextLowerCase: TMenuItem; mnuTextGoto: TMenuItem; MenuItem2: TMenuItem; MenuItem3: TMenuItem; + MenuItem4: TMenuItem; + MenuItem5: TMenuItem; + MenuItem6: TMenuItem; mnuOptions: TMenuItem; mnuTextCopy: TMenuItem; mnuTextSel: TMenuItem; @@ -66,10 +77,16 @@ TfmMain = class(TForm) procedure FormDestroy(Sender: TObject); procedure mnuFindClick(Sender: TObject); procedure mnuOptionsClick(Sender: TObject); + procedure mnuTextCutClick(Sender: TObject); procedure mnuTextCopyClick(Sender: TObject); procedure mnuTextGotoClick(Sender: TObject); procedure mnuTextPasteClick(Sender: TObject); + procedure mnuTextDeleteClick(Sender: TObject); procedure mnuTextReadonlyClick(Sender: TObject); + procedure mnuTextUpperCaseClick(Sender: TObject); + procedure mnuTextLowerCaseClick(Sender: TObject); + procedure mnuTextUndoClick(Sender: TObject); + procedure mnuTextRedoClick(Sender: TObject); procedure mnuTextSaveClick(Sender: TObject); procedure mnuTextSelClick(Sender: TObject); procedure mnuWrapClick(Sender: TObject); @@ -86,13 +103,21 @@ TfmMain = class(TForm) FPrevKeyShift: TShiftState; FPrevKeyTick: Qword; FPrevNoCaret: boolean; + FindConfirmAll: TModalResult; + FindMarkAll: boolean; Statusbar: TATStatus; Adapter: TATAdapterEControl; - // + procedure ApplyNoCaret; procedure ApplyThemes; procedure DoFindDialog; procedure FinderFound(Sender: TObject; APos1, APos2: TPoint); + procedure FinderNext; + procedure FinderUpdateEditor(AUpdateText: boolean); + procedure DoFindError; + procedure ShowBadRegex; + procedure FinderConfirmReplace(Sender: TObject; APos1, APos2: TPoint; + AForMany: boolean; var AConfirm, AContinue: boolean; var AReplacement: UnicodeString); function GetEncodingName: string; procedure LoadOptions; procedure MenuEncNoReloadClick(Sender: TObject); @@ -108,6 +133,7 @@ TfmMain = class(TForm) public { public declarations } Finder: TATEditorFinder; + OptRep: boolean; // constructor CreateParented(AParentWindow: HWND); class function PluginShow(AListerWin: HWND; AFileName: string): HWND; @@ -117,7 +143,7 @@ TfmMain = class(TForm) procedure SetWrapMode(AValue: boolean); procedure SetEncodingName(const Str: string; EncId: TEncConvId); procedure ToggleWrapMode; - procedure DoFind(AFindNext, ABack, ACaseSens, AWords: boolean; const AStrFind: Widestring); +// procedure DoFind(AFindNext, ABack, ACaseSens, AWords: boolean; const AStrFind: Widestring); procedure ConfirmSave; end; @@ -151,7 +177,8 @@ implementation StatusbarIndex_LineEnds = 2; StatusbarIndex_Lexer = 3; StatusbarIndex_Wrap = 4; - StatusbarIndex_Message = 5; + StatusbarIndex_UndoRedo = 5; + StatusbarIndex_Message = 6; type TAppEncodingRecord = record @@ -303,6 +330,7 @@ procedure TfmMain.edKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); if (Key=VK_F2) and (Shift=[]) then begin if ed.Modified then + //if MessageBox(Handle, '文件已经被修改. 您确定要从磁盘重新加载它吗?', 'CudaLister', if MessageBox(Handle, 'File is modified. Are you sure you want to reload it from disk?', 'CudaLister', MB_OKCANCEL or MB_ICONWARNING)=ID_OK then ed.LoadFromFile(FFileName); @@ -310,6 +338,16 @@ procedure TfmMain.edKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); exit; end; + //support F3, find next + if (Key=VK_F3) and (Shift=[]) then + begin + //DoFind(true, true, Finder.OptCase, Finder.OptWords, ''); + Finder.OptBack:= false; + FinderNext; + Key:= 0; + exit + end; + //Shift+F10: context menu if (Key=VK_F10) and (Shift=[ssShift]) then begin @@ -371,15 +409,16 @@ procedure TfmMain.edKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); exit end; - //support Ctrl+F - if (Key=VK_F) and (Shift=[ssCtrl]) then + //support Ctrl+H + if (Key=VK_H) and (Shift=[ssCtrl]) then begin + OptRep:= true; DoFindDialog; Key:= 0; exit end; - //support Ctrl+V + //support Ctrl+V if (Key=VK_V) and (Shift=[ssCtrl]) then begin ed.DoCommand(cCommand_ClipboardAltPaste, cInvokeMenuContext); @@ -387,10 +426,30 @@ procedure TfmMain.edKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); exit end; + //support Ctrl+Y + //if (Key=VK_Y) and (Shift=[ssCtrl]) then + //begin + // ed.DoCommand(cCommand_Redo, cInvokeMenuContext); + // ed.SetFocus; + // Key:= 0; + // exit + //end; + + //support Ctrl+Z + //if (Key=VK_Z) and (Shift=[ssCtrl]) then + //begin + // ed.DoCommand(cCommand_Undo, cInvokeMenuContext); + // ed.SetFocus; + // Key:= 0; + // exit + //end; + //support Shift+F3, find back if (Key=VK_F3) and (Shift=[ssShift]) then begin - DoFind(true, true, Finder.OptCase, Finder.OptWords, ''); + //DoFind(true, true, Finder.OptCase, Finder.OptWords, ''); + Finder.OptBack:= true; + FinderNext; Key:= 0; exit end; @@ -450,9 +509,197 @@ procedure TfmMain.edKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); end; procedure TfmMain.DoFindDialog; +//begin +// PostMessage(FListerWindow, WM_KEYDOWN, VK_F7, 0); +// PostMessage(FListerWindow, WM_KEYUP, VK_F7, 0); +//end; +var + res: TModalResult; + cnt: integer; + ok, bChanged: boolean; +begin + with TfmFind.Create(nil) do + try + if ed.ModeReadOnly then + begin + chkRep.Enabled:= not ed.ModeReadOnly; + chkRep.Checked:= not ed.ModeReadOnly; + OptRep:= false; + end; + if ed.TextSelected<>'' then Finder.StrFind:= ed.TextSelected; + Finder.OptBack:= false; + Finder.OptFromCaret:= false; + edFind.Text:= Utf8Encode(Finder.StrFind); + edRep.Text:= Utf8Encode(Finder.StrReplace); + chkRep.Checked:= OptRep; + chkBack.Checked:= Finder.OptBack; + chkCase.Checked:= Finder.OptCase; + chkWords.Checked:= Finder.OptWords; + chkRegex.Checked:= Finder.OptRegex; + chkFromCaret.Checked:= Finder.OptFromCaret; + chkConfirm.Checked:= Finder.OptConfirmReplace; + chkInSel.Enabled:= ed.Carets.IsSelection; + + res:= ShowModal; + if res=mrCancel then Exit; + if edFind.Text='' then Exit; + + Finder.StrFind:= Utf8Decode(edFind.Text); + Finder.StrReplace:= Utf8Decode(edRep.Text); + OptRep:= chkRep.Checked; + Finder.OptBack:= chkBack.Checked; + Finder.OptCase:= chkCase.Checked; + Finder.OptWords:= chkWords.Checked; + Finder.OptRegex:= chkRegex.Checked; + Finder.OptFromCaret:= chkFromCaret.Checked; + Finder.OptConfirmReplace:= chkConfirm.Checked; + Finder.OptInSelection:= chkInSel.Checked; + + FindConfirmAll:= mrNone; + FindMarkAll:= false; + //btnStop.Show; + //progress.Show; + //progress.Position:= 0; + + ed.Markers.Clear; //support "find first" in selection + + case res of + mrOk: //find + begin + ok:= Finder.DoAction_FindOrReplace(false, false, bChanged, true); + FinderUpdateEditor(false); + if not ok then + if Finder.IsRegexBad then + ShowBadRegex + else + DoFindError; + end; + mrYes: //replace + begin + ok:= Finder.DoAction_FindOrReplace(true, false, bChanged, true); + FinderUpdateEditor(true); + if not ok then + if Finder.IsRegexBad then + ShowBadRegex + else + DoFindError; + end; + mrYesToAll: //replace all + begin + cnt:= Finder.DoAction_ReplaceAll; + FinderUpdateEditor(true); + //MsgStatus('已替换 '+Inttostr(cnt)+' 处.'); + MsgStatus('Replaces made: '+Inttostr(cnt)); + end; + mrIgnore: //count all + begin + cnt:= Finder.DoAction_CountAll(false); + //MsgStatus('共计找到 "'+Utf8Encode(Finder.StrFind)+'": '+Inttostr(cnt)+' 处.'); + MsgStatus('Count of "'+Utf8Encode(Finder.StrFind)+'": '+Inttostr(cnt)); + end; + mrRetry: //mark all + begin + FindMarkAll:= true; + ed.Markers.Clear; + cnt:= Finder.DoAction_CountAll(true); + FindMarkAll:= false; + FinderUpdateEditor(false); + //MsgStatus('已标记 '+Inttostr(cnt)+' 处.'); + MsgStatus('Markers placed: '+Inttostr(cnt)); + end; + end; + finally + Free; + end; +end; + +procedure TfmMain.DoFindError; +begin + //MsgStatus('未找到 "'+Utf8Encode(Finder.StrFind)+'".'); + MsgStatus('Cannot find: '+Utf8Encode(Finder.StrFind)); +end; + +procedure TfmMain.FinderConfirmReplace(Sender: TObject; APos1, APos2: TPoint; + AForMany: boolean; var AConfirm, AContinue: boolean; + var AReplacement: UnicodeString); +var + Res: TModalResult; + Buttons: TMsgDlgButtons; +begin + case FindConfirmAll of + mrYesToAll: begin AConfirm:= true; exit end; + mrNoToAll: begin AConfirm:= false; exit end; + end; + + with Ed.Carets[0] do + begin + PosX:= APos1.X; + PosY:= APos1.Y; + EndX:= APos2.X; + EndY:= APos2.Y; + end; + + Ed.DoCommand(cCommand_ScrollToCaretTop, cInvokeAppInternal); + Ed.Update(true); + + Buttons:= [mbYes, mbNo]; + if AForMany then + Buttons:= Buttons+[mbYesToAll, mbNoToAll]; + //Str:= Ed.Strings.TextSubstring(APos1.X, APos1.Y, APos2.X, APos2.Y); + Res:= MessageDlg( + //'确认替换', + 'Confirm replace', + //'替换字符串在第 '+Inttostr(APos1.Y+1)+' 行.', + 'Replace string at line '+Inttostr(APos1.Y+1), + mtConfirmation, + Buttons, ''); + + AConfirm:= Res in [mrYes, mrYesToAll]; + AContinue:= Res<>mrNoToAll; + if Res in [mrYesToAll, mrNoToAll] then + FindConfirmAll:= Res; +end; + + +procedure TfmMain.ShowBadRegex; +begin + MessageDlg( + 'Incorrect RegEx', + Utf8Encode(Finder.StrFind)+#10+ + Finder.RegexErrorMsg, + mtError, + [mbOk], '' + ); +end; + +procedure TfmMain.FinderUpdateEditor(AUpdateText: boolean); +begin + Finder.Editor.Update(AUpdateText); + Finder.Editor.DoGotoCaret(cEdgeTop); + UpdateStatusbar; +end; + +procedure TfmMain.FinderFound(Sender: TObject; APos1, APos2: TPoint); begin - PostMessage(FListerWindow, WM_KEYDOWN, VK_F7, 0); - PostMessage(FListerWindow, WM_KEYUP, VK_F7, 0); + if FindMarkAll then + begin + ed.Markers.Add( + Point(APos1.X, APos1.Y), + Point(Abs(APos2.X-APos1.X), 0), + TATMarkerTags.Init(0, 0) + ); + end; +end; + +procedure TfmMain.FinderNext; +var + ok, bChanged: boolean; +begin + if Finder.StrFind='' then Exit; + Finder.OptFromCaret:= true; + ok:= Finder.DoAction_FindOrReplace(false, false, bChanged, true); + FinderUpdateEditor(false); + if not ok then DoFindError; end; procedure TfmMain.ConfirmSave; @@ -460,12 +707,18 @@ procedure TfmMain.ConfirmSave; if (FFileName<>'') and ed.Modified then begin ed.Modified:= false; - if MsgBox('File was modified. Save it?', MB_OKCANCEL or MB_ICONQUESTION)=ID_OK then - try - ed.SaveToFile(FFileName); - except + //case MsgBox('文件已经被修改. 是否保存?', MB_YESNOCANCEL or MB_ICONQUESTION) of + case MsgBox('File was modified. Save it?', MB_YESNOCANCEL or MB_ICONQUESTION) of + ID_YES: + try + ed.SaveToFile(FFileName); + except + //MsgBox('无法保存文件', MB_OK or MB_ICONERROR); MsgBox('Cannot save file', MB_OK or MB_ICONERROR); - end; + end; + ID_CANCEL: + exit; + end; end; end; @@ -499,9 +752,9 @@ procedure TfmMain.FormCreate(Sender: TObject); var N: integer; begin - N:= ed.Keymap.IndexOf(cCommand_ToggleReadOnly); - if N>=0 then - ed.Keymap[N].Keys1.Data[0]:= Shortcut(VK_R, [ssCtrl]); + //N:= ed.Keymap.IndexOf(cCommand_ToggleReadOnly); + //if N>=0 then + // ed.Keymap[N].Keys1.Data[0]:= Shortcut(VK_R, [ssCtrl]); ed.OptScrollbarsNew:= true; ed.OptScrollStyleHorz:= aessShow; @@ -526,7 +779,8 @@ procedure TfmMain.FormCreate(Sender: TObject); Statusbar.AddPanel(-1, 110, taCenter); Statusbar.AddPanel(-1, 50, taCenter); Statusbar.AddPanel(-1, 150, taCenter); - Statusbar.AddPanel(-1, 50, taCenter); + Statusbar.AddPanel(-1, 80, taCenter); + Statusbar.AddPanel(-1, 150, taCenter); Statusbar.AddPanel(-1, 1600, taLeftJustify); UpdateMenuLexersTo(PopupLexers.Items); @@ -538,8 +792,10 @@ procedure TfmMain.FormCreate(Sender: TObject); Adapter.AddEditor(ed); Finder:= TATEditorFinder.Create; - Finder.OnFound:= @FinderFound; Finder.Editor:= ed; + //Finder.OptRegex:= true; + Finder.OnFound:= @FinderFound; + Finder.OnConfirmReplace:= @FinderConfirmReplace; LoadOptions; UpdateMenuEnc(PopupEnc.Items); @@ -581,6 +837,7 @@ procedure TfmMain.mnuTextGotoClick(Sender: TObject); S: string; N: integer; begin + //S:= InputBox('转到', '行号:', ''); S:= InputBox('Go to', 'Line number:', ''); if S='' then exit; N:= StrToIntDef(S, 0); @@ -594,22 +851,63 @@ procedure TfmMain.mnuTextGotoClick(Sender: TObject); true, true ); + //MsgStatus('转到行 '+IntToStr(N)); MsgStatus('Go to line '+IntToStr(N)); end else + //MsgStatus('行号不正确: '+S); MsgStatus('Incorrect line number: '+S); end; +procedure TfmMain.mnuTextUndoClick(Sender: TObject); +begin + ed.SetFocus; + ed.DoCommand(cCommand_Undo, cInvokeMenuContext); + ed.SetFocus; +end; + +procedure TfmMain.mnuTextRedoClick(Sender: TObject); +begin + ed.SetFocus; + ed.DoCommand(cCommand_Redo, cInvokeMenuContext); + ed.SetFocus; +end; + +procedure TfmMain.mnuTextCutClick(Sender: TObject); +begin + ed.DoCommand(cCommand_ClipboardCut, cInvokeMenuContext); +end; + +procedure TfmMain.mnuTextDeleteClick(Sender: TObject); +begin + ed.DoCommand(cCommand_TextDeleteSelection, cInvokeMenuContext); +end; + procedure TfmMain.mnuTextPasteClick(Sender: TObject); begin ed.DoCommand(cCommand_ClipboardAltPaste, cInvokeMenuContext); end; +procedure TfmMain.mnuTextUpperCaseClick(Sender: TObject); +begin + ed.SetFocus; + ed.DoCommand(cCommand_TextCaseUpper, cInvokeMenuContext); + ed.SetFocus; +end; + +procedure TfmMain.mnuTextLowerCaseClick(Sender: TObject); +begin + ed.SetFocus; + ed.DoCommand(cCommand_TextCaseLower, cInvokeMenuContext); + ed.SetFocus; +end; + procedure TfmMain.mnuTextReadonlyClick(Sender: TObject); begin if cEditorIsReadOnly then exit; ed.ModeReadOnly:= not ed.ModeReadOnly; + ed.SetFocus; ed.Update; if not ed.ModeReadOnly then @@ -632,6 +930,7 @@ procedure TfmMain.mnuTextSaveClick(Sender: TObject); ed.SaveToFile(FFileName); ed.Modified:= false; except + //MsgBox('无法保存文件', MB_OK or MB_ICONERROR); MsgBox('Cannot save file', MB_OK or MB_ICONERROR); end; end; @@ -652,6 +951,12 @@ procedure TfmMain.mnuWrapClick(Sender: TObject); procedure TfmMain.PopupTextPopup(Sender: TObject); begin + mnuTextUndo.Enabled:= not ed.ModeReadOnly and (ed.UndoCount>0); + mnuTextRedo.Enabled:= not ed.ModeReadOnly and (ed.RedoCount>0); + mnuTextCut.Enabled:= not ed.ModeReadOnly and ed.Carets.IsSelection; + mnuTextDelete.Enabled:= not ed.ModeReadOnly and ed.Carets.IsSelection; + mnuTextUpperCase.Enabled:= not ed.ModeReadOnly and ed.Carets.IsSelection; + mnuTextLowerCase.Enabled:= not ed.ModeReadOnly and ed.Carets.IsSelection; mnuTextSave.Enabled:= ed.Modified; mnuTextPaste.Enabled:= not ed.ModeReadOnly; mnuWrap.Checked:= ed.OptWrapMode=cWrapOn; @@ -768,6 +1073,7 @@ procedure TfmMain.UpdateStatusbar; begin Caret:= ed.Carets[0]; StatusBar.Captions[StatusbarIndex_Caret]:= + //Format('行 %d, 列 %d', [Caret.PosY+1, Caret.PosX+1]); Format('Line %d, Col %d', [Caret.PosY+1, Caret.PosX+1]); end; @@ -788,10 +1094,14 @@ procedure TfmMain.UpdateStatusbar; StatusBar.Captions[StatusbarIndex_Lexer]:= S; case ed.OptWrapMode of + //cWrapOff: S:= '未换行'; cWrapOff: S:= 'no wrap'; + //else S:= '换行'; else S:= 'wrap'; end; StatusBar.Captions[StatusbarIndex_Wrap]:= S; + //StatusBar.Captions[StatusbarIndex_UndoRedo]:= Format('撤销: %d, 重做: %d', [ed.UndoCount, ed.RedoCount]); + StatusBar.Captions[StatusbarIndex_UndoRedo]:= Format('Undo: %d, Redo: %d', [ed.UndoCount, ed.RedoCount]); end; @@ -1178,37 +1488,34 @@ procedure TfmMain.UpdateMenuEnc(AMenu: TMenuItem); true); end; - -procedure TfmMain.FinderFound(Sender: TObject; APos1, APos2: TPoint); -begin - ed.DoGotoPos(APos1, APos2, - 10, 3, - true, - true - ); -end; - -procedure TfmMain.DoFind(AFindNext, ABack, ACaseSens, AWords: boolean; const AStrFind: Widestring); -var - Msg: string; - bChanged: boolean; -begin - Finder.OptBack:= ABack; - Finder.OptCase:= ACaseSens; - Finder.OptFromCaret:= AFindNext; - Finder.OptWords:= AWords; - if AStrFind<>'' then - Finder.StrFind:= AStrFind; - if Finder.StrFind='' then exit; - - if Finder.DoAction_FindOrReplace(false, false, bChanged, true) then - Msg:= IfThen(AFindNext, 'Found next', 'Found first') - else - Msg:= 'Not found'; - MsgStatus(Msg+': "'+UTF8Encode(Finder.StrFind)+'"'); -end; - - +//procedure TfmMain.FinderFound(Sender: TObject; APos1, APos2: TPoint); +//begin +// ed.DoGotoPos(APos1, APos2, +// 10, 3, +// true, +// true +// ); +//end; + +//procedure TfmMain.DoFind(AFindNext, ABack, ACaseSens, AWords: boolean; const AStrFind: Widestring); +//var +// Msg: string; +// bChanged: boolean; +//begin +// Finder.OptBack:= ABack; +// Finder.OptCase:= ACaseSens; +// Finder.OptFromCaret:= AFindNext; +// Finder.OptWords:= AWords; +// if AStrFind<>'' then +// Finder.StrFind:= AStrFind; +// if Finder.StrFind='' then exit; +// +// if Finder.DoAction_FindOrReplace(false, false, bChanged, true) then +// Msg:= IfThen(AFindNext, 'Found next', 'Found first') +// else +// Msg:= 'Not found'; +// MsgStatus(Msg+': "'+UTF8Encode(Finder.StrFind)+'"'); +//end; initialization AppManager:= TecSyntaxManager.Create(nil);