Fixed: revert commit abdf1156d4 for CPComboBox

This commit is contained in:
Alexandre Wilhelm committed 2014-08-20 15:11:21 -07:00
1 parent 0479e9b3f3
commit ce0233d0a2
1 file changed
+80 -122
+80 -122
View File
@@ -210,11 +210,42 @@ var CPComboBoxTextSubview = @"text",
if (aDelegate === delegate)
return;
var defaultCenter = [CPNotificationCenter defaultCenter];
if (delegate)
[self _removeObserversDelegate:delegate];
{
[defaultCenter removeObserver:delegate name:CPComboBoxSelectionIsChangingNotification object:self];
[defaultCenter removeObserver:delegate name:CPComboBoxSelectionDidChangeNotification object:self];
[defaultCenter removeObserver:delegate name:CPComboBoxWillDismissNotification object:self];
[defaultCenter removeObserver:delegate name:CPComboBoxWillPopUpNotification object:self];
}
if (aDelegate)
[self _addObserversDelegate:aDelegate];
{
if ([aDelegate respondsToSelector:@selector(comboBoxSelectionIsChanging:)])
[defaultCenter addObserver:delegate
selector:@selector(comboBoxSelectionIsChanging:)
name:CPComboBoxSelectionIsChangingNotification
object:self];
if ([aDelegate respondsToSelector:@selector(comboBoxSelectionDidChange:)])
[defaultCenter addObserver:delegate
selector:@selector(comboBoxSelectionDidChange:)
name:CPComboBoxSelectionDidChangeNotification
object:self];
if ([aDelegate respondsToSelector:@selector(comboBoxWillPopUp:)])
[defaultCenter addObserver:delegate
selector:@selector(comboBoxWillPopUp:)
name:CPComboBoxWillPopUpNotification
object:self];
if ([aDelegate respondsToSelector:@selector(comboBoxWillDismiss:)])
[defaultCenter addObserver:delegate
selector:@selector(comboBoxWillDissmis:)
name:CPComboBoxWillDismissNotification
object:self];
}
[super setDelegate:aDelegate];
}
@@ -366,11 +397,56 @@ var CPComboBoxTextSubview = @"text",
var defaultCenter = [CPNotificationCenter defaultCenter];
if (_listDelegate)
[self _removeObserversListDelegate:_listDelegate]
{
[defaultCenter removeObserver:self name:_CPPopUpListWillPopUpNotification object:_listDelegate];
[defaultCenter removeObserver:self name:_CPPopUpListWillDismissNotification object:_listDelegate];
[defaultCenter removeObserver:self name:_CPPopUpListDidDismissNotification object:_listDelegate];
[defaultCenter removeObserver:self name:_CPPopUpListItemWasClickedNotification object:_listDelegate];
var oldTableView = [_listDelegate tableView];
if (oldTableView)
{
[defaultCenter removeObserver:self name:CPTableViewSelectionIsChangingNotification object:oldTableView];
[defaultCenter removeObserver:self name:CPTableViewSelectionDidChangeNotification object:oldTableView];
}
}
_listDelegate = aDelegate;
[self _addObserversListDelegate:_listDelegate]
[defaultCenter addObserver:self
selector:@selector(comboBoxWillPopUp:)
name:_CPPopUpListWillPopUpNotification
object:_listDelegate];
[defaultCenter addObserver:self
selector:@selector(comboBoxWillDismiss:)
name:_CPPopUpListWillDismissNotification
object:_listDelegate];
[defaultCenter addObserver:self
selector:@selector(listDidDismiss:)
name:_CPPopUpListDidDismissNotification
object:_listDelegate];
[defaultCenter addObserver:self
selector:@selector(itemWasClicked:)
name:_CPPopUpListItemWasClickedNotification
object:_listDelegate];
[[_listDelegate scrollView] setHasVerticalScroller:_hasVerticalScroller];
var tableView = [_listDelegate tableView];
[defaultCenter addObserver:self
selector:@selector(comboBoxSelectionIsChanging:)
name:CPTableViewSelectionIsChangingNotification
object:tableView];
[defaultCenter addObserver:self
selector:@selector(comboBoxSelectionDidChange:)
name:CPTableViewSelectionDidChangeNotification
object:tableView];
// Apply our text style to the list
[_listDelegate setFont:[self font]];
@@ -897,124 +973,6 @@ var CPComboBoxTextSubview = @"text",
}
}
- (void)_removeObservers
{
[super _removeObservers];
if (_listDelegate)
[self _removeObserversListDelegate:_listDelegate];
if ([self delegate])
[self _removeObserversDelegate:[self delegate]];
}
- (void)_removeObserversDelegate:(id)aDelegate
{
var defaultCenter = [CPNotificationCenter defaultCenter];
[defaultCenter removeObserver:aDelegate name:CPComboBoxSelectionIsChangingNotification object:self];
[defaultCenter removeObserver:aDelegate name:CPComboBoxSelectionDidChangeNotification object:self];
[defaultCenter removeObserver:aDelegate name:CPComboBoxWillDismissNotification object:self];
[defaultCenter removeObserver:aDelegate name:CPComboBoxWillPopUpNotification object:self];
}
- (void)_removeObserversListDelegate:(id)aDelegate
{
var defaultCenter = [CPNotificationCenter defaultCenter];
[defaultCenter removeObserver:self name:_CPPopUpListWillPopUpNotification object:aDelegate];
[defaultCenter removeObserver:self name:_CPPopUpListWillDismissNotification object:aDelegate];
[defaultCenter removeObserver:self name:_CPPopUpListDidDismissNotification object:aDelegate];
[defaultCenter removeObserver:self name:_CPPopUpListItemWasClickedNotification object:aDelegate];
var oldTableView = [aDelegate tableView];
if (oldTableView)
{
[defaultCenter removeObserver:self name:CPTableViewSelectionIsChangingNotification object:oldTableView];
[defaultCenter removeObserver:self name:CPTableViewSelectionDidChangeNotification object:oldTableView];
}
}
- (void)_addObservers
{
[super _addObservers];
if (_listDelegate)
[self _addObserversListDelegate:_listDelegate];
if ([self delegate])
[self _addObserversDelegate:[self delegate]];
}
- (void)_addObserversDelegate:(id)aDelegate
{
var defaultCenter = [CPNotificationCenter defaultCenter];
if ([aDelegate respondsToSelector:@selector(comboBoxSelectionIsChanging:)])
[defaultCenter addObserver:aDelegate
selector:@selector(comboBoxSelectionIsChanging:)
name:CPComboBoxSelectionIsChangingNotification
object:self];
if ([aDelegate respondsToSelector:@selector(comboBoxSelectionDidChange:)])
[defaultCenter addObserver:aDelegate
selector:@selector(comboBoxSelectionDidChange:)
name:CPComboBoxSelectionDidChangeNotification
object:self];
if ([aDelegate respondsToSelector:@selector(comboBoxWillPopUp:)])
[defaultCenter addObserver:aDelegate
selector:@selector(comboBoxWillPopUp:)
name:CPComboBoxWillPopUpNotification
object:self];
if ([aDelegate respondsToSelector:@selector(comboBoxWillDismiss:)])
[defaultCenter addObserver:aDelegate
selector:@selector(comboBoxWillDissmis:)
name:CPComboBoxWillDismissNotification
object:self];
}
- (void)_addObserversListDelegate:(id)aDelegate
{
var defaultCenter = [CPNotificationCenter defaultCenter];
[defaultCenter addObserver:self
selector:@selector(comboBoxWillPopUp:)
name:_CPPopUpListWillPopUpNotification
object:aDelegate];
[defaultCenter addObserver:self
selector:@selector(comboBoxWillDismiss:)
name:_CPPopUpListWillDismissNotification
object:aDelegate];
[defaultCenter addObserver:self
selector:@selector(listDidDismiss:)
name:_CPPopUpListDidDismissNotification
object:aDelegate];
[defaultCenter addObserver:self
selector:@selector(itemWasClicked:)
name:_CPPopUpListItemWasClickedNotification
object:aDelegate];
[[aDelegate scrollView] setHasVerticalScroller:_hasVerticalScroller];
var tableView = [aDelegate tableView];
[defaultCenter addObserver:self
selector:@selector(comboBoxSelectionIsChanging:)
name:CPTableViewSelectionIsChangingNotification
object:tableView];
[defaultCenter addObserver:self
selector:@selector(comboBoxSelectionDidChange:)
name:CPTableViewSelectionDidChangeNotification
object:tableView];
}
@end
@implementation CPComboBox (CPComboBoxDelegate)