Menu designer: Use generics containers. Move some funcs and props to base classes.

git-svn-id: trunk@54375 -
This commit is contained in:
juha 2017-03-08 20:33:58 +00:00
parent b77306c3df
commit 3439d5486e
5 changed files with 182 additions and 233 deletions

View File

@ -6,15 +6,16 @@ interface
uses uses
// FCL + LCL // FCL + LCL
Classes, SysUtils, Classes, SysUtils, fgl,
Controls, Forms, Menus, LCLProc, Controls, Forms, Menus, Graphics, LCLProc,
// IdeIntf // IdeIntf
FormEditingIntf, ComponentEditors, PropEdits, FormEditingIntf, ComponentEditors,
// IDE // IDE
MenuShortcuts, MenuTemplates; MenuShortcuts, MenuTemplates;
type type
TShadowItemDisplayState = (dsNormal, dsSelected, dsDisabled);
TByteArray = Array of Byte; TByteArray = Array of Byte;
{ TShadowItemBase } { TShadowItemBase }
@ -23,13 +24,21 @@ type
private private
protected protected
FRealItem: TMenuItem; FRealItem: TMenuItem;
FState: TShadowItemDisplayState;
public public
constructor Create(AOwner: TComponent; aRealItem: TMenuItem); reintroduce; constructor Create(AOwner: TComponent; aRealItem: TMenuItem); reintroduce;
destructor Destroy; override; destructor Destroy; override;
function GetHeight: integer;
function GetWidth: integer; virtual; abstract;
procedure ShowDisabled;
procedure ShowNormal;
procedure ShowSelected;
public public
property RealItem: TMenuItem read FRealItem write FRealItem; property RealItem: TMenuItem read FRealItem write FRealItem;
end; end;
TShadowItemList = specialize TFPGList<TShadowItemBase>;
{ TShadowBoxBase } { TShadowBoxBase }
TShadowBoxBase = class(TCustomControl) TShadowBoxBase = class(TCustomControl)
@ -38,21 +47,28 @@ type
protected protected
FLevel: integer; FLevel: integer;
FLastRIValue: boolean; FLastRIValue: boolean;
FParentBox: TShadowBoxBase;
FParentMenuItem: TMenuItem; FParentMenuItem: TMenuItem;
FShadowList: TFPList; FShadowList: TShadowItemList;
function GetShadowCount: integer; function GetIsMainMenu: boolean; virtual; abstract;
function GetIsMenuBar: boolean; virtual; abstract;
public public
constructor Create(AOwner: TComponent; aParentItem: TMenuItem); reintroduce; constructor Create(AOwner: TComponent; aParentItem: TMenuItem); reintroduce;
destructor Destroy; override; destructor Destroy; override;
public public
function GetInnerDims: TPoint;
property IsMainMenu: boolean read GetIsMainMenu;
property IsMenuBar: boolean read GetIsMenuBar;
property Level: integer read FLevel; property Level: integer read FLevel;
property LastRIValue: boolean read FLastRIValue write FLastRIValue; property LastRIValue: boolean read FLastRIValue write FLastRIValue;
property ParentMenuItem: TMenuItem read FParentMenuItem; property ParentMenuItem: TMenuItem read FParentMenuItem;
property ShadowList: TFPList read FShadowList; property ParentBox: TShadowBoxBase read FParentBox;
property ShadowCount: integer read GetShadowCount; property ShadowList: TShadowItemList read FShadowList;
property RadioGroupValues: TByteArray read GetRadioGroupValues; property RadioGroupValues: TByteArray read GetRadioGroupValues;
end; end;
TShadowBoxList = specialize TFPGList<TShadowBoxBase>;
{ TShadowMenuBase } { TShadowMenuBase }
TShadowMenuBase = class(TScrollBox) TShadowMenuBase = class(TScrollBox)
@ -60,9 +76,11 @@ type
protected protected
FEditorDesigner: TComponentEditorDesigner; FEditorDesigner: TComponentEditorDesigner;
FLookupRoot: TComponent; FLookupRoot: TComponent;
FMainCanvas: TCanvas;
FMenu: TMenu; FMenu: TMenu;
FSelectedMenuItem: TMenuItem; FSelectedMenuItem: TMenuItem;
FBoxList: TFPList; FBoxList: TShadowBoxList;
function GetStringWidth(const aText: string; isBold: boolean): integer;
public public
constructor Create(AOwner: TComponent; aMenu: TMenu); reintroduce; constructor Create(AOwner: TComponent; aMenu: TMenu); reintroduce;
destructor Destroy; override; destructor Destroy; override;
@ -77,7 +95,7 @@ type
property EditorDesigner: TComponentEditorDesigner read FEditorDesigner; property EditorDesigner: TComponentEditorDesigner read FEditorDesigner;
property LookupRoot: TComponent read FLookupRoot; property LookupRoot: TComponent read FLookupRoot;
property SelectedMenuItem: TMenuItem read FSelectedMenuItem write FSelectedMenuItem; property SelectedMenuItem: TMenuItem read FSelectedMenuItem write FSelectedMenuItem;
property BoxList: TFPList read FBoxList; property BoxList: TShadowBoxList read FBoxList;
end; end;
{ TMenuDesignerBase } { TMenuDesignerBase }
@ -125,6 +143,40 @@ begin
inherited Destroy; inherited Destroy;
end; end;
function TShadowItemBase.GetHeight: integer;
begin
if FRealItem.IsInMenuBar then
Result:=MenuBar_Height
else if FRealItem.IsLine then
Result:=Separator_Height
else
Result:=DropDown_Height;
end;
procedure TShadowItemBase.ShowDisabled;
begin
if (FState <> dsDisabled) then begin
FState:=dsDisabled;
Invalidate;
end;
end;
procedure TShadowItemBase.ShowNormal;
begin
if (FState <> dsNormal) then begin
FState:=dsNormal;
Invalidate;
end;
end;
procedure TShadowItemBase.ShowSelected;
begin
if (FState <> dsSelected) then begin
FState:=dsSelected;
Invalidate;
end;
end;
{ TShadowBoxBase } { TShadowBoxBase }
constructor TShadowBoxBase.Create(AOwner: TComponent; aParentItem: TMenuItem); constructor TShadowBoxBase.Create(AOwner: TComponent; aParentItem: TMenuItem);
@ -132,7 +184,7 @@ begin
inherited Create(AOwner); inherited Create(AOwner);
Assert(aParentItem<>nil,'TShadowBox.CreateWithParentBox: aParentItem parameter is nil'); Assert(aParentItem<>nil,'TShadowBox.CreateWithParentBox: aParentItem parameter is nil');
FParentMenuItem:=aParentItem; FParentMenuItem:=aParentItem;
FShadowList:=TFPList.Create; FShadowList:=TShadowItemList.Create;
end; end;
destructor TShadowBoxBase.Destroy; destructor TShadowBoxBase.Destroy;
@ -145,12 +197,11 @@ function TShadowBoxBase.GetRadioGroupValues: TByteArray;
var var
rgSet: set of byte = []; rgSet: set of byte = [];
g: byte; g: byte;
p: pointer; si: TShadowItemBase;
si: TShadowItemBase absolute p;
mi: TMenuItem; mi: TMenuItem;
begin begin
SetLength(Result, 0); SetLength(Result, 0);
for p in FShadowList do for si in FShadowList do
begin begin
mi:=si.RealItem; mi:=si.RealItem;
if mi.RadioItem then begin if mi.RadioItem then begin
@ -164,9 +215,18 @@ begin
end; end;
end; end;
function TShadowBoxBase.GetShadowCount: integer; function TShadowBoxBase.GetInnerDims: TPoint;
var
si: TShadowItemBase;
w: integer;
begin begin
Result:=FShadowList.Count; FillChar(Result{%H-}, SizeOf(Result), 0);
for si in FShadowList do begin
Inc(Result.y, si.GetHeight);
w:=si.GetWidth;
if (Result.x < w) then
Result.x:=w;
end;
end; end;
{ TShadowMenuBase } { TShadowMenuBase }
@ -177,7 +237,7 @@ begin
FMenu := aMenu; FMenu := aMenu;
FEditorDesigner := FindRootDesigner(FMenu) as TComponentEditorDesigner; FEditorDesigner := FindRootDesigner(FMenu) as TComponentEditorDesigner;
FLookupRoot := FEditorDesigner.LookupRoot; FLookupRoot := FEditorDesigner.LookupRoot;
FBoxList := TFPList.Create; FBoxList := TShadowBoxList.Create;
end; end;
destructor TShadowMenuBase.Destroy; destructor TShadowMenuBase.Destroy;
@ -187,29 +247,34 @@ begin
inherited Destroy; inherited Destroy;
end; end;
function TShadowMenuBase.GetStringWidth(const aText: string; isBold: boolean): integer;
begin
if isBold then
FMainCanvas.Font.Style:=[fsBold]
else
FMainCanvas.Font.Style:=[];
Result:=FMainCanvas.TextWidth(aText);
end;
function TShadowMenuBase.GetParentBoxForMenuItem(aMI: TMenuItem): TShadowBoxBase; function TShadowMenuBase.GetParentBoxForMenuItem(aMI: TMenuItem): TShadowBoxBase;
var var
p: pointer; sb: TShadowBoxBase;
sb: TShadowBoxBase absolute p; si: TShadowItemBase;
ps: pointer;
si: TShadowItemBase absolute ps;
begin begin
for p in FBoxList do for sb in FBoxList do
for ps in sb.ShadowList do for si in sb.ShadowList do
if (si.RealItem = aMI) then if si.RealItem = aMI then
Exit(sb); Exit(sb);
Result:=nil; Result:=nil;
end; end;
function TShadowMenuBase.GetShadowForMenuItem(aMI: TMenuItem): TShadowItemBase; function TShadowMenuBase.GetShadowForMenuItem(aMI: TMenuItem): TShadowItemBase;
var var
p: pointer; sb: TShadowBoxBase;
sb: TShadowBoxBase absolute p; si: TShadowItemBase;
ps: pointer;
si: TShadowItemBase absolute ps;
begin begin
for p in FBoxList do for sb in FBoxList do
for ps in sb.ShadowList do for si in sb.ShadowList do
if (si.RealItem = aMI) then if (si.RealItem = aMI) then
Exit(si); Exit(si);
Result:=nil; Result:=nil;

