编辑器

将tsl代码树嵌入编辑器左侧
This commit is contained in:
JianjunLiu 2023-03-24 17:15:09 +08:00
parent 16e449ea50
commit 03d73ebec9
4 changed files with 337 additions and 46 deletions

View File

@ -1579,6 +1579,7 @@ type tdirviewer = class(tcustomcontrol)
FEdit.parent := self;
FEdit.Align := alTop;
FTree := new TTreeView(self);
FTree.Border := false;
FTree.Align := alClient;
FTree.parent := self;
ftree.ImageList := fimgs;
@ -1692,7 +1693,7 @@ type tdirviewer = class(tcustomcontrol)
fimgs.addbmp(bmp);
bt.ImageId := fimgs.ImageCount-1;
bt.parent := ftb;
if i in array("添加工作目录","移除工作目录","打开","刷新") then ftbns[i] := bt;
if i in array("移除工作目录","打开","刷新") then ftbns[i] := bt;
if i in array("²éÕÒ","·´Ïò²éÕÒ") then fsbtns[i] := bt;
bt.onclick := thisfunction(toolclick);
end

View File

@ -613,6 +613,7 @@ F47AC96526C21CCB26FD326A2180CC21F5CAC302CA5C842B865FD9D7003D1F17B
begin
end
end
type TEditerAuxiliary=class(TPage) //辅助窗口
function Create(AOwner);
begin
@ -1753,7 +1754,7 @@ type TEditer=class(TCustomcontrol) //
"charset":0,"outprecision":0,"clipprecision":0,"quality":1,"pitchandfamily":1,"facename":"Courier New","color":0);
FTslDebug := new TTslDebug(self);
FFindListWnd := new TFindListWnd(self);
FCodeMap := new TTslCodeMap(self);
//FCodeMap := new TTslCodeMap(self);
FFileopen := new TOpenFileADlg(self);
FFileSave := new TSavefileADlg(self);
FFileopen.WndOwner := self;
@ -1768,7 +1769,7 @@ type TEditer=class(TCustomcontrol) //
FFindListWnd.OnDblClick := thisfunction(FindListChoosed);
FGotoLineWnd.Visible := false;
/////////////////////////
FCodeMap.visible := false;
//FCodeMap.visible := false;
FFindWnd.Visible := false;
FFileSave.Filter := array("any":"*.*","tsl文件":"*.tsl;*.tsf");
FFileSave.Caption := "另存为";
@ -1850,12 +1851,17 @@ type TEditer=class(TCustomcontrol) //
//FInfoShowWnd.Caption := "信息:";
////构造节点////////////////////////////////////////////////////
//FToolBar.Parent := self;
FinCodemap := new tfincodemap(self);
FinCodemap.WsSizeBox := true;
fcoolbar.arrange := "0,1";
fcoolbar.Parent := self;
FStatus.Parent := self;
FInfoShowWnd.Parent := self;
FinCodemap.Parent := self;
fcoolbar.Parent := self;
FPageEditer.Parent := self;
FCodeMap.parent := self;
//FCodeMap.parent := self;
FGotoLineWnd.Parent := self;
FFindWnd.parent := self;
FFileopen.parent := self;
@ -1885,6 +1891,7 @@ type TEditer=class(TCustomcontrol) //
begin
CreateAFile();
end
end
function PopUpAuxiliary();
begin
@ -2318,6 +2325,7 @@ type TEditer=class(TCustomcontrol) //
cp.PrePareCompletion(it.Caption);
end
EditerCaretChanged(it.FEditer,nil);
if FinCodemap then FinCodemap.ontimerdo();
end
function docloseapageitem(it);
begin
@ -2708,11 +2716,13 @@ type TEditer=class(TCustomcontrol) //
if it.ScriptPathIs(n)then return it;
end
end
function EditerCaretChanged(o,e);
function EditerCaretChanged(o,e); //caret 位置改变
begin
if GetCurrentEditer()=o then
begin
FStatus.setitemtext(format("col:%d | %s",o.CaretX,o.PageItem.EnCode),1);
if FinCodemap and FinCodemap.Visible then
FinCodemap.caretchanged(o.CaretY);
end
end
function OpenScriptByFileName(n);
@ -3095,8 +3105,13 @@ type TEditer=class(TCustomcontrol) //
end
"代码地图(alt+m)":
begin
InitShowWndPos(FCodeMap,"cm",250,100);
FCodeMap.ShowMap();
//InitShowWndPos(FCodeMap,"cm",250,100);
//FCodeMap.ShowMap();
if FinCodemap and not(FinCodemap.Visible) then
begin
FinCodemap.doshow(true);
end
end
end
end
@ -3112,21 +3127,24 @@ type TEditer=class(TCustomcontrol) //
function DoControlAlign();override; // 对齐
begin
if not(FPageEditer and FPageEditer.parent=self) then return;
rr := ClientRect;
r := rr;
codemapin := false;
if FinCodemap and not(FinCodemap.WSpOPUp)and FinCodemap.Visible and FinCodemap.Parent=self then
begin
codemapin := min(FinCodemap.Width,integer(r[2] * 0.5));
//FinCodemap.SetBoundsRect(r);
end
if fcoolbar.Parent = self then
begin
htoolbar := true;
end
if htoolbar then
begin
//th := FToolbar.CalcHeightFixWidth(rr[2]-rr[0]);
//r[3]:= r[0]+th;
//FToolBar.SetBoundsRect(r);
fcoolbar.DoControlAlign();
r[3]:= r[0]+fcoolbar.Height;
r[0]+=codemapin+2;
fcoolbar.SetBoundsRect(r);
end
r := rr;
@ -3138,26 +3156,21 @@ type TEditer=class(TCustomcontrol) //
rr[1]:= fcoolbar.Height+1;
end
rr[3]:= rr[3]-FStatus.Height-1;
{if ffolderdlg and ffolderdlg.Visible then
begin
r := rr;
fwd := min(ffolderdlg.Width,integer(r[2] * 0.6));
r[2] := r[0]+fwd;
rr[0] := r[2]+1;
ffolderdlg.SetBoundsRect(r);
end }
if FInfoShowWnd.Visible and not(FInfoShowWnd.WSpOPUp)then
begin
r := rr;
r[1]:= r[3]-min(FInfoShowWnd.Height,integer(r[3] * 0.8)); //0.6 靠扩大到 0.8
rr[3]:= r[1]-1;
{fwd := min(FInfoShowWnd.Width,integer(r[2] * 0.6)); //ÓÒ²à
r[0] := r[2]-fwd;
rr[2] := r[0]-1;}
FInfoShowWnd.SetBoundsRect(r);
end
if codemapin then
begin
r := rr;
r[1] := 1;
r[2] := codemapin;
rr[0] := codemapin+2;
FinCodemap.SetBoundsRect(r);
end
FPageEditer.SetBoundsRect(rr);
end
function CreateAFile(); //构造文件
@ -3337,8 +3350,12 @@ type TEditer=class(TCustomcontrol) //
end
ord("M"):
begin
InitShowWndPos(FCodeMap,"cm",250,100);
FCodeMap.ShowMap();
//InitShowWndPos(FCodeMap,"cm",250,100);
//FCodeMap.ShowMap();
if FinCodemap and not(FinCodemap.Visible) then
begin
FinCodemap.doshow(1);
end
e.skip := true;
return true;
end
@ -3422,6 +3439,7 @@ type TEditer=class(TCustomcontrol) //
begin
it.FEditer.ChangedFlag := true;
end
if FinCodemap then FinCodemap.ontimerdo();
return true;
end
end
@ -3561,7 +3579,7 @@ type TEditer=class(TCustomcontrol) //
FOnPageEditerChanged := nil;
fOnPageItemSelChanged := nil;
FListPages := nil;
FCodeMap := nil;
FinCodemap := nil;
FEchoWnd := nil;
FFindListWnd := nil;
FTempPageItem := nil;
@ -4095,7 +4113,8 @@ type TEditer=class(TCustomcontrol) //
FToolbar;
FStatus;
FInfoShowWnd;
FCodeMap;
//FCodeMap;
FinCodemap;
FListPages;
FFindWnd;
FFindListWnd;
@ -4833,7 +4852,278 @@ type TEditerEchoWnd=class(TSynMemoNorm) //
FDoLockTime;
F_Highlighter;
end
type tfincodemap = class(tcustomcontrol)
function create(AOwner);
begin
inherited;
Visible := false;
FTempNodes := array();
Width := 230;
Ftimer := new TTimer(self);
Ftimer.Interval := 200;
Ftimer.Ontimer := thisfunction(BdownTimeOut);
Ftimer.Enabled := false;
FList := new TCombobox(self);
flist.Width := 180;
ar := array("Class","Function","Statements","If","Else","SubCase","Goto","Try","Empty_Begin_End","NeedSql","Unit","property","Member");
flist.Multisel := true;
FList.AppendItems(ar);
flist.ItemIndex := 0->(length(ar)-1);
FList.Parent := self;
initbtn();
FTree := new TTreeView(self);
FTree.OnSelChanged := thisfunction(SynNodeSelected);
FTree.Parent := self;
end
function caretchanged(y);
begin
if fisloading then return ;
fissetnode := true;
GoToTheNode(y);
fissetnode := false;
end
function DoControlAlign();override;
begin
if FList and fcbtn and FTree and ffbtn then
begin
rr := ClientRect;
ffbtn.left := 1;
r := rr;
r[0] := 25;
r[2] := min(200,r[2]-55);
r[3] := 25;
FList.SetBoundsRect(r);
fcbtn.left := rr[2]-25;
r := rr;
r[1]:= 27;
r[0]:=1;
r[2]:=r[2]-3;
FTree.SetBoundsRect(r);
end
end
function doshow(f); //显示
begin
st := f?true:false;
Visible := st;
BdownTimeOut();
if st then
begin
ontimerdo();
//FTree.SetFocus();
end
end
function SynNodeSelected(o,e);
begin
if fisloading then return ;
if fissetnode then return ;
edt := geteditor();
if not edt then return;
nd := FTree.CurrentNode;
if not nd then return ;
line := nd._tag;
if line>0 then
begin
edt.ExecuteCommand(edt.ecGoToXY,array(line,1));
end
end
function hasFocus();override;
begin
return true;
end
function ontimerdo(o,e);
begin
{ 代码块快类型
#define Block_TypeClass 1
#define Block_Function 2
#define Block_Statements 4
#define Block_If 8
#define Block_Else 16
#define Block_SubCase 32
#define Block_Goto_Label 64
#define Block_Empty_Begin_End 128
#define Block_Try 256
#define Block_NeedSql 512
#define Block_UnitStruct 1024
}
// 处理逻辑
//定时器中重算节点,如果发生改变,并定位节点到当前行位置
//行位置变化,=== 定位到节点
//节点选中定位到 编辑器
//if Parent then o.Enabled := false;
if not Visible then return ;
if not FTree then return ;
edt := geteditor();
nd := FTree.RootNode;
if not edt then return nd.RecyclingChildren();
y := edt.CaretY;
s := edt.Text;
if FString = s then //文本没变
begin
if flistv=getblocktypes() then //类型没变
begin
return ;
end
end else
FString := s;
flistv := getblocktypes();
if s then r := tsl_tokenizeex_2_(s,flistv);
else r := array();
fisloading := true;
nd.RecyclingChildren();
FTempNodes := array();
ScriptDelBlocks(r["blcks"],str2array(s,"\r\n"),nd,0);
GoToTheNode(y);
fisloading := false;
end
function WMNCLBUTTONDOWN(o,e):WM_NCLBUTTONDOWN;override;
begin
FIgnoreSize := true;
Ftimer.Enabled := true;
end
function BdownTimeOut(o,e); //定时器处理
begin
if(_wapi.GetAsyncKeyState(VK_LBUTTON).& 0xFF00)>0 then
begin
end else
begin
FIgnoreSize := false;
Ftimer.Enabled := false;
p := Parent;
if p then p.DoControlAlign();
end
end
private
function GoToTheNode(line);
begin
nd := FTempNodes[0];
for i,v in FTempNodes do
begin
if v._tag <= line then
begin
nd := v;
end else
if v._tag >= Line then
begin
FTree.SetSel(nd);
break;
end
end
end
function ScriptDelBlocks(blcks,strs,Node,ct);
begin
if not blcks then return;
for i,v in blcks do
begin
if v["mtype"]<> 1 then
begin
cnd := FTree.CreateTreeNode();
cnd.Caption := trim(strs[v["mbeg"]-1]);
cnd._tag := v["mbeg"];
FTempNodes[length(FTempNodes)]:= cnd;
cnd.parent := node;
end
if not cnd then cnd := node;
ScriptDelBlocks(v["msub"],strs,cnd,ct+1);
end
end
function getblocktypes();
begin
r := 0;
for i,v in FList.itemindex do
begin
r += 2^v;
end
return r;
end
function initbtn();
begin
fcbtn := new TBtn(self);
fcbtn.OnClick := function(o,e)
begin
doshow(0);
end
fcbtn.Caption := "";
fcbtn.top := 3;
fcbtn.Width := 20;
fcbtn.Height := 20;
fcbtn.Parent := self;
s := "0502000000060400000074797065000203000000696D670006040000006461746
10002C401000089504E470D0A1A0A0000000D4948445200000014000000140806
0000008D891D0D000000017352474200AECE1CE90000000467414D410000B18F0
BFC6105000000097048597300000EC300000EC301C76FA8640000015949444154
384F9D9431CA83401085F7625E21E015BC8156D639809D95AD36C142248568ED0
93C8277B0B0D99F4F32B2EB8EE1270F1EAC3B6FBE85901963156DDB66C771B455
55D93CCF6D1CC7873973478D8CA600B82C8B4D92C44651F4D564C85EE501BBAE5
39BBF991E5727709E67B5E13FA6577400D775F502455178DF9AAF19180770DF77
9BA6A917444DD3780DAEA921170A03961986C10B636968DB36A87187B4076199B
22C830296C6F7FB7DDE7146DA431896C9B24C2D6201F0BFC3C87DE06A58E6F178
A845B18010672D2386659800AD289EA6E983B3C759CB886119C6492BE2BEEF4F9
080B9D3B218966136B5E2EBF50A00F20035372B8665B4DFA5AEEBDB467988CCB5
06CBB035DC65F07C3E6F1BC4F22059B98301EB183DB686DBE006EF7CCDC8E6399
7C32F9B46EC6E1C6F7DFDB271DC4D833C20626BB8CBE2CE6464C3B80A8088ADC1
A0339B8C1313803973478D4C286BFF00D135DFBA6F19E4A90000000049454E44A
E42608200";
bmp := new TBitmap();
bmp.ReadVcon(HexformatStrToTsl(s));
fcbtn.BKBitmap := bmp;
ffbtn := new TBtn(self);
ffbtn.OnClick := function(o,e)
begin
//doshow(1);
ontimerdo();
end
ffbtn.Caption := "";
ffbtn.top := 3;
ffbtn.Width := 20;
ffbtn.Height := 20;
ffbtn.Parent := self;
s := "0502000000060400000074797065000203000000696D670006040000006461746
100029C01000089504E470D0A1A0A0000000D4948445200000014000000140806
0000008D891D0D000000017352474200AECE1CE90000000467414D410000B18F0
BFC6105000000097048597300000EC300000EC301C76FA8640000013149444154
384FBD940D8D834010464F10064000064000180001200004A0000318000128C00
0063030CD9B63B62D85CB5ED3F42513C8EEEC373F3BF0231FE67B82EBBA4ADBB6
92A6A90441A0C67B5DD732CFF3EEF5CAA960DFF72A1086A15455255DD7A9F11EC
7B1EE956529DBB6ED27EE3C099215360C83DAD9012020C1C8F8E8A382E338BAD2
78FAB02C8B8AE679BEAFFCA2824551489224AE5764E90355E0FFD85357323D222
23DC2D117FC49C87082599669D3C9EEAA7767344DA3591A4E9045B2FC2F9CF98E
209742D9BE585B6C360D2768BDF0BD6184B88C63654E102136F9027CB091C1984
51375826059F2BDFAC098E14FAB18747812044AB1A8D334EDAB7758638FE00CF4
B1452F8240FA163D8A221578FCEBB07735FCA782C02D7288C653920D3E6B7F0DF
EA5E0BB7C5850E4063EDA83420076B5E10000000049454E44AE42608200";
bmp := new TBitmap();
bmp.ReadVcon(HexformatStrToTsl(s));
ffbtn.BKBitmap := bmp;
end
function geteditor();
begin
if not owner then return 0;
it := Owner.GetCurrentItem();
edit := it.FEditer;
if not edit then return 0;
m := edit.HighLighter ;
if not(m is class(TTslSynHighLighter)) then
begin
return 0;
end
return edit;
end
fissetnode;
fisloading;
ffbtn;
FTempNodes; //节点
FTree;
fcbtn;
FList;
flistv;
Ftimer;
Ftimer2;
FString;
end
(*
type TTslCodeMap=class(TTreeView) //tsl代码地图
function Create(AOwner);
begin
@ -4971,7 +5261,7 @@ type TTslCodeMap=class(TTreeView) //tsl
FTempNodes; //节点
FString; //字符串
FTreeEditer; //编辑框
end
end *)
type TListPages=class(TListBox)
function Create(AOwner);override;
begin
@ -5026,7 +5316,7 @@ type TListPages=class(TListBox)
SetYpos(1+GetYPos()+(rc[3]-c[3]+1)/GetYScrollDelta());
end
end
function GetSelFileName;
function GetSelFileName();
begin
r := GetItem(getCurrentSelection());
if pos("*",r)then

