编辑器

修复
This commit is contained in:
JianjunLiu
2023-05-22 15:36:07 +08:00
parent d71f0753f1
commit 7f8ea00181
15 changed files with 970 additions and 702 deletions
@@ -0,0 +1,80 @@
object extcompclassadder:textcompclassadder
caption="添加"
height=406
left=474
minmaxbox=false
onclose=extcompclassadder_close
top=316
width=402
wssizebox=false
object e_classname:tedit
caption="edit1"
height=25
left=91
readonly=true
top=28
width=255
end
object label1:tlabel
left=20
top=28
width=50
height=25
caption="控件类"
end
object b_classfile:tbtn
caption="..."
height=24
left=354
onclick=b_classfile_clk
top=29
width=21
end
object label2:tlabel
left=20
top=72
width=64
height=25
caption="图标"
end
object p_imgshow:tpanel
caption="img"
height=187
left=91
top=120
width=245
wsdlgmodalframe=false
end
object b_img:tbtn
caption="添加图标"
height=25
left=91
onclick=b_img_clk
top=73
width=94
end
object b_ok:tbtn
caption="确定"
enabled=true
height=31
left=133
onclick=b_ok_clk
top=317
width=72
end
object b_cancel:tbtn
caption="取消"
height=31
left=283
onclick=b_cancel_clk
top=317
width=73
end
object f_open:topenfileadlg
left=22
top=146
height=30
width=30
caption="文件选择"
end
end
@@ -0,0 +1,64 @@
object extcompclassmgr:textcompclassmgr
caption="注册控件-管理"
height=467
left=447
minmaxbox=false
onclose=extcompclassmgr_close
top=272
width=477
wssizebox=true
object listbox1:tlistbox
caption="listbox1"
height=345
left=4
onselchanged=listbox1_sel
top=38
width=344
end
object b_del:tbtn
caption="删除"
enabled=false
height=31
left=364
onclick=b_del_clk
top=248
width=88
end
object b_add:tbtn
caption="添加"
height=31
left=364
onclick=b_add_clk
top=299
width=88
end
object b_ok:tbtn
caption="完成"
height=31
left=364
onclick=b_ok_clk
top=346
width=88
wssizebox=false
wssysmenu=false
end
object statusbar1:tstatusbar
caption="statusbar1"
height=25
items= [<
width=500
text="控件管理"
>
]
left=0
top=403
width=461
end
object label1:tlabel
left=8
top=10
width=80
height=25
caption="控件列表"
end
end
+151
View File
@@ -0,0 +1,151 @@
type textcompclassadder=class(tdcreateform)
uses tslvcl;
e_classname:tedit;
label1:tlabel;
b_classfile:tbtn;
label2:tlabel;
p_imgshow:tpanel;
b_img:tbtn;
b_ok:tbtn;
b_cancel:tbtn;
f_open:topenfileadlg;
function Create(AOwner);override; //构造
begin
inherited;
end
function extcompclassadder_close(o;e);virtual;
begin
e.skip := true;
Visible := false;
EndModal(0);
inherited;
end
function b_cancel_clk(o;e);virtual;
begin
EndModal(0);
end
function b_ok_clk(o;e);virtual;
begin
s := e_classname.text;
if fclasshash and fclasshash[s] then
begin
messageboxa("该控件已经注册","提示",0,self);
return ;
end
o := findclass(s);
if not (o is class(TWinControl)) then
begin
messageboxa("组件类型错误,或者组件不存在","提示",0,self);
return ;
end
if not fbmp then
begin
messageboxa("请选择合适的图标","提示",0,self);
return ;
end
EndModal(1);
end
function b_img_clk(o;e);virtual;
begin
f_open.filter := array("图片文件":"*");
if not(f_open.OpenDlg()) then return ;
fbmp := new TBitmap();
fbmp.id := f_open.filename;
p_imgshow.BKBitmap := fbmp;
if fbmp.HandleAllocated() then return ;
fbmp := nil;
end
function b_classfile_clk(o;e);virtual;
begin
f_open.filter := array("控件类文件":"*.tsf");
e_classname.text := "";
if not(f_open.OpenDlg()) then return ;
iof := iofileseparator();
fn := f_open.filename;
nf := fn[1:length(fn)-4];
n := "";
for i:= length(nf) downto 1 do
begin
vi := nf[i];
if vi=iof then
begin
break;
end
n := vi+n;
end
ln := lowercase(n);
e_classname.text := ln;
end
function DoControlAlign();override;//对齐子控件
begin
//当窗口大小改变时,该函数会被调用,
//可以通过 clientrect 获取客户区大小,设置子控件的位置以及大小
//如果自己处理了子控件的对齐,就可以去掉 inherited
inherited;
end
function Recycling();override; //回收变量
begin
inherited;
ci := self.classinfo(); //将成员变量赋值为nil避免循环引用
for i,v in ci["members"] do
begin
if v["static"] then continue;
invoke(self,v["name"],nil);
end
end
function createdclass();
begin
ra := %% type %s =class(TDComponent)
uses utslvcldcomponents;
function create(AOwner);
begin
inherited;
end
function classification();override;
begin
return "自定义";
end
function bitmapinfo();override;
begin
return "%s";
end
function WndClass();override;
begin
return Class(%s);
end
end
%%;
r := format(ra,"td_a_"+e_classname.text,TslToHexFormatStr(fbmp.tovcon()),e_classname.text);
return r;
end
function getreginfo();
begin
r := array();
r["name"] := e_classname.text;
r["dclassname"] := "td_a_"+e_classname.text;
r["dclassbody"] := createdclass();
return r;
end
property classhash read fclasshash write setclasshash;
fclasshash;
fbmp;
private
function setclasshash(v);
begin
if v<>fclasshash then
begin
fclasshash := array();
for i,vi in v do
begin
fclasshash[vi] := true;
end
end
end
end
+97
View File
@@ -0,0 +1,97 @@
type textcompclassmgr=class(tdcreateform)
uses tslvcl;
listbox1:tlistbox;
b_del:tbtn;
b_add:tbtn;
b_ok:tbtn;
statusbar1:tstatusbar;
label1:tlabel;
function Create(AOwner);override; //构造
begin
inherited;
end
function extcompclassmgr_close(o;e);virtual;
begin
{**
@explan(说明) 主窗口关闭回调 %%
@param(e)(tuievent) 消息对象 %%
@param(o)(ttimer) 当前主窗口 %%
**}
e.skip:= true;
Visible := false;
inherited;
end
function b_ok_clk(o;e);virtual;
begin
Visible := false;
end
function b_del_clk(o;e);virtual;
begin
idx := listbox1.ItemIndex;
if idx>=0 and parent then
begin
p := parent;
p.delexttypeclass(listbox1.getItemText(idx));
relisttypeclass();
end
end
function b_add_clk(o;e);virtual;
begin
if not fadder then
begin
fadder := new textcompclassadder(self);
fadder.Visible := false;
fadder.parent := self;
fadder.Left := left-10;
fadder.top := top-10;
end
fadder.classhash := ftypelist;
if fadder.ShowModal() then
begin
//echo tostn(fadder.getreginfo());
p := parent;
if p then
begin
p.addexttypeclass(fadder.getreginfo());
end
relisttypeclass();
end
end
function relisttypeclass();
begin
p := parent;
if p then
begin
ts := p.getexttypeclass();
r := array();
idx := 0;
for i,v in ts do
begin
r[idx++] := v.dclassname();
end
if r<>ftypelist then
begin
listbox1.Items := r;
ftypelist := r;
end
end
end
function showmgr();
begin
relisttypeclass();
show();
end
function listbox1_sel(o;e);virtual;
begin
idx := o.ItemIndex;
if idx>=0 then
begin
b_del.Enabled := true;
end
end
[weakref]fdesginer;
ftypelist;
end
+10
View File
@@ -78,3 +78,13 @@ function PostMessageA(hWnd:pointer;Msg:integer;wParam:pointer;lParam:pointer):in
function FindWindowA(lpClassName:string;lpWindowName:string):pointer;stdcall;external "User32.dll" name "FindWindowA";//引入api
{$endif}
function getdcompath();
begin
{$ifdef linux}
bpath := ".vcl/tsl/";
{$else}
bpath := TS_GetUserProfileHome();
{$endif}
return bpath+"designer"+ioFileseparator()+"dcmps"+ioFileseparator();
end
+175 -45
View File
@@ -21,6 +21,7 @@ type TVclDesigner = class(tvcform)
FChmHelper; //帮助文档
fdimagelist; //图标
FViewBitmap; //图片管理器
fmgr_ctl;//控件管理
FVariableSelecter; //当前控件树的变量
FFunctionSelecter; //当前控件树的函数
//**********菜单***************
@@ -69,20 +70,27 @@ type TVclDesigner = class(tvcform)
**}
for i,v in class(TDComponent).GetClassItem() do
begin
fdimagelist.RegisterDitem(v);
//if not v.InToolBar() then continue;
tb := new TToolButton(self);
tb.caption := v.HitTip;
tb.Enabled := v.InToolBar();
ig := fdimagelist.GetImageId(V.dclassname);
tb.imageid := ig;
v.Imgs := ig;
tb._tag := v;
tb.onclick := thisfunction(OnToolButtonCick);
FToolBars.addbtn(tb,v.classification);
addaboolbutton(v);
end
end
function addaboolbutton(v);
begin
fdimagelist.RegisterDitem(v);
//if not v.InToolBar() then continue;
tb := new TToolButton(self);
tb.caption := v.HitTip;
tb.Enabled := v.InToolBar();
ig := fdimagelist.GetImageId(V.dclassname);
tb.imageid := ig;
v.Imgs := ig;
tb._tag := v;
tb.onclick := thisfunction(OnToolButtonCick);
FToolBars.addbtn(tb,v.classification);
end
function delttolbutton(n);
begin
FToolBars.delbtn(n);
end
function calcheight(twidth); //高度计算
begin
//extheight := CaptionHeight()+MenuBarHeight();
@@ -495,6 +503,7 @@ type TVclDesigner = class(tvcform)
)),
("type":"menu","caption":"工具","items":(
("type":"menu","caption":"控件管理","checked":0,"onclick":thisfunction(mgr_control)),
("type":"menu","caption":"打开图片","checked":0,"onclick":thisfunction(ViewBitmap)),
("type":"menu","caption":"编辑器颜色","checked":0,"onclick":thisfunction(showhltcolor))
)),
@@ -1095,6 +1104,40 @@ type TVclDesigner = class(tvcform)
end
end
end
public //类型注册相关
function addexttypeclass(info);//注册额外的类
begin
addextdtypeclass(info["dclassname"],info["dclassbody"]); //添加容器类
addexttypeclasstoini(info["name"],info["dclassname"]);//添加ini文件
fwilladdclasstype := info["dclassname"];
fwilladdclass := info["name"];
dc := findclass(fwilladdclasstype);
if not dc then return ;
addexttypeclasscomp(dc);
it := class(TDComponent).GetClassItemext(fwilladdclass);
if not it then return ;
addaboolbutton(it);
//name
//class
//dclassbody
//添加类型
//添加工具栏
end
function delexttypeclass(n);//删除注册类
begin
delexttypeclassini(n);//移除ini文件
delexttypeclasscomp(n);//移除类型
delttolbutton(n);//移除工具栏
end
function getexttypeclass(n);//获得注册类列表
begin
r:= class(TDComponent).GetClassItemext(n);
return r;
end
public //加载以及处理
function ExecuteCommand(cmd,p);override;
begin
@@ -1270,7 +1313,6 @@ type TVclDesigner = class(tvcform)
function create(AOwner);
begin
inherited;
top := 10;
left := 10;
rect := _wapi.GetScreenRect();
@@ -1406,6 +1448,18 @@ type TVclDesigner = class(tvcform)
begin
FProjectManager.showhltcolor();
end
function mgr_control();
begin
if not fmgr_ctl then
begin
fmgr_ctl := new textcompclassmgr(self);
fmgr_ctl.visible:= false;
fmgr_ctl.left := left+300;
fmgr_ctl.top := top+300;
fmgr_ctl.parent := self;
end
fmgr_ctl.showmgr();
end
function ViewBitmap(o,e);
begin
if not FViewBitmap then
@@ -1743,6 +1797,7 @@ type TDesignertoolbars = class(TPageControl) //
function Create(AOwner);override;
begin
inherited;
ftbs := array();
align := alClient;
FToolbars := array();
Flabelcharlen := 0;
@@ -1802,9 +1857,17 @@ type TDesignertoolbars = class(TPageControl) //
tb.imagelist := fimg;
FToolbars[t] := tb;
end
ftbs[btn._tag.dclassname()] := btn;
btn.parent := tb;
end
function delbtn(n);
begin
btn := ftbs[n];
if btn then btn.Recycling();
end
property ImageList write SetImageList;
private
[weakref]ftbs;
end
@@ -1918,45 +1981,112 @@ type TViewBitmap = class(TvcForm)
end
end
type tdcompextmgr = class()
function create(AOwner);
begin
fini := new TIniFileExta("",ffile);
end
function getcomplist();
begin
class(TDComponent).GetClassItemext();
end
function addclass(f)
begin
end
private
fini;
ffile ;
end
function getdesignerpath();
begin
{$ifdef linux}
bpath := ".vcl/tsl/";
{$else}
bpath := TS_GetUserProfileHome();
{$endif}
return bpath+"designer"+ioFileseparator();
end
function getdesginerini();
begin
vclini := static getdesignerpath()+"tslvcldesigner.ini";
CreateDirWithFileName(vclini);
ini := new TIniFileExta("",vclini);
ini.LowerKey := true;
return ini;
end
function addextdtypeclass(n,body);
begin
dir := static getdesignerpath()+"dcmps"+ioFileseparator();
nf := dir+n+".tsf";
CreateDirWithFileName(nf);
filedelete("",nf);
len := length(body);
p := 0;
writefile(rwraw(),"",nf,p,len,body);
end
function addexttypeclasstoini(n,dn);
begin
ini := static getdesginerini();
ini.WriteKey("components",n,dn);
end
function delexttypeclassini(n);
begin
ini := static getdesginerini();
kn := ini.ReadKey("components",n,"");
ini.DeleteKey("components",n);
if kn then
begin
dir := static getdesignerpath()+"dcmps"+ioFileseparator();
nf := dir+kn+".tsf";
filedelete("",nf);
end
end
function addexttypeclasscomp(cmp);
begin
class(TDComponent).RegestorClassItemsext(array(cmp));
end
function delexttypeclasscomp(n);
begin
class(TDComponent).unregestorclassitemsext(n);
end
function staticInit();
begin
np := getdesignerpath()+"dcmps"+ioFileseparator();
CreateDirWithFileName(np+"1.txt");
tsl_setlibpath_( np+";"+tsl_getlibpath_());
ini := static getdesginerini();
//class(TDSocketServer),class(TDSocketClient),
//注册的componet
vclini := pluginpath()+"tslvcldesigner.ini";
if fileexists("",vclini) then
//注册的componet
its := array();
for i,v in ini.ReadSectionValues("components") do //控件
begin
ini := new TIniFileExta("",vclini);
ini.LowerKey := true;
its := array();
for i,v in ini.ReadSectionValues("components") do //控件
if v then
begin
if v then
cv := findclass(v);
if cv then
begin
cv := findclass(v);
if cv then
begin
its[length(its)] := cv;
end
end
end
o := class(TDComponent);
o.RegestorClassItems(its);
its := array();
o := class(TPropGrid);
for i,v in ini.ReadSectionValues("properties") do //属性
begin
if v then
begin
cv := findclass(v);
if cv then
begin
it := createobject( cv,0);
o.RegCellRender(it);
end
end
its[length(its)] := cv;
end
end
end
end
o := class(TDComponent);
o.RegestorClassItemsext(its);
its := array();
o := class(TPropGrid);
for i,v in ini.ReadSectionValues("properties") do //属性
begin
if v then
begin
cv := findclass(v);
if cv then
begin
it := createobject( cv,0);
o.RegCellRender(it);
end
end
end
end
////5108321
initialization
+88 -1
View File
@@ -649,6 +649,92 @@ type TProjectView = class(TVCForm) //
RenameCurrentDir(FInput.GetEditV(1));
end
end
function add_exist(); //添加
begin
if not FCProjectPath then return Messageboxa("工程没打开","提示",0,self);
if not ffileadder then
begin
ffileadder := new TOpenFileADlg(self);
ffileadder.parent := self;
end
if not ffileadder.OpenDlg() then return ;
fn := ffileadder.filename;
if 1=parseregexpr("(.+)(\\W)(\\w+)\\.tsl$",fn,"",m,mp,ml) then
begin
//return "add tsl";
addexisttsl(m);
end
if 1=parseregexpr("(.+)(\\W)([A-Za-z]\\w+)\\.tsf$",fn,"",m,mp,ml) then
begin
//return "add tsf";
addexisttsf(m);
end
//
end
function addexisttsl(m);
begin
//检查变量名是否合规
//拷贝文件
//添加信息
end
function addexisttsf(m,cnd);
begin
//检查变量名是否合规
c_n := lowercase(m[0,3]);
if FTree.NameInTree(c_n,nil,true)then return MessageboxA("已经存在同名的文件","提示",0,self);
if cnd then
begin
ph := cnd.FPath;
end else
begin
ph := FTree.CurrentNode.FPath;
end
fn := array("name":n,"type":"tsf","dir":ph);
if fileexists("",m[0,1]+m[0,2]+m[0,3]+".tfm") then
begin
pr := new ttslscripparser();
pr.ScriptPath := m[0,0];
abt := pr.GetClassAbstract();
if abt and (lowercase(abt["name"]) = c_n) then
begin
hi := abt["inherited",0];
if ifstring(hi) then
begin
case lowercase(hi) of
"tdcreatepanel":
begin
end
"tdcreateform":
begin
end else
begin
ns := array();
FTree.GetNodesByName(ns,hi) ;
for i,v in ns do
begin
if lowercase(v.Fname)=hi then
begin
return ;
end
end
end
end
end
end
end
//添加普通tsf文件
end
function Add_form();
begin
if not FCProjectPath then return Messageboxa("工程没打开","提示",0,self);
@@ -1817,6 +1903,7 @@ end
end
private //私有成员变量
FWrapFolder;
ffileadder;
FDesigner;
FCurrentOpend;
FOpenProjectFile;
@@ -2056,7 +2143,7 @@ type TDesignerProjectsRecoder = class() //
function Create();
begin
{$ifdef linux}
bpath := ".vcl/tsl/";
bpath := ".vcl/tsl/";
{$else}
bpath := TS_GetUserProfileHome();
{$endif}
+32 -20
View File
@@ -12,6 +12,11 @@ type TDComponent = class()
if ifnil(n) then return fdcomponentobjects;
return fdcomponentobjects[n];
end
class function GetClassItemext(n);
begin
if ifnil(n) then return fdcomponentobjectsext;
return fdcomponentobjectsext[n];
end
class function RegestorClassItems(its);
begin
{**
@@ -33,10 +38,36 @@ type TDComponent = class()
end
end
end
class function RegestorClassItemsext(its);
begin
if not ifarray(fdcomponentobjectsext) then fdcomponentobjectsext := array();
if not ifarray(fdcomponentobjects) then fdcomponentobjects := array();
for i,v in its do
begin
if (v is class(TDComponent) ) then
begin
o := createobject(v);
n := o.dclassname();
if n and ifstring(n) then
begin
n := lowercase(n);
if fdcomponentobjects[n] then continue;
fdcomponentobjectsext[n] := o;
fdcomponentobjects[n]:= o;
end
end
end
end
class function unregestorclassitemsext(n);
begin
if not fdcomponentobjectsext then return 0;
reindex(fdcomponentobjectsext,array(n:nil));
end
private
fisiherted;
finheritedparent;
static fdcomponentobjects;
static fdcomponentobjectsext;
protected
fiscontainerdcmp;
fcomponentclassname;
@@ -3640,25 +3671,6 @@ type TDTabSheet = class(TDComponent)
inherited;
end
end
type tdtabctl = class(TDComponent)
function HitTip();override;
begin
return inherited;
end
function bitmapinfo();override;
begin
return gettabctlbitmapinfo();
end
function WndClass();override;
begin
return Class(ttabctl);
end
function Create(AOwner);override;
begin
inherited;
end
end
type TDPage = class(TDComponent)
function HitTip();override;
begin
@@ -3725,7 +3737,7 @@ begin
class(TDForm),class(TDPanelForm),
class(TDPanel),class(TDGroupBox),
class(TDPairSplitter),class(TDPairSplitterSide),
class(tdtabctl),class(TDPage),class(TDTabSheet),
class(TDPage),class(TDTabSheet),
class(TDTimer),
class(tdworkerctl),
class(TDImageList),
+1 -18
View File
@@ -72,7 +72,6 @@ function gettoolbarbitmapinfo();
function getlabelbitmapinfo();
function getlistviewbitmapinfo();
function getgridctlbitmapinfo();
function gettabctlbitmapinfo();
implementation
function getexamplesbmpinfo();
begin
@@ -1477,21 +1476,5 @@ BFC6105000000097048597300000EC300000EC301C76FA864000000A849444154
12E4B502CC89C700EAB666231483F3AA0AF0F4080A6710003344D453040D37C80
0EF0594008906401B620220406970F686A01C850644C2C20CA024A008D2DF8FF1
F0006015AA04B38837B0000000049454E44AE42608200";
end
function gettabctlbitmapinfo();
begin
return "0502000000060400000074797065000203000000696D670006040000006461746
100025F01000089504E470D0A1A0A0000000D4948445200000014000000140806
0000008D891D0D000000017352474200AECE1CE90000000467414D410000B18F0
BFC6105000000097048597300000EC300000EC301C76FA864000000F449444154
384FD595A10E84301044EF93F9051CC18244D460B120B128122C966FC0F6F236E
CD123A55072E626D96C774A67A785949731C62649E28D711C6D2C5E2CCCB2CCB6
6D2BD1759D64152DCBF276B04E04191CC1033EC1B346CA07057D3C3B60EE088EE
7A782F33C5F0BEA1C811001E7E3790F4141757237B4D1A9602CD4FD9F0852B8A0
41DFF736CF733B4D938CAF1074B8AEAB08354DB3313BE09765D9AA1D41878026C
3306CD50E78BEB923820E415555B210376CB9AE6BE18BA290466417970ED33495
8C20DBD45A33E7EB22E810017875E73A24E3FC781C970E631174F8045F82EE05F
B343E9743E817101BC618FB068D943D91A4D430F90000000049454E44AE426082
00";
end
end
end.