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

Commit

Permalink
Linux native menus lost shortcuts (#637)
Browse files Browse the repository at this point in the history
* Initial commit. Some shortcuts still not seen.

* Shorcuts return (to Linux native menus)

* Indentation fix.

* More indentation fixes.
  • Loading branch information
pelatx authored and nethip committed Apr 17, 2018
1 parent 964cafd commit d22ab4c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
14 changes: 9 additions & 5 deletions appshell/appshell_extensions_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ int32 AddMenuItem(CefRefPtr<CefBrowser> browser, ExtensionString parentCommand,

ExtensionString commandId = model.getCommandId(tag);
model.setOsItem(tag, entry);
model.setKey(tag, key);
ParseShortcut(browser, entry, key, commandId);
GtkWidget* menuHeader = (GtkWidget*) model.getOsItem(parentTag);
GtkWidget* menuWidget = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menuHeader));
Expand Down Expand Up @@ -1140,13 +1141,16 @@ int32 SetMenuItemState(CefRefPtr<CefBrowser> browser, ExtensionString command, b
if (checked == true) {
newMenuItem = gtk_check_menu_item_new_with_label(label);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(newMenuItem), true);
} else if (checked == false){
} else {
newMenuItem = gtk_menu_item_new_with_label(label);
}
gtk_widget_destroy(menuItem);

InstallMenuHandler(newMenuItem, browser, tag);

model.setOsItem(tag, newMenuItem);
ExtensionString key = model.getKey(tag);
ParseShortcut(browser, newMenuItem, key, command);
gtk_menu_shell_insert(GTK_MENU_SHELL(parent), newMenuItem, position);
gtk_widget_set_sensitive(newMenuItem, enabled);
gtk_widget_show(newMenuItem);
Expand Down Expand Up @@ -1191,13 +1195,15 @@ int32 GetMenuTitle(CefRefPtr<CefBrowser> browser, ExtensionString commandId, Ext

int32 SetMenuItemShortcut(CefRefPtr<CefBrowser> browser, ExtensionString commandId, ExtensionString shortcut, ExtensionString displayStr)
{
NativeMenuModel model = NativeMenuModel::getInstance(getMenuParent(browser));
int32 tag = model.getTag(commandId);
NativeMenuModel& model = NativeMenuModel::getInstance(getMenuParent(browser));
int tag = model.getTag(commandId);
if (tag == kTagNotFound) {
return ERR_NOT_FOUND;
}
GtkWidget* entry = (GtkWidget*) model.getOsItem(tag);
model.setKey(tag, shortcut);
ParseShortcut(browser, entry, shortcut, commandId);

return NO_ERROR;
}

Expand Down Expand Up @@ -1396,5 +1402,3 @@ std::string GetSystemUniqueID()

return buf;
}


16 changes: 16 additions & 0 deletions appshell/native_menu_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ ExtensionString NativeMenuModel::getParentId(int tag) {
return menuItems[tag].parentId;
}

ExtensionString NativeMenuModel::getKey(int tag) {
menu::iterator foundItem = menuItems.find(tag);
if(foundItem == menuItems.end()) {
return ExtensionString();
}
return menuItems[tag].key;
}

void NativeMenuModel::setKey (int tag, ExtensionString theKey) {
menu::iterator foundItem = menuItems.find(tag);
if(foundItem == menuItems.end()) {
return;
}
menuItems[tag].key = theKey;
}

int NativeMenuModel::getOrCreateTag(ExtensionString command, ExtensionString parent)
{
menuTag::iterator foundItem = commandMap.find(command);
Expand Down
11 changes: 5 additions & 6 deletions appshell/native_menu_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ class NativeMenuItemModel
enabled(enabled),
osItem(NULL),
commandId(commandId),
parentId(parentId)
parentId(parentId),
key(ExtensionString())
{
}
bool checked;
bool enabled;
void *osItem;
ExtensionString commandId;
ExtensionString parentId;
ExtensionString key;
};

//command name -> menutag
Expand Down Expand Up @@ -91,13 +93,10 @@ class NativeMenuModel {
int setTag(ExtensionString command, ExtensionString parent, int tag);
ExtensionString getCommandId(int tag);
ExtensionString getParentId(int tag);
ExtensionString getKey(int tag);
void setKey(int tag, ExtensionString theKey);
void setOsItem (int tag, void* theItem);
void* getOsItem (int tag);

int removeMenuItem(const ExtensionString& command);
};





0 comments on commit d22ab4c

Please sign in to comment.