From 2a1c1680bf60dd198d68c889c00030ff56c6fbaa Mon Sep 17 00:00:00 2001 From: JianjunLiu Date: Wed, 15 Mar 2023 15:05:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加windows linux 文本文件换行符转换功能 --- designer/utslcodeeditor.tsf | 90 +++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 13 deletions(-) diff --git a/designer/utslcodeeditor.tsf b/designer/utslcodeeditor.tsf index 97cb15c..f869753 100644 --- a/designer/utslcodeeditor.tsf +++ b/designer/utslcodeeditor.tsf @@ -1099,6 +1099,7 @@ type TPageEditerItem=class(TPageItem) FEditer.Align := FEditer.alClient; FEditer.Visible := false; FEditer._Tag := self; + Fscripttype := 0; end function Recycling();override; begin @@ -1125,6 +1126,7 @@ type TPageEditerItem=class(TPageItem) return filenameIsTheSame(v,FScriptPath); end published + property scripttype read Fscripttype write setFscripttype; property ScriptPath read FScriptPath write SetScriptPath; //ļ property OrigScriptPath read FOrgScriptPath; property TslSynText read FTslSynText write FTslSynText; @@ -1132,6 +1134,7 @@ type TPageEditerItem=class(TPageItem) property EnCode read FEnCode; RepreComple; FISstm; + Fscripttype; ///////////////////////////////////////////////////////// public function Addfiled(fld); //ӳԱ @@ -1538,6 +1541,14 @@ type TPageEditerItem=class(TPageItem) FLastVersion; //ű FScriptPath; //· FOrgScriptPath; //ԭʼ· + function setFscripttype(v); + begin + if (v=0 or v=1) and v<>Fscripttype then + begin + Fscripttype := v; + FLastVersion := FEditer.Text; + end + end function SetScriptPath(v); begin sp := ioFileseparator(); @@ -2137,6 +2148,10 @@ type TEditer=class(TCustomcontrol) // except end end + if it.scripttype=1 then + begin + s := replacetext(s,"\r\n","\n"); + end r := ReWriteString(fp,s); it.ReGetLastLoadTime(); dopageitemsaved(it); @@ -2427,11 +2442,27 @@ type TEditer=class(TCustomcontrol) // end function PageEditerMenuClick(o,e); begin - if ("Ϊ"=o.Caption) then + cp := o.Caption; + if ("תunix(LF)"=cp) then + begin + it := GetCurrentItem(); + it.scripttype := 1; + SavePageItem(it,1); + //it.FEditer.ChangedFlag := true; + return ; + end else + if ("תwindows(CR LF)"=cp) then + begin + it := GetCurrentItem(); + it.scripttype := 0; + SavePageItem(it,1); + return ; + end else + if ("Ϊ"=cp) then begin return PageMenuClick(o,e); end else - if pos("",o.caption)=1 then + if pos("",cp)=1 then begin it := GetCurrentItem(); if it then @@ -2445,7 +2476,7 @@ type TEditer=class(TCustomcontrol) // end return; end else - if pos("ճ",o.caption)=1 then + if pos("ճ",cp)=1 then begin it := GetCurrentItem(); if it then @@ -2459,7 +2490,7 @@ type TEditer=class(TCustomcontrol) // end return; end else - if pos("",o.caption)=1 then + if pos("",cp)=1 then begin it := GetCurrentItem(); if it then @@ -2473,13 +2504,13 @@ type TEditer=class(TCustomcontrol) // end return; end else - if pos("λ",o.caption)=1 then + if pos("λ",cp)=1 then begin InitShowWndPos(FGotoLineWnd,"g",200,200); FGotoLineWnd.ShowGoto(); return; end else - if pos("鿴",o.caption)=1 then + if pos("鿴",cp)=1 then begin cs := o.Caption; if length(cs)<6 then return; @@ -2487,7 +2518,7 @@ type TEditer=class(TCustomcontrol) // GetCurrentEditer().Tryjump(s); return; end else - if pos("ֻ",o.caption)=1 then + if pos("ֻ",cp)=1 then begin it := GetCurrentItem(); if it then @@ -2496,26 +2527,26 @@ type TEditer=class(TCustomcontrol) // end return; end else - if pos("ִ",o.Caption)=1 then + if pos("ִ",cp)=1 then begin it := GetCurrentItem(); ExecutePageItem(it); return; end else - if pos("ֹͣ",o.Caption)=1 then + if pos("ֹͣ",cp)=1 then begin if FEchoWnd.Exeing()then FEchoWnd.EndExe(); return; end else - if o.Caption = "תΪд" then + if cp = "תΪд" then begin upperorlowercase(1); end else - if o.Caption = "תΪСд" then + if cp = "תΪСд" then begin upperorlowercase(0); end else - if o.Caption = "ɾβհ" then + if cp = "ɾβհ" then begin seltrimright(); end @@ -2527,15 +2558,31 @@ type TEditer=class(TCustomcontrol) // begin FPageEditerMenu := new TPopUpMenu(self); FPageEditerMenus := array(); - for i,v in array("鿴","(C)","ճ(V)","(X)","λ(G)","ֻ","תΪд","תΪСд","ɾβհ","ִ(F9)","ִֹͣ","Ϊ") do + for i,v in array("鿴","(C)","ճ(V)","(X)","λ(G)","ֻ","תΪд","תΪСд","ɾβհ","ĵʽ","ִ(F9)","ִֹͣ","Ϊ") do begin it := new TMenu(self); it.Caption := v; + it.parent := FPageEditerMenu; + if "ĵʽ"=v then + begin + for j,vj in array("תunix(LF)","תwindows(CR LF)") do + begin + subit := new TMenu(self); + FPageEditerMenus[vj]:= subit; + subit.Caption := vj ; + subit.Parent := it; + subit.OnClick := thisfunction(PageEditerMenuClick); + end + continue; + end FPageEditerMenus[v]:= it; it.OnClick := thisfunction(PageEditerMenuClick); end end + iflx := GetCurrentItem().scripttype = 1; + FPageEditerMenus["תunix(LF)"].Enabled := not iflx; + FPageEditerMenus["תwindows(CR LF)"].Enabled := iflx; rd := FPageEditerMenus["ֻ"]; if rd then begin @@ -4148,6 +4195,23 @@ type TEditer=class(TCustomcontrol) // edt := it.FEditer; tl := edt.TopLine; cxy := edt.CaretXY; + {$ifdef linux} + it.scripttype := 1; + {$else} + it.scripttype := 0; + {$endif} + if pos("\r\n",s) then + begin + it.scripttype := 0; + end else + if pos("\n",s) then + begin + it.scripttype := 1; + end + if it.scripttype<>0 and length(p)>3 and (lowercase(p[length(p)-3:length(p)]) in array(".tsl",".tsf")) then + begin + it.scripttype := 0; + end it.SetLoadScript(s); if ifinit then begin