当前位置: 首页>>代码示例>>C#>>正文


C# NSMenu.InsertItem方法代码示例

本文整理汇总了C#中MonoMac.AppKit.NSMenu.InsertItem方法的典型用法代码示例。如果您正苦于以下问题:C# NSMenu.InsertItem方法的具体用法?C# NSMenu.InsertItem怎么用?C# NSMenu.InsertItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MonoMac.AppKit.NSMenu的用法示例。


在下文中一共展示了NSMenu.InsertItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PopulateArrayItems

		void PopulateArrayItems (CommandArrayInfo infos, NSMenu parent, ref NSMenuItem lastSeparator, ref int index)
		{
			foreach (CommandInfo ci in infos) {
				if (ci.IsArraySeparator) {
					var n = NSMenuItem.SeparatorItem;
					n.Hidden = true;
					n.Target = this;
					lastSeparator = n;
					parent.InsertItem (n, index++);
					continue;
				}

				var item = new MDExpandedArrayItem {
					Info = ci,
					Target = this,
					Action = ActionSel,
				};

				if (ci is CommandInfoSet) {
					item.Submenu = new NSMenu ();
					int i = 0;
					NSMenuItem sep = null;
					PopulateArrayItems (((CommandInfoSet)ci).CommandInfos, item.Submenu, ref sep, ref i);
				}
				SetItemValues (item, ci);

				if (!item.Hidden)
					MDMenu.ShowLastSeparator (ref lastSeparator);
				parent.InsertItem (item, index++);
			}
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:31,代码来源:MDMenuItem.cs

示例2: AwakeFromNib

		//strongly typed window accessor
		public override void AwakeFromNib ()
		{
			// add the searchMenu to this control, allowing recent searches to be added.
			//
			// note that we could build this menu inside our nib, but for clarity we're
			// building the menu in code to illustrate the use of tags:
			//		NSSearchFieldRecentsTitleMenuItemTag, NSSearchFieldNoRecentsMenuItemTag, etc.
			//			
			if (searchField.RespondsToSelector(new Selector("setRecentSearches:")))
			{
				NSMenu searchMenu = new NSMenu("Search Menu") {
					AutoEnablesItems = true
				};
				
				var item = new NSMenuItem("Custom","",(o,e) => actionMenuItem());
				searchMenu.InsertItem(item,0);
				
				var separator = NSMenuItem.SeparatorItem;
				searchMenu.InsertItem(separator,1);
				
				var recentsTitleItem = new NSMenuItem("Recent Searches","");
				// tag this menu item so NSSearchField can use it and respond to it appropriately
				recentsTitleItem.Tag = NSSearchFieldRecentsTitleMenuItemTag;
				searchMenu.InsertItem (recentsTitleItem,2);

				var norecentsTitleItem = new NSMenuItem("No recent searches","");
				// tag this menu item so NSSearchField can use it and respond to it appropriately
				norecentsTitleItem.Tag = NSSearchFieldNoRecentsMenuItemTag;
				searchMenu.InsertItem (norecentsTitleItem,3);
				
				var recentsItem = new NSMenuItem("Recents","");
				// tag this menu item so NSSearchField can use it and respond to it appropriately
				recentsItem.Tag = NSSearchFieldRecentsMenuItemTag;
				searchMenu.InsertItem (recentsItem,4);

				var separatorItem = NSMenuItem.SeparatorItem;
				// tag this menu item so NSSearchField can use it, by hiding/show it appropriately:
				separatorItem.Tag = NSSearchFieldRecentsTitleMenuItemTag;
				searchMenu.InsertItem (separatorItem,5);

				var clearItem = new NSMenuItem ("Clear", "");
				// tag this menu item so NSSearchField can use it
				clearItem.Tag = NSSearchFieldClearRecentsMenuItemTag;
				searchMenu.InsertItem (clearItem, 6);
				
				var searchCell = searchField.Cell;
				searchCell.MaximumRecents = 20;
				searchCell.SearchMenuTemplate = searchMenu;
				
				// with lamda
				//searchField.ControlTextDidChange += (o,e) => controlTextDidChange((NSNotification)o);
				// or delegate
				searchField.Changed += delegate (object sender, EventArgs e) {
					handleTextDidChange ((NSNotification) sender);
				};
				searchField.DoCommandBySelector = handleCommandSelectors;
				searchField.GetCompletions = handleFilterCompletions;
			}
				
			// build the list of keyword strings for our type completion dropdown list in NSSearchField
			builtInKeywords = new List<string>() {"Favorite", "Favorite1", "Favorite11", "Favorite3", "Vacations1", "Vacations2",
					"Hawaii", "Family", "Important", "Important2", "Personal"};
		}
开发者ID:RafasTavares,项目名称:mac-samples,代码行数:64,代码来源:SearchFieldWindowController.cs


注:本文中的MonoMac.AppKit.NSMenu.InsertItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。