Menu designer: Separate GUI from logic better. Reduce dependencies. Use a new TMenuDesignerBase.

git-svn-id: trunk@51542 -
This commit is contained in:
juha 2016-02-08 20:00:31 +00:00
parent b406073c5d
commit 3f1790264f
5 changed files with 434 additions and 1668 deletions

View File

@ -1,4 +1,4 @@
object MenuDesigner: TMenuDesigner object MenuDesignerForm: TMenuDesignerForm
Left = 504 Left = 504
Height = 400 Height = 400
Top = 291 Top = 291

View File

@ -27,18 +27,18 @@ interface
uses uses
// FCL + LCL // FCL + LCL
Classes, SysUtils, Classes, SysUtils, typinfo,
Controls, StdCtrls, ExtCtrls, Forms, Graphics, Buttons, Menus, LCLintf, LCLProc, Controls, StdCtrls, ExtCtrls, Forms, Graphics, Buttons, Menus, LCLintf, LCLProc,
// IdeIntf // IdeIntf
LazIDEIntf, FormEditingIntf, IDEWindowIntf, ComponentEditors, PropEdits, LazIDEIntf, FormEditingIntf, PropEdits,
// IDE // IDE
LazarusIDEStrConsts, MenuShadows, MenuShortcuts; LazarusIDEStrConsts, MenuDesignerBase, MenuShortcuts;
type type
{ TMenuDesigner } { TMenuDesignerForm }
TMenuDesigner = class(TForm) TMenuDesignerForm = class(TForm)
AddItemAboveButton: TSpeedButton; AddItemAboveButton: TSpeedButton;
AddItemBelowButton: TSpeedButton; AddItemBelowButton: TSpeedButton;
AddSeparatorAboveButton: TSpeedButton; AddSeparatorAboveButton: TSpeedButton;
@ -63,21 +63,16 @@ type
procedure FormDestroy(Sender: TObject); procedure FormDestroy(Sender: TObject);
procedure HelpButtonClick(Sender: TObject); procedure HelpButtonClick(Sender: TObject);
strict private strict private
FAcceleratorMenuItemsCount: integer; FDesigner: TMenuDesignerBase;
FCaptionedItemsCount:integer;
FDeepestNestingLevel: integer;
FEditedMenu: TMenu; FEditedMenu: TMenu;
FAcceleratorMenuItemsCount: integer;
FCaptionedItemsCount: integer;
FDeepestNestingLevel: integer;
FGUIEnabled: boolean; FGUIEnabled: boolean;
FIconsCount: integer; FIconsCount: integer;
FUpdateCount: integer;
FPopupAssignments: TStringList; FPopupAssignments: TStringList;
FPopupAssignmentsListBox: TListBox; FPopupAssignmentsListBox: TListBox;
FSavedTemplatesCount: integer;
FShadowMenu: TShadowMenu;
FShortcuts: TMenuShortcuts;
FTemplatesSaved: boolean;
FTotalMenuItemsCount: integer;
FVariableGlyphsInMenuBar: boolean;
FUpdateCount: integer;
function GetItemCounts(out aCaptionedItemCount, aShortcutItemCount, function GetItemCounts(out aCaptionedItemCount, aShortcutItemCount,
anIconCount, anAccelCount: integer): integer; anIconCount, anAccelCount: integer): integer;
function GetPopupAssignmentCount: integer; function GetPopupAssignmentCount: integer;
@ -93,106 +88,84 @@ type
procedure ScanLookupRoot(aForm: TCustomForm); procedure ScanLookupRoot(aForm: TCustomForm);
procedure SetupPopupAssignmentsDisplay; procedure SetupPopupAssignmentsDisplay;
public public
constructor Create(aDesigner: TMenuDesignerBase);
destructor Destroy; override;
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 UpdateStatistics;
procedure UpdateTemplatesCount;
procedure UpdateSubmenuGroupBox(selMI: TMenuItem; selBox: TShadowBox; boxIsRoot:boolean);
procedure BeginUpdate; procedure BeginUpdate;
procedure EndUpdate; procedure EndUpdate;
function IsUpdate: Boolean; function IsUpdate: Boolean;
procedure UpdateStatistics;
procedure UpdateSubmenuGroupBox(selMI: TMenuItem; selBox: TShadowBoxBase; boxIsRoot:boolean);
procedure UpdateItemInfo(aMenu: TMenu; aMenuItem: TMenuItem;
aShadowBox: TShadowBoxBase; aPropEditHook: TPropertyEditorHook);
//property EditedMenu: TMenu read FEditedMenu;
//property AcceleratorMenuItemsCount: integer read FAcceleratorMenuItemsCount; //property AcceleratorMenuItemsCount: integer read FAcceleratorMenuItemsCount;
property EditedMenu: TMenu read FEditedMenu;
//property SavedTemplatesCount: integer read FSavedTemplatesCount;
property ShadowMenu: TShadowMenu read FShadowMenu;
property TemplatesSaved: boolean read FTemplatesSaved;
property TotalMenuItemsCount: integer read FTotalMenuItemsCount;
property VariableGlyphsInMenuBar: boolean read FVariableGlyphsInMenuBar;
end; end;
{ TMenuComponentEditor - the default component editor for TMenu } function GetNestingLevelDepth(aMenu: TMenu): integer;
TMainMenuComponentEditor = class(TComponentEditor)
public
procedure Edit; override;
function GetVerbCount: Integer; override;
function GetVerb(Index: Integer): string; override;
procedure ExecuteVerb(Index: Integer); override;
end;
{ TMenuItemsPropertyEditor - property editor for TMenuItem properties.
Invokes the parent menu's component editor }
TMenuItemsPropertyEditor = class(TClassPropertyEditor)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
end;
procedure ShowMenuEditor(aMenu: TMenu);
function MenuDesigner: TMenuDesigner;
implementation implementation
{$R *.lfm} {$R *.lfm}
function GetNestingLevelDepth(aMenu: TMenu): integer;
procedure CheckLevel(aMI: TMenuItem; aLevel: integer);
var
j: integer;
begin
if (aMI.Count > 0) then begin
if (Succ(aLevel) > Result) then
Result:=Succ(aLevel);
for j:=0 to aMI.Count-1 do
CheckLevel(aMI.Items[j], Succ(aLevel));
end;
end;
var var
MenuDesignerSingleton: TMenuDesigner = nil; i: integer;
procedure ShowMenuEditor(aMenu: TMenu);
begin begin
if (aMenu = nil) then Result:=0;
RaiseGDBException(lisMenuEditorShowMenuEditorTMenuParameterIsNil); for i:=0 to aMenu.Items.Count-1 do
MenuDesigner.SetMenu(aMenu, nil); CheckLevel(aMenu.Items[i], 0);
SetPopupModeParentForPropertyEditor(MenuDesigner);
MenuDesigner.ShowOnTop;
end; end;
function MenuDesigner: TMenuDesigner; // refer always to a single instance { TMenuDesignerForm }
constructor TMenuDesignerForm.Create(aDesigner: TMenuDesignerBase);
begin begin
if (MenuDesignerSingleton = nil) then Inherited Create(LazarusIDE.OwningComponent);
MenuDesignerSingleton:=TMenuDesigner.Create(LazarusIDE.OwningComponent); FDesigner := aDesigner;
Result:=MenuDesignerSingleton;
end; end;
{ TMenuDesigner } destructor TMenuDesignerForm.Destroy;
begin
inherited Destroy;
end;
procedure TMenuDesigner.FormCreate(Sender: TObject); procedure TMenuDesignerForm.FormCreate(Sender: TObject);
begin begin
Name:='MenuDesignerWindow'; Name:='MenuDesignerWindow';
Caption:=lisMenuEditorMenuEditor; Caption:=lisMenuEditorMenuEditor;
ButtonsGroupBox.Caption:=lisMenuEditorMenuItemActions; ButtonsGroupBox.Caption:=lisMenuEditorMenuItemActions;
FEditedMenu:=nil;
FGUIEnabled:=False; FGUIEnabled:=False;
LoadFixedButtonGlyphs; LoadFixedButtonGlyphs;
LoadVariableButtonGlyphs(True); LoadVariableButtonGlyphs(True);
KeyPreview:=True; KeyPreview:=True;
GlobalDesignHook.AddHandlerSetSelection(@OnDesignerSetSelection); GlobalDesignHook.AddHandlerSetSelection(@OnDesignerSetSelection);
FShortcuts:=TMenuShortcuts.Create;
InitializeStatisticVars; InitializeStatisticVars;
FTemplatesSaved:=SavedTemplatesExist;
SetupPopupAssignmentsDisplay; SetupPopupAssignmentsDisplay;
end; end;
procedure TMenuDesigner.FormDestroy(Sender: TObject); procedure TMenuDesignerForm.FormDestroy(Sender: TObject);
begin begin
FEditedMenu:=nil;
if (GlobalDesignHook <> nil) then
GlobalDesignHook.RemoveAllHandlersForObject(Self);
if (FShadowMenu <> nil) then begin
FShadowMenu.Parent:=nil;
FreeAndNil(FShadowMenu);
end;
FreeAndNil(FShortcuts);
FreeAndNil(FPopupAssignments); FreeAndNil(FPopupAssignments);
if MenuDesignerSingleton=Self then
MenuDesignerSingleton := nil;
end; end;
procedure TMenuDesigner.HelpButtonClick(Sender: TObject); procedure TMenuDesignerForm.HelpButtonClick(Sender: TObject);
const const
helpPath = 'http://wiki.lazarus.freepascal.org/IDE_Window:_menu_editor'; helpPath = 'http://wiki.lazarus.freepascal.org/IDE_Window:_menu_editor';
begin begin
@ -200,7 +173,7 @@ begin
OpenURL(helpPath); OpenURL(helpPath);
end; end;
procedure TMenuDesigner.OnDesignerSetSelection(const ASelection: TPersistentSelectionList); procedure TMenuDesignerForm.OnDesignerSetSelection(const ASelection: TPersistentSelectionList);
var var
mnu: TMenu; mnu: TMenu;
mi, tmp: TMenuItem; mi, tmp: TMenuItem;
@ -223,8 +196,8 @@ begin
mnu:=tmp.Menu; mnu:=tmp.Menu;
if (mnu = nil) then if (mnu = nil) then
mnu:=mi.GetParentMenu; mnu:=mi.GetParentMenu;
if (mnu = FEditedMenu) and (FShadowMenu <> nil) then if (mnu = FEditedMenu) and (FDesigner.ShadowMenu <> nil) then
FShadowMenu.SetSelectedMenuItem(mi, True, False) FDesigner.ShadowMenu.SetSelectedMenuItem(mi, True, False)
else if (mnu <> nil) then else if (mnu <> nil) then
SetMenu(mnu, mi); SetMenu(mnu, mi);
end; end;
@ -233,7 +206,7 @@ begin
SetMenu(nil, nil); SetMenu(nil, nil);
end; end;
procedure TMenuDesigner.ShowPopupAssignmentsInfo; procedure TMenuDesignerForm.ShowPopupAssignmentsInfo;
var var
count: integer; count: integer;
begin begin
@ -242,19 +215,22 @@ begin
PopupAssignmentsCountLabel.Enabled:=True; PopupAssignmentsCountLabel.Enabled:=True;
if (count > 0) then if (count > 0) then
PopupAssignmentsCountLabel.BorderSpacing.Bottom:=0 PopupAssignmentsCountLabel.BorderSpacing.Bottom:=0
else PopupAssignmentsCountLabel.BorderSpacing.Bottom:=Double_Margin; else
PopupAssignmentsCountLabel.BorderSpacing.Bottom:=Double_Margin;
if (count= -1) then if (count= -1) then
PopupAssignmentsCountLabel.Caption:=Format(lisMenuEditorPopupAssignmentsS,[lisMenuEditorNA]) PopupAssignmentsCountLabel.Caption:=Format(lisMenuEditorPopupAssignmentsS,[lisMenuEditorNA])
else PopupAssignmentsCountLabel.Caption:=Format(lisMenuEditorPopupAssignmentsS, [IntToStr(count)]); else
PopupAssignmentsCountLabel.Caption:=Format(lisMenuEditorPopupAssignmentsS, [IntToStr(count)]);
if (count > 0) then begin if (count > 0) then begin
FPopupAssignmentsListBox.Items.Assign(FPopupAssignments); FPopupAssignmentsListBox.Items.Assign(FPopupAssignments);
FPopupAssignmentsListBox.Visible:=True; FPopupAssignmentsListBox.Visible:=True;
end end
else FPopupAssignmentsListBox.Visible:=False; else
FPopupAssignmentsListBox.Visible:=False;
end; end;
end; end;
procedure TMenuDesigner.HidePopupAssignmentsInfo; procedure TMenuDesignerForm.HidePopupAssignmentsInfo;
begin begin
if (FEditedMenu <> nil) and (FEditedMenu is TMainMenu) then begin if (FEditedMenu <> nil) and (FEditedMenu is TMainMenu) then begin
PopupAssignmentsCountLabel.Caption:=Format(lisMenuEditorPopupAssignmentsS,[lisMenuEditorNA]); PopupAssignmentsCountLabel.Caption:=Format(lisMenuEditorPopupAssignmentsS,[lisMenuEditorNA]);
@ -263,7 +239,7 @@ begin
end; end;
end; end;
procedure TMenuDesigner.SetupPopupAssignmentsDisplay; procedure TMenuDesignerForm.SetupPopupAssignmentsDisplay;
begin begin
FPopupAssignmentsListBox:=TListBox.Create(Self); FPopupAssignmentsListBox:=TListBox.Create(Self);
with FPopupAssignmentsListBox do begin with FPopupAssignmentsListBox do begin
@ -289,7 +265,7 @@ begin
end; end;
end; end;
function TMenuDesigner.GetItemCounts(out aCaptionedItemCount, function TMenuDesignerForm.GetItemCounts(out aCaptionedItemCount,
aShortcutItemCount, anIconCount, anAccelCount: integer): integer; aShortcutItemCount, anIconCount, anAccelCount: integer): integer;
var var
imgCount: integer; imgCount: integer;
@ -333,7 +309,7 @@ begin
ProcessItems(FEditedMenu.Items[i]); ProcessItems(FEditedMenu.Items[i]);
end; end;
function TMenuDesigner.GetSelectedMenuComponent(const aSelection: TPersistentSelectionList; function TMenuDesignerForm.GetSelectedMenuComponent(const aSelection: TPersistentSelectionList;
out isTMenu: boolean; out isTMenuItem: boolean): TPersistent; out isTMenu: boolean; out isTMenuItem: boolean): TPersistent;
begin begin
if (aSelection.Count = 1) then begin if (aSelection.Count = 1) then begin
@ -356,10 +332,11 @@ begin
Result:=nil; Result:=nil;
end; end;
end end
else Result:=nil; else
Result:=nil;
end; end;
procedure TMenuDesigner.ProcessForPopup(aControl: TControl); procedure TMenuDesignerForm.ProcessForPopup(aControl: TControl);
var var
wc: TWinControl; wc: TWinControl;
j:integer; j:integer;
@ -373,7 +350,7 @@ begin
end; end;
end; end;
procedure TMenuDesigner.ScanLookupRoot(aForm: TCustomForm); procedure TMenuDesignerForm.ScanLookupRoot(aForm: TCustomForm);
var var
i: integer; i: integer;
begin begin
@ -383,7 +360,7 @@ begin
ProcessForPopup(aForm.Controls[i]); ProcessForPopup(aForm.Controls[i]);
end; end;
function TMenuDesigner.GetPopupAssignmentCount: integer; function TMenuDesignerForm.GetPopupAssignmentCount: integer;
var var
lookupRoot: TPersistent; lookupRoot: TPersistent;
begin begin
@ -398,7 +375,7 @@ begin
end end
end; end;
procedure TMenuDesigner.LoadVariableButtonGlyphs(isInMenubar: boolean); procedure TMenuDesignerForm.LoadVariableButtonGlyphs(isInMenubar: boolean);
begin begin
if isInMenubar then if isInMenubar then
begin begin
@ -416,10 +393,10 @@ begin
AddSubMenuButton.LoadGlyphFromResourceName(HINSTANCE,'add_submenu_right'); AddSubMenuButton.LoadGlyphFromResourceName(HINSTANCE,'add_submenu_right');
end; end;
UpdateSubmenuGroupBox(nil, nil, False); UpdateSubmenuGroupBox(nil, nil, False);
FVariableGlyphsInMenuBar:=isInMenubar; FDesigner.VariableGlyphsInMenuBar:=isInMenubar;
end; end;
procedure TMenuDesigner.LoadFixedButtonGlyphs; procedure TMenuDesignerForm.LoadFixedButtonGlyphs;
begin begin
DeleteItemButton.LoadGlyphFromResourceName(HINSTANCE,'laz_delete'); DeleteItemButton.LoadGlyphFromResourceName(HINSTANCE,'laz_delete');
AddSeparatorAboveButton.LoadGlyphFromResourceName(HINSTANCE,'add_sep_above'); AddSeparatorAboveButton.LoadGlyphFromResourceName(HINSTANCE,'add_sep_above');
@ -427,7 +404,7 @@ begin
HelpButton.Hint:=lisMenuEditorGetHelpToUseThisEditor; HelpButton.Hint:=lisMenuEditorGetHelpToUseThisEditor;
end; end;
procedure TMenuDesigner.EnableGUI(selectedIsNil: boolean); procedure TMenuDesignerForm.EnableGUI(selectedIsNil: boolean);
var var
isPopupMenu: boolean; isPopupMenu: boolean;
begin begin
@ -449,15 +426,15 @@ begin
end; end;
end; end;
procedure TMenuDesigner.InitializeStatisticVars; procedure TMenuDesignerForm.InitializeStatisticVars;
begin begin
FShortcuts.ResetMenuItemsCount; FDesigner.Shortcuts.ResetMenuItemsCount;
FIconsCount := -1; FIconsCount := -1;
FDeepestNestingLevel := -1; FDeepestNestingLevel := -1;
FCaptionedItemsCount := -1; FCaptionedItemsCount := -1;
end; end;
procedure TMenuDesigner.DisableGUI; procedure TMenuDesignerForm.DisableGUI;
begin begin
if FGUIEnabled then begin if FGUIEnabled then begin
StatisticsGroupBox.Font.Style:=[]; StatisticsGroupBox.Font.Style:=[];
@ -477,65 +454,78 @@ begin
end; end;
end; end;
procedure TMenuDesigner.SetMenu(aMenu: TMenu; aMenuItem: TMenuItem); procedure TMenuDesignerForm.SetMenu(aMenu: TMenu; aMenuItem: TMenuItem);
var var
selection: TMenuItem; selection: TMenuItem;
begin begin
if (aMenu = nil) then if (aMenu = nil) then
begin begin
DisableGUI; DisableGUI;
if FShadowMenu <> nil then FDesigner.FreeShadowMenu;
FShadowMenu.SelectedMenuItem:=nil;
if Assigned(GlobalDesignHook) then
GlobalDesignHook.RemoveAllHandlersForObject(FShadowMenu);
FreeAndNil(FShadowMenu);
FEditedMenu:=nil; FEditedMenu:=nil;
Application.ProcessMessages; Application.ProcessMessages;
end end
else begin else begin
if (aMenu = FEditedMenu) and (FShadowMenu <> nil) then if (aMenu = FEditedMenu) and (FDesigner.ShadowMenu <> nil) then
FShadowMenu.SetSelectedMenuItem(aMenuItem, True, False) FDesigner.ShadowMenu.SetSelectedMenuItem(aMenuItem, True, False)
else begin else begin
if (aMenu = FEditedMenu) and (FShadowMenu = nil) then if (aMenu = FEditedMenu) and (FDesigner.ShadowMenu = 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 else
selection:=nil; selection := nil;
end end
else if (aMenu <> FEditedMenu) then else if (aMenu <> FEditedMenu) then
begin begin
FreeAndNil(FShadowMenu); FDesigner.ShadowMenu.Free;
FEditedMenu:=aMenu; FDesigner.ShadowMenu := Nil;
selection:=aMenuItem; FEditedMenu := aMenu;
selection := aMenuItem;
end; end;
FGUIEnabled:=False; FGUIEnabled := False;
EnableGUI(selection = nil); EnableGUI(selection = nil);
UpdateStatistics; UpdateStatistics;
FShadowMenu:=TShadowMenu.CreateWithMenuAndDims(Canvas, FShortcuts, FDesigner.CreateShadowMenu(FEditedMenu, selection, Width-LeftPanel.Width, Height);
FEditedMenu, selection, Width-LeftPanel.Width, Height);
FShadowMenu.Parent := Self;
FShadowMenu.Align := alClient;
end; end;
end; end;
end; end;
procedure TMenuDesigner.UpdateStatistics; procedure TMenuDesignerForm.BeginUpdate;
begin
Inc(FUpdateCount);
end;
procedure TMenuDesignerForm.EndUpdate;
begin
if FUpdateCount<=0 then
RaiseGDBException('');
Dec(FUpdateCount);
if FUpdateCount = 0 then
OnDesignerSetSelection(FormEditingHook.GetCurrentObjectInspector.Selection);
end;
function TMenuDesignerForm.IsUpdate: Boolean;
begin
Result := FUpdateCount > 0;
end;
procedure TMenuDesignerForm.UpdateStatistics;
var var
captions, shortcuts, icons, accels, tmp: integer; captions, shrtcuts, icons, accels, tmp: integer;
s: String; 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;
FTotalMenuItemsCount:=GetItemCounts(captions, shortcuts, icons, accels); FDesigner.TotalMenuItemsCount:=GetItemCounts(captions, shrtcuts, icons, accels);
if (FCaptionedItemsCount <> captions) then begin if (FCaptionedItemsCount <> captions) then begin
FCaptionedItemsCount:=captions; FCaptionedItemsCount:=captions;
CaptionedItemsCountLabel.Caption:= CaptionedItemsCountLabel.Caption:=
Format(lisMenuEditorCaptionedItemsS, [IntToStr(captions)]); Format(lisMenuEditorCaptionedItemsS, [IntToStr(captions)]);
end; end;
s:=FShortcuts.Statistics(shortcuts); s:=FDesigner.Shortcuts.Statistics(shrtcuts);
if s <> '' then if s <> '' then
ShortcutItemsCountLabel.Caption := s; ShortcutItemsCountLabel.Caption := s;
if (FIconsCount <> icons) then begin if (FIconsCount <> icons) then begin
@ -554,34 +544,8 @@ begin
StatisticsGroupBox.Invalidate; StatisticsGroupBox.Invalidate;
end; end;
procedure TMenuDesigner.UpdateTemplatesCount; procedure TMenuDesignerForm.UpdateSubmenuGroupBox(selMI: TMenuItem;
begin selBox: TShadowBoxBase; boxIsRoot: boolean);
FTemplatesSaved:=SavedTemplatesExist;
DebugLn('SavedTemplatesExist is %s',[booltostr(FTemplatesSaved)]);
FSavedTemplatesCount:=GetSavedTemplatesCount;
end;
procedure TMenuDesigner.BeginUpdate;
begin
Inc(FUpdateCount);
end;
procedure TMenuDesigner.EndUpdate;
begin
if FUpdateCount<=0 then
RaiseGDBException('');
Dec(FUpdateCount);
if FUpdateCount = 0 then
OnDesignerSetSelection(FormEditingHook.GetCurrentObjectInspector.Selection);
end;
function TMenuDesigner.IsUpdate: Boolean;
begin
Result := FUpdateCount > 0;
end;
procedure TMenuDesigner.UpdateSubmenuGroupBox(selMI: TMenuItem;
selBox: TShadowBox; boxIsRoot: boolean);
begin begin
if SubmenuGroupBox = nil then if SubmenuGroupBox = nil then
Exit; Exit;
@ -621,58 +585,30 @@ begin
end; end;
end; end;
{ TMainMenuComponentEditor} procedure TMenuDesignerForm.UpdateItemInfo(aMenu: TMenu; aMenuItem: TMenuItem;
aShadowBox: TShadowBoxBase; aPropEditHook: TPropertyEditorHook);
procedure TMainMenuComponentEditor.Edit;
begin
ShowMenuEditor(Component as TMenu);
end;
function TMainMenuComponentEditor.GetVerbCount: Integer;
begin
Result:=1;
end;
function TMainMenuComponentEditor.GetVerb(Index: Integer): string;
begin
case Index of
0: Result:=lisMenuEditorMenuEditor + ' ...';
else Result:='';
end;
end;
procedure TMainMenuComponentEditor.ExecuteVerb(Index: Integer);
begin
if (Index = 0) then
Edit;
end;
{ TMenuItemsPropertyEditor }
procedure TMenuItemsPropertyEditor.Edit;
var var
mnu: TMenu; s: string;
mnuItem: TMenuItem; method: TMethod;
designer: TComponentEditorDesigner;
begin begin
mnuItem:=TMenuItem(GetObjectValue(TMenuItem)); if aMenuItem = nil then
if (mnuItem <> nil) then
begin begin
mnu:=mnuItem.GetParentMenu; Caption:=Format(lisMenuEditorEditingSSNoMenuitemSelected,
designer:=FindRootDesigner(mnu) as TComponentEditorDesigner; [aMenu.Owner.Name, aMenu.Name]);
if (mnu <> nil) and (designer <> nil) then ButtonsGroupBox.Enabled:=False;
ShowMenuEditor(mnu); UpdateSubmenuGroupBox(nil, nil, False);
end
else begin
method:=GetMethodProp(aMenuItem, 'OnClick');
s:=aPropEditHook.GetMethodName(method, aMenuItem);
if s = '' then
s:=lisMenuEditorIsNotAssigned;
Caption:=Format(lisMenuEditorSSSOnClickS,
[aMenu.Owner.Name, aMenu.Name, aMenuItem.Name, s]);
ButtonsGroupBox.Enabled:=True;
UpdateSubmenuGroupBox(aMenuItem, aShadowBox, aShadowBox.Level=0);
end; end;
end; end;
function TMenuItemsPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paRevertable, paReadOnly];
end;
initialization
RegisterComponentEditor(TMenu, TMainMenuComponentEditor);
RegisterPropertyEditor(TypeInfo(TMenu), TMenu, 'Items', TMenuItemsPropertyEditor);
end. end.

File diff suppressed because it is too large Load Diff

View File

@ -5,13 +5,13 @@ unit MenuShortcuts;
interface interface
uses uses
Classes, SysUtils, types, typinfo, Classes, SysUtils, types,
ActnList, ButtonPanel, Buttons, Controls, Dialogs, StdCtrls, ExtCtrls, Menus, ActnList, ButtonPanel, Controls, Dialogs, StdCtrls, Menus,
Forms, Graphics, Themes, LCLType, LCLIntf, LCLProc, Forms, Graphics, LCLType, LCLIntf, LCLProc,
// LazUtils // LazUtils
LazUTF8, LazFileUtils, LazUTF8,
// IdeIntf // IdeIntf
ComponentEditors, IDEDialogs, PropEdits, IDEDialogs, PropEdits,
// IDE // IDE
LazarusIDEStrConsts; LazarusIDEStrConsts;
@ -324,7 +324,8 @@ begin
aShortcut:=KeyToShortCut(Ord(accelStr[1]), aShortcut:=KeyToShortCut(Ord(accelStr[1]),
{$if defined(darwin) or defined(macos) or defined(iphonesim)} [ssMeta] {$if defined(darwin) or defined(macos) or defined(iphonesim)} [ssMeta]
{$else} [ssAlt] {$endif}) {$else} [ssAlt] {$endif})
else aShortcut:=0; else
aShortcut:=0;
end; end;
{ {
function GetAcceleratedItemsCount(aMenu: TMenu): integer; function GetAcceleratedItemsCount(aMenu: TMenu): integer;

View File

@ -93,7 +93,7 @@ uses
// designer // designer
JITForms, ComponentPalette, ComponentList, CompPagesPopup, IdeCoolbarData, JITForms, ComponentPalette, ComponentList, CompPagesPopup, IdeCoolbarData,
ObjInspExt, Designer, FormEditor, CustomFormEditor, lfmUnitResource, ObjInspExt, Designer, FormEditor, CustomFormEditor, lfmUnitResource,
ControlSelection, AnchorEditor, TabOrderDlg, MenuEditorForm, ControlSelection, AnchorEditor, TabOrderDlg, MenuShadows,
// LRT stuff // LRT stuff
Translations, Translations,
// debugger // debugger