|
95 | 95 |
|
96 | 96 | typedef char s8;
|
97 | 97 |
|
| 98 | +bool StMenuCommandSkipper::sSkipMenuCommand = false; |
| 99 | + |
98 | 100 | extern CefRefPtr<ClientHandler> g_handler;
|
99 | 101 |
|
100 | 102 | // Supported browsers (order matters):
|
@@ -721,6 +723,12 @@ int ShowFolderInOSWindow(ExtensionString pathname)
|
721 | 723 | GError *gerror = NULL;
|
722 | 724 | gchar *uri = NULL, *parentdir = NULL;
|
723 | 725 |
|
| 726 | + // Check if file exist in OS |
| 727 | + struct stat fileStat; |
| 728 | + if (stat(pathname.c_str(), &fileStat) != 0) { |
| 729 | + return ERR_NOT_FOUND; |
| 730 | + } |
| 731 | + |
724 | 732 | if (g_file_test(pathname.c_str(), G_FILE_TEST_IS_DIR)) {
|
725 | 733 | uri = g_filename_to_uri(pathname.c_str(), NULL, NULL);
|
726 | 734 | if (!gtk_show_uri(NULL, uri, GDK_CURRENT_TIME, &gerror)) {
|
@@ -1062,6 +1070,7 @@ int32 AddMenuItem(CefRefPtr<CefBrowser> browser, ExtensionString parentCommand,
|
1062 | 1070 |
|
1063 | 1071 | ExtensionString commandId = model.getCommandId(tag);
|
1064 | 1072 | model.setOsItem(tag, entry);
|
| 1073 | + model.setKey(tag, key); |
1065 | 1074 | ParseShortcut(browser, entry, key, commandId);
|
1066 | 1075 | GtkWidget* menuHeader = (GtkWidget*) model.getOsItem(parentTag);
|
1067 | 1076 | GtkWidget* menuWidget = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menuHeader));
|
@@ -1098,16 +1107,60 @@ int32 GetMenuItemState(CefRefPtr<CefBrowser> browser, ExtensionString commandId,
|
1098 | 1107 | return NO_ERROR;
|
1099 | 1108 | }
|
1100 | 1109 |
|
| 1110 | +int _getMenuItemPosition(GtkWidget* parent, GtkWidget* menuItem) |
| 1111 | +{ |
| 1112 | + GList* children = gtk_container_get_children(GTK_CONTAINER(parent)); |
| 1113 | + int index = 0; |
| 1114 | + do { |
| 1115 | + GtkWidget* widget = (GtkWidget*) children->data; |
| 1116 | + if (widget == menuItem) { |
| 1117 | + return index; |
| 1118 | + } |
| 1119 | + index++; |
| 1120 | + } while ((children = g_list_next(children)) != NULL); |
| 1121 | + |
| 1122 | + return -1; |
| 1123 | +} |
| 1124 | + |
1101 | 1125 | int32 SetMenuItemState(CefRefPtr<CefBrowser> browser, ExtensionString command, bool& enabled, bool& checked)
|
1102 | 1126 | {
|
1103 |
| - // TODO: Implement functionality for checked |
1104 | 1127 | NativeMenuModel& model = NativeMenuModel::getInstance(getMenuParent(browser));
|
1105 | 1128 | int tag = model.getTag(command);
|
1106 | 1129 | if (tag == kTagNotFound) {
|
1107 | 1130 | return ERR_NOT_FOUND;
|
1108 | 1131 | }
|
1109 | 1132 | GtkWidget* menuItem = (GtkWidget*) model.getOsItem(tag);
|
1110 |
| - gtk_widget_set_sensitive(menuItem, enabled); |
| 1133 | + if (menuItem == NULL) { |
| 1134 | + return ERR_UNKNOWN; |
| 1135 | + } |
| 1136 | + GtkWidget* parent = gtk_widget_get_parent(menuItem); |
| 1137 | + if (parent == NULL) { |
| 1138 | + return ERR_UNKNOWN; |
| 1139 | + } |
| 1140 | + int position = _getMenuItemPosition(parent, menuItem); |
| 1141 | + if (position < 0) { |
| 1142 | + return ERR_UNKNOWN; |
| 1143 | + } |
| 1144 | + const gchar* label = gtk_menu_item_get_label(GTK_MENU_ITEM(menuItem)); |
| 1145 | + |
| 1146 | + GtkWidget* newMenuItem; |
| 1147 | + if (checked == true) { |
| 1148 | + newMenuItem = gtk_check_menu_item_new_with_label(label); |
| 1149 | + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(newMenuItem), true); |
| 1150 | + } else { |
| 1151 | + newMenuItem = gtk_menu_item_new_with_label(label); |
| 1152 | + } |
| 1153 | + gtk_widget_destroy(menuItem); |
| 1154 | + |
| 1155 | + InstallMenuHandler(newMenuItem, browser, tag); |
| 1156 | + |
| 1157 | + model.setOsItem(tag, newMenuItem); |
| 1158 | + ExtensionString key = model.getKey(tag); |
| 1159 | + ParseShortcut(browser, newMenuItem, key, command); |
| 1160 | + gtk_menu_shell_insert(GTK_MENU_SHELL(parent), newMenuItem, position); |
| 1161 | + gtk_widget_set_sensitive(newMenuItem, enabled); |
| 1162 | + gtk_widget_show(newMenuItem); |
| 1163 | + |
1111 | 1164 | return NO_ERROR;
|
1112 | 1165 | }
|
1113 | 1166 |
|
@@ -1148,13 +1201,15 @@ int32 GetMenuTitle(CefRefPtr<CefBrowser> browser, ExtensionString commandId, Ext
|
1148 | 1201 |
|
1149 | 1202 | int32 SetMenuItemShortcut(CefRefPtr<CefBrowser> browser, ExtensionString commandId, ExtensionString shortcut, ExtensionString displayStr)
|
1150 | 1203 | {
|
1151 |
| - NativeMenuModel model = NativeMenuModel::getInstance(getMenuParent(browser)); |
1152 |
| - int32 tag = model.getTag(commandId); |
| 1204 | + NativeMenuModel& model = NativeMenuModel::getInstance(getMenuParent(browser)); |
| 1205 | + int tag = model.getTag(commandId); |
1153 | 1206 | if (tag == kTagNotFound) {
|
1154 | 1207 | return ERR_NOT_FOUND;
|
1155 | 1208 | }
|
1156 | 1209 | GtkWidget* entry = (GtkWidget*) model.getOsItem(tag);
|
| 1210 | + model.setKey(tag, shortcut); |
1157 | 1211 | ParseShortcut(browser, entry, shortcut, commandId);
|
| 1212 | + |
1158 | 1213 | return NO_ERROR;
|
1159 | 1214 | }
|
1160 | 1215 |
|
@@ -1353,5 +1408,3 @@ std::string GetSystemUniqueID()
|
1353 | 1408 |
|
1354 | 1409 | return buf;
|
1355 | 1410 | }
|
1356 |
| - |
1357 |
| - |
|
0 commit comments