Designer: cleanup for MenuEditor

git-svn-id: trunk@37661 -
This commit is contained in:
juha 2012-06-15 20:25:23 +00:00
parent d73084acb7
commit 3b50e92d50
4 changed files with 63 additions and 87 deletions

View File

@ -11,14 +11,14 @@ object TemplateMenuForm: TTemplateMenuForm
OnCreate = FormCreate OnCreate = FormCreate
OnResize = FormResize OnResize = FormResize
Position = poScreenCenter Position = poScreenCenter
LCLVersion = '0.9.27' LCLVersion = '1.1'
object Label_template_description: TLabel object Label_template_description: TLabel
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner AnchorSideTop.Control = Owner
Left = 6 Left = 6
Height = 14 Height = 15
Top = 6 Top = 6
Width = 132 Width = 139
BorderSpacing.Left = 6 BorderSpacing.Left = 6
BorderSpacing.Top = 6 BorderSpacing.Top = 6
Caption = 'Label_template_description' Caption = 'Label_template_description'
@ -28,18 +28,26 @@ object TemplateMenuForm: TTemplateMenuForm
AnchorSideLeft.Control = ListBoxView AnchorSideLeft.Control = ListBoxView
AnchorSideTop.Control = Owner AnchorSideTop.Control = Owner
Left = 262 Left = 262
Height = 14 Height = 15
Top = 6 Top = 6
Width = 102 Width = 107
BorderSpacing.Top = 6 BorderSpacing.Top = 6
Caption = 'Label_template_view' Caption = 'Label_template_view'
ParentColor = False ParentColor = False
end end
object ButtonPanel1: TButtonPanel object ButtonPanel1: TButtonPanel
Left = 6 Left = 6
Height = 26 Height = 33
Top = 212 Top = 205
Width = 508 Width = 508
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
HelpButton.Name = 'HelpButton'
HelpButton.DefaultCaption = True
CloseButton.Name = 'CloseButton'
CloseButton.DefaultCaption = True
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
TabOrder = 3 TabOrder = 3
ShowButtons = [pbOK, pbCancel] ShowButtons = [pbOK, pbCancel]
ShowBevel = False ShowBevel = False
@ -51,8 +59,8 @@ object TemplateMenuForm: TTemplateMenuForm
AnchorSideBottom.Control = ListBoxView AnchorSideBottom.Control = ListBoxView
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 6 Left = 6
Height = 180 Height = 172
Top = 26 Top = 27
Width = 244 Width = 244
Anchors = [akTop, akLeft, akBottom] Anchors = [akTop, akLeft, akBottom]
BorderSpacing.Left = 6 BorderSpacing.Left = 6
@ -70,8 +78,8 @@ object TemplateMenuForm: TTemplateMenuForm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ButtonPanel1 AnchorSideBottom.Control = ButtonPanel1
Left = 262 Left = 262
Height = 180 Height = 172
Top = 26 Top = 27
Width = 252 Width = 252
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 6 BorderSpacing.Left = 6
@ -86,8 +94,8 @@ object TemplateMenuForm: TTemplateMenuForm
AnchorSideRight.Control = TemplatesListBox AnchorSideRight.Control = TemplatesListBox
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 6 Left = 6
Height = 23 Height = 24
Top = 212 Top = 205
Width = 244 Width = 244
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6 BorderSpacing.Top = 6

View File