View File

@ -6164,12 +6164,12 @@ type tgtk_ctl_scroll_window = class(tgtk_ctl_object)
scrlsize := 12;
if (fbarshow .& 1)=1 then //v
begin
_wapi.gtk_widget_set_size_request(FHscrollbar,w-scrlsize,scrlsize);
end else _wapi.gtk_widget_set_size_request(FHscrollbar,w,scrlsize);
_wapi.gtk_widget_set_size_request(FHscrollbar,max(0,w-scrlsize),scrlsize);
end else _wapi.gtk_widget_set_size_request(FHscrollbar,max(0,w),scrlsize);
if (fbarshow .& 2)=2 then //h
begin
_wapi.gtk_widget_set_size_request(Fvscrollbar,scrlsize,h-scrlsize);
end else _wapi.gtk_widget_set_size_request(Fvscrollbar,scrlsize,h);
_wapi.gtk_widget_set_size_request(Fvscrollbar,scrlsize,max(0,h-scrlsize));
end else _wapi.gtk_widget_set_size_request(Fvscrollbar,scrlsize,max(0,h));
_wapi.gtk_layout_move( FLayouter,FHscrollbar,0,h-scrlsize);
_wapi.gtk_layout_move( FLayouter,Fvscrollbar,w-scrlsize,0);
if FClientWideget then
@ -6182,7 +6182,7 @@ type tgtk_ctl_scroll_window = class(tgtk_ctl_object)
begin
w-=11;
end
_wapi.gtk_widget_set_size_request(FClientWideget,w,h);
_wapi.gtk_widget_set_size_request(FClientWideget,max(0,w),max(0,h));
//inherited widgetsizechanged(h,w);
end //else inherited widgetsizechanged(h,w);
inherited widgetsizechanged(h,w); //clientrect

View File

@ -2265,7 +2265,7 @@ implementation
function iffuncptr(fn);
begin
//return datatype(fn)=7;
return ifobj(fn);
return fn and ifobj(fn);
end
function includestate(u,s);
begin