| 
									
										
										
										
											2014-10-31 11:17:05 -07:00
										 |  |  | // Copyright (c) 2013 GitHub, Inc.
 | 
					
						
							| 
									
										
										
										
											2014-04-25 17:49:37 +08:00
										 |  |  | // Use of this source code is governed by the MIT license that can be
 | 
					
						
							| 
									
										
										
										
											2013-05-06 20:27:09 +08:00
										 |  |  | // found in the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-04 12:19:40 -08:00
										 |  |  | #include "shell/browser/api/electron_api_menu.h"
 | 
					
						
							| 
									
										
										
										
											2013-05-06 20:27:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-20 20:17:39 +09:00
										 |  |  | #include <utility>
 | 
					
						
							| 
									
										
										
										
											2019-08-06 23:55:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-29 18:32:02 -07:00
										 |  |  | #include "shell/browser/api/ui_event.h"
 | 
					
						
							| 
									
										
										
										
											2020-06-22 09:35:24 -07:00
										 |  |  | #include "shell/browser/javascript_environment.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 |  |  | #include "shell/browser/native_window.h"
 | 
					
						
							| 
									
										
										
										
											2019-10-25 22:03:28 +09:00
										 |  |  | #include "shell/common/gin_converters/accelerator_converter.h"
 | 
					
						
							| 
									
										
										
										
											2019-09-06 14:52:54 +09:00
										 |  |  | #include "shell/common/gin_converters/callback_converter.h"
 | 
					
						
							| 
									
										
										
										
											2020-10-20 10:33:06 +09:00
										 |  |  | #include "shell/common/gin_converters/file_path_converter.h"
 | 
					
						
							|  |  |  | #include "shell/common/gin_converters/gurl_converter.h"
 | 
					
						
							| 
									
										
										
										
											2019-09-19 11:09:15 -04:00
										 |  |  | #include "shell/common/gin_converters/image_converter.h"
 | 
					
						
							|  |  |  | #include "shell/common/gin_helper/dictionary.h"
 | 
					
						
							|  |  |  | #include "shell/common/gin_helper/object_template_builder.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 |  |  | #include "shell/common/node_includes.h"
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:39:26 -07:00
										 |  |  | #include "ui/base/models/image_model.h"
 | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 18:58:52 -08:00
										 |  |  | #if BUILDFLAG(IS_MAC)
 | 
					
						
							| 
									
										
										
										
											2020-10-20 10:33:06 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gin { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using SharingItem = electron::ElectronMenuModel::SharingItem; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template <> | 
					
						
							|  |  |  | struct Converter<SharingItem> { | 
					
						
							|  |  |  |   static bool FromV8(v8::Isolate* isolate, | 
					
						
							|  |  |  |                      v8::Local<v8::Value> val, | 
					
						
							|  |  |  |                      SharingItem* out) { | 
					
						
							|  |  |  |     gin_helper::Dictionary dict; | 
					
						
							|  |  |  |     if (!ConvertFromV8(isolate, val, &dict)) | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  |     dict.GetOptional("texts", &(out->texts)); | 
					
						
							|  |  |  |     dict.GetOptional("filePaths", &(out->file_paths)); | 
					
						
							|  |  |  |     dict.GetOptional("urls", &(out->urls)); | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace gin
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-29 12:55:47 -07:00
										 |  |  | namespace electron::api { | 
					
						
							| 
									
										
										
										
											2013-05-06 20:27:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  | gin::WrapperInfo Menu::kWrapperInfo = {gin::kEmbedderNativeGin}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 19:00:05 -07:00
										 |  |  | Menu::Menu(gin::Arguments* args) | 
					
						
							|  |  |  |     : model_(std::make_unique<ElectronMenuModel>(this)) { | 
					
						
							| 
									
										
										
										
											2018-01-27 10:40:50 -05:00
										 |  |  |   model_->AddObserver(this); | 
					
						
							| 
									
										
										
										
											2020-10-20 10:33:06 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 18:58:52 -08:00
										 |  |  | #if BUILDFLAG(IS_MAC)
 | 
					
						
							| 
									
										
										
										
											2020-10-20 10:33:06 +09:00
										 |  |  |   gin_helper::Dictionary options; | 
					
						
							|  |  |  |   if (args->GetNext(&options)) { | 
					
						
							|  |  |  |     ElectronMenuModel::SharingItem item; | 
					
						
							|  |  |  |     if (options.Get("sharingItem", &item)) | 
					
						
							|  |  |  |       model_->SetSharingItem(std::move(item)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-05-06 20:27:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Menu::~Menu() { | 
					
						
							| 
									
										
										
										
											2018-01-27 10:40:50 -05:00
										 |  |  |   if (model_) { | 
					
						
							|  |  |  |     model_->RemoveObserver(this); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-05-06 20:27:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  | bool InvokeBoolMethod(const Menu* menu, | 
					
						
							|  |  |  |                       const char* method, | 
					
						
							|  |  |  |                       int command_id, | 
					
						
							|  |  |  |                       bool default_value = false) { | 
					
						
							| 
									
										
										
										
											2020-06-22 09:35:24 -07:00
										 |  |  |   v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  |   v8::HandleScope scope(isolate); | 
					
						
							|  |  |  |   // We need to cast off const here because GetWrapper() is non-const, but
 | 
					
						
							|  |  |  |   // ui::SimpleMenuModel::Delegate's methods are const.
 | 
					
						
							|  |  |  |   v8::Local<v8::Value> val = gin_helper::CallMethod( | 
					
						
							|  |  |  |       isolate, const_cast<Menu*>(menu), method, command_id); | 
					
						
							|  |  |  |   bool ret = false; | 
					
						
							|  |  |  |   return gin::ConvertFromV8(isolate, val, &ret) ? ret : default_value; | 
					
						
							| 
									
										
										
										
											2015-02-13 11:47:22 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-06 20:27:09 +08:00
										 |  |  | bool Menu::IsCommandIdChecked(int command_id) const { | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  |   return InvokeBoolMethod(this, "_isCommandIdChecked", command_id); | 
					
						
							| 
									
										
										
										
											2013-05-06 20:27:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool Menu::IsCommandIdEnabled(int command_id) const { | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  |   return InvokeBoolMethod(this, "_isCommandIdEnabled", command_id); | 
					
						
							| 
									
										
										
										
											2013-05-06 20:27:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-14 16:50:56 +08:00
										 |  |  | bool Menu::IsCommandIdVisible(int command_id) const { | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  |   return InvokeBoolMethod(this, "_isCommandIdVisible", command_id); | 
					
						
							| 
									
										
										
										
											2013-05-14 16:50:56 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-28 17:00:54 +00:00
										 |  |  | bool Menu::ShouldCommandIdWorkWhenHidden(int command_id) const { | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  |   return InvokeBoolMethod(this, "_shouldCommandIdWorkWhenHidden", command_id); | 
					
						
							| 
									
										
										
										
											2019-02-28 17:00:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-02 11:47:40 +09:00
										 |  |  | bool Menu::GetAcceleratorForCommandIdWithParams( | 
					
						
							|  |  |  |     int command_id, | 
					
						
							|  |  |  |     bool use_default_accelerator, | 
					
						
							|  |  |  |     ui::Accelerator* accelerator) const { | 
					
						
							| 
									
										
										
										
											2020-06-22 09:35:24 -07:00
										 |  |  |   v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  |   v8::HandleScope scope(isolate); | 
					
						
							|  |  |  |   v8::Local<v8::Value> val = gin_helper::CallMethod( | 
					
						
							|  |  |  |       isolate, const_cast<Menu*>(this), "_getAcceleratorForCommandId", | 
					
						
							|  |  |  |       command_id, use_default_accelerator); | 
					
						
							|  |  |  |   return gin::ConvertFromV8(isolate, val, accelerator); | 
					
						
							| 
									
										
										
										
											2013-05-14 16:50:56 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 19:43:55 +01:00
										 |  |  | bool Menu::ShouldRegisterAcceleratorForCommandId(int command_id) const { | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  |   return InvokeBoolMethod(this, "_shouldRegisterAcceleratorForCommandId", | 
					
						
							|  |  |  |                           command_id); | 
					
						
							| 
									
										
										
										
											2018-11-26 19:43:55 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 18:58:52 -08:00
										 |  |  | #if BUILDFLAG(IS_MAC)
 | 
					
						
							| 
									
										
										
										
											2020-10-20 10:33:06 +09:00
										 |  |  | bool Menu::GetSharingItemForCommandId( | 
					
						
							|  |  |  |     int command_id, | 
					
						
							|  |  |  |     ElectronMenuModel::SharingItem* item) const { | 
					
						
							|  |  |  |   v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); | 
					
						
							|  |  |  |   v8::HandleScope handle_scope(isolate); | 
					
						
							|  |  |  |   v8::Local<v8::Value> val = | 
					
						
							|  |  |  |       gin_helper::CallMethod(isolate, const_cast<Menu*>(this), | 
					
						
							|  |  |  |                              "_getSharingItemForCommandId", command_id); | 
					
						
							|  |  |  |   return gin::ConvertFromV8(isolate, val, item); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 11:22:14 +09:00
										 |  |  | void Menu::ExecuteCommand(int command_id, int flags) { | 
					
						
							| 
									
										
										
										
											2020-06-22 09:35:24 -07:00
										 |  |  |   v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  |   v8::HandleScope scope(isolate); | 
					
						
							|  |  |  |   gin_helper::CallMethod(isolate, const_cast<Menu*>(this), "_executeCommand", | 
					
						
							|  |  |  |                          CreateEventFromFlags(flags), command_id); | 
					
						
							| 
									
										
										
										
											2013-05-06 20:27:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-25 20:26:59 +05:30
										 |  |  | void Menu::OnMenuWillShow(ui::SimpleMenuModel* source) { | 
					
						
							| 
									
										
										
										
											2020-06-22 09:35:24 -07:00
										 |  |  |   v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  |   v8::HandleScope scope(isolate); | 
					
						
							|  |  |  |   gin_helper::CallMethod(isolate, const_cast<Menu*>(this), "_menuWillShow"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | base::OnceClosure Menu::BindSelfToClosure(base::OnceClosure callback) { | 
					
						
							|  |  |  |   // return ((callback, ref) => { callback() }).bind(null, callback, this)
 | 
					
						
							| 
									
										
										
										
											2020-06-22 09:35:24 -07:00
										 |  |  |   v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  |   v8::HandleScope scope(isolate); | 
					
						
							|  |  |  |   v8::Local<v8::Object> self; | 
					
						
							|  |  |  |   if (GetWrapper(isolate).ToLocal(&self)) { | 
					
						
							|  |  |  |     v8::Global<v8::Value> ref(isolate, self); | 
					
						
							|  |  |  |     return base::BindOnce( | 
					
						
							|  |  |  |         [](base::OnceClosure callback, v8::Global<v8::Value> ref) { | 
					
						
							|  |  |  |           std::move(callback).Run(); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         std::move(callback), std::move(ref)); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     return base::DoNothing(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-05-25 15:25:36 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | void Menu::InsertItemAt(int index, | 
					
						
							|  |  |  |                         int command_id, | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  |                         const std::u16string& label) { | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  |   model_->InsertItemAt(index, command_id, label); | 
					
						
							| 
									
										
										
										
											2013-05-06 20:27:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  | void Menu::InsertSeparatorAt(int index) { | 
					
						
							|  |  |  |   model_->InsertSeparatorAt(index, ui::NORMAL_SEPARATOR); | 
					
						
							| 
									
										
										
										
											2013-05-07 00:03:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  | void Menu::InsertCheckItemAt(int index, | 
					
						
							|  |  |  |                              int command_id, | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  |                              const std::u16string& label) { | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  |   model_->InsertCheckItemAt(index, command_id, label); | 
					
						
							| 
									
										
										
										
											2013-05-07 00:03:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  | void Menu::InsertRadioItemAt(int index, | 
					
						
							|  |  |  |                              int command_id, | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  |                              const std::u16string& label, | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  |                              int group_id) { | 
					
						
							|  |  |  |   model_->InsertRadioItemAt(index, command_id, label, group_id); | 
					
						
							| 
									
										
										
										
											2013-05-07 00:03:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  | void Menu::InsertSubMenuAt(int index, | 
					
						
							|  |  |  |                            int command_id, | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  |                            const std::u16string& label, | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  |                            Menu* menu) { | 
					
						
							| 
									
										
										
										
											2014-05-26 11:34:36 +08:00
										 |  |  |   menu->parent_ = this; | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  |   model_->InsertSubMenuAt(index, command_id, label, menu->model_.get()); | 
					
						
							| 
									
										
										
										
											2013-05-07 00:03:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-13 12:11:50 +08:00
										 |  |  | void Menu::SetIcon(int index, const gfx::Image& image) { | 
					
						
							| 
									
										
										
										
											2020-04-13 16:39:26 -07:00
										 |  |  |   model_->SetIcon(index, ui::ImageModel::FromImage(image)); | 
					
						
							| 
									
										
										
										
											2015-02-13 12:11:50 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  | void Menu::SetSublabel(int index, const std::u16string& sublabel) { | 
					
						
							| 
									
										
										
										
											2020-05-26 13:06:26 -07:00
										 |  |  |   model_->SetSecondaryLabel(index, sublabel); | 
					
						
							| 
									
										
										
										
											2013-05-07 00:03:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  | void Menu::SetToolTip(int index, const std::u16string& toolTip) { | 
					
						
							| 
									
										
										
										
											2019-07-11 01:56:22 -07:00
										 |  |  |   model_->SetToolTip(index, toolTip); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  | void Menu::SetRole(int index, const std::u16string& role) { | 
					
						
							| 
									
										
										
										
											2015-09-01 19:48:11 +08:00
										 |  |  |   model_->SetRole(index, role); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  | void Menu::Clear() { | 
					
						
							|  |  |  |   model_->Clear(); | 
					
						
							| 
									
										
										
										
											2013-05-07 00:03:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 16:28:16 -07:00
										 |  |  | int Menu::GetIndexOfCommandId(int command_id) const { | 
					
						
							| 
									
										
										
										
											2022-08-17 11:35:53 -07:00
										 |  |  |   return model_->GetIndexOfCommandId(command_id).value_or(-1); | 
					
						
							| 
									
										
										
										
											2013-05-07 00:03:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  | int Menu::GetItemCount() const { | 
					
						
							|  |  |  |   return model_->GetItemCount(); | 
					
						
							| 
									
										
										
										
											2013-05-07 00:03:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  | int Menu::GetCommandIdAt(int index) const { | 
					
						
							|  |  |  |   return model_->GetCommandIdAt(index); | 
					
						
							| 
									
										
										
										
											2013-05-07 00:03:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  | std::u16string Menu::GetLabelAt(int index) const { | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  |   return model_->GetLabelAt(index); | 
					
						
							| 
									
										
										
										
											2013-05-07 00:03:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  | std::u16string Menu::GetSublabelAt(int index) const { | 
					
						
							| 
									
										
										
										
											2020-05-26 13:06:26 -07:00
										 |  |  |   return model_->GetSecondaryLabelAt(index); | 
					
						
							| 
									
										
										
										
											2013-05-07 00:03:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  | std::u16string Menu::GetToolTipAt(int index) const { | 
					
						
							| 
									
										
										
										
											2019-07-11 01:56:22 -07:00
										 |  |  |   return model_->GetToolTipAt(index); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-02 16:32:48 +09:00
										 |  |  | std::u16string Menu::GetAcceleratorTextAtForTesting(int index) const { | 
					
						
							| 
									
										
										
										
											2018-10-31 15:13:44 +01:00
										 |  |  |   ui::Accelerator accelerator; | 
					
						
							|  |  |  |   model_->GetAcceleratorAtWithParams(index, true, &accelerator); | 
					
						
							|  |  |  |   return accelerator.GetShortcutText(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  | bool Menu::IsItemCheckedAt(int index) const { | 
					
						
							|  |  |  |   return model_->IsItemCheckedAt(index); | 
					
						
							| 
									
										
										
										
											2013-05-07 00:03:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  | bool Menu::IsEnabledAt(int index) const { | 
					
						
							|  |  |  |   return model_->IsEnabledAt(index); | 
					
						
							| 
									
										
										
										
											2013-05-07 00:03:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  | bool Menu::IsVisibleAt(int index) const { | 
					
						
							|  |  |  |   return model_->IsVisibleAt(index); | 
					
						
							| 
									
										
										
										
											2013-05-07 00:03:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-28 17:00:54 +00:00
										 |  |  | bool Menu::WorksWhenHiddenAt(int index) const { | 
					
						
							|  |  |  |   return model_->WorksWhenHiddenAt(index); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-27 09:35:58 -05:00
										 |  |  | void Menu::OnMenuWillClose() { | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  |   Unpin(); | 
					
						
							| 
									
										
										
										
											2018-01-27 09:35:58 -05:00
										 |  |  |   Emit("menu-will-close"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Menu::OnMenuWillShow() { | 
					
						
							| 
									
										
										
										
											2021-03-29 10:45:08 +00:00
										 |  |  |   Pin(JavascriptEnvironment::GetIsolate()); | 
					
						
							| 
									
										
										
										
											2018-01-27 09:35:58 -05:00
										 |  |  |   Emit("menu-will-show"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-14 16:50:56 +08:00
										 |  |  | // static
 | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  | v8::Local<v8::ObjectTemplate> Menu::FillObjectTemplate( | 
					
						
							|  |  |  |     v8::Isolate* isolate, | 
					
						
							|  |  |  |     v8::Local<v8::ObjectTemplate> templ) { | 
					
						
							|  |  |  |   return gin::ObjectTemplateBuilder(isolate, "Menu", templ) | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  |       .SetMethod("insertItem", &Menu::InsertItemAt) | 
					
						
							|  |  |  |       .SetMethod("insertCheckItem", &Menu::InsertCheckItemAt) | 
					
						
							|  |  |  |       .SetMethod("insertRadioItem", &Menu::InsertRadioItemAt) | 
					
						
							|  |  |  |       .SetMethod("insertSeparator", &Menu::InsertSeparatorAt) | 
					
						
							|  |  |  |       .SetMethod("insertSubMenu", &Menu::InsertSubMenuAt) | 
					
						
							| 
									
										
										
										
											2015-02-13 12:11:50 +08:00
										 |  |  |       .SetMethod("setIcon", &Menu::SetIcon) | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  |       .SetMethod("setSublabel", &Menu::SetSublabel) | 
					
						
							| 
									
										
										
										
											2019-07-11 01:56:22 -07:00
										 |  |  |       .SetMethod("setToolTip", &Menu::SetToolTip) | 
					
						
							| 
									
										
										
										
											2015-09-01 19:48:11 +08:00
										 |  |  |       .SetMethod("setRole", &Menu::SetRole) | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  |       .SetMethod("clear", &Menu::Clear) | 
					
						
							|  |  |  |       .SetMethod("getIndexOfCommandId", &Menu::GetIndexOfCommandId) | 
					
						
							|  |  |  |       .SetMethod("getItemCount", &Menu::GetItemCount) | 
					
						
							|  |  |  |       .SetMethod("getCommandIdAt", &Menu::GetCommandIdAt) | 
					
						
							|  |  |  |       .SetMethod("getLabelAt", &Menu::GetLabelAt) | 
					
						
							|  |  |  |       .SetMethod("getSublabelAt", &Menu::GetSublabelAt) | 
					
						
							| 
									
										
										
										
											2019-07-11 01:56:22 -07:00
										 |  |  |       .SetMethod("getToolTipAt", &Menu::GetToolTipAt) | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  |       .SetMethod("isItemCheckedAt", &Menu::IsItemCheckedAt) | 
					
						
							|  |  |  |       .SetMethod("isEnabledAt", &Menu::IsEnabledAt) | 
					
						
							| 
									
										
										
										
											2019-02-28 17:00:54 +00:00
										 |  |  |       .SetMethod("worksWhenHiddenAt", &Menu::WorksWhenHiddenAt) | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  |       .SetMethod("isVisibleAt", &Menu::IsVisibleAt) | 
					
						
							| 
									
										
										
										
											2017-02-16 10:58:02 -08:00
										 |  |  |       .SetMethod("popupAt", &Menu::PopupAt) | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  |       .SetMethod("closePopupAt", &Menu::ClosePopupAt) | 
					
						
							| 
									
										
										
										
											2021-09-27 16:58:03 +02:00
										 |  |  |       .SetMethod("_getAcceleratorTextAt", &Menu::GetAcceleratorTextAtForTesting) | 
					
						
							| 
									
										
										
										
											2022-02-09 18:58:52 -08:00
										 |  |  | #if BUILDFLAG(IS_MAC)
 | 
					
						
							| 
									
										
										
										
											2021-06-29 16:28:16 -07:00
										 |  |  |       .SetMethod("_getUserAcceleratorAt", &Menu::GetUserAcceleratorAt) | 
					
						
							| 
									
										
										
										
											2021-06-02 16:32:48 +09:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  |       .Build(); | 
					
						
							| 
									
										
										
										
											2013-05-14 16:50:56 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-29 12:55:47 -07:00
										 |  |  | }  // namespace electron::api
 | 
					
						
							| 
									
										
										
										
											2013-05-14 16:50:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  | namespace { | 
					
						
							| 
									
										
										
										
											2013-05-16 10:54:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | using electron::api::Menu; | 
					
						
							| 
									
										
										
										
											2016-08-02 17:02:04 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | void Initialize(v8::Local<v8::Object> exports, | 
					
						
							|  |  |  |                 v8::Local<v8::Value> unused, | 
					
						
							|  |  |  |                 v8::Local<v8::Context> context, | 
					
						
							|  |  |  |                 void* priv) { | 
					
						
							| 
									
										
										
										
											2014-06-29 20:48:44 +08:00
										 |  |  |   v8::Isolate* isolate = context->GetIsolate(); | 
					
						
							| 
									
										
										
										
											2016-08-02 17:02:04 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-19 11:09:15 -04:00
										 |  |  |   gin_helper::Dictionary dict(isolate, exports); | 
					
						
							| 
									
										
										
										
											2020-04-02 16:07:56 -07:00
										 |  |  |   dict.Set("Menu", Menu::GetConstructor(context)); | 
					
						
							| 
									
										
										
										
											2022-02-09 18:58:52 -08:00
										 |  |  | #if BUILDFLAG(IS_MAC)
 | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  |   dict.SetMethod("setApplicationMenu", &Menu::SetApplicationMenu); | 
					
						
							|  |  |  |   dict.SetMethod("sendActionToFirstResponder", | 
					
						
							|  |  |  |                  &Menu::SendActionToFirstResponder); | 
					
						
							| 
									
										
										
										
											2013-05-16 20:31:58 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-05-06 20:27:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 23:40:10 +08:00
										 |  |  | }  // namespace
 | 
					
						
							| 
									
										
										
										
											2013-05-06 20:27:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-14 03:25:39 -08:00
										 |  |  | NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_menu, Initialize) |