Window.visible = true not functioning - need work around

I have seen a couple of posts here about the difference between (immediate) and window.visible = true (executes at the end of the loop) and the fact that in Cocoa window.visible = true often seems to not function at all. Feedback cases 29638 and 28580 seem to apply.

My need is for a workaround. I have a search text box (using MBS’s NSSearchToolbar) and a floating window in which to display the results, if any. Obviously if no results (or nothing in the search text) then I hide the floating window with window.visible = false. If I find something then visible= true doesn’t work (not even when the loop finishes executing), whilst removes the focus from the search text box so interrupts the users ability to continue typing.

What I need is something that will make the window visible without loosing the focus in the text box.

Any ideas?


The way how I do it, is to add a shared property called ‘isOpen’. In the open event of the window I set this to True, and false in the close event.

This way I can check to see if the window is open, without opening it to do so.

Thanks Sam, but that’s not quite the issue. The problem is that:

  1. Using window.visible = true - doesn’t make the window visible - so can’t use that. Interestingly if check if visible.true you get true, even when the window isn’t actually visible. A bug I think.

  2. Using - grabs the focus from the current control, so the user can’t continue to type.

So the problem is not when the window is visible - that works fine, it is when the window is not visible i.e. how do I make it visible without losing focus from the calling window control?

You can use anyway without loosing focus.

Let us say you want to make Window2 visible and keep focus on your calling window1

  • Create a boolean module property called window2focus set to false as default
  • In Window2 activate, enter :

If window2focus = false then end if

When you do it shows it, but sets the focus back to Window1. If you want to actually show and set focus to Window2, set window2focus to true before calling

That did it. Thanks. Just a in the original window after showing the new window fixed it.