@ -339,8 +339,7 @@ begin
PopupMenuItem.OnClick := @DeleteFromTemplateClick; PopupMenuItem.OnClick := @DeleteFromTemplateClick;
FDesignerPopupMenu.Items.Add(PopupMenuItem); FDesignerPopupMenu.Items.Add(PopupMenuItem);
//Handler for renaming a caption in the OI for some menuitem to rename also a //Handler for renaming a caption in OI for some menuitem to rename also designermenuitem
// designermenuitem
GlobalDesignHook.AddHandlerModified(@OnDesignerModified); GlobalDesignHook.AddHandlerModified(@OnDesignerModified);
//GlobalDesignHook.AddHandlerPersistentAdded(@OnComponentAdded); //GlobalDesignHook.AddHandlerPersistentAdded(@OnComponentAdded);
GlobalDesignHook.AddHandlerPersistentDeleting(@PersistentDeleting); GlobalDesignHook.AddHandlerPersistentDeleting(@PersistentDeleting);
@ -563,13 +562,10 @@ begin
end; end;
end; end;
if (DMenuItem.Selected) or ((DMenuItem.Level = 1) and (fMenu is TMainMenu)) then if (DMenuItem.Selected) or ((DMenuItem.Level = 1) and (fMenu is TMainMenu)) then
begin Bevelouter:=bvraised
Bevelouter:=bvraised; else
end else
begin
Bevelouter:=bvnone; Bevelouter:=bvnone;
end; end;
end;
DMenuItem.CaptionLabel.Caption:=DMenuItem.Caption; DMenuItem.CaptionLabel.Caption:=DMenuItem.Caption;
@ -606,12 +602,9 @@ begin
if (DMenuItem.SubMenu <> nil) then if (DMenuItem.SubMenu <> nil) then
begin begin
if (DMenuItem.Level = 1) and (fMenu is TMainMenu) then if (DMenuItem.Level = 1) and (fMenu is TMainMenu) then
begin DMenuItem.SubMenuArrow.ArrowType:=atdown
DMenuItem.SubMenuArrow.ArrowType:=atdown; else
end else
begin
DMenuItem.SubMenuArrow.ArrowType:=atright; DMenuItem.SubMenuArrow.ArrowType:=atright;
end;
DMenuItem.SubMenuArrow.Left:=DMenuItem.SelfPanel.Width - DMenuItem.SubMenuArrow.Width - 1; DMenuItem.SubMenuArrow.Left:=DMenuItem.SelfPanel.Width - DMenuItem.SubMenuArrow.Width - 1;
DMenuItem.SubMenuArrow.Top:=(DMenuItem.SelfPanel.Height - DMenuItem.SubMenuArrow.Height) div 2; DMenuItem.SubMenuArrow.Top:=(DMenuItem.SelfPanel.Height - DMenuItem.SubMenuArrow.Height) div 2;
DMenuItem.SubMenuArrow.Visible:=true; DMenuItem.SubMenuArrow.Visible:=true;
@ -1853,12 +1846,9 @@ function TDesignerMainMenu.FindDesignerMenuItem(AMenuItem: TMenuItem): TDesigner
if ParentDesignerMenuItem <> nil then if ParentDesignerMenuItem <> nil then
Result := ParentDesignerMenuItem.SubMenu; Result := ParentDesignerMenuItem.SubMenu;
end; end;
if Result <> nil then
begin
while (Result <> nil) and (Result.RealMenuItem <> TheMenuItem) do while (Result <> nil) and (Result.RealMenuItem <> TheMenuItem) do
Result := Result.NextItem; Result := Result.NextItem;
end; end;
end;
begin begin
Result := FindRecursive(AMenuItem); Result := FindRecursive(AMenuItem);
@ -1893,7 +1883,7 @@ begin
else else
index_sequence[Ind + 1]:=-1; index_sequence[Ind + 1]:=-1;
end; end;
if not (Result) then if not Result then
if (DMenuItem.NextItem <> nil) then if (DMenuItem.NextItem <> nil) then
if (CreateIndexSequence(DMenuItem.NextItem,Ident,Ind)) then if (CreateIndexSequence(DMenuItem.NextItem,Ident,Ind)) then
Result:=true; Result:=true;
@ -2108,14 +2098,12 @@ var
i: Integer; i: Integer;
begin begin
for i:=0 to TemplatesListBox.Items.Count-1 do for i:=0 to TemplatesListBox.Items.Count-1 do
if TemplatesListBox.Selected[i] then SelectedMenuTemplate:=i + 1; if TemplatesListBox.Selected[i] then
if (fAction = 2) and (Edit_template_description.Text <> '') then SelectedMenuTemplate:=i + 1;
begin if (fAction = 2) then begin
Description:=Edit_template_description.Text; if Edit_template_description.Text <> '' then
end else Description:=Edit_template_description.Text
begin else // content of "Description" is generated from LazarusIDEStrConsts
if (fAction = 2) then
// content of "Description" is generated from LazarusIDEStrConsts
Description:=lisMenuEditorNewTemplateDescription; Description:=lisMenuEditorNewTemplateDescription;
end; end;
end; end;

View File

@ -1,7 +1,7 @@
object MainMenuEditorForm: TMainMenuEditorForm object MainMenuEditorForm: TMainMenuEditorForm
Left = 397 Left = 395
Height = 220 Height = 220
Top = 505 Top = 480
Width = 600 Width = 600
Caption = 'MainMenuEditorForm' Caption = 'MainMenuEditorForm'
ClientHeight = 220 ClientHeight = 220
@ -11,7 +11,7 @@ object MainMenuEditorForm: TMainMenuEditorForm
OnCreate = FormCreate OnCreate = FormCreate
OnDestroy = FormDestroy OnDestroy = FormDestroy
Position = poScreenCenter Position = poScreenCenter
LCLVersion = '0.9.31' LCLVersion = '1.1'
object MenuScrollBox: TScrollBox object MenuScrollBox: TScrollBox
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner AnchorSideTop.Control = Owner
@ -56,9 +56,9 @@ object MainMenuEditorForm: TMainMenuEditorForm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = List_menus AnchorSideBottom.Control = List_menus
Left = 8 Left = 8
Height = 16 Height = 15
Top = 10 Top = 11
Width = 70 Width = 65
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
Caption = 'Label_menus' Caption = 'Label_menus'
ParentColor = False ParentColor = False

View File

