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

View File

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

View File

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

View File

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

View File

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