# Cocoa - Closing Windows / Dock Clicking / pllist files



## benixau (Mar 29, 2003)

How do i, in cocoa : obj-c do something when someone clicks the close button on a window?

i am trying to find this out so that when they do it i can ask them if they want to quit. Then if they do I quit the app, otherwise they have to click the dock to bring the window back or file:new (i have this already).

I also would like to know how to save a boolean preference and a double value in a plist preferences file. Could you also show me how to recover these prefernces when the app starts.

I have looked at the o'reily and apple exxamples and they are either irrelevant (o'reily) or dont work in x.2.4 and DevTools Dec2002.

I know this is alot but thanx for any help.


----------



## jeremys (Apr 3, 2003)

use this to close a window,

[NSWindow *window close];

you can proballly just link the button to a function, using control+drag.

- (IBAction)closeButtonid)sender
{
  [NSWindow *window close];
}


----------



## benixau (Apr 3, 2003)

thanx - but i am specifically looking for something when someone clicks t he red close button in the window, to diable the menu items which also close a window


----------



## jeremys (Apr 3, 2003)

there must be a class for close control. sorry that i cant be of more help.


----------



## jeremys (Apr 3, 2003)

i think it could also be done with a delegate. if i was you, i would take a look into this.


----------



## benixau (Apr 3, 2003)

i am using the delegate now. thanx for that. documentation on doing this is very very thin. i actiually found that out by emailing apple's cocoa-feedback email.

i whinged and said that it was weird that such things either didnt exists or were not documetned well. A also indirectly insulted cocoa and obj-c and got a response in no time (two working days)

she gave me the functions i needed and what they did. The only problem is that the dock function she gave me still doesnt do it fully. how? i need a dock function that sends a message that the dock has been clicked regardless of that applications active status.

oh well - time for another email.


----------

