整体更新
This commit is contained in:
2024-03-22 16:44:34 +08:00
parent e8c5223f00
commit 33ba905e99
31 changed files with 1108 additions and 411 deletions
+131 -389
View File
@@ -2124,12 +2124,13 @@ type TEditer=class(TCustomcontrol) //
o.SaveCurrentEditer();
self.Enabled := false;
FIsFinding := true;
if not(d["c_reg"])then
if {not(d["c_reg"])}true then
begin
if(d["section"]="查找")and(d["btn"]="计数")then
begin
ct := "noshow";
FindAllInCurrent(d,o,nil,ct);
//FindAllInCurrent(d,o,nil,ct);
Find_All(d,o,nil,ct);
o.SetStatusText(format("查找到 %d处",ct));
return EndFind();
end else
@@ -2137,18 +2138,25 @@ type TEditer=class(TCustomcontrol) //
begin
FFindListWnd.Clean();
ShowFindWnd();
FindAllInCurrent(d,o,nil,ct);
//FindAllInCurrent(d,o,nil,ct);
Find_All(d,o,nil,ct);
o.SetStatusText(format("查找到 %d处",ct));
return EndFind();
end else
if(d["section"]in array("查找","替换"))and(d["btn"]="查找")then
begin
FindInCurrent(d,o);
find_one(d,o);
//FindInCurrent(d,o);
return EndFind();
end else
if(d["section"]in array("替换"))and(d["btn"]="替换")then
begin
if d["replace"]<> d["target"]then FindInCurrent(d,o,nil,1);
if d["replace"]<> d["target"]then
begin
//FindInCurrent(d,o,nil,1);
find_one(d,o,nil,1);
end
return EndFind();
end else
if(d["section"]in array("替换"))and(d["btn"]="全部替换")then
@@ -2157,7 +2165,8 @@ type TEditer=class(TCustomcontrol) //
begin
FFindListWnd.Clean();
ShowFindWnd();
ReplaceAllInCurrent(d,o,nil,idx);
//ReplaceAllInCurrent(d,o,nil,idx);
replace_allincurrent(d,o,nil,idx);
o.SetStatusText(format("替换 %d处",idx));
end
return EndFind();
@@ -2167,7 +2176,8 @@ type TEditer=class(TCustomcontrol) //
if messageboxa("即将在目录中替换内容!!","提示",mb_YesNo,self.Handle)<> IDYES then return EndFind();
FFindListWnd.Clean();
ShowFindWnd();
FindInFiles(d,o,true,ct);
//FindInFiles(d,o,true,ct);
Find_InFiles(d,o,true,ct);
o.SetStatusText(format("总共替换 %d处",ct));
return EndFind();
end else
@@ -2175,7 +2185,8 @@ type TEditer=class(TCustomcontrol) //
begin
FFindListWnd.Clean();
ShowFindWnd();
FindInFiles(d,o,false,ct);
//FindInFiles(d,o,false,ct);
Find_InFiles(d,o,false,ct);
o.SetStatusText(format("总共查找 %d处",ct));
return EndFind();
end
@@ -3913,216 +3924,46 @@ type TEditer=class(TCustomcontrol) //
r["c_reg"] := FCheck_reg.Checked;
r["c_dir"] := FCheck_subdir.Checked;
}
function ReplaceAllInCurrent(data,fo,it,idx);
function replace_allincurrent(data,fo,it,idx);
begin
data["c_revers"]:= 0;
data["c_cycle"]:= 0;
//data["c_revers"]:= 0;
//data["c_cycle"]:= 0;
if not it then it := GetCurrentItem();
if not it then return;
ed := it.FEditer;
if not ed then return;
if ed.ReadOnly then return ;//不能替换
TryDispatch();
if not FIsFinding then return rt;
fs := data["target"];
finder := finder_set_info(data,ed.Text);
idx := 0;
try
ed.IncPaintLock();
ed.ExecuteCommand(ed.ecGotoXY,array(1,1));
cidx := 0;
while FindInCurrent(data,fo,it,1)=0 do
begin
if idx=0 then
begin
FFindListWnd.AppendItem(array("caption":format("replace:%s in file:%s",data["target"],it.OrigScriptPath)));
end
if idx>0 then
begin
ed.MergeLastUndo();
end
idx++;
L := ed.CaretY;
if cidx=L then continue;
cidx := L;
scap := format(" %d:(第%d行) ",idx,L)+limitstringlength(ed.LineText);
FFindListWnd.AppendItem(array("caption":scap,"file":it.OrigScriptPath,"line":L));
end
finally
ed.DecPaintLock();
end
//fo.SetStatusText(format("共替换:%d 处",idx));
end
function matchword(f,d);
begin
wr := d["c_wrap"];
cw := d["c_case"];
tg := d["target"];
if not tg then return ;
ctl2 := "m";
if not d["c_reg"] then
begin
ntg := "";
ltg := length(tg);
for i := 1 to length(tg) do
begin
vi := tg[i];
cvi := ord(vi);
if cvi>=9 and cvi<=13 then
begin
ntg +="\\s";
if i=1 then wrp :=1;
if i=ltg then wrp .|= 2;
end else
if (cvi>=0x21 and cvi<=0x2f) or
(cvi>=0x3a and cvi<=0x40) or
(cvi>=0x5b and cvi<=0x60) or
(cvi>=0x7b and cvi<=0x7e) then
begin
ntg +="\\"+vi;
if i=1 then wrp :=1;
if i=ltg then wrp .|= 2;
end else
begin
ntg+=vi;
end
rsult := finder.replace_all(r);
if rsult then
begin
idx := length(rsult);
ed.ExecuteCommand(ed.ecSelectAll);
ed.SelText := r;
lastidx := -1;
for i,v in rsult do
begin
if i=0 then
FFindListWnd.AppendItem(array("caption":format("replace:%s in file:%s",fs,it.OrigScriptPath),"file":it.OrigScriptPath,"line":1));
rdx := v[1,0];
if rdx=lastidx then continue;
lastidx := rdx;
if not ifstring(v[3]) then continue;
scap := format(" %d:(第%d行) ",i,rdx)+limitstringlength(v[3]);
FFindListWnd.AppendItem(array("caption":scap,"file":it.OrigScriptPath,"line":rdx));
end
tg := ntg;
end
ctl := tg;
if wr then
begin
if not((wrp .& 1) >1) then ctl := "\\b"+ctl;
if not((wrp .& 2) >1) then ctl := ctl+"\\b";
end
if cw then ctl2 += "i";
linesi := array(0:1);
if (1 = readfile(rwraw(),"",f,0,filesize("",f),s)) and s then
begin
strcode := 0;
if(length(s)>= 2)and ord(s[1])=0xFE and ord(s[2])=0xFF then //ucs2-big
begin
strcode := 1;
if length(s)=2 then s := "";
else
begin
s1 := "";
setlength(s1,length(s)-2);
for i := 3 to length(s)-1 step 2 do
begin
s1[i-2]:= s[i+1];
s1[i-1]:= s[i];
end
s := unicodetomultibyte(s1,936);
end
end else
if(length(s)>= 2)and ord(s[1])=0xFF and ord(s[2])=0xFE then //ucs2-little
begin
strcode := 1;
if length(s)=2 then s := "";
else
begin
s := unicodetomultibyte(s[3:],936);
end
end else
if(length(s)>= 3)and ord(s[1])=0xEF and ord(s[2])=0xBB and ord(s[3])=0xBF then
begin
strcode := 1;
if length(s)=3 then s := "";
else s := utf8toansi(s[4:]);
end
if(0=strcode)then
begin
if IsTextUTF8(s)=1 then
begin
s := utf8toansi(s);
end
end
////////////////////////////////////////////////////////////////////////////////////
slen := length(s);
orid := -1;
if 1= parseregexpr(ctl,s,ctl2,m,mp,mlen) then
begin
r := array();
idx := 1;
rid := 1;
jid := 1;
ip := 1;
if pos("\r\n",s) or pos("\n",s) then
begin
fgf := "\n";
end else
fgf := "\r";
p1 := 1;
p2 := 0;
for i,v in m do
begin
mi := mp[i,0];
while idx<mi do
begin
vi := s[idx];
idx++;
jid++;
if vi=fgf then
begin
linesi[rid]:=idx;
rid++;
jid := 1;
end
end
r[i][0] := rid; //行
r[i][1] := jid; //列
p1 := linesi[rid-1];
p2 := idx+mlen[i,0]-1;
if (p2>p1) and (rid<>orid) then
begin
isset := 1;
for ii := p2 to slen do
begin
if s[ii]=fgf then
begin
isset := 0;
p2 := ii;
break;
end
end
if isset then p2 := slen;
r[i][2] := trim(s[p1:p2]);
end
else r[i,2] := "";
orid := rid;
end
return r;
end
end
end
function FindInFiles(d,o,rep,ct);
function Find_InFiles(d,o,rep,ct);
begin
fs := GetFilesFormSearchInfo(d);
ct := 0;
if not rep then
begin
for i,v in fs do
begin
if not FIsFinding then break;
ri := matchword(i,d);
if ri then
begin
ril := length(ri);
FFindListWnd.AppendItem(array("caption":format("find:%s in file:%s has:%d",d["target"],i,ril)));
orii := -1;
for ii,vi in ri do
begin
rii := vi[0];
ct++;
if orii=rii then continue;
orii := rii;
scap := format(" %d:(第%d行) ",ct,rii)+limitstringlength(vi[2]);
FFindListWnd.AppendItem(array("caption":scap,"file":i,"line":rii));
end
end
end
return ;
end
for i,v in fs do
begin
if not FIsFinding then break;
@@ -4136,130 +3977,76 @@ type TEditer=class(TCustomcontrol) //
end
if rep then
begin
ReplaceAllInCurrent(d,o,it,idx);
//ReplaceAllInCurrent(d,o,it,idx);
replace_allincurrent(d,o,it,idx);
SavePageItem(it);
end else
begin
FindAllInCurrent(d,o,it,idx);
//FindAllInCurrent(d,o,it,idx);
Find_All(d,o,it,idx);
end
ct += idx;
end
end
function FindInCurrent(data,fo,it,rep);
function finder_set_info(data,txt);
begin
finder := static new t_gbk_text_finder();
finder.set_text(txt);
finder.set_find_str(data["target"]);
finder.iscase := data["c_case"];
finder.iswrap := data["c_wrap"];
finder.isReg := data["c_reg"];
finder.isprev := data["c_revers"];
finder.iscycle := data["c_cycle"];
finder.ismline := data["c_mline"];
finder.set_replace_str(data["replace"]);
return finder;
end
function find_one(data,fo,it,rep);
begin
if not it then it := GetCurrentItem();
if not it then return -2;
ed := it.FEditer;
if not ed then return -2;
cy := ed.CaretY;
cx := ed.CaretX;
wordwrap := data["c_wrap"];
cx := ed.CaretX;
fs := data["target"];
if not(fs and ifstring(fs))then
begin
fo.SetStatusText("查找内容为空!");
return -2;
end
stringiswrapword := isCaseWords(fs);
if data["c_case"]then fs := lowercase(fs);
rstring := data["replace"];
lfs := length(fs);
L := ed.Lines;
ct := L.length();
if data["c_revers"]then
begin
for i := cy-1 downto cy-ct do
finder := finder_set_info(data,ed.Text);
finder.set_rc(array(cy,cx));
reslt := finder.find_one();
if reslt then
begin
if data["c_revers"] then
begin
p1 := reslt[0,4];
p2 := reslt[0,3];
end else
begin
p1 := reslt[0,3];
p2 := reslt[0,4];
end
ed.ExecuteCommand(ed.ecGotoXY,p1);
ed.ExecuteCommand(ed.ecSelGotoXY,p2);
fo.SetStatusText(format("位置: %d %d",p1[0],p1[1]));
if rep then
begin
ridx := i;
if data["c_cycle"]then
begin
ridx :=(ridx<0)?(ridx+ct):ridx;
end
if ridx<0 then
begin
fo.SetStatusText("到达顶部");
return -2;
end
s := L.GetStringByIndex(ridx);
ls := length(s);
while cx-lfs+1>1 do
begin
if not FIsFinding then return-2;
TryDispatch();
subs := s[cx-lfs:cx-1];
if data["c_case"]then subs := lowercase(subs);
if subs=fs and(wordwrap?((stringiswrapword=3)or(((stringiswrapword .& 1)or IsWordsChar(s,cx-1,ls))and((stringiswrapword .& 2)or IsWordsChar(s,cx+lfs,ls)))):true)then //找到了
begin
ed.ExecuteCommand(ed.ecGotoXY,array(ridx+1,cx));
ed.ExecuteCommand(ed.ecSelGotoXY,array(ridx+1,cx-lfs));
if rep then
begin
ed.SelText := rstring;
end
fo.SetStatusText(format("位置: %d %d",ridx+1,cx-lfs));
return 0;
end
cx--;
end
tidx := ridx-1;
if data["c_cycle"]then
begin
tidx += ct;
tidx := tidx mod ct;
end else
begin
if tidx<0 then
begin
fo.SetStatusText("到达顶部");
return-2;
end
end
s := L.GetStringByIndex(tidx);
cx := length(s)+1;
end
fo.SetStatusText("到达顶部");
rs := finder.format_rep_Str(reslt);
ed.SelText := rs;
end
return 0;
end else
begin
fo.SetStatusText("没找到");
return -2;
end
for i := 0 to ct do
begin
ridx := i+cy-1;
if data["c_cycle"]then
begin
ridx := ridx mod ct;
end
if ridx >= ct then
begin
fo.SetStatusText("到达底部");
return-2;
end
s := L.GetStringByIndex(ridx);
ls := length(s);
if data["c_case"] then s := lowercase(s);
while cx+lfs-1 <= ls do
begin
if not FIsFinding then return-2;
//GetAndDispatchMessageA();
TryDispatch();
subs := s[cx:cx+lfs-1];
if subs=fs and(wordwrap?((stringiswrapword=3)or(((stringiswrapword .& 1)or IsWordsChar(s,cx-1,ls))and((stringiswrapword .& 2)or IsWordsChar(s,cx+lfs,ls)))):true)then //找到了
begin
ed.ExecuteCommand(ed.ecGotoXY,array(ridx+1,cx));
ed.ExecuteCommand(ed.ecSelGotoXY,array(ridx+1,cx+lfs));
if rep then
begin
ed.SelText := rstring;
end
fo.SetStatusText(format("位置: %d %d",ridx+1,cx));
return 0;
end
//没找到
cx++;
end
cx := 1;
end
fo.SetStatusText("到达底部");
return -2;
end
end
end
function FindListChoosed(o,e);
begin
it := o.GetItem(o.GetCurrentSelection());
@@ -4283,77 +4070,46 @@ type TEditer=class(TCustomcontrol) //
GetAndDispatchMessageA();
end
end
function FindAllInCurrent(data,fo,it,rt);
function Find_All(data,fo,it,rt);
begin
if rt = "noshow" then
begin
fnoshow := true;
end
TryDispatch();
if not FIsFinding then return rt;
rt := 0;
if not it then it := GetCurrentItem();
if not it then return;
ed := it.FEditer;
if not ed then return;
wordwrap := data["c_wrap"];
finder := finder_set_info(data,ed.Text);
rsult := finder.find_all();
fs := data["target"];
if not(fs and ifstring(fs))then return fo.SetStatusText("找到 0 处");
if data["c_case"]then fs := lowercase(fs);
stringiswrapword := isCaseWords(fs);
lfs := length(fs);
L := ed.Lines;
ct := L.length();
for i := 0 to ct-1 do
begin
s := L.GetStringByIndex(i);
ls := length(s);
cx := 1;
if data["c_case"] then s := lowercase(s);
cidx := 0;
while cx+lfs-1 <= ls do
begin
if not FIsFinding then return rt;
//GetAndDispatchMessageA();
TryDispatch();
subs := s[cx:cx+lfs-1];
//((stringiswrapword .& 2) and (IsWordsChar(s,cx-1,ls)) ( (stringiswrapword .& 1) and IsWordsChar(s,cx+lfs,ls)) )
if subs=fs and(wordwrap?((stringiswrapword=3)or(((stringiswrapword .& 1)or IsWordsChar(s,cx-1,ls))and((stringiswrapword .& 2)or IsWordsChar(s,cx+lfs,ls)))):true)then //找到了
begin
if rt=0 and (not fnoshow) then FFindListWnd.AppendItem(array("caption":format("find:%s in file:%s",fs,it.OrigScriptPath),"file":it.OrigScriptPath,"line":1));
cx += lfs;
rt++;
if cidx then continue;
cidx := 1;
if not fnoshow then
begin
scap := format(" %d:(第%d行) ",rt,i+1)+limitstringlength(s);
FFindListWnd.AppendItem(array("caption":scap,"file":it.OrigScriptPath,"line":i+1));
end
continue;
end
//没找到
cx++;
end
end
return rt;
end
function isCaseWords(s); //判断全词匹配
begin
if ifstring(s)and s then
begin
len := length(s);
if len=1 then return IsWordsChar(s,1,1);
return IsWordsChar(s,1,1).|(2 * IsWordsChar(s,len,len));
end
end
function IsWordsChar(s,idx,len);
begin
if not(len>0)then len := length(s);
if idx>len then return true;
if idx<1 then return true;
ivi := ord(s[idx]);
if(ivi<48)or(ivi>57 and ivi<65)or(ivi>90 and ivi<95)or(ivi>95 and ivi<97)or(ivi>122 and ivi <= 127)then return true;
end
lastidx := -1;
if rsult then
begin
rt := length(rsult);
for i,v in rsult do
begin
if i=0 and (not fnoshow) then
FFindListWnd.AppendItem(array("caption":format("find:%s in file:%s",fs,it.OrigScriptPath),"file":it.OrigScriptPath,"line":1));
if not fnoshow then
begin
rdx := v[1,0];
if rdx=lastidx then continue;
lastidx := rdx;
if not ifstring(v[3]) then continue;
scap := format(" %d:(第%d行) ",i,rdx)+limitstringlength(v[3]);
FFindListWnd.AppendItem(array("caption":scap,"file":it.OrigScriptPath,"line":rdx));
end
end
end else
begin
fo.SetStatusText("找到 0 处");
end
end
function TabCheckChanged();
begin
if not FListPages.Visible then return;
@@ -6053,23 +5809,16 @@ type TFindWnd=class(TPage)
FCheck_cycle.top := lg * 8;
FCheck_cycle.parent := self;
FCheck_reg.caption := "正则匹配";
FCheck_reg.Enabled := false;
FCheck_reg.Enabled := true;
FCheck_reg.top := lg * 9;
FCheck_reg.parent := self;
FCheck_gt.caption := "\\t转义tab";
FCheck_gt.Checked := false;
FCheck_gt.Visible := true;
FCheck_gt.caption := "多行";
FCheck_gt.Checked := true;
FCheck_gt.top := lg * 9;
FCheck_gt.Left := FCheck_reg.width+FCheck_reg.Left+10;
FCheck_gt.parent := self;
//FCheck_gt.parent := self;
FCheck_subdir.parent := self;
FCheck_reg.OnClick := function(o,e)
begin
ck := o.Checked;
FCheck_revers.Enabled := not(ck);
FCheck_wrap.Enabled := not(ck);
//FCheck_case.Enabled := not(ck);
FCheck_cycle.Enabled := not(ck);
end
FStatus := new TStatusBar(self);
//FStatus.Align := alNone;
FStatus.Items := array(("text":"","width":700));
@@ -6099,16 +5848,9 @@ type TFindWnd=class(TPage)
r := array();
r["section"]:= CurrentITem.Caption;
s := FEdit_target.Editer.Text;
if FCheck_gt.Checked then
begin
s := Replacestr(s,"\\t","\t");
end
r["target"]:= s;
r["c_mline"] := FCheck_gt.Checked;
s := FEdit_repace.Editer.Text;
if FCheck_gt.Checked then
begin
s := Replacestr(s,"\\t","\t");
end
r["replace"]:= s;
r["filetype"]:= FEdit_type.Editer.Text;
r["dir"]:= FEdit_dir.Editer.Text;
+11 -13
View File
@@ -638,27 +638,25 @@ type tslparserbase= class //
{**
@explan(说明) tsl语言解析基类 %%
**}
static TT_IDE; //标示符
static TT_STR; //字符串
static TT_SYM; //分隔符
static TT_OK;
private
fcomments;
fcomments2;
public
static TT_IDE = "标示符"; //标示符
static TT_STR = "字符串"; //字符串
static TT_SYM = "分割"; //分隔符
function create();
begin
if not TT_OK then
begin
TT_IDE := "标示符";
TT_STR := "字符串";
TT_SYM := "分割";
TT_OK := true;
end
fcomments := array("说明0":1,"说明1":1,"说明2":1,"说明":1);
fcomments2 := array("空格":1,"回车":1,"换行":1);
end
function setdata(ret,nk,vs,tp,idx,hh) //解析
begin
{**
@explan(说明)保存数据
**}
if tp="空格" or tp="回车" or tp="换行" then return;
if tp in array("说明0","说明1","说明2","说明")then
if fcomments2[tp] then return;
if fcomments[tp] then
begin
vs := "";
return;