Best way to ope and display other nibs ?

Hi,

This is rather a stupid question but I’m looking for the best way to do this.

I’ve got two nibs (actually 6 but it doesn’t matter in this case), one with lots of things and actions, it has its own toolbar etc. It’s a preferences window.
And another nib, with the MainMenu, and the main window. I would like to have something when clicked on Preferences in the menu bar that it loads and displays the other nib.

But the problem is, since the preferences window has lots of actions, and then main window too (they have both the on clicked handler etc.), how can I do it the best way ? Do I need two separate scripts ? I’d rather have one but if it isn’t possible then I’ll have to go with more than one
-I already looked at the Display Panel example

Thanks

You can do this all in one applescript file, as you wish. If you’ve already read the Display Panel example, you should know what to do.

Put the line(s) of code below at the top of your script. You can create different values for each window you’ll want to load:


property panelWIndow : missing value
property panelWindow2 : missing value
--as many as you need

Then use the code as given in the Display Panel to load the window.

If I understand correctly, you seem to be concerned that the preferences window and the main window both share many of the same handlers. That’s okay. To differentiate between handlers, just do the following (using the “on clicked theObject” handler as an example):


on clicked theObject
if name of theObject is "button_on_main_window" then
    --do something (like load preferences window)
else if name of theObject is "button_on_preferences_window" then
     --do something else (perhaps close the preferences window)
end if
end clicked

In other words, if you give your buttons applescript names in Interface Builder, then you can direct the on Clicked handler to do different things for each button you have, regardless of which window the button is on. You can do the same thing for menu items, etc.

I hope this answers your question.

Thanks for the reply. I already got the answer before you posted. But now it seems a bit more clear.
But I don’t use the missing value thing. I don’t see the point of using that…

usually you should check if the panel is already referenced and loaded. That’s the missing value thing for :wink:

Oh, ok, but here it works without them… I can’t open the same window twice so it seems to work.

That’s true, it will continue to work, and you will only see one copy of the window.

However: every time the “load nib” command is used, Applescript, in effect, creates a new instance of the window. Displaying the window shows that instance of the window. If you let the “load nib” command run every time the window opens, then Applescript will keep creating new instances of the window. They will look and act the same as if it were one instance. You will not see more than one window. However, each “loaded nib” will continue to take up space in memory.

So, it’s bad programming technique to keep loading the nib. Hence, as Stefan said, you should check if the window has already been loaded, and if so, then just display the window, don’t reload the nib. Hope that helps at least explain why that missing value thing exists.

Mike

OK, that makes sense. I"ll use the missing value code.