@@ -601,13 +601,49 @@ void RootWindowGtk::MenubarSizeAllocated(GtkWidget* widget,
601601 self->menubar_height_ = allocation->height ;
602602}
603603
604+ // Brackets specific change.
605+ // GTK is toggling the menu state just by
606+ // clicking on the menu entry. So posting a task to undo that
607+ // unwanted side effect. This is a @nethip hack.
608+ void DelayedMenuMarkToggle (GtkWidget *menuItem){
609+
610+ if (GTK_IS_CHECK_MENU_ITEM (menuItem)) {
611+ // It is important to make sure our MenuItemACtivated
612+ // knows that we are only changing the state and not
613+ // firing any command as such.
614+ StMenuCommandSkipper skipCmd;
615+
616+ // Get the current state of the menu.
617+ gboolean menuState = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (menuItem));
618+
619+ // Now go about toggling the state. If Brackets is triggering a menu state change,
620+ // that will get executed later than DelayedMenuMarkToggle, as this task would have been
621+ // posted prior to shell call to fire a command, so need not worry about this function
622+ // getting executed after the shell call.
623+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuItem), !menuState);
624+ }
625+ }
626+
604627// static
605628gboolean RootWindowGtk::MenuItemActivated (GtkWidget* widget,
606629 RootWindowGtk* self) {
607- // Retrieve the menu ID set in AddMenuEntry.
608- int tag = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), kMenuIdKey ));
609- if (self && self->browser_window_ )
610- self->browser_window_ ->DispatchCommandToBrowser (self->GetBrowser (), tag);
630+ // Since we have migrated to checked menu items, setting the
631+ // state of the menu is triggering a menu activation. So made
632+ // sure we actually execute a command only when is menu is
633+ // actually activated by the user and not when setting the menu
634+ // state.
635+ if (!StMenuCommandSkipper::GetMenuCmdSkipFlag ()){
636+
637+ // Post a message to undo the undesired menu state change.
638+ // See the comments above for explanation.
639+ CefPostTask (TID_UI, base::Bind (&DelayedMenuMarkToggle, widget));
640+
641+ // Retrieve the menu ID set in AddMenuEntry.
642+ int tag = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), kMenuIdKey ));
643+ if (self && self->browser_window_ )
644+ self->browser_window_ ->DispatchCommandToBrowser (self->GetBrowser (), tag);
645+ }
646+
611647}
612648
613649// static
0 commit comments