View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0012776LazarusLCLpublic2008-12-09 21:102009-06-13 12:08
ReporterMichael Van Canneyt 
Assigned ToPaul Ishenin 
PriorityhighSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
PlatformLinuxOSLinuxOS Version
Product Version0.9.27 (SVN)Product Build 
Target Version1.0.0Fixed in Version0.9.27 (SVN) 
Summary0012776: Actions not updated if only in menu
DescriptionWhen an action is attached only to a menu item, it is not updated
when the menu item is made visible. Actions that are attached to menu items are not updated when a menu is popped up.
Steps To ReproduceCompile and run attached sample program.
Note that the checkbox is not checked, and hence the action should be disabled.
- Click 'Test' menu: 'Test action' menu item should be enabled.
- Click it.
  The action is NOT executed, because update handler is executed first
  and it disables the action.
- Click 'test' menu again: 'Test action' menu item is now disabled.
The 'OnUpdate' handler should be executed whenever the associated menu item becomes visible.
TagsNo tags attached.
Fixed in Revision18006
LazTarget1.0
WidgetsetGTK
Attached Fileszip file icon actionbug.zip [^] (231,131 bytes) 2008-12-09 21:10

- Relationships

-  Notes
(0023738)
Vincent Snijders (manager)
2008-12-09 21:14
edited on: 2008-12-09 21:14

0.9.28, if a patch is provided or this is a regression (= it worked correctly in earlier Lazarus versions).

(0023844)
Leslie Kaye (reporter)
2008-12-15 13:49
edited on: 2008-12-18 09:54

The problem is caused by a missing call to TMainMenu.FItems.InitiateActions
I suggest the resolution is to place the following at the start of TMenuItem.Click;
****
if IsInMenuBar then
  InitiateActions;
****
Note: missing feature...
TPopupMenu should have a published a property override from TMenu:
    property OnChange;

(0024078)
Klaus Reimer (reporter)
2008-12-31 15:56

I stumbled over the same problem (In 0.9.26 release and daily snapshot 20081231) . Actions which are connected to buttons are correctly updated by a timer, actions connected to a popup menu are updated when the popup menu opens but actions which are only connected to a main menu item are only updated when the action is executed. This is pretty useless. I have a "CloseAction" which must be disabled when nothing is there to close. The result is, the user can click "Close" which does nothing but disabling the Close Action.

My workaround is putting this code into my form:

procedure TForm1.FormCreate(Sender: TObject);
begin
  InstallActionUpdateFix(MainMenu1.Items);
end;

procedure TForm1.InstallActionUpdateFix(MenuItem: TMenuItem);
var
  i: Integer;
begin
  if (MenuItem.Count > 0) and (not Assigned(MenuItem.OnClick)) then
  begin
    MenuItem.OnClick := @FixActionUpdate;
    for i := 0 to MenuItem.Count - 1 do
      InstallActionUpdateFix(MenuItem.Items[i]);
  end;
end;

procedure TForm1.FixActionUpdate(Sender: TObject);
var
  i: Integer;
  MenuItem: TMenuItem;
begin
  for i := 0 to TMenuItem(Sender).Count - 1 do
  begin
    MenuItem := TMenuItem(Sender).Items[i];
    if Assigned(MenuItem.Action) and Assigned(MenuItem.Action.OnUpdate) then
    begin
      MenuItem.Action.OnUpdate(MenuItem.Action);
    end;
  end;
end;

This code does the following: When the form is created then a special OnClick handler is installed into ALL main menu items which have sub menu items. This special OnClick handler calls the OnUpdate method of all actions connected to sub menu items of the clicked menu item.

Works great but I hope that a similiar functionality will be implemented in LCL some day because without it the ActionList is quite useless if most actions are only referenced in a main menu.
(0024079)
Paul Ishenin (manager)
2009-01-01 11:11

Please test and close if ok.

- Issue History
Date Modified Username Field Change
2008-12-09 21:10 Michael Van Canneyt New Issue
2008-12-09 21:10 Michael Van Canneyt File Added: actionbug.zip
2008-12-09 21:10 Michael Van Canneyt LazTarget => -
2008-12-09 21:10 Michael Van Canneyt Widgetset => GTK
2008-12-09 21:13 Vincent Snijders LazTarget - => 1.0
2008-12-09 21:13 Vincent Snijders Status new => acknowledged
2008-12-09 21:13 Vincent Snijders Target Version 0.9.28 => 1.0.0
2008-12-09 21:14 Vincent Snijders Note Added: 0023738
2008-12-09 21:14 Vincent Snijders Note Edited: 0023738
2008-12-15 13:49 Leslie Kaye Note Added: 0023844
2008-12-18 09:53 Leslie Kaye Note Edited: 0023844
2008-12-18 09:54 Leslie Kaye Note Edited: 0023844
2008-12-31 15:56 Klaus Reimer Note Added: 0024078
2009-01-01 11:11 Paul Ishenin Fixed in Revision => 18006
2009-01-01 11:11 Paul Ishenin Status acknowledged => resolved
2009-01-01 11:11 Paul Ishenin Fixed in Version => 0.9.27 (SVN)
2009-01-01 11:11 Paul Ishenin Resolution open => fixed
2009-01-01 11:11 Paul Ishenin Assigned To => Paul Ishenin
2009-01-01 11:11 Paul Ishenin Note Added: 0024079
2009-06-13 12:08 Marc Weustink Status resolved => closed



MantisBT 1.2.12[^]
Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker