LCL: setting Action.OnExecute no longer changes the TMenuItem.OnClick

git-svn-id: trunk@41416 -
This commit is contained in:
mattias 2013-05-26 12:47:37 +00:00
parent 66a30a311c
commit 9a518d7730
5 changed files with 35 additions and 27 deletions

View File

@ -2693,13 +2693,24 @@ end;
TControl Click
------------------------------------------------------------------------------}
procedure TControl.Click;
function OnClickIsActionExecute: boolean;
begin
Result:=false;
if Action=nil then exit;
if not Assigned(Action.OnExecute) then exit;
if not Assigned(FOnClick) then exit;
Result:=CompareMethods(TMethod(FOnClick),TMethod(Action.OnExecute));
end;
begin
//DebugLn(['TControl.Click ',DbgSName(Self)]);
// first call our own OnClick
if Assigned(FOnClick) then
FOnClick(Self);
// then trigger the Action
if (not (csDesigning in ComponentState)) and (ActionLink <> nil) then
if (not (csDesigning in ComponentState)) and (ActionLink <> nil)
and (not OnClickIsActionExecute) then
ActionLink.Execute(Self);
end;

View File

@ -58,8 +58,7 @@ end;
function TControlActionLink.IsOnExecuteLinked: Boolean;
begin
Result := inherited IsOnExecuteLinked
and CompareMethods(TMethod(FClient.OnClick),TMethod(Action.OnExecute));
Result := inherited IsOnExecuteLinked;
end;
procedure TControlActionLink.SetCaption(const Value: string);

View File

@ -76,8 +76,7 @@ end;
function TMenuActionLink.IsOnExecuteLinked: Boolean;
begin
Result := inherited IsOnExecuteLinked
and CompareMethods(TMethod(FClient.OnClick),TMethod(Action.OnExecute));
Result := inherited IsOnExecuteLinked;
end;
procedure TMenuActionLink.SetAutoCheck(Value: Boolean);
@ -127,7 +126,8 @@ end;
procedure TMenuActionLink.SetOnExecute(Value: TNotifyEvent);
begin
if IsOnExecuteLinked then FClient.OnClick := Value;
// Note: formerly this changed FClient.OnClick, but that is unneeded, because
// TMenuItem.Click executes Action
end;

View File

@ -50,13 +50,24 @@ end;
Call hooks and actions.
------------------------------------------------------------------------------}
procedure TMenuItem.Click;
function OnClickIsActionExecute: boolean;
begin
Result:=false;
if Action=nil then exit;
if not Assigned(Action.OnExecute) then exit;
if not Assigned(FOnClick) then exit;
Result:=CompareMethods(TMethod(FOnClick),TMethod(Action.OnExecute));
end;
begin
if Enabled then
begin
if Assigned(OnMenuPopupHandler) then OnMenuPopupHandler(Self);
if (not Assigned(ActionLink) and AutoCheck) or (Assigned(ActionLink) and
not (ActionLink.IsAutoCheckLinked) and AutoCheck) then
if AutoCheck
and ((not Assigned(ActionLink))
or (Assigned(ActionLink) and not ActionLink.IsAutoCheckLinked)) then
begin
// Break a little Delphi compatibility
// It makes no sense to uncheck a checked RadioItem (besides, GTK can't handle it)
@ -64,17 +75,13 @@ begin
Checked := not Checked;
end;
{ Call OnClick if assigned and not equal to associated action's OnExecute.
If associated action's OnExecute assigned then call it, otherwise, call
OnClick. }
if Assigned(FOnClick) and (Action <> nil) and (FOnClick <> Action.OnExecute) then
FOnClick(Self)
else
if not (csDesigning in ComponentState) and (ActionLink <> nil) then
FActionLink.Execute(Self)
else
// first call our OnClick
if Assigned(FOnClick) then
FOnClick(Self);
// then trigger the Action
if not (csDesigning in ComponentState) and (ActionLink <> nil)
and not OnClickIsActionExecute then
FActionLink.Execute(Self);
end;
end;
@ -388,8 +395,6 @@ begin
ShortCut := NewAction.ShortCut;
if (not CheckDefaults) or (Visible = True) then
Visible := NewAction.Visible;
if (not CheckDefaults) or not Assigned(OnClick) then
OnClick := NewAction.OnExecute;
end;
end;
@ -537,11 +542,6 @@ begin
Result := (ActionLink = nil) or not FActionLink.IsImageIndexLinked;
end;
function TMenuItem.IsOnClickStored: Boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsOnExecuteLinked;
end;
{------------------------------------------------------------------------------
function TMenuItem.IsShortCutStored: boolean;
@ -1497,7 +1497,6 @@ begin
HelpContext := Self.HelpContext;
Hint := Self.Hint;
ImageIndex := Self.ImageIndex;
OnExecute := Self.OnClick;
Visible := Self.Visible;
end
end else

View File

@ -153,7 +153,6 @@ type
function IsHelpContextStored: boolean;
function IsHintStored: Boolean;
function IsImageIndexStored: Boolean;
function IsOnClickStored: Boolean;
function IsShortCutStored: boolean;
function IsVisibleStored: boolean;
procedure SetAutoCheck(const AValue: boolean);
@ -284,7 +283,7 @@ type
property SubMenuImages: TCustomImageList read FSubMenuImages write SetSubMenuImages;
property Visible: Boolean read FVisible write SetVisible
stored IsVisibleStored default True;
property OnClick: TNotifyEvent read FOnClick write FOnClick stored IsOnClickStored;
property OnClick: TNotifyEvent read FOnClick write FOnClick;
end;
TMenuItemClass = class of TMenuItem;