Recent

Author Topic: TActionList group...  (Read 890 times)

Espectr0

  • Full Member
  • ***
  • Posts: 217
TActionList group...
« on: April 02, 2023, 12:56:52 pm »
Hola,

Could it be that in Lazarus 2.2.6 TActionList groups do not work properly?
In other words, it allows all the action of the same group to be unchecked.
Or maybe I missed some option?

I attach @wp code to show.

Thanks!

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: TActionList group...
« Reply #1 on: April 02, 2023, 02:11:33 pm »
You can add extra code to make sure that there is always one checked action in each group (you must uncheck the "AutoCheck" option of the actions grouped this way) - see below. However, while this works in the menu it does not work in the toolbar where it is still possible to uncheck the checked toolbutton. This is the same behaviour as in Delphi. Therefore, i guess it results from some internal Windows issue. Nevertheless, you can query the Action property ActionComponent which is the component firing the action's OnExecute event and check it if it is a TToolButton:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Action1Execute(Sender: TObject);
  2. const
  3.   CHECKED: array[boolean] of char = ('.', 'X');
  4. var
  5.   i: Integer;
  6.   SenderAction: TAction;
  7.   ac: TAction;
  8.   c: TComponent;
  9. begin
  10.   if Sender = nil then
  11.     exit;
  12.   SenderAction := Sender as TAction;
  13.   c := SenderAction.ActionComponent;
  14.  
  15.   for i := 0 to ActionList1.ActionCount-1 do
  16.     if (ActionList1.Actions[i] is TAction) then
  17.     begin
  18.       ac := TAction(ActionList1.Actions[i]);
  19.       if ac.GroupIndex = SenderAction.GroupIndex then
  20.       begin
  21.         ac.Checked := (ac = SenderAction);
  22.         if ac.Checked and (c is TToolButton) then
  23.           TToolButton(c).Down := true;
  24.       end;
  25.     end;
  26.  
  27.   Label1.Caption := CHECKED[Action1.Checked] + CHECKED[Action2.Checked] + CHECKED[Action3.Checked] + CHECKED[Action4.Checked];
  28.   Label2.Caption := CHECKED[Action5.Checked] + CHECKED[Action6.Checked] + CHECKED[Action7.Checked] + CHECKED[Action8.Checked];
  29. end;

Espectr0

  • Full Member
  • ***
  • Posts: 217
Re: TActionList group...
« Reply #2 on: April 02, 2023, 02:24:55 pm »
Thanks @wp

I'm not sure but I think that in previous versions of lazarus it worked correctly (or Windows?) but the groups worked without extra code before  :-\

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: TActionList group...
« Reply #3 on: April 02, 2023, 04:31:17 pm »
I went back to Laz1.4.4, the oldest version that I have on my disk, and still see the issue. But I am on Windows 11 now. Therefore, also tested on my VMs with Win 7, XP and 2000 (now with Laz/main) - still the same issue. Even on Manjaro-Linux, gtk2 and qt3.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: TActionList group...
« Reply #4 on: April 02, 2023, 05:01:56 pm »
AFAIR it worked always like this. TToolButton has property AllowAllUp which is ignored once you link the button with Action.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: TActionList group...
« Reply #5 on: April 02, 2023, 06:42:44 pm »
TToolButton has property AllowAllUp which is ignored once you link the button with Action.
Sounds like a bug... (even if Delphi has the same behaviour)

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: TActionList group...
« Reply #6 on: April 02, 2023, 06:53:25 pm »
IMO when you link Actions with MenuItems and ToolButtons then Actions are "master" an the others are "slaves". An since Actions do not have any AllowAllUp property, it is silently assumed that AllowAllUp is True.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: TActionList group...
« Reply #7 on: April 02, 2023, 07:26:50 pm »
IMO when you link Actions with MenuItems and ToolButtons then Actions are "master" an the others are "slaves". An since Actions do not have any AllowAllUp property, it is silently assumed that AllowAllUp is True.
That Actions are "master" is reasonable. But then MenuItems and ToolButtons should not behave differently. (Strange: cannot reproduce this any more...)

Found this on StackOverflow and it gave me the idea to set the Grouped property of the grouped Toolbuttons to true and their Style to tbsCheck. Now it is no longer possible to switch a checked toolbutton back to the off-state when it is clicked a second time. Unfortunately the second click is passed on to the action, and thus the associated menuitem becomes unchecked. Examined this also in Delphi where I found the behaviour to be correct.

Another issue is that a group of speedbuttons to which the same actions are assigned does not respond to the change in the actions; it does propagate their own clicks back to the actions, though. But this is the same as in Delphi.
« Last Edit: April 02, 2023, 07:42:48 pm by wp »

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: TActionList group...
« Reply #8 on: April 02, 2023, 11:10:10 pm »
I've played with Actions a few times; I just can't seem to find anything useful for it?

 I understand what it does and all, but it seems to have a specific place in someone's toolbox.

Have a good day.

 
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018