Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
Added @nethip hack to avoid seeing the checkbox disabled in `No Split…
Browse files Browse the repository at this point in the history
…`, etc. And addressing review comments.
  • Loading branch information
pelatx committed Mar 7, 2018
1 parent d6834b4 commit db7e018
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
3 changes: 2 additions & 1 deletion appshell/appshell_extensions_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@

typedef char s8;

bool StMenuCommandSkipper::sSkipMenuCommand = false;

extern CefRefPtr<ClientHandler> g_handler;

// Supported browsers (order matters):
Expand Down Expand Up @@ -1109,7 +1111,6 @@ int _getMenuItemPosition(GtkWidget* parent, GtkWidget* menuItem)
}
index++;
} while ((children = g_list_next(children)) != NULL);
g_list_free(children);

return -1;
}
Expand Down
14 changes: 14 additions & 0 deletions appshell/appshell_extensions_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ class CharSetEncode
void operator()(std::string &contents);
};

#if defined(OS_LINUX)
class StMenuCommandSkipper {
public:

StMenuCommandSkipper() { sSkipMenuCommand = true; }
~StMenuCommandSkipper() { sSkipMenuCommand = false;}

static bool GetMenuCmdSkipFlag () { return sSkipMenuCommand;}

private:
static bool sSkipMenuCommand;
};
#endif

#if defined(OS_MACOSX) || defined(OS_LINUX)
void DecodeContents(std::string &contents, const std::string& encoding);
#endif
Expand Down
44 changes: 40 additions & 4 deletions appshell/browser/root_window_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -601,13 +601,49 @@ void RootWindowGtk::MenubarSizeAllocated(GtkWidget* widget,
self->menubar_height_ = allocation->height;
}

// Brackets specific change.
// GTK is toggling the menu state just by
// clicking on the menu entry. So posting a task to undo that
// unwanted side effect. This is a @nethip hack.
void DelayedMenuMarkToggle(GtkWidget *menuItem){

if (GTK_IS_CHECK_MENU_ITEM(menuItem)) {
// It is important to make sure our MenuItemACtivated
// knows that we are only changing the state and not
// firing any command as such.
StMenuCommandSkipper skipCmd;

// Get the current state of the menu.
gboolean menuState = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuItem));

// Now go about toggling the state. If Brackets is triggering a menu state change,
// that will get executed later than DelayedMenuMarkToggle, as this task would have been
// posted prior to shell call to fire a command, so need not worry about this function
// getting executed after the shell call.
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuItem), !menuState);
}
}

// static
gboolean RootWindowGtk::MenuItemActivated(GtkWidget* widget,
RootWindowGtk* self) {
// Retrieve the menu ID set in AddMenuEntry.
int tag = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), kMenuIdKey));
if (self && self->browser_window_)
self->browser_window_->DispatchCommandToBrowser(self->GetBrowser(), tag);
// Since we have migrated to checked menu items, setting the
// state of the menu is triggering a menu activation. So made
// sure we actually execute a command only when is menu is
// actually activated by the user and not when setting the menu
// state.
if(!StMenuCommandSkipper::GetMenuCmdSkipFlag()){

// Post a message to undo the undesired menu state change.
// See the comments above for explanation.
CefPostTask(TID_UI, base::Bind(&DelayedMenuMarkToggle, widget));

// Retrieve the menu ID set in AddMenuEntry.
int tag = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), kMenuIdKey));
if (self && self->browser_window_)
self->browser_window_->DispatchCommandToBrowser(self->GetBrowser(), tag);
}

}

// static
Expand Down

0 comments on commit db7e018

Please sign in to comment.