From cd05d30f86028d871eea35b7454e654e3d6a9505 Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Sun, 1 May 2011 21:01:13 -0400 Subject: [PATCH 1/2] Fix for setting a new platform window on a visisble window throwing a DOM exception. --- AppKit/CPWindow/CPWindow.j | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 8a2f6e43f..d133d41d0 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -466,12 +466,26 @@ CPTexturedBackgroundWindowMask return _platformWindow; } +/*! + Sets the platform window of the reciver. + This method will first close the reciever, + change the platform window, then reopen the window (if it was originally open). +*/ - (void)setPlatformWindow:(CPPlatformWindow)aPlatformWindow { - // FIXME: already visible. + var wasVisible = [self isVisible]; + + // we have to close it first, otherwise we get a DOM exception. + if (wasVisible) + [self close]; + _platformWindow = aPlatformWindow; + + if (wasVisible) + [self orderFront:self]; } + /*! @ignore */ From 21a50b990f8244adba6e2baaf243ebe6729376d6 Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Wed, 4 May 2011 19:07:06 +0200 Subject: [PATCH 2/2] fix 2 bugs in CPIndexPath 1. we didn't return a copy of the indexes 2. indexPathByRemovingLastIndex didn't remove the last index --- Foundation/CPIndexPath.j | 12 +++++++++++- Tests/Foundation/CPIndexPathTest.j | 20 ++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Foundation/CPIndexPath.j b/Foundation/CPIndexPath.j index a7ee64137..720d859c8 100644 --- a/Foundation/CPIndexPath.j +++ b/Foundation/CPIndexPath.j @@ -83,6 +83,16 @@ return [_indexes objectAtIndex:position]; } +- (void)setIndexes:(CPArray)theIndexes +{ + _indexes = [theIndexes copy]; +} + +- (CPArray)indexes +{ + return [_indexes copy]; +} + #pragma mark - #pragma mark Modification @@ -93,7 +103,7 @@ - (CPIndexPath)indexPathByRemovingLastIndex { - return [CPIndexPath indexPathWithIndexes:_indexes length:[self length]]; + return [CPIndexPath indexPathWithIndexes:_indexes length:[self length] - 1]; } #pragma mark - diff --git a/Tests/Foundation/CPIndexPathTest.j b/Tests/Foundation/CPIndexPathTest.j index 4c85f9d30..49bc5a851 100644 --- a/Tests/Foundation/CPIndexPathTest.j +++ b/Tests/Foundation/CPIndexPathTest.j @@ -35,11 +35,23 @@ - (void)testIndexPathByRemovingLastIndex { - var ip = [indexPath indexes]; - [ip removeLastObject]; + // Keep removing indexes until the indexPath is empty + while ([indexPath length] > 0) + { + var expectedIndexes = [[indexPath indexes] copy]; + [expectedIndexes removeObject:[expectedIndexes lastObject]]; - [self assert:[CPIndexPath indexPathWithIndexes:ip] - equals:[indexPath indexPathByRemovingLastIndex]]; + indexPath = [indexPath indexPathByRemovingLastIndex]; + [self assert:[CPIndexPath indexPathWithIndexes:expectedIndexes] equals:indexPath]; + } +} + +- (void)testIndexes +{ + var newIndexes = [indexPath indexes]; + [newIndexes removeObjectAtIndex:0]; + + [self assert:[indexPath indexes] notEqual:newIndexes]; } - (void)testCompareThrowsOnNil