handle external deletion of menuitems; note: deleting "root" menu item will cause a crash still

git-svn-id: trunk@9628 -
This commit is contained in:
micha 2006-07-18 14:14:05 +00:00
parent e07af6a39f
commit 88558ed640

View File

@ -101,6 +101,8 @@ type
fDesignerPopupMenu: TPopupMenu;
TemplateMenuForm: TTemplateMenuForm;
function GetDesigner: TComponentEditorDesigner;
protected
procedure PersistentDeleting(APersistent: TPersistent);
public
// Constructor and destructor
constructor CreateWithMenu(aOwner: TComponent; aMenu: TMenu);
@ -284,8 +286,10 @@ begin
// designermenuitem
GlobalDesignHook.AddHandlerModified(@OnDesignerModified);
//GlobalDesignHook.AddHandlerPersistentAdded(@OnComponentAdded);
GlobalDesignHook.AddHandlerPersistentDeleting(@PersistentDeleting);
new(Root);
fillchar(root^, sizeof(root^), #0);
fMenu:=aMenu;
@ -377,7 +381,7 @@ begin
GetDesigner.PropertyEditorHook.PersistentAdded(firstmenuitem, true);
GetDesigner.Modified;
end;
prevtemp:=nil;
for i:= 0 to fMenu.Items.Count-1 do
begin
@ -447,6 +451,7 @@ procedure TDesignerMainMenu.Draw(MenuItem: PDesignerMenuItem; FormPanel,SubMenuP
var
SubMenuDimensions: TRect;
begin
if MenuItem^.SelfPanel = nil then exit;
with MenuItem^.SelfPanel do
begin
if (fMenu is TPopupMenu) and (MenuItem^.Level = 1) then
@ -863,6 +868,17 @@ begin
end;
end;
procedure TDesignerMainMenu.PersistentDeleting(APersistent: TPersistent);
begin
if APersistent is TMenuItem then
begin
DeleteItem(FindDesignerMenuItem(TMenuItem(APersistent)));
SetCoordinates(POSITION_LEFT, POSITION_TOP, 0, Root);
Parent.Invalidate;
end;
inherited;
end;
// -----------------------------------------------------------------//
// Insert From Template has been selected from context menu --------//
// -----------------------------------------------------------------//