@ -60,7 +60,6 @@ type
FDesigner: TComponentEditorDesigner; FDesigner: TComponentEditorDesigner;
procedure OnPersistentDeleting(APersistent: TPersistent); procedure OnPersistentDeleting(APersistent: TPersistent);
procedure OnPersistentAdded(APersistent: TPersistent; Select: boolean); procedure OnPersistentAdded(APersistent: TPersistent; Select: boolean);
procedure CreateDesignerMenu;
procedure UpdateListOfMenus; procedure UpdateListOfMenus;
public public
procedure SetMenu(NewMenu: TMenu); procedure SetMenu(NewMenu: TMenu);
@ -68,8 +67,8 @@ type
write FDesignerMainMenu; write FDesignerMainMenu;
end; end;
{ TMenuComponentEditor { TMenuComponentEditor -- The default component editor for TMenu. }
The default component editor for TMenu. }
TMainMenuComponentEditor = class(TComponentEditor) TMainMenuComponentEditor = class(TComponentEditor)
private private
FDesigner: TComponentEditorDesigner; FDesigner: TComponentEditorDesigner;
@ -85,8 +84,7 @@ type
{ TMenuItemsPropertyEditor { TMenuItemsPropertyEditor
PropertyEditor editor for the TMenu.Items properties. PropertyEditor editor for the TMenu.Items properties. Brings up the menu editor. }
Brings up the menu editor. }
TMenuItemsPropertyEditor = class(TClassPropertyEditor) TMenuItemsPropertyEditor = class(TClassPropertyEditor)
public public
@ -126,8 +124,7 @@ begin
GlobalDesignHook.AddHandlerPersistentAdded(@OnPersistentAdded); GlobalDesignHook.AddHandlerPersistentAdded(@OnPersistentAdded);
end; end;
procedure TMainMenuEditorForm.FormClose(Sender: TObject; procedure TMainMenuEditorForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
var CloseAction: TCloseAction);
begin begin
SetMenu(nil); SetMenu(nil);
end; end;
@ -144,9 +141,7 @@ var
CurComponent: TComponent; CurComponent: TComponent;
begin begin
for i := 0 to List_menus.Items.Count - 1 do for i := 0 to List_menus.Items.Count - 1 do
begin
if List_menus.Selected[i] then if List_menus.Selected[i] then
begin
for j := 0 to FDesigner.Form.ComponentCount - 1 do for j := 0 to FDesigner.Form.ComponentCount - 1 do
begin begin
CurComponent:=FDesigner.Form.Components[j]; CurComponent:=FDesigner.Form.Components[j];
@ -157,8 +152,6 @@ begin
end; end;
end; end;
end; end;
end;
end;
procedure TMainMenuEditorForm.OnPersistentDeleting(APersistent: TPersistent); procedure TMainMenuEditorForm.OnPersistentDeleting(APersistent: TPersistent);
var var
@ -172,7 +165,8 @@ begin
i := List_menus.Items.IndexOf(AComponent.Name); i := List_menus.Items.IndexOf(AComponent.Name);
if i >= 0 then List_menus.Items.Delete(i); if i >= 0 then List_menus.Items.Delete(i);
if AComponent = FMenu then SetMenu(nil); if AComponent = FMenu then
SetMenu(nil);
end; end;
end; end;
@ -184,19 +178,6 @@ begin
UpdateListOfMenus; UpdateListOfMenus;
end; end;
procedure TMainMenuEditorForm.CreateDesignerMenu;
begin
DesignerMainMenu := TDesignerMainMenu.CreateWithMenu(Self, FMenu);
with DesignerMainMenu do
begin
Parent := Self;
ParentCanvas := Canvas;
LoadMainMenu;
SetCoordinates(10, 10, 0, DesignerMainMenu.Root);
end;
DesignerMainMenu.Panel := Panel;
end;
procedure TMainMenuEditorForm.UpdateListOfMenus; procedure TMainMenuEditorForm.UpdateListOfMenus;
var var
i: Integer; i: Integer;
@ -211,38 +192,37 @@ begin
CurComponent:=FDesigner.Form.Components[i]; CurComponent:=FDesigner.Form.Components[i];
//debugln('TMainMenuEditorForm.UpdateListOfMenus A ',dbgsName(CurComponent)); //debugln('TMainMenuEditorForm.UpdateListOfMenus A ',dbgsName(CurComponent));
if (CurComponent is TMainMenu) or (CurComponent is TPopupMenu) then if (CurComponent is TMainMenu) or (CurComponent is TPopupMenu) then
begin
List_menus.Items.Add(CurComponent.Name); List_menus.Items.Add(CurComponent.Name);
end; end;
end; end;
end;
List_menus.Items.EndUpdate; List_menus.Items.EndUpdate;
if FMenu <> nil then if FMenu <> nil then
begin
for i := 0 to List_menus.Items.Count - 1 do for i := 0 to List_menus.Items.Count - 1 do
begin
if (FMenu.Name = List_menus.Items[i]) then if (FMenu.Name = List_menus.Items[i]) then
begin
List_menus.Selected[i] := True; List_menus.Selected[i] := True;
end; end;
end;
end;
end;
procedure TMainMenuEditorForm.SetMenu(NewMenu: TMenu); procedure TMainMenuEditorForm.SetMenu(NewMenu: TMenu);
begin begin
if NewMenu <> FMenu then if NewMenu <> FMenu then
begin begin
DesignerMainMenu.Free; FreeAndNil(FDesignerMainMenu);
DesignerMainMenu := nil;
FMenu := NewMenu; FMenu := NewMenu;
FDesigner := FindRootDesigner(FMenu) as TComponentEditorDesigner; FDesigner := FindRootDesigner(FMenu) as TComponentEditorDesigner;
UpdateListOfMenus; UpdateListOfMenus;
if FMenu <> nil then if FMenu <> nil then
begin begin
CreateDesignerMenu; FDesignerMainMenu := TDesignerMainMenu.CreateWithMenu(Self, FMenu);
DesignerMainMenu.RealignDesigner; with FDesignerMainMenu do
begin
Parent := Self;
ParentCanvas := Canvas;
LoadMainMenu;
SetCoordinates(10, 10, 0, FDesignerMainMenu.Root);
end;
FDesignerMainMenu.Panel := Panel;
FDesignerMainMenu.RealignDesigner;
end end
else else
Close; Close;