Use the new unit MenuShortcuts in MenuEditorForm and MenuShadows.

git-svn-id: trunk@51492 -
This commit is contained in:
juha 2016-02-03 20:17:28 +00:00
parent d8eb3a2d5c
commit 23e3213c00
2 changed files with 725 additions and 1980 deletions

View File

@ -32,7 +32,7 @@ uses
// IdeIntf // IdeIntf
LazIDEIntf, FormEditingIntf, IDEWindowIntf, ComponentEditors, PropEdits, LazIDEIntf, FormEditingIntf, IDEWindowIntf, ComponentEditors, PropEdits,
// IDE // IDE
LazarusIDEStrConsts, MenuShadows; LazarusIDEStrConsts, MenuShadows, MenuShortcuts;
type type
@ -73,9 +73,7 @@ type
FPopupAssignmentsListBox: TListBox; FPopupAssignmentsListBox: TListBox;
FSavedTemplatesCount: integer; FSavedTemplatesCount: integer;
FShadowMenu: TShadowMenu; FShadowMenu: TShadowMenu;
FShortcutConflictsCount: integer; FShortcuts: TMenuShortcuts;
FShortcutList: TSCList;
FShortcutMenuItemsCount: integer;
FTemplatesSaved: boolean; FTemplatesSaved: boolean;
FTotalMenuItemsCount: integer; FTotalMenuItemsCount: integer;
FVariableGlyphsInMenuBar: boolean; FVariableGlyphsInMenuBar: boolean;
@ -98,20 +96,16 @@ type
procedure LoadVariableButtonGlyphs(isInMenubar: boolean); procedure LoadVariableButtonGlyphs(isInMenubar: boolean);
procedure SetMenu(aMenu: TMenu; aMenuItem: TMenuItem); procedure SetMenu(aMenu: TMenu; aMenuItem: TMenuItem);
procedure ShowPopupAssignmentsInfo; procedure ShowPopupAssignmentsInfo;
procedure UpdateShortcutList(includeAccelerators: boolean=False);
procedure UpdateStatistics; procedure UpdateStatistics;
procedure UpdateTemplatesCount; procedure UpdateTemplatesCount;
procedure UpdateSubmenuGroupBox(selMI: TMenuItem; selBox: TShadowBox; boxIsRoot:boolean); procedure UpdateSubmenuGroupBox(selMI: TMenuItem; selBox: TShadowBox; boxIsRoot:boolean);
procedure BeginUpdate; procedure BeginUpdate;
procedure EndUpdate; procedure EndUpdate;
function IsUpdate: Boolean; function IsUpdate: Boolean;
property AcceleratorMenuItemsCount: integer read FAcceleratorMenuItemsCount; //property AcceleratorMenuItemsCount: integer read FAcceleratorMenuItemsCount;
property EditedMenu: TMenu read FEditedMenu; property EditedMenu: TMenu read FEditedMenu;
property SavedTemplatesCount: integer read FSavedTemplatesCount; //property SavedTemplatesCount: integer read FSavedTemplatesCount;
property ShadowMenu: TShadowMenu read FShadowMenu; property ShadowMenu: TShadowMenu read FShadowMenu;
property ShortcutConflictsCount: integer read FShortcutConflictsCount;
property ShortcutList: TSCList read FShortcutList;
property ShortcutMenuItemsCount: integer read FShortcutMenuItemsCount;
property TemplatesSaved: boolean read FTemplatesSaved; property TemplatesSaved: boolean read FTemplatesSaved;
property TotalMenuItemsCount: integer read FTotalMenuItemsCount; property TotalMenuItemsCount: integer read FTotalMenuItemsCount;
property VariableGlyphsInMenuBar: boolean read FVariableGlyphsInMenuBar; property VariableGlyphsInMenuBar: boolean read FVariableGlyphsInMenuBar;
@ -177,7 +171,7 @@ begin
LoadVariableButtonGlyphs(True); LoadVariableButtonGlyphs(True);
KeyPreview:=True; KeyPreview:=True;
GlobalDesignHook.AddHandlerSetSelection(@OnDesignerSetSelection); GlobalDesignHook.AddHandlerSetSelection(@OnDesignerSetSelection);
FShortcutList:=TSCList.Create; FShortcuts:=TMenuShortcuts.Create;
InitializeStatisticVars; InitializeStatisticVars;
FTemplatesSaved:=SavedTemplatesExist; FTemplatesSaved:=SavedTemplatesExist;
SetupPopupAssignmentsDisplay; SetupPopupAssignmentsDisplay;
@ -190,10 +184,9 @@ begin
GlobalDesignHook.RemoveAllHandlersForObject(Self); GlobalDesignHook.RemoveAllHandlersForObject(Self);
if (FShadowMenu <> nil) then begin if (FShadowMenu <> nil) then begin
FShadowMenu.Parent:=nil; FShadowMenu.Parent:=nil;
FShadowMenu.Free; FreeAndNil(FShadowMenu);
FShadowMenu:=nil;
end; end;
FreeAndNil(FShortcutList); FreeAndNil(FShortcuts);
FreeAndNil(FPopupAssignments); FreeAndNil(FPopupAssignments);
if MenuDesignerSingleton=Self then if MenuDesignerSingleton=Self then
MenuDesignerSingleton := nil; MenuDesignerSingleton := nil;
@ -233,10 +226,11 @@ begin
if (mnu = FEditedMenu) and (FShadowMenu <> nil) then if (mnu = FEditedMenu) and (FShadowMenu <> nil) then
FShadowMenu.SetSelectedMenuItem(mi, True, False) FShadowMenu.SetSelectedMenuItem(mi, True, False)
else if (mnu <> nil) then else if (mnu <> nil) then
SetMenu(mnu, mi); SetMenu(mnu, mi);
end; end;
end end
else SetMenu(nil, nil); else
SetMenu(nil, nil);
end; end;
procedure TMenuDesigner.ShowPopupAssignmentsInfo; procedure TMenuDesigner.ShowPopupAssignmentsInfo;
@ -457,10 +451,10 @@ end;
procedure TMenuDesigner.InitializeStatisticVars; procedure TMenuDesigner.InitializeStatisticVars;
begin begin
FShortcutMenuItemsCount:= -1; FShortcuts.ResetMenuItemsCount;
FIconsCount:= -1; FIconsCount := -1;
FDeepestNestingLevel:= -1; FDeepestNestingLevel := -1;
FCaptionedItemsCount:= -1; FCaptionedItemsCount := -1;
end; end;
procedure TMenuDesigner.DisableGUI; procedure TMenuDesigner.DisableGUI;
@ -486,9 +480,9 @@ end;
procedure TMenuDesigner.SetMenu(aMenu: TMenu; aMenuItem: TMenuItem); procedure TMenuDesigner.SetMenu(aMenu: TMenu; aMenuItem: TMenuItem);
var var
selection: TMenuItem; selection: TMenuItem;
w: integer;
begin begin
if (aMenu = nil) then begin if (aMenu = nil) then
begin
DisableGUI; DisableGUI;
if FShadowMenu <> nil then if FShadowMenu <> nil then
FShadowMenu.SelectedMenuItem:=nil; FShadowMenu.SelectedMenuItem:=nil;
@ -498,41 +492,39 @@ begin
FEditedMenu:=nil; FEditedMenu:=nil;
Application.ProcessMessages; Application.ProcessMessages;
end end
else else begin
begin if (aMenu = FEditedMenu) and (FShadowMenu <> nil) then
if (aMenu = FEditedMenu) and (FShadowMenu <> nil) then FShadowMenu.SetSelectedMenuItem(aMenuItem, True, False)
FShadowMenu.SetSelectedMenuItem(aMenuItem, True, False) else begin
else begin if (aMenu = FEditedMenu) and (FShadowMenu = nil) then
if (aMenu = FEditedMenu) and (FShadowMenu = nil) then begin begin
if (FEditedMenu.Items.Count > 0) then if (FEditedMenu.Items.Count > 0) then
selection:=FEditedMenu.Items[0] selection:=FEditedMenu.Items[0]
else selection:=nil; else
end selection:=nil;
else if (aMenu <> FEditedMenu) then begin end
if (FShadowMenu <> nil) then else if (aMenu <> FEditedMenu) then
FreeAndNil(FShadowMenu); begin
FEditedMenu:=aMenu; FreeAndNil(FShadowMenu);
selection:=aMenuItem; FEditedMenu:=aMenu;
end; selection:=aMenuItem;
FGUIEnabled:=False;
EnableGUI(selection = nil);
UpdateStatistics;
FShortcutList.ClearAllLists;
FShortcutList.ScanContainerForShortcutsAndAccelerators;
FShortcutConflictsCount:=FShortcutList.InitialDuplicatesCount;
w:=Width - LeftPanel.Width;
FShadowMenu:=TShadowMenu.CreateWithMenuAndDims(Canvas, FEditedMenu, selection,
w, Height);
FShadowMenu.Parent := Self;
FShadowMenu.Align := alClient;
end; end;
FGUIEnabled:=False;
EnableGUI(selection = nil);
UpdateStatistics;
FShadowMenu:=TShadowMenu.CreateWithMenuAndDims(Canvas, FShortcuts,
FEditedMenu, selection, Width-LeftPanel.Width, Height);
FShadowMenu.Parent := Self;
FShadowMenu.Align := alClient;
end; end;
end;
end; end;
procedure TMenuDesigner.UpdateStatistics; procedure TMenuDesigner.UpdateStatistics;
var var
captions, shortcuts, icons, accels, tmp: integer; captions, shortcuts, icons, accels, tmp: integer;
s: String;
begin begin
if not SameText(StatisticsGroupBox.Caption, FEditedMenu.Name) then if not SameText(StatisticsGroupBox.Caption, FEditedMenu.Name) then
StatisticsGroupBox.Caption:=FEditedMenu.Name; StatisticsGroupBox.Caption:=FEditedMenu.Name;
@ -543,11 +535,9 @@ begin
CaptionedItemsCountLabel.Caption:= CaptionedItemsCountLabel.Caption:=
Format(lisMenuEditorCaptionedItemsS, [IntToStr(captions)]); Format(lisMenuEditorCaptionedItemsS, [IntToStr(captions)]);
end; end;
if (FShortcutMenuItemsCount <> shortcuts) then begin s:=FShortcuts.Statistics(shortcuts);
FShortcutMenuItemsCount:=shortcuts; if s <> '' then
ShortcutItemsCountLabel.Caption:= ShortcutItemsCountLabel.Caption := s;
Format(lisMenuEditorShortcutItemsS, [IntToStr(FShortcutMenuItemsCount)]);
end;
if (FIconsCount <> icons) then begin if (FIconsCount <> icons) then begin
FIconsCount:=icons; FIconsCount:=icons;
IconCountLabel.Caption:= IconCountLabel.Caption:=
@ -564,13 +554,6 @@ begin
StatisticsGroupBox.Invalidate; StatisticsGroupBox.Invalidate;
end; end;
procedure TMenuDesigner.UpdateShortcutList(includeAccelerators: boolean);
begin
if includeAccelerators then
FShortcutList.ScanContainerForShortcutsAndAccelerators
else FShortcutList.ScanContainerForShortcutsOnly;
end;
procedure TMenuDesigner.UpdateTemplatesCount; procedure TMenuDesigner.UpdateTemplatesCount;
begin begin
FTemplatesSaved:=SavedTemplatesExist; FTemplatesSaved:=SavedTemplatesExist;

File diff suppressed because it is too large Load Diff