Set focus for NSToolbarSearchfieldMBS

Does anyone know how to set the focus for a NSToolbarSearchfieldMBS? Adding the searchfield is no problem:

[code] SearchField = New NSToolbarSearchField(self.getWindowName)
SearchFieldItem = New NSToolbarItemMBS(kSearch)
SearchFieldItem.paletteLabel = kSearch
SearchFieldItem.view = SearchField
SearchFieldItem.

dim theToolbar as NSToolbarMBS = self.NSToolbarMBS
dim items() as NSToolbarItemMBS = theToolbar.items

for each currentItem as NSToolbarItemMBS in items
if currentItem.label = “Search” then
currentItem.label = kSearch
currentItem.view = SearchField
currentItem.maxSize = NSMakeSizeMBS(300, SearchFieldExtras.MainToolbarNSSearchFieldHeight)
currentItem.minSize = NSMakeSizeMBS(150, SearchFieldExtras.MainToolbarNSSearchFieldHeight)
end if
next[/code]

But how do I set the focus in code to this control?

Mac OS 10.10.2, Xojo 2015r22, latest MBS.

you normally call makeFirstResponder for the control on the NSWindowMBS object.

https://www.monkeybreadsoftware.net/cocoa-nswindowmbs-method1.shtml#9

I use it like this:

// Set Focus on Searchfield #If TargetCocoa Call WindowMain.NSWindowMBS.makeFirstResponder(NSToolbarMain(WindowMain.OSXMainToolbar).SearchField) #EndIf

Thanks for the info! But how do I use makeFirstResponder? The code I’ve tried just gives an IllegalCastException:

self.NSWindowMBS.makeFirstResponder(NSToolbarSearchField(self.CCToolbar1.MainToolbar1.TISearch))

self in the main Window. The toolbar lives on a container called CCToolbar. And TISearch is the ToolItem that is converted to a searchfield.

you pass the NSViewMBS object to self.NSWindowMBS.makeFirstResponder.
What is TISearch in your case?

Got it:

[code] dim theToolbar as NSToolbarMBS = self.NSToolbarMBS
dim items() as NSToolbarItemMBS = theToolbar.items

for each currentItem as NSToolbarItemMBS in items
if currentItem.label = kSearch then
call self.NSWindowMBS.makeFirstResponder(currentItem.view)
end if
next[/code]

Should the cursor blink? This isn’t happening.

Since Yosemite I’m getting the focusring, but not a blinking cursor first. Only after I start typing, then I have a blinking cursor.

The same thing happens when I click to another window and then clicking back to the searchfield of the initial window: the window gets activated and the searchfield shows a focusring, but no blinker.

Only after a second click onto the field, then a blinking cursor appears.

@Oliver: so you think it’s an OS thing and not a bug?

I have not verified it, but yes, that was my explanation, so far

Since Yosemite, this is the normal behaviour of the native searchfield. :slight_smile: