Window.visible = true not functioning - need work around

I have seen a couple of posts here about the difference between window.show (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 window.show 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?

Jim

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 window.show - 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 Window.show 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 Window1.show end if

When you do Window2.show 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 Window2.show

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