View Issue Details

IDProjectCategoryView StatusLast Update
0020115LazarusLCLpublic2011-10-17 08:47
ReporterDavid Noriega Assigned ToAndrewH  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Summary0020115: MenuItem OnClick Event called twice using keyboard shortcut
DescriptionIf you have a keyboard shortcut on a menuitem, and the keyboard shortcut is used to click the menuitem, the OnClick event is executed twice.
Additional InformationSteps to reproduce:
Add a MainMenu to a form
On the MenuItem Caption property, add a '&' at the beginning eg. &MenuItem1
On the OnClick event procedure add: ShowMessage('MenuItem Clicked');
Run the form
If you click on the menuitem with the mouse you will get one showmessage (correct)
If you type the keyboard shortcut (eg Alt-M) you will get TWO showmessages (incorrect).

Apparently this is a GTK2 specific issue as Windows it runs fine.
TagsNo tags attached.
Fixed in Revision
LazTarget-
WidgetsetGTK 2
Attached Files

Relationships

related to 0017565 closedJuha Manninen Gtk2: MainMenu.OnClick not triggered [Comment/Uncomment IDE menu items become disabled] 

Activities

David Noriega

2011-08-31 19:13

reporter   ~0051330

I tried adding the Shortcut property of the MenuItem to: Alt+N and now it works even with the & on the Caption. Perhaps a quick fix would be to simply add the shortcut property when the Caption property is edited and a & is used.

August Klein

2011-09-19 19:25

reporter   ~0052037

It happens only when MenuItem have not subitems.

I upload a fix. It's code no longer needed since r30426

2011-09-19 19:26

 

menu_double.diff (1,171 bytes)   
Index: lcl/interfaces/gtk2/gtk2proc.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2proc.inc	(revisiĆ³n: 32422)
+++ lcl/interfaces/gtk2/gtk2proc.inc	(copia de trabajo)
@@ -2135,7 +2135,6 @@
     var
       i: Integer;
       Item: TMenuItem;
-      MenuItemWidget: PGtkWidget;
     begin
       Result:=false;
       if (AMenuItem=nil) or (not AMenuItem.HandleAllocated) then exit;
@@ -2143,17 +2142,7 @@
         Item:=AMenuItem[i];
         if not Item.HandleAllocated then continue;
         if not GTK_WIDGET_SENSITIVE(PGTKWidget(Item.Handle)) then continue;
-        if IsAccel(Msg.CharCode,Item.Caption) then begin
-          // found
-          Result:=true;
-          MenuItemWidget:=PGTKWidget(Item.Handle);
-          if GtkWidgetIsA(MenuItemWidget,gtk_menu_item_get_type) then begin
-            //DebugLn(['CheckMenuChilds popup: ',dbgsName(Item)]);
-            // popup the submenu
-            gtk_signal_emit_by_name(PGtkObject(MenuItemWidget),'activate-item');
-          end;
-          exit;
-        end;
+        if IsAccel(Msg.CharCode,Item.Caption) then Result:=true;
       end;
     end;
   

menu_double.diff (1,171 bytes)   

AndrewH

2011-09-29 05:02

developer   ~0052268

Last edited: 2011-09-29 05:04

I think it's fixed in r 32552 please verify. I applied the patch from August Klein.

David Noriega

2011-10-17 03:42

reporter   ~0053064

it is working correctly r32759

Issue History

Date Modified Username Field Change
2011-08-31 17:30 David Noriega New Issue
2011-08-31 17:30 David Noriega Widgetset => GTK 2
2011-08-31 19:13 David Noriega Note Added: 0051330
2011-09-19 19:25 August Klein Note Added: 0052037
2011-09-19 19:26 August Klein File Added: menu_double.diff
2011-09-29 04:42 AndrewH Relationship added related to 0017565
2011-09-29 05:02 AndrewH LazTarget => -
2011-09-29 05:02 AndrewH Note Added: 0052268
2011-09-29 05:02 AndrewH Assigned To => AndrewH
2011-09-29 05:02 AndrewH Status new => feedback
2011-09-29 05:04 AndrewH Note Edited: 0052268
2011-10-17 03:42 David Noriega Note Added: 0053064
2011-10-17 08:47 Vincent Snijders Status feedback => resolved
2011-10-17 08:47 Vincent Snijders Resolution open => fixed