mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 04:10:38 +00:00
Minor corrections to toolbar to correct a memory leak.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19684 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d8efe75de4
commit
6e7ef17e28
3 changed files with 59 additions and 15 deletions
|
@ -1041,6 +1041,8 @@ static id validationCenter;
|
|||
|
||||
- (void) _setDelegate: (id)delegate broadcast: (BOOL)broadcast
|
||||
{
|
||||
if(_delegate)
|
||||
[nc removeObserver: _delegate name: nil object: self];
|
||||
|
||||
if (_delegate == delegate
|
||||
|| (broadcast == NO && [_delegate isMemberOfClass: [delegate class]]))
|
||||
|
@ -1063,10 +1065,8 @@ static id validationCenter;
|
|||
CHECK_REQUIRED_METHOD(toolbarAllowedItemIdentifiers:);
|
||||
CHECK_REQUIRED_METHOD(toolbarDefaultItemIdentifiers:);
|
||||
|
||||
if (_delegate)
|
||||
[nc removeObserver: _delegate name: nil object: self];
|
||||
|
||||
ASSIGN(_delegate, delegate);
|
||||
// assign the delegate...
|
||||
_delegate = delegate;
|
||||
|
||||
#define SET_DELEGATE_NOTIFICATION(notif_name) \
|
||||
if ([_delegate respondsToSelector: @selector(toolbar##notif_name:)]) \
|
||||
|
|
|
@ -247,13 +247,43 @@ static const int current_version = 1;
|
|||
}
|
||||
}
|
||||
|
||||
// handle notifications
|
||||
|
||||
- (void) handleNotification: (NSNotification *)notification
|
||||
{
|
||||
NSMutableArray *toolbars = [GSToolbar _toolbars];
|
||||
|
||||
// We currently only worry about when our window closes.
|
||||
// It's necessary to remove the toolbar which belongs to this
|
||||
// window from the master list, so that it doesn't cause a
|
||||
// memory leak.
|
||||
[toolbars removeObjectIdenticalTo: self];
|
||||
}
|
||||
|
||||
// Private Accessors
|
||||
|
||||
- (void)_setWindow: (NSWindow *)window
|
||||
{
|
||||
_window = window;
|
||||
if(_window != window)
|
||||
{
|
||||
if(_window)
|
||||
{
|
||||
[nc removeObserver: _window];
|
||||
}
|
||||
|
||||
if(window)
|
||||
{
|
||||
// watch for this window closing....
|
||||
[nc addObserver: self
|
||||
selector: @selector(handleNotification:)
|
||||
name: NSWindowWillCloseNotification
|
||||
object: window];
|
||||
}
|
||||
}
|
||||
|
||||
// We don't do an ASSIGN because the toolbar view retains us.
|
||||
// call [NSWindow(Toolbar) setToolbar:] to set the toolbar window
|
||||
_window = window;
|
||||
}
|
||||
|
||||
- (NSWindow *) _window
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue