Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cromestant

macrumors member
Original poster
Apr 27, 2006
59
3
Hello, i'm trying to change the behaviour of my window when i press the close button ( or command + w), the idea is that it is only hidden ( like ichat) as if i had done command + h

i ve yet been unsuccessful with this

what i tried was simply putting my AppController as the delegate of my window and overwrite the windowShouldClose method, inside i did
Code:
[mainWindow orderOut:[notification object]];
return;
but that did not work, i still can t get it back after closing...

any ideas?

thank you
 

MrFusion

macrumors 6502a
Jun 8, 2005
613
0
West-Europe
Hello, i'm trying to change the behaviour of my window when i press the close button ( or command + w), the idea is that it is only hidden ( like ichat) as if i had done command + h

i ve yet been unsuccessful with this

what i tried was simply putting my AppController as the delegate of my window and overwrite the windowShouldClose method, inside i did
Code:
[mainWindow orderOut:[notification object]];
return;
but that did not work, i still can t get it back after closing...

any ideas?

thank you

windowShouldClose expects a BOOL as return value. You just do return, instead of return NO;
 

cromestant

macrumors member
Original poster
Apr 27, 2006
59
3
thank you for your reply, i fixed this and i know it does go through it because
a) it closes/hides ( don t really know)
b) i get my log message

currently the method looks like this
Code:
- (BOOL)windowShouldClose:(NSNotification *)notification
{
	NSLog(@"cerrando");
	[mainWindow orderOut:self];
	return NO;
}

same result if I pass the orderOut with nil

now, if I try to do this
Code:
- (BOOL)windowShouldClose:(NSNotification *)notification
{
	NSLog(@"cerrando");
	[mainWindow orderOut:[notification object]];
	return NO;
}

so that the real object that ordered the close gets passed as the sender to the orderout message i then get this error
Code:
2009-03-13 16:07:04.790 Tweety[5885:10b] *** -[NSWindow object]: unrecognized selector sent to instance 0x10332a0

so basically its a matter now of being able to make this work properly.

I wan t to be able to bring it back to the front by clicking on the dock icon and this is not happening, so i'm guessing that this means that the window has been released , and not just ordered out.

thanks again, i ll keep looking
 

MrFusion

macrumors 6502a
Jun 8, 2005
613
0
West-Europe
thank you for your reply, i fixed this and i know it does go through it because
a) it closes/hides ( don t really know)
b) i get my log message

currently the method looks like this
Code:
- (BOOL)windowShouldClose:(NSNotification *)notification
{
	NSLog(@"cerrando");
	[mainWindow orderOut:self];
	return NO;
}

same result if I pass the orderOut with nil

now, if I try to do this
Code:
- (BOOL)windowShouldClose:(NSNotification *)notification
{
	NSLog(@"cerrando");
	[mainWindow orderOut:[notification object]];
	return NO;
}

so that the real object that ordered the close gets passed as the sender to the orderout message i then get this error
Code:
2009-03-13 16:07:04.790 Tweety[5885:10b] *** -[NSWindow object]: unrecognized selector sent to instance 0x10332a0

so basically its a matter now of being able to make this work properly.

I wan t to be able to bring it back to the front by clicking on the dock icon and this is not happening, so i'm guessing that this means that the window has been released , and not just ordered out.

thanks again, i ll keep looking

The error most likely indicates that the window has already been released.
windowShouldClose is also not always called.

Maybe you are going about this the wrong way?
When the window closes, save everything you need to know and focus on how to get the window (or a new instance thereof) to appear when the dock is clicked. After that, populate the (new) window with the previously saved data.
 

cromestant

macrumors member
Original poster
Apr 27, 2006
59
3
although that is a solution i doubt it is the way ichat does it.

the close button on the buddy list just hides the list or does it actually re-instantiate it?

anyhow, i ll keep looking into this but i don't think allowing it to close is the way to go..

specially, i have NOT ticked the release on close button in IB, so this is starting to make no-sense.

thanks for the input
 

WhiteRabbit

macrumors newbie
Jan 11, 2005
26
0
Recreating the window is actually what iChat does. If you change the Dock preferences (via the terminal) to indicate apps that are hidden, there is no such indication when iChat windows are closed. If the system hides the app it must keep track of everything. If you keep track of only what you need to and let the window close, you will save memory.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Windows don't automatically reopen when the Dock icon is clicked, or the app becomes active. You need to do this manually. In your NSApplication's delegate, override the applicationShouldHandleReopen:hasVisibleWindows: method. Here's some code from a (very) old project of mine (which I haven't retested):

Code:
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag {
    if (![NSApp keyWindow])
        [_mainController showWindow:self];
    return YES;
}

It should probably check for flag instead of a keyWindow though.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.