| 
									
										
										
										
											2015-08-10 12:39:05 +08:00
										 |  |  | // Copyright (c) 2015 GitHub, Inc.
 | 
					
						
							|  |  |  | // Use of this source code is governed by the MIT license that can be
 | 
					
						
							|  |  |  | // found in the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "atom/browser/ui/atom_menu_model.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-01 19:48:11 +08:00
										 |  |  | #include "base/stl_util.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:39:05 +08:00
										 |  |  | namespace atom { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AtomMenuModel::AtomMenuModel(Delegate* delegate) | 
					
						
							|  |  |  |     : ui::SimpleMenuModel(delegate), | 
					
						
							|  |  |  |       delegate_(delegate) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AtomMenuModel::~AtomMenuModel() { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-01 19:48:11 +08:00
										 |  |  | void AtomMenuModel::SetRole(int index, const base::string16& role) { | 
					
						
							| 
									
										
										
										
											2016-06-21 15:25:14 -07:00
										 |  |  |   int command_id = GetCommandIdAt(index); | 
					
						
							|  |  |  |   roles_[command_id] = role; | 
					
						
							| 
									
										
										
										
											2015-09-01 19:48:11 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | base::string16 AtomMenuModel::GetRoleAt(int index) { | 
					
						
							| 
									
										
										
										
											2016-06-21 15:25:14 -07:00
										 |  |  |   int command_id = GetCommandIdAt(index); | 
					
						
							|  |  |  |   if (ContainsKey(roles_, command_id)) | 
					
						
							|  |  |  |     return roles_[command_id]; | 
					
						
							| 
									
										
										
										
											2015-09-01 19:48:11 +08:00
										 |  |  |   else | 
					
						
							|  |  |  |     return base::string16(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-02 11:47:40 +09:00
										 |  |  | bool AtomMenuModel::GetAcceleratorAtWithParams( | 
					
						
							|  |  |  |     int index, | 
					
						
							|  |  |  |     bool use_default_accelerator, | 
					
						
							|  |  |  |     ui::Accelerator* accelerator) const { | 
					
						
							|  |  |  |   if (delegate_) { | 
					
						
							|  |  |  |     return delegate_->GetAcceleratorForCommandIdWithParams( | 
					
						
							|  |  |  |         GetCommandIdAt(index), use_default_accelerator, accelerator); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:39:05 +08:00
										 |  |  | void AtomMenuModel::MenuClosed() { | 
					
						
							|  |  |  |   ui::SimpleMenuModel::MenuClosed(); | 
					
						
							|  |  |  |   FOR_EACH_OBSERVER(Observer, observers_, MenuClosed()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-06 16:04:18 -07:00
										 |  |  | AtomMenuModel* AtomMenuModel::GetSubmenuModelAt(int index) { | 
					
						
							|  |  |  |   return static_cast<AtomMenuModel*>( | 
					
						
							|  |  |  |     ui::SimpleMenuModel::GetSubmenuModelAt(index)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:39:05 +08:00
										 |  |  | }  // namespace atom
 |