View File

@ -56,8 +56,6 @@ type
procedure SetVisibilitySizeAndPosition; override; procedure SetVisibilitySizeAndPosition; override;
end; end;
TShadowItemDisplayState = (dsNormal, dsSelected, dsDisabled);
TMenuDesigner = class; TMenuDesigner = class;
{ TShadowItem } { TShadowItem }
@ -70,7 +68,6 @@ type
FShadowMenu: TShadowMenu; FShadowMenu: TShadowMenu;
FShowingBottomFake: boolean; FShowingBottomFake: boolean;
FShowingRightFake: boolean; FShowingRightFake: boolean;
FState: TShadowItemDisplayState;
function GetBitmapLeftTop: TPoint; function GetBitmapLeftTop: TPoint;
function GetBottomFake: TFake; function GetBottomFake: TFake;
function GetIconTopLeft: TPoint; function GetIconTopLeft: TPoint;
@ -83,18 +80,12 @@ type
function GetShowingRightFake: boolean; function GetShowingRightFake: boolean;
function GetSubImagesIconTopLeft: TPoint; function GetSubImagesIconTopLeft: TPoint;
procedure RecursiveHideChildren(aMI: TMenuItem); procedure RecursiveHideChildren(aMI: TMenuItem);
procedure SetState(AValue: TShadowItemDisplayState);
private private
function GetHeight: integer; function HasChildBox(out aChildBox: TShadowBoxBase): boolean;
function GetWidth: integer;
function HasChildBox(out aChildBox: TShadowBox): boolean;
procedure HideChainFromRoot; procedure HideChainFromRoot;
procedure HideChildren; procedure HideChildren;
procedure ShowChainToRoot; procedure ShowChainToRoot;
procedure ShowChildBox; procedure ShowChildBox;
procedure ShowDisabled;
procedure ShowNormal;
procedure ShowSelected;
protected protected
procedure DblClick; override; procedure DblClick; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure KeyDown(var Key: Word; Shift: TShiftState); override;
@ -103,6 +94,8 @@ type
public public
constructor CreateWithBoxAndItem(aSMenu: TShadowMenu; aParentBox: TShadowBox; constructor CreateWithBoxAndItem(aSMenu: TShadowMenu; aParentBox: TShadowBox;
aRealItem: TMenuItem); aRealItem: TMenuItem);
function GetWidth: integer; override;
public
property BottomFake: TFake read GetBottomFake write FBottomFake; property BottomFake: TFake read GetBottomFake write FBottomFake;
property IsInMenuBar: boolean read GetIsInMenuBar; property IsInMenuBar: boolean read GetIsInMenuBar;
property IsMainMenu: boolean read GetIsMainMenu; property IsMainMenu: boolean read GetIsMainMenu;
@ -111,32 +104,26 @@ type
property RightFake: TFake read GetRightFake write FRightFake; property RightFake: TFake read GetRightFake write FRightFake;
property ShowingBottomFake: boolean read GetShowingBottomFake write FShowingBottomFake; property ShowingBottomFake: boolean read GetShowingBottomFake write FShowingBottomFake;
property ShowingRightFake: boolean read GetShowingRightFake write FShowingRightFake; property ShowingRightFake: boolean read GetShowingRightFake write FShowingRightFake;
//property State: TShadowItemDisplayState read FState;
end; end;
{ TShadowBox } { TShadowBox }
TShadowBox = class(TShadowBoxBase) TShadowBox = class(TShadowBoxBase)
strict private strict private
FParentBox: TShadowBox;
FShadowMenu: TShadowMenu; FShadowMenu: TShadowMenu;
FUpdating: boolean; FUpdating: boolean;
function GetIsMainMenu: boolean; function GetIsMainMenu: boolean; override;
function GetIsMenuBar: boolean; function GetIsMenuBar: boolean; override;
procedure BeginUpdate; procedure BeginUpdate;
procedure EndUpdate; procedure EndUpdate;
procedure ShowAllUnSelected; procedure ShowAllUnSelected;
private private
function GetInnerDims: TPoint;
procedure AddItemAndShadow(existingSI: TShadowItem; addBefore: boolean; procedure AddItemAndShadow(existingSI: TShadowItem; addBefore: boolean;
isSeparator: boolean=False); isSeparator: boolean=False);
procedure LocateShadows; procedure LocateShadows;
procedure RemoveAllSeparators; procedure RemoveAllSeparators;
procedure SelectPrevious(aSI: TShadowItem); procedure SelectPrevious(aSI: TShadowItem);
procedure SelectSuccessor(aSI: TShadowItem); procedure SelectSuccessor(aSI: TShadowItem);
property IsMainMenu: boolean read GetIsMainMenu;
property IsMenuBar: boolean read GetIsMenuBar;
property ParentBox: TShadowBox read FParentBox;
property Updating: boolean read FUpdating; property Updating: boolean read FUpdating;
protected protected
procedure Paint; override; procedure Paint; override;
@ -172,15 +159,12 @@ type
FInitialising: boolean; FInitialising: boolean;
FInitialSelectedMenuItem: TMenuItem; FInitialSelectedMenuItem: TMenuItem;
FItemsPopupMenu: TPopupMenu; FItemsPopupMenu: TPopupMenu;
FMainCanvas: TCanvas;
FRootBox: TShadowBox; FRootBox: TShadowBox;
FInPlaceEditor: TEdit; FInPlaceEditor: TEdit;
FEditedMenuItem: TMenuItem; FEditedMenuItem: TMenuItem;
procedure DeleteBox(aMI: TMenuItem); procedure DeleteBox(aMI: TMenuItem);
procedure DeleteItm(anItem: TMenuItem); procedure DeleteItm(anItem: TMenuItem);
function GetActionForEnum(anEnum: TPopEnum): TAction; function GetActionForEnum(anEnum: TPopEnum): TAction;
//function GetBoxContainingMenuItem(aMI: TMenuItem): TShadowBox;
function GetHighestLevelVisibleBox: TShadowBox;
function GetMaxVisibleBoxDims(aSB: TShadowBox): TPoint; function GetMaxVisibleBoxDims(aSB: TShadowBox): TPoint;
function GetMaxVisibleFakeDims: TPoint; function GetMaxVisibleFakeDims: TPoint;
function GetMenuBarCumWidthForItemIndex(anIndex: integer): integer; function GetMenuBarCumWidthForItemIndex(anIndex: integer): integer;
@ -221,12 +205,11 @@ type
procedure SaveAsTemplate(Sender: TObject); procedure SaveAsTemplate(Sender: TObject);
private private
FDesigner: TMenuDesigner; FDesigner: TMenuDesigner;
function GetStringWidth(const aText: string; isBold: boolean): integer;
function GetMenuBarIconWidth(aMI: TMenuItem): integer; function GetMenuBarIconWidth(aMI: TMenuItem): integer;
function OnClickIsAssigned(aMI: TMenuItem): boolean; function OnClickIsAssigned(aMI: TMenuItem): boolean;
procedure AddOnClick(Sender: TObject); procedure AddOnClick(Sender: TObject);
procedure DeleteItem(Sender: TObject); procedure DeleteItem(Sender: TObject);
function GetBoxWithParentItem(aParentMI: TMenuItem): TShadowBox; function GetBoxWithParentItem(aParentMI: TMenuItem): TShadowBoxBase;
procedure HideFakes; procedure HideFakes;
procedure RemoveEmptyBox(aSB: TShadowBox); procedure RemoveEmptyBox(aSB: TShadowBox);
procedure SetSelectedShadow(const prevSelectedItem, curSelectedItem: TMenuItem; viaDesigner: boolean); procedure SetSelectedShadow(const prevSelectedItem, curSelectedItem: TMenuItem; viaDesigner: boolean);
@ -320,12 +303,12 @@ begin
end; end;
// utility functions // utility functions
{
function ItemStateToStr(aState: TShadowItemDisplayState): string; function ItemStateToStr(aState: TShadowItemDisplayState): string;
begin begin
Result:=GetEnumName(TypeInfo(TShadowItemDisplayState), Ord(aState)); Result:=GetEnumName(TypeInfo(TShadowItemDisplayState), Ord(aState));
end; end;
}
function GetPreviousNonSepItem(aMI: TMenuItem): TMenuItem; function GetPreviousNonSepItem(aMI: TMenuItem): TMenuItem;
var var
idx: integer; idx: integer;
@ -437,14 +420,12 @@ begin
Exit(False); Exit(False);
end; end;
function SortByItemMenuIndex(Item1, Item2: Pointer): Integer; function SortByItemMenuIndex(const Item1, Item2: TShadowItemBase): Integer;
var var
si1: TShadowItem absolute Item1;
si2: TShadowItem absolute Item2;
i1, i2: integer; i1, i2: integer;
begin begin
i1:=si1.RealItem.MenuIndex; i1:=Item1.RealItem.MenuIndex;
i2:=si2.RealItem.MenuIndex; i2:=Item2.RealItem.MenuIndex;
if (i1 > i2) then if (i1 > i2) then
Result:=1 Result:=1
else if (i2 > i1) then else if (i2 > i1) then
@ -453,14 +434,12 @@ begin
Result:=0; Result:=0;
end; end;
function SortByBoxLevel(Item1, Item2: Pointer): Integer; function SortByBoxLevel(const Item1, Item2: TShadowBoxBase): Integer;
var var
sb1: TShadowBox absolute Item1;
sb2: TShadowBox absolute Item2;
lvl1, lvl2: integer; lvl1, lvl2: integer;
begin begin
lvl1:=sb1.Level; lvl1:=Item1.Level;
lvl2:=sb2.Level; lvl2:=Item2.Level;
if (lvl1 > lvl2) then if (lvl1 > lvl2) then
Result:=1 Result:=1
else if (lvl1 < lvl2) then else if (lvl1 < lvl2) then
@ -927,7 +906,7 @@ begin
FreeAndNil(mi); FreeAndNil(mi);
FEditorDesigner.Modified; FEditorDesigner.Modified;
if (box.ShadowCount = 0) then if (box.ShadowList.Count = 0) then
begin begin
FBoxList.Remove(box); FBoxList.Remove(box);
box.Parent:=nil; box.Parent:=nil;
@ -953,11 +932,11 @@ var
begin begin
for i:=aMI.Count-1 downto 0 do for i:=aMI.Count-1 downto 0 do
DeleteBox(aMI.Items[i]); DeleteBox(aMI.Items[i]);
sb:=GetParentBoxForMenuItem(aMI); //GetBoxContainingMenuItem(aMI); sb:=GetParentBoxForMenuItem(aMI);
Assert(sb<>nil,'TShadowMenu.DeleteBox: internal error'); Assert(sb<>nil,'TShadowMenu.DeleteBox: internal error');
sb.Hide; sb.Hide;
sb.ShadowList.Remove(GetShadowForMenuItem(aMI)); sb.ShadowList.Remove(GetShadowForMenuItem(aMI));
if (sb.ShadowCount = 0) then if (sb.ShadowList.Count = 0) then
begin begin
FBoxList.Remove(sb); FBoxList.Remove(sb);
sb.Parent:=nil; sb.Parent:=nil;
@ -982,7 +961,7 @@ end;
procedure TShadowMenu.DeleteShadowAndItemAndChildren(anExistingSI: TShadowItem); procedure TShadowMenu.DeleteShadowAndItemAndChildren(anExistingSI: TShadowItem);
var var
firstBoxToDelete: TShadowBox; firstBoxToDelete: TShadowBoxBase;
mi: TMenuItem; mi: TMenuItem;
i: integer; i: integer;
begin begin
@ -1011,15 +990,6 @@ begin
Result:=TShadowItem(GetShadowForMenuItem(FSelectedMenuItem)); Result:=TShadowItem(GetShadowForMenuItem(FSelectedMenuItem));
end; end;
function TShadowMenu.GetStringWidth(const aText: string; isBold: boolean): integer;
begin
if isBold then
FMainCanvas.Font.Style:=[fsBold]
else
FMainCanvas.Font.Style:=[];
Result:=FMainCanvas.TextWidth(aText);
end;
function TShadowMenu.GetMenuBarIconWidth(aMI: TMenuItem): integer; function TShadowMenu.GetMenuBarIconWidth(aMI: TMenuItem): integer;
begin begin
Result:=0; Result:=0;
@ -1085,29 +1055,17 @@ begin
FDesigner.FGui.UpdateStatistics; FDesigner.FGui.UpdateStatistics;
end; end;
function TShadowMenu.GetBoxWithParentItem(aParentMI: TMenuItem): TShadowBox; function TShadowMenu.GetBoxWithParentItem(aParentMI: TMenuItem): TShadowBoxBase;
var var
p: pointer; sb: TShadowBoxBase;
sb: TShadowBox absolute p;
begin begin
Assert(aParentMI<>nil,'TShadowMenu.GetBoxWithParentItem: parent item is nil'); Assert(aParentMI<>nil,'TShadowMenu.GetBoxWithParentItem: parent item is nil');
for p in FBoxList do for sb in FBoxList do
if (sb.ParentMenuItem = aParentMI) then if (sb.ParentMenuItem = aParentMI) then
Exit(sb); Exit(sb);
Result:=nil; Result:=nil;
end; end;
function TShadowMenu.GetHighestLevelVisibleBox: TShadowBox;
var
i: integer;
begin
FBoxList.Sort(@SortByBoxLevel);
for i:=FBoxList.Count-1 downto 0 do
if TShadowBox(FBoxList[i]).Visible then
Exit(TShadowBox(FBoxList[i]));
Result:=nil;
end;
function TShadowMenu.GetMaxVisibleBoxDims(aSB: TShadowBox): TPoint; function TShadowMenu.GetMaxVisibleBoxDims(aSB: TShadowBox): TPoint;
begin begin
Result:=Point(0,0); Result:=Point(0,0);
@ -1336,21 +1294,19 @@ end;
procedure TShadowMenu.UpdateBoxLocationsAndSizes; procedure TShadowMenu.UpdateBoxLocationsAndSizes;
var var
p: pointer; sb: TShadowBoxBase;
sb: TShadowBox absolute p; si: TShadowItemBase;
s: pointer;
si: TShadowItem absolute s;
lft, w, idx: integer; lft, w, idx: integer;
pt: TPoint; pt: TPoint;
begin begin
FBoxList.Sort(@SortByBoxLevel); FBoxList.Sort(@SortByBoxLevel);
for p in FBoxList do begin for sb in FBoxList do begin
if sb.IsMenuBar then if sb.IsMenuBar then
begin begin
sb.Align:=alTop; sb.Align:=alTop;
sb.Height:=MenuBar_Height; sb.Height:=MenuBar_Height;
lft:=0; lft:=0;
for s in sb.ShadowList do begin for si in sb.ShadowList do begin
w:=si.GetWidth; w:=si.GetWidth;
si.SetBounds(lft, 0, w, MenuBar_Height); si.SetBounds(lft, 0, w, MenuBar_Height);
Inc(lft, w); Inc(lft, w);
@ -1379,7 +1335,7 @@ procedure TShadowMenu.RemoveEmptyBox(aSB: TShadowBox);
var var
miToSelect: TMenuItem; miToSelect: TMenuItem;
begin begin
if (aSB.ShadowCount = 0) then begin if (aSB.ShadowList.Count = 0) then begin
miToSelect:=aSB.ParentMenuItem; miToSelect:=aSB.ParentMenuItem;
FBoxList.Remove(aSB); FBoxList.Remove(aSB);
aSB.Parent:=nil; aSB.Parent:=nil;
@ -1517,8 +1473,7 @@ begin
end; end;
end; end;
procedure TShadowMenu.OnObjectPropertyChanged(Sender: TObject; procedure TShadowMenu.OnObjectPropertyChanged(Sender: TObject; NewObject: TPersistent);
NewObject: TPersistent);
var var
propertyEditor: TPropertyEditor absolute Sender; propertyEditor: TPropertyEditor absolute Sender;
i: Integer; i: Integer;
@ -1828,7 +1783,7 @@ begin
ac.Caption:=Format(lisMenuEditorListShortcutsAndAccelerators,[FLookupRoot.Name]); ac.Caption:=Format(lisMenuEditorListShortcutsAndAccelerators,[FLookupRoot.Name]);
end; end;
popResolveShortcutConflicts: ac.Enabled:= popResolveShortcutConflicts: ac.Enabled:=
(FDesigner.Shortcuts.ShortcutList.InitialDuplicatesCount > 0); (FDesigner.Shortcuts.ShortcutList.InitialDuplicates.Count > 0);
popTemplates_: ac.Enabled:=levelZero or FDesigner.TemplatesSaved; popTemplates_: ac.Enabled:=levelZero or FDesigner.TemplatesSaved;
popSaveAsTemplate: ac.Enabled:=levelZeroOr1; popSaveAsTemplate: ac.Enabled:=levelZeroOr1;
popAddFromTemplate: ac.Enabled:=levelZero; popAddFromTemplate: ac.Enabled:=levelZero;
@ -1921,11 +1876,10 @@ end;
procedure TShadowMenu.HideBoxesAboveLevel(aLevel: integer); procedure TShadowMenu.HideBoxesAboveLevel(aLevel: integer);
var var
p: pointer; sb: TShadowBoxBase;
sb: TShadowBox absolute p;
begin begin
for p in FBoxList do for sb in FBoxList do
if (sb.Level > aLevel) then if sb.Level > aLevel then
sb.Hide; sb.Hide;
end; end;
@ -1949,10 +1903,9 @@ end;
procedure TShadowBox.ShowAllUnSelected; procedure TShadowBox.ShowAllUnSelected;
var var
p: pointer; si: TShadowItemBase;
si: TShadowItem absolute p;
begin begin
for p in FShadowList do for si in FShadowList do
si.ShowNormal; si.ShowNormal;
end; end;
@ -2068,7 +2021,7 @@ begin
end; end;
end; end;
end; end;
if (GetShadowCount = 0) then if (ShadowList.Count = 0) then
FShadowMenu.RemoveEmptyBox(Self) FShadowMenu.RemoveEmptyBox(Self)
else begin else begin
FShadowMenu.UpdateBoxLocationsAndSizes; FShadowMenu.UpdateBoxLocationsAndSizes;
@ -2079,16 +2032,15 @@ end;
procedure TShadowBox.LocateShadows; procedure TShadowBox.LocateShadows;
var var
p: pointer; si: TShadowItemBase;
si: TShadowItem absolute p;
len, t, w, h: integer; len, t, w, h: integer;
begin begin
if (ShadowCount = 0) then if (ShadowList.Count = 0) then
Exit; Exit;
FShadowList.Sort(@SortByItemMenuIndex); FShadowList.Sort(@SortByItemMenuIndex);
if IsMenuBar then begin if IsMenuBar then begin
len:=0; len:=0;
for p in FShadowList do begin for si in FShadowList do begin
w:=si.GetWidth; w:=si.GetWidth;
si.SetBounds(len, 0, w, MenuBar_Height); si.SetBounds(len, 0, w, MenuBar_Height);
Inc(len, w); Inc(len, w);
@ -2097,7 +2049,7 @@ begin
else begin else begin
w:=GetInnerDims.x; w:=GetInnerDims.x;
t:=1; t:=1;
for p in FShadowList do begin for si in FShadowList do begin
h:=si.GetHeight; h:=si.GetHeight;
si.SetBounds(1, t, w, h); si.SetBounds(1, t, w, h);
Inc(t, h); Inc(t, h);
@ -2105,21 +2057,6 @@ begin
end; end;
end; end;
function TShadowBox.GetInnerDims: TPoint;
var
p: pointer;
si: TShadowItem absolute p;
w: integer;
begin
FillChar(Result{%H-}, SizeOf(Result), 0);
for p in FShadowList do begin
Inc(Result.y, si.GetHeight);
w:=si.GetWidth;
if (Result.x < w) then
Result.x:=w;
end;
end;
constructor TShadowBox.CreateWithParentBox(aSMenu: TShadowMenu; constructor TShadowBox.CreateWithParentBox(aSMenu: TShadowMenu;
aParentBox: TShadowBox; aParentItem: TMenuItem); aParentBox: TShadowBox; aParentItem: TMenuItem);
begin begin
@ -2177,7 +2114,7 @@ begin
Result:=w + Double_DropDown_Text_Offset + GetShortcutWidth; Result:=w + Double_DropDown_Text_Offset + GetShortcutWidth;
end; end;
function TShadowItem.HasChildBox(out aChildBox: TShadowBox): boolean; function TShadowItem.HasChildBox(out aChildBox: TShadowBoxBase): boolean;
begin begin
aChildBox:=nil; aChildBox:=nil;
Result:=(FRealItem.Count > 0); Result:=(FRealItem.Count > 0);
@ -2219,16 +2156,6 @@ begin
FShadowMenu.AddOnClick(nil); FShadowMenu.AddOnClick(nil);
end; end;
function TShadowItem.GetHeight: integer;
begin
if FRealItem.IsInMenuBar then
Result:=MenuBar_Height
else if FRealItem.IsLine then
Result:=Separator_Height
else
Result:=DropDown_Height;
end;
function TShadowItem.GetIsInMenuBar: boolean; function TShadowItem.GetIsInMenuBar: boolean;
begin begin
Result:=FRealItem.IsInMenuBar; Result:=FRealItem.IsInMenuBar;
@ -2299,14 +2226,6 @@ begin
Result:=(RightFake <> nil) and RightFake.Visible; Result:=(RightFake <> nil) and RightFake.Visible;
end; end;
procedure TShadowItem.SetState(AValue: TShadowItemDisplayState);
begin
if (FState <> AValue) then begin
FState:=AValue;
Invalidate;
end;
end;
function TShadowItem.GetIconTopLeft: TPoint; function TShadowItem.GetIconTopLeft: TPoint;
begin begin
Result:=Point(1, 1); Result:=Point(1, 1);
@ -2671,33 +2590,9 @@ begin
inherited MouseDown(Button, Shift, X, Y); inherited MouseDown(Button, Shift, X, Y);
end; end;
procedure TShadowItem.ShowNormal;
begin
if (FState <> dsNormal) then begin
FState:=dsNormal;
Invalidate;
end;
end;
procedure TShadowItem.ShowSelected;
begin
if (FState <> dsSelected) then begin
FState:=dsSelected;
Invalidate;
end;
end;
procedure TShadowItem.ShowDisabled;
begin
if (FState <> dsDisabled) then begin
FState:=dsDisabled;
Invalidate;
end;
end;
procedure TShadowItem.ShowChainToRoot; procedure TShadowItem.ShowChainToRoot;
var var
sb: TShadowBox; sb: TShadowBoxBase;
begin begin
sb:=FParentBox; sb:=FParentBox;
while (sb <> FShadowMenu.RootBox) do begin while (sb <> FShadowMenu.RootBox) do begin
@ -2708,7 +2603,7 @@ end;
procedure TShadowItem.HideChainFromRoot; procedure TShadowItem.HideChainFromRoot;
var var
sb: TShadowBox; sb: TShadowBoxBase;
begin begin
sb:=FParentBox; sb:=FParentBox;
while (sb <> FShadowMenu.RootBox) do begin while (sb <> FShadowMenu.RootBox) do begin
@ -2719,7 +2614,7 @@ end;
procedure TShadowItem.ShowChildBox; procedure TShadowItem.ShowChildBox;
var var
sb: TShadowBox; sb: TShadowBoxBase;
begin begin
if HasChildBox(sb) then if HasChildBox(sb) then
sb.Show; sb.Show;

View File

@ -54,7 +54,7 @@ begin
inherited CreateNew(Nil); inherited CreateNew(Nil);
FShortcuts:=aShortcuts; FShortcuts:=aShortcuts;
FShortcuts.ShortcutList.ScanContainerForShortcutsAndAccelerators; FShortcuts.ShortcutList.ScanContainerForShortcutsAndAccelerators;
FInitialConflictsCount:=FShortcuts.ShortcutList.InitialDuplicatesCount; FInitialConflictsCount:=FShortcuts.ShortcutList.InitialDuplicates.Count;
FShadowMenu:=aShadowMenu; FShadowMenu:=aShadowMenu;
FResolvedConflictsCount:=0; FResolvedConflictsCount:=0;
Position:=poScreenCenter; Position:=poScreenCenter;
@ -65,7 +65,7 @@ begin
FConflictsGroupBox:=TGroupBox.Create(Self); FConflictsGroupBox:=TGroupBox.Create(Self);
with FConflictsGroupBox do begin with FConflictsGroupBox do begin
Caption:=Format(lisMenuEditorConflictsFoundInitiallyD, Caption:=Format(lisMenuEditorConflictsFoundInitiallyD,
[FShortcuts.ShortcutList.InitialDuplicatesCount]); [FShortcuts.ShortcutList.InitialDuplicates.Count]);
Align:=alTop; Align:=alTop;
Top:=0; Top:=0;
BorderSpacing.Around:=Margin; BorderSpacing.Around:=Margin;
@ -166,12 +166,11 @@ var
sUnique: string; sUnique: string;
sDup: string; sDup: string;
infUnique: TSCInfo; infUnique: TSCInfo;
p: pointer; infDup: TSCInfo;
infDup: TSCInfo absolute p;
begin begin
FConflictsListBox.OnSelectionChange:=nil; FConflictsListBox.OnSelectionChange:=nil;
FConflictsListBox.Items.Clear; FConflictsListBox.Items.Clear;
for p in FShortcuts.ShortcutList.InitialDuplicates do begin for infDup in FShortcuts.ShortcutList.InitialDuplicates do begin
sDup:=Format(lisMenuEditorSInS, [ShortCutToText(infDup.Shortcut), sDup:=Format(lisMenuEditorSInS, [ShortCutToText(infDup.Shortcut),
infDup.ComponentName]); infDup.ComponentName]);
infUnique:=FShortcuts.ShortcutList.FindUniqueInfoForShortcut(infDup.Shortcut); infUnique:=FShortcuts.ShortcutList.FindUniqueInfoForShortcut(infDup.Shortcut);
@ -242,7 +241,7 @@ end;
procedure TResolveConflictsDlg.InitialPopulateListBox; procedure TResolveConflictsDlg.InitialPopulateListBox;
begin begin
if (FShortcuts.ShortcutList.InitialDuplicatesCount > 0) then begin if (FShortcuts.ShortcutList.InitialDuplicates.Count > 0) then begin
FResolvedConflictsCount:=0; FResolvedConflictsCount:=0;
FResolvedConflictsCountLabel.Caption:=Format( FResolvedConflictsCountLabel.Caption:=Format(
lisMenuEditorResolvedConflictsS, [IntToStr(FResolvedConflictsCount)]); lisMenuEditorResolvedConflictsS, [IntToStr(FResolvedConflictsCount)]);
@ -269,7 +268,7 @@ begin
FConflictsListBox.ItemIndex:= -1; FConflictsListBox.ItemIndex:= -1;
FButtonPanel.OKButton.Enabled:=False; FButtonPanel.OKButton.Enabled:=False;
FShortcuts.ShortcutList.ScanContainerForShortcutsAndAccelerators; FShortcuts.ShortcutList.ScanContainerForShortcutsAndAccelerators;
if (FShortcuts.ShortcutList.InitialDuplicatesCount > 0) then begin if (FShortcuts.ShortcutList.InitialDuplicates.Count > 0) then begin
CreateListboxItems; CreateListboxItems;
UpdateStatistics; UpdateStatistics;
FConflictsListBox.ItemIndex:=0; FConflictsListBox.ItemIndex:=0;

View File

@ -5,7 +5,7 @@ unit MenuShortcuts;
interface interface
uses uses
Classes, SysUtils, strutils, types, Classes, SysUtils, strutils, types, fgl,
ActnList, ButtonPanel, Controls, Dialogs, StdCtrls, Menus, ActnList, ButtonPanel, Controls, Dialogs, StdCtrls, Menus,
Forms, Graphics, LCLType, LCLIntf, LCLProc, Forms, Graphics, LCLType, LCLIntf, LCLProc,
// LazUtils // LazUtils
@ -71,16 +71,17 @@ type
property ToCompositeString: string read GetToCompositeString; property ToCompositeString: string read GetToCompositeString;
end; end;
TSCInfoList = specialize TFPGList<TSCInfo>;
{ TSCList } { TSCList }
TSCList = class(TObject) TSCList = class(TObject)
strict private strict private
FAcceleratorsInContainerCount: integer; FAcceleratorsInContainerCount: integer;
FInitialDuplicates: TFPList;
FScanList: TStringList; FScanList: TStringList;
FShortcutsInContainerCount: integer; FShortcutsInContainerCount: integer;
FUniqueList: TFPList; FInitialDuplicates: TSCInfoList;
function GetInitialDuplicatesCount: integer; FUniqueList: TSCInfoList;
function GetScanListCompName(index: integer): string; function GetScanListCompName(index: integer): string;
function GetUniqueCount: integer; function GetUniqueCount: integer;
public public
@ -95,8 +96,7 @@ type
procedure SortByComponentPropertyName; procedure SortByComponentPropertyName;
property AcceleratorsInContainerCount: integer read FAcceleratorsInContainerCount property AcceleratorsInContainerCount: integer read FAcceleratorsInContainerCount
write FAcceleratorsInContainerCount; write FAcceleratorsInContainerCount;
property InitialDuplicates: TFPList read FInitialDuplicates; property InitialDuplicates: TSCInfoList read FInitialDuplicates;
property InitialDuplicatesCount: integer read GetInitialDuplicatesCount;
property ScanList: TStringList read FScanList; property ScanList: TStringList read FScanList;
property ScanListCompName[index: integer]: string read GetScanListCompName; property ScanListCompName[index: integer]: string read GetScanListCompName;
property ShortcutsInContainerCount: integer read FShortcutsInContainerCount property ShortcutsInContainerCount: integer read FShortcutsInContainerCount
@ -490,27 +490,21 @@ begin
Result:=Copy(aCommaText, Succ(p), Length(aCommaText)-p); Result:=Copy(aCommaText, Succ(p), Length(aCommaText)-p);
end; end;
function SortByShortcut(Item1, Item2: Pointer): Integer; function SortByShortcut(const Item1, Item2: TSCInfo): Integer;
var
inf1: TSCInfo absolute Item1;
inf2: TSCInfo absolute Item2;
begin begin
if (inf1.Shortcut > inf2.Shortcut) then if (Item1.Shortcut > Item2.Shortcut) then
Result:= +1 Result:= +1
else if (inf1.Shortcut < inf2.Shortcut) then else if (Item1.Shortcut < Item2.Shortcut) then
Result:= -1 Result:= -1
else else
Result:=0; Result:=0;
end; end;
function SortFPListByComponentPropertyName(Item1, Item2: Pointer): Integer; function SortFPListByComponentPropertyName(const Item1, Item2: TSCInfo): Integer;
var
inf1: TSCInfo absolute Item1;
inf2: TSCInfo absolute Item2;
begin begin
if (inf1.ComponentName > inf2.ComponentName) then if (Item1.ComponentName > Item2.ComponentName) then
Result:= +1 Result:= +1
else if (inf1.ComponentName < inf2.ComponentName) then else if (Item1.ComponentName < Item2.ComponentName) then
Result:= -1 Result:= -1
else else
Result:=0; Result:=0;
@ -586,8 +580,8 @@ end;
constructor TSCList.Create; constructor TSCList.Create;
begin begin
FScanList:=TStringList.Create; FScanList:=TStringList.Create;
FUniqueList:=TFPList.Create; FUniqueList:=TSCInfoList.Create;
FInitialDuplicates:=TFPList.Create; FInitialDuplicates:=TSCInfoList.Create;
ScanContainerForShortcutsAndAccelerators; ScanContainerForShortcutsAndAccelerators;
end; end;
@ -616,11 +610,6 @@ begin
[index]); [index]);
end; end;
function TSCList.GetInitialDuplicatesCount: integer;
begin
Result:=FInitialDuplicates.Count;
end;
function TSCList.GetUniqueCount: integer; function TSCList.GetUniqueCount: integer;
begin begin
Result:=FUniqueList.Count; Result:=FUniqueList.Count;
@ -639,10 +628,9 @@ end;
function TSCList.UniqueListContainsShortcut(aSC: TShortCut): boolean; function TSCList.UniqueListContainsShortcut(aSC: TShortCut): boolean;
var var
p: pointer; inf: TSCInfo;
inf: TSCInfo absolute p;
begin begin
for p in FUniqueList do for inf in FUniqueList do
if (inf.Shortcut = aSC) then if (inf.Shortcut = aSC) then
Exit(True); Exit(True);
Result:=False; Result:=False;
@ -650,10 +638,9 @@ end;
function TSCList.FindUniqueInfoForShortcut(aSC: TShortCut): TSCInfo; function TSCList.FindUniqueInfoForShortcut(aSC: TShortCut): TSCInfo;
var var
p: pointer; inf: TSCInfo;
inf: TSCInfo absolute p;
begin begin
for p in FUniqueList do for inf in FUniqueList do
if (inf.Shortcut = aSC) then if (inf.Shortcut = aSC) then
Exit(inf); Exit(inf);
Result:=nil; Result:=nil;
@ -668,6 +655,13 @@ begin
if (FUniqueList.Count > 0) then if (FUniqueList.Count > 0) then
FUniqueList.Sort(@SortByShortcut); FUniqueList.Sort(@SortByShortcut);
end; end;
//menushortcuts.pas(667,44) Error: Incompatible type for arg no. 1:
// Got "<address of function(const TSCInfo;const TSCInfo):LongInt;Register>",
// expected "<procedure variable type of function(Pointer;Pointer):LongInt;Register>"
//menushortcuts.pas(669,37) Error: Incompatible type for arg no. 1:
// Got "<address of function(Pointer;Pointer):LongInt;Register>",
// expected "TFPGList$1$crc13D57BB4.<procedure variable type of function(const TSCInfo;const TSCInfo):LongInt;Register>"
procedure TSCList.ScanContainerForShortcutsOnly; procedure TSCList.ScanContainerForShortcutsOnly;
begin begin
@ -681,18 +675,18 @@ var
begin begin
FreeAndNil(FUniqueList); FreeAndNil(FUniqueList);
FreeAndNil(FInitialDuplicates); FreeAndNil(FInitialDuplicates);
FUniqueList:=TFPList.Create; FUniqueList:=TSCInfoList.Create;
FInitialDuplicates:=TFPList.Create; FInitialDuplicates:=TSCInfoList.Create;
for i:=0 to FScanList.Count-1 do for i:=0 to FScanList.Count-1 do
if UniqueListContainsShortcut(TSCInfo(FScanList.Objects[i]).Shortcut) then if UniqueListContainsShortcut(TSCInfo(FScanList.Objects[i]).Shortcut) then
FInitialDuplicates.Add(FScanList.Objects[i]) FInitialDuplicates.Add(FScanList.Objects[i] as TSCInfo)
else else
FUniqueList.Add(FScanList.Objects[i]); FUniqueList.Add(FScanList.Objects[i] as TSCInfo);
if (FInitialDuplicates.Count > 0) then begin if (FInitialDuplicates.Count > 0) then begin
FInitialDuplicates.Sort(@SortFPListByComponentPropertyName); FInitialDuplicates.Sort(@SortFPListByComponentPropertyName);
for i:=FInitialDuplicates.Count-1 downto 1 do begin for i:=FInitialDuplicates.Count-1 downto 1 do begin
inf2:=TSCInfo(FInitialDuplicates[i]); inf2:=FInitialDuplicates[i];
inf1:=TSCInfo(FInitialDuplicates[i-1]); inf1:=FInitialDuplicates[i-1];
if (CompareText(inf2.ComponentName, inf1.ComponentName) = 0) if (CompareText(inf2.ComponentName, inf1.ComponentName) = 0)
and (inf2.Shortcut = inf1.Shortcut) then and (inf2.Shortcut = inf1.Shortcut) then
FInitialDuplicates.Delete(i); FInitialDuplicates.Delete(i);
@ -1298,7 +1292,7 @@ procedure TMenuShortcuts.Initialize;
begin begin
FShortcutList.ClearAllLists; FShortcutList.ClearAllLists;
FShortcutList.ScanContainerForShortcutsAndAccelerators; FShortcutList.ScanContainerForShortcutsAndAccelerators;
FShortcutConflictsCount:=FShortcutList.InitialDuplicatesCount; FShortcutConflictsCount:=FShortcutList.InitialDuplicates.Count;
end; end;
procedure TMenuShortcuts.UpdateShortcutList(includeAccelerators: boolean); procedure TMenuShortcuts.UpdateShortcutList(includeAccelerators: boolean);

View File

@ -5,7 +5,7 @@ unit MenuTemplates;
interface interface
uses uses
Classes, SysUtils, types, Classes, SysUtils, types, fgl,
Buttons, Controls, Dialogs, StdCtrls, ExtCtrls, Menus, Buttons, Controls, Dialogs, StdCtrls, ExtCtrls, Menus,
ComCtrls, Forms, Graphics, Themes, LCLType, LCLIntf, LCLProc, ComCtrls, Forms, Graphics, Themes, LCLType, LCLIntf, LCLProc,
// LazUtils // LazUtils
@ -41,12 +41,13 @@ type
end; end;
TDialogMode = (dmInsert, dmSave, dmDelete); TDialogMode = (dmInsert, dmSave, dmDelete);
TMenuTemplateList = specialize TFPGObjectList<TMenuTemplate>;
{ TMenuTemplates } { TMenuTemplates }
TMenuTemplates = class(TObject) TMenuTemplates = class(TObject)
strict private strict private
FTemplateList: TFPList; FTemplateList: TMenuTemplateList;
function GetDescription(index: integer): string; function GetDescription(index: integer): string;
function GetMenu(index: integer): TMenuItem; function GetMenu(index: integer): TMenuItem;
function GetMenuCount: integer; function GetMenuCount: integer;
@ -368,7 +369,7 @@ end;
function TMenuTemplates.GetDescription(index: integer): string; function TMenuTemplates.GetDescription(index: integer): string;
begin begin
CheckIndex(index); CheckIndex(index);
Result:=TMenuTemplate(FTemplateList[index]).Description; Result:=FTemplateList[index].Description;
end; end;
function TMenuTemplates.GetMenu(index: integer): TMenuItem; function TMenuTemplates.GetMenu(index: integer): TMenuItem;
@ -378,7 +379,7 @@ var
i: integer; i: integer;
begin begin
CheckIndex(index); CheckIndex(index);
mt:=TMenuTemplate(FTemplateList[index]); mt:=FTemplateList[index];
mi:=TMenuItem.Create(nil); mi:=TMenuItem.Create(nil);
mi.Caption:=mt.PrimaryItem; mi.Caption:=mt.PrimaryItem;
for i:=0 to mt.SubItemCount-1 do for i:=0 to mt.SubItemCount-1 do
@ -399,13 +400,13 @@ end;
function TMenuTemplates.GetMenuTemplate(index: integer): TMenuTemplate; function TMenuTemplates.GetMenuTemplate(index: integer): TMenuTemplate;
begin begin
CheckIndex(index); CheckIndex(index);
Result:=TMenuTemplate(FTemplateList[index]); Result:=FTemplateList[index];
end; end;
function TMenuTemplates.GetPrimaryItem(index: integer): string; function TMenuTemplates.GetPrimaryItem(index: integer): string;
begin begin
CheckIndex(index); CheckIndex(index);
Result:=TMenuTemplate(FTemplateList[index]).PrimaryItem; Result:=FTemplateList[index].PrimaryItem;
end; end;
procedure TMenuTemplates.CheckIndex(anIndex: integer); procedure TMenuTemplates.CheckIndex(anIndex: integer);
@ -467,19 +468,14 @@ end;
constructor TMenuTemplates.CreateForMode(aDialogMode: TDialogMode); constructor TMenuTemplates.CreateForMode(aDialogMode: TDialogMode);
begin begin
inherited Create; inherited Create;
FTemplateList:=TFPList.Create; FTemplateList:=TMenuTemplateList.Create;
if (aDialogMode = dmInsert) then if (aDialogMode = dmInsert) then
LoadDefaultTemplates; LoadDefaultTemplates;
LoadSavedTemplates; LoadSavedTemplates;
end; end;
destructor TMenuTemplates.Destroy; destructor TMenuTemplates.Destroy;
var
p: pointer;
mt: TMenuTemplate absolute p;
begin begin
for p in FTemplateList do
mt.Free;
FreeAndNil(FTemplateList); FreeAndNil(FTemplateList);
inherited Destroy; inherited Destroy;
end; end;