Menu Button to display new window

Hi

I am going to build an app that I want to contain in separate categories and want to display them in their own window by clicking on a Menu Button. This will be something similar to TinkerTool app, or VLC’s Preferences Window.

Could anyone suggest a way to begin such an app in code or in Bindings please.

Regards,
t.

The easiest way is to add extra windows to your MainMenu.xib, add outlets for them, and then have handlers that orderFront and orderOut as required. It’s not really a bindings thing.

Hi Shane and thank you for replying. Would the code below achieve the same result.

Regards,
t.

From Stack OverFlow

  • Create a class which is a sub class of NSWindowController e.g. NewWindowController
    Create a window xib for NewWindowController class.

  • On button click code as:

    NewWindowController *controllerWindow = [[NewWindowController alloc] initWithWindowNibName:@“You Window XIB Name”];
    [controllerWindow showWindow:self];

Yes, that’s how you do it if you want the windows in separate .xib files. Indeed, if you’re using Objective-C, that’s very much the recommended way to go.

In ASObjC, I think it adds a level of complexity that’s probably not justified for simpler jobs. For more complex jobs it is – but then I’d argue that more complex jobs are usually better off written in Objective-C in the first place.

Anyway, that’s I said “easiest way”.

Hi Shane,

What I want to do is every time a MenuList button is clicked, new UI elements are displayed inline in a single Window and not a second Window.

I looked at few Objective-C books, but didn’t find any project similar.

Regards,
t

I’mm afraid that description is way too fuzzy…

Hi Shane,

Sorry if I wan’t clear, but I got an idea on how to go about doing the app.

Regards,
t.

You can use a NSToolBar.

Drag a NSToolBar to your window.

Select each of its toolbar items and remove them.

( You will notice that the tool bar acts like it does when you customize a tool bar )

Now add as many Image Tool bar items as you need to the NSToolbar. ( this makes sure they are clean )

Select each Image Tool bar item. and Set it up using it’s attributes inspector .

Set its Image.
Check ‘Selectable’ – This gives it the depressed look when it is selected. Like system preferences and VLC.

Drag the Image Tool bar item into the Default Toolbar Items. This will make them show when running.

Click the done button and the customise sheet will close.

Because you do not want the user to customise the Toolbar and you want it to act like a normal preference type toolbar.

Uncheck ‘Customizable’ in it’s attributes inspector.


Now drag a NSTabView onto your window.

Set it to ‘Tabless’ in it’s attributes inspector.

Size it so it fills the window and top edge is under the NSToolBar

Connect the NSTabView as an outlet .

Place you other UI in each Tab as needed.


You now need each Image Tool bar item to be connected to an Action. Either one each or a single one that checks the sender and acts accordingly.

For example a single action per Image Tool bar item.


One thing you should also do is for each Image Tool bar item you should set it’s identifier in it’s attributes inspector.

This will allow you to set which tool bar is selected when the window is open. Otherwise the default tab will be showing but the Tool bar item will not be selected.

You can set the selected tool bar item in for example the AwakeFromNib or when the window is opened using:

remember to connect the NSTool bar with an outlet.

This also assumes the default Tab is the first tab.

If the tab was the second Tab the you would need to make sure the selected tool bar item matches that.

This all is in Objective-c, but should be easy to convert.

I should add that I have only just figured all of this out to answer your question as it was also of interest to me. I wish I had looked at the before because it is actually relatively easy compared to all the messing around to get this effect I have done in the past. But I guess my learning curve as allowed me to see what needs to be done now where as before I could not. :slight_smile:

Thank you for your reply.

Best,
t.