编辑器

添加windows linux 文本文件换行符转换功能
This commit is contained in:
JianjunLiu 2023-03-15 15:05:46 +08:00
parent 8d828d167f
commit 2a1c1680bf
1 changed files with 77 additions and 13 deletions

View File

@ -1099,6 +1099,7 @@ type TPageEditerItem=class(TPageItem)
FEditer.Align := FEditer.alClient; FEditer.Align := FEditer.alClient;
FEditer.Visible := false; FEditer.Visible := false;
FEditer._Tag := self; FEditer._Tag := self;
Fscripttype := 0;
end end
function Recycling();override; function Recycling();override;
begin begin
@ -1125,6 +1126,7 @@ type TPageEditerItem=class(TPageItem)
return filenameIsTheSame(v,FScriptPath); return filenameIsTheSame(v,FScriptPath);
end end
published published
property scripttype read Fscripttype write setFscripttype;
property ScriptPath read FScriptPath write SetScriptPath; //文件名 property ScriptPath read FScriptPath write SetScriptPath; //文件名
property OrigScriptPath read FOrgScriptPath; property OrigScriptPath read FOrgScriptPath;
property TslSynText read FTslSynText write FTslSynText; property TslSynText read FTslSynText write FTslSynText;
@ -1132,6 +1134,7 @@ type TPageEditerItem=class(TPageItem)
property EnCode read FEnCode; property EnCode read FEnCode;
RepreComple; RepreComple;
FISstm; FISstm;
Fscripttype;
///////////////////设计器相关////////////////////////////////////// ///////////////////设计器相关//////////////////////////////////////
public public
function Addfiled(fld); //添加成员变量 function Addfiled(fld); //添加成员变量
@ -1538,6 +1541,14 @@ type TPageEditerItem=class(TPageItem)
FLastVersion; //脚本 FLastVersion; //脚本
FScriptPath; //路径 FScriptPath; //路径
FOrgScriptPath; //原始路径 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); function SetScriptPath(v);
begin begin
sp := ioFileseparator(); sp := ioFileseparator();
@ -2137,6 +2148,10 @@ type TEditer=class(TCustomcontrol) //
except except
end end
end end
if it.scripttype=1 then
begin
s := replacetext(s,"\r\n","\n");
end
r := ReWriteString(fp,s); r := ReWriteString(fp,s);
it.ReGetLastLoadTime(); it.ReGetLastLoadTime();
dopageitemsaved(it); dopageitemsaved(it);
@ -2427,11 +2442,27 @@ type TEditer=class(TCustomcontrol) //
end end
function PageEditerMenuClick(o,e); function PageEditerMenuClick(o,e);
begin 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 begin
return PageMenuClick(o,e); return PageMenuClick(o,e);
end else end else
if pos("复制",o.caption)=1 then if pos("复制",cp)=1 then
begin begin
it := GetCurrentItem(); it := GetCurrentItem();
if it then if it then
@ -2445,7 +2476,7 @@ type TEditer=class(TCustomcontrol) //
end end
return; return;
end else end else
if pos("粘贴",o.caption)=1 then if pos("粘贴",cp)=1 then
begin begin
it := GetCurrentItem(); it := GetCurrentItem();
if it then if it then
@ -2459,7 +2490,7 @@ type TEditer=class(TCustomcontrol) //
end end
return; return;
end else end else
if pos("剪切",o.caption)=1 then if pos("剪切",cp)=1 then
begin begin
it := GetCurrentItem(); it := GetCurrentItem();
if it then if it then
@ -2473,13 +2504,13 @@ type TEditer=class(TCustomcontrol) //
end end
return; return;
end else end else
if pos("定位",o.caption)=1 then if pos("定位",cp)=1 then
begin begin
InitShowWndPos(FGotoLineWnd,"g",200,200); InitShowWndPos(FGotoLineWnd,"g",200,200);
FGotoLineWnd.ShowGoto(); FGotoLineWnd.ShowGoto();
return; return;
end else end else
if pos("查看",o.caption)=1 then if pos("查看",cp)=1 then
begin begin
cs := o.Caption; cs := o.Caption;
if length(cs)<6 then return; if length(cs)<6 then return;
@ -2487,7 +2518,7 @@ type TEditer=class(TCustomcontrol) //
GetCurrentEditer().Tryjump(s); GetCurrentEditer().Tryjump(s);
return; return;
end else end else
if pos("只读",o.caption)=1 then if pos("只读",cp)=1 then
begin begin
it := GetCurrentItem(); it := GetCurrentItem();
if it then if it then
@ -2496,26 +2527,26 @@ type TEditer=class(TCustomcontrol) //
end end
return; return;
end else end else
if pos("执行",o.Caption)=1 then if pos("执行",cp)=1 then
begin begin
it := GetCurrentItem(); it := GetCurrentItem();
ExecutePageItem(it); ExecutePageItem(it);
return; return;
end else end else
if pos("停止",o.Caption)=1 then if pos("停止",cp)=1 then
begin begin
if FEchoWnd.Exeing()then FEchoWnd.EndExe(); if FEchoWnd.Exeing()then FEchoWnd.EndExe();
return; return;
end else end else
if o.Caption = "转换为大写" then if cp = "转换为大写" then
begin begin
upperorlowercase(1); upperorlowercase(1);
end else end else
if o.Caption = "转换为小写" then if cp = "转换为小写" then
begin begin
upperorlowercase(0); upperorlowercase(0);
end else end else
if o.Caption = "删除尾空白" then if cp = "删除尾空白" then
begin begin
seltrimright(); seltrimright();
end end
@ -2527,15 +2558,31 @@ type TEditer=class(TCustomcontrol) //
begin begin
FPageEditerMenu := new TPopUpMenu(self); FPageEditerMenu := new TPopUpMenu(self);
FPageEditerMenus := array(); 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 begin
it := new TMenu(self); it := new TMenu(self);
it.Caption := v; it.Caption := v;
it.parent := FPageEditerMenu; 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; FPageEditerMenus[v]:= it;
it.OnClick := thisfunction(PageEditerMenuClick); it.OnClick := thisfunction(PageEditerMenuClick);
end end
end end
iflx := GetCurrentItem().scripttype = 1;
FPageEditerMenus["转unix(LF)"].Enabled := not iflx;
FPageEditerMenus["转windows(CR LF)"].Enabled := iflx;
rd := FPageEditerMenus["只读"]; rd := FPageEditerMenus["只读"];
if rd then if rd then
begin begin
@ -4148,6 +4195,23 @@ type TEditer=class(TCustomcontrol) //
edt := it.FEditer; edt := it.FEditer;
tl := edt.TopLine; tl := edt.TopLine;
cxy := edt.CaretXY; 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); it.SetLoadScript(s);
if ifinit then if ifinit then
begin begin