コード例 #1
0
        void PopulateArrayItems(CommandArrayInfo infos, NSMenu parent, ref int index)
        {
            if (infos == null)
            {
                return;
            }

            foreach (CommandInfo ci in infos)
            {
                if (ci.IsArraySeparator)
                {
                    var n = NSMenuItem.SeparatorItem;
                    n.Hidden = true;
                    n.Target = this;
                    if (parent.Count > index)
                    {
                        parent.InsertItem(n, index);
                    }
                    else
                    {
                        parent.AddItem(n);
                    }
                    index++;
                    continue;
                }

                var item = new MDExpandedArrayItem {
                    Info   = ci,
                    Target = this
                };
                if (ci is CommandInfoSet)
                {
                    item.Submenu = new NSMenu();
                    int i = 0;
                    PopulateArrayItems(((CommandInfoSet)ci).CommandInfos, item.Submenu, ref i);
                }
                SetItemValues(item, ci, true);
                if (item.Enabled)
                {
                    item.Action = ActionSel;
                }

                if (parent.Count > index)
                {
                    parent.InsertItem(item, index);
                }
                else
                {
                    parent.AddItem(item);
                }
                index++;
            }
            index--;
        }
コード例 #2
0
        void PopulateArrayItems(CommandArrayInfo infos, NSMenu parent, ref NSMenuItem lastSeparator, ref int index)
        {
            if (infos == null)
            {
                return;
            }

            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++);
            }
        }
コード例 #3
0
        public void RunPopUp(NSEvent theEvent)
        {
            // create the menu the popup will use
            NSMenu popUpMenu = this.Menu;

            if (popUpCell.Count > 0)
            {
                NSMenuItem item = popUpCell [0];

                if (item.Title != "")
                {
                    popUpMenu.InsertItem("", null, "", 0);
                }
            }

            popUpCell.Menu = popUpMenu;

            // and show it
            popUpCell.PerformClick(Bounds, this);

            NeedsDisplay = true;
        }
コード例 #4
0
        //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"
            };
        }
コード例 #5
0
		void PopulateArrayItems (CommandArrayInfo infos, NSMenu parent, ref NSMenuItem lastSeparator, ref int index)
		{
			if (infos == null)
				return;

			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, true);

				if (!item.Hidden)
					MDMenu.ShowLastSeparator (ref lastSeparator);
				parent.InsertItem (item, index++);
			}
		}
コード例 #6
0
        public void InsertItem(IMenuItemWrapper menuItem, int index)
        {
            var item = (NSMenuItem)menuItem.NativeObject;

            submenu.InsertItem(item, index);
        }
コード例 #7
0
		//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"};
		}