Exemplo n.º 1
0
        public void AwakeFromNib()
        {
            if (this.searchField.RespondsToSelector(ObjectiveCRuntime.Selector("setRecentSearches:")))
            {
                NSMenu searchMenu = new NSMenu("Search Menu");
                searchMenu.Autorelease();
                searchMenu.AutoenablesItems = true;

                // first add our custom menu item (Important note: "action" MUST be valid or the menu item is disabled)
                NSMenuItem item = new NSMenuItem("Custom", ObjectiveCRuntime.Selector("actionMenuItem:"), NSString.Empty);
                item.Target = this;
                searchMenu.InsertItemAtIndex(item, 0);
                item.Release();

                // add our own separator to keep our custom menu separate
                NSMenuItem separator = NSMenuItem.SeparatorItem;
                searchMenu.InsertItemAtIndex(separator, 1);

                NSMenuItem recentsTitleItem = new NSMenuItem("Recent Searches", IntPtr.Zero, NSString.Empty);
                // tag this menu item so NSSearchField can use it and respond to it appropriately
                recentsTitleItem.Tag = NSSearchFieldCell.NSSearchFieldRecentsTitleMenuItemTag;
                searchMenu.InsertItemAtIndex(recentsTitleItem, 2);
                recentsTitleItem.Release();

                NSMenuItem norecentsTitleItem = new NSMenuItem("No recent searches", IntPtr.Zero, NSString.Empty);
                // tag this menu item so NSSearchField can use it and respond to it appropriately
                norecentsTitleItem.Tag = NSSearchFieldCell.NSSearchFieldNoRecentsMenuItemTag;
                searchMenu.InsertItemAtIndex(norecentsTitleItem, 3);
                norecentsTitleItem.Release();

                NSMenuItem recentsItem = new NSMenuItem("Recents", IntPtr.Zero, NSString.Empty);
                // tag this menu item so NSSearchField can use it and respond to it appropriately
                recentsItem.Tag = NSSearchFieldCell.NSSearchFieldRecentsMenuItemTag;
                searchMenu.InsertItemAtIndex(recentsItem, 4);
                recentsItem.Release();

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

                NSMenuItem clearItem = new NSMenuItem("Clear", IntPtr.Zero, NSString.Empty);
                // tag this menu item so NSSearchField can use it and respond to it appropriately
                clearItem.Tag = NSSearchFieldCell.NSSearchFieldClearRecentsMenuItemTag;
                searchMenu.InsertItemAtIndex(clearItem, 6);
                clearItem.Release();

                NSSearchFieldCell searchCell = this.searchField.Cell.CastTo<NSSearchFieldCell>();
                searchCell.MaximumRecents = 20;
                searchCell.SearchMenuTemplate = searchMenu;
            }

            // build the list of keyword strings for our type completion dropdown list in NSSearchField
            this._builtInKeywords = new NSMutableArray();
            this._builtInKeywords.AddObject((NSString) "Favorite");
            this._builtInKeywords.AddObject((NSString) "Favorite1");
            this._builtInKeywords.AddObject((NSString) "Favorite11");
            this._builtInKeywords.AddObject((NSString) "Favorite3");
            this._builtInKeywords.AddObject((NSString) "Vacations1");
            this._builtInKeywords.AddObject((NSString) "Vacations2");
            this._builtInKeywords.AddObject((NSString) "Hawaii");
            this._builtInKeywords.AddObject((NSString) "Family");
            this._builtInKeywords.AddObject((NSString) "Important");
            this._builtInKeywords.AddObject((NSString) "Important2");
            this._builtInKeywords.AddObject((NSString) "Personal");
        }