mirror of https://gitlab.com/basile.b/dexed.git
added ICEMainMenuProvider to custom tools
This commit is contained in:
parent
6262ac9802
commit
7a23e84828
|
@ -5,7 +5,7 @@ unit ce_tools;
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileUtil, process, asyncprocess,
|
Classes, SysUtils, FileUtil, process, asyncprocess, menus,
|
||||||
ce_common, ce_writableComponent, ce_interfaces, ce_observer;
|
ce_common, ce_writableComponent, ce_interfaces, ce_observer;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -38,11 +38,15 @@ type
|
||||||
procedure execute;
|
procedure execute;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TCETools = class(TWritableComponent)
|
TCETools = class(TWritableComponent, ICEMainMenuProvider)
|
||||||
private
|
private
|
||||||
fTools: TCollection;
|
fTools: TCollection;
|
||||||
function getTool(index: Integer): TCEToolItem;
|
function getTool(index: Integer): TCEToolItem;
|
||||||
procedure setTools(const aValue: TCollection);
|
procedure setTools(const aValue: TCollection);
|
||||||
|
//
|
||||||
|
procedure menuDeclare(item: TMenuItem);
|
||||||
|
procedure menuUpdate(item: TMenuItem);
|
||||||
|
procedure executeToolFromMenu(sender: TObject);
|
||||||
published
|
published
|
||||||
property tools: TCollection read fTools write setTools;
|
property tools: TCollection read fTools write setTools;
|
||||||
public
|
public
|
||||||
|
@ -126,17 +130,63 @@ begin
|
||||||
inherited;
|
inherited;
|
||||||
fTools := TCollection.Create(TCEToolItem);
|
fTools := TCollection.Create(TCEToolItem);
|
||||||
fname := getDocPath + toolsFname;
|
fname := getDocPath + toolsFname;
|
||||||
if fileExists(fname) then loadFromFile(fname)
|
if fileExists(fname) then loadFromFile(fname);
|
||||||
|
//
|
||||||
|
EntitiesConnector.addObserver(self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TCETools.destroy;
|
destructor TCETools.destroy;
|
||||||
begin
|
begin
|
||||||
|
EntitiesConnector.removeObserver(self);
|
||||||
|
//
|
||||||
forceDirectory(getDocPath);
|
forceDirectory(getDocPath);
|
||||||
saveToFile(getDocPath + toolsFname);
|
saveToFile(getDocPath + toolsFname);
|
||||||
fTools.Free;
|
fTools.Free;
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCETools.executeToolFromMenu(sender: TObject);
|
||||||
|
begin
|
||||||
|
TCEToolItem(TMenuItem(sender).tag).execute;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCETools.menuDeclare(item: TMenuItem);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
itm: TMenuItem;
|
||||||
|
begin
|
||||||
|
if tools.Count = 0 then exit;
|
||||||
|
//
|
||||||
|
item.Caption := 'Custom tools';
|
||||||
|
item.Clear;
|
||||||
|
for i := 0 to tools.Count-1 do begin
|
||||||
|
itm := TMenuItem.Create(item);
|
||||||
|
itm.Caption := tool[i].toolAlias;
|
||||||
|
itm.tag := ptrInt(tool[i]);
|
||||||
|
itm.onClick := @executeToolFromMenu;
|
||||||
|
item.add(itm);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCETools.menuUpdate(item: TMenuItem);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
if item = nil then exit;
|
||||||
|
if item.Count <> tools.Count then
|
||||||
|
begin
|
||||||
|
menuDeclare(item);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
for i:= 0 to tools.Count-1 do
|
||||||
|
begin
|
||||||
|
if ptrInt(tool[i]) <> item.Items[i].Tag then
|
||||||
|
item.Items[i].Tag := ptrInt(tool[i]);
|
||||||
|
if item.Items[i].Caption <> tool[i].toolAlias then
|
||||||
|
item.Items[i].Caption := tool[i].toolAlias;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCETools.setTools(const aValue: TCollection);
|
procedure TCETools.setTools(const aValue: TCollection);
|
||||||
begin
|
begin
|
||||||
fTools.Assign(aValue);
|
fTools.Assign(aValue);
|
||||||
|
|
Loading…
Reference in New Issue