mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-29 09:52:03 +00:00
-_enumerateViewsInRows:columns:usingBlock: and -_enumerateViewsInRows:tableColumns:usingBlock: previously executed a run loop pass before visiting views. Running timers, delayed performs, and the display server mid-operation caused views to render prematurely before load, selection, or expansion changes completed. - CPTableView: Restrict -_enumerateViewsInRows:columns:usingBlock: and -_enumerateViewsInRows:tableColumns:usingBlock: to enumerating existing views without pumping the run loop. - CPTableView: Call -layoutIfNeeded to complete reloads in -enumerateAvailableViewsUsingBlock: and -removeTableColumn:. - Tests: Update tests affected by the removal of the implicit run loop pass and the interaction test helper fix—dispatch events once through the application in the interaction test helper (which command-click and shift-click tests depend on), force layout prior to assertions in the reload and lazy preparation tests, and target clicks below the rows of a scroll-view-hosted table in the click-outside tests.
76 lines
2.4 KiB
Plaintext
76 lines
2.4 KiB
Plaintext
@import <AppKit/AppKit.j>
|
|
|
|
@implementation CPTableViewReloadDataTest : OJTestCase
|
|
{
|
|
CPWindow theWindow;
|
|
CPTableView tableView;
|
|
CPArray tableContent;
|
|
}
|
|
|
|
- (void)setUp
|
|
{
|
|
// This will init the global var CPApp which are used internally in the AppKit
|
|
[[CPApplication alloc] init];
|
|
|
|
tableContent = [];
|
|
// setup a reasonable table
|
|
theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0)
|
|
styleMask:CPWindowNotSizable];
|
|
|
|
tableView = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
|
|
[tableView setDataSource:self];
|
|
|
|
var itemIndex = 0,
|
|
items = [@"Colonne1", @"Colonne2", @"Colonne3", @"Colonne4"];
|
|
|
|
for (itemIndex ; itemIndex < [items count]; itemIndex++)
|
|
{
|
|
var item = [items objectAtIndex:itemIndex],
|
|
column = [[CPTableColumn alloc] initWithIdentifier:item];
|
|
[column setEditable:YES];
|
|
[column setMinWidth:50];
|
|
[[column headerView] setStringValue:item];
|
|
[tableView addTableColumn:column];
|
|
}
|
|
|
|
[[theWindow contentView] addSubview:tableView];
|
|
}
|
|
|
|
- (void)testReloadDataAfterModelCountChangesFromZero
|
|
{
|
|
tableContent = ["A", "B", "C"];
|
|
|
|
[tableView reloadData];
|
|
|
|
/*
|
|
The reload happens in the next layout. The enumeration below visits the data views that
|
|
exist, so the layout must come first. The enumeration ran a run loop pass, which did
|
|
the layout, until that pass was removed.
|
|
*/
|
|
[tableView layoutIfNeeded];
|
|
|
|
var enumerateViewsInRowsCall = 0;
|
|
|
|
[tableView _enumerateViewsInRows:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, 3)] columns:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, 4)] usingBlock:function(view, row, column, stop)
|
|
{
|
|
var tableColumn = [[tableView tableColumns] objectAtIndex:column],
|
|
expected = [tableColumn identifier] + "_" + [tableContent objectAtIndex:row];
|
|
|
|
[self assertTrue:([view stringValue] == expected)];
|
|
enumerateViewsInRowsCall++;
|
|
}];
|
|
|
|
[self assert:enumerateViewsInRowsCall equals:12];
|
|
}
|
|
|
|
- (int)numberOfRowsInTableView:(CPTableView)aTableView
|
|
{
|
|
return [tableContent count];
|
|
}
|
|
|
|
- (id)tableView:(CPTableView)aTableView objectValueForTableColumn:(CPTableColumn)aColumn row:(int)aRowIndex
|
|
{
|
|
return [aColumn identifier] + "_" + [tableContent objectAtIndex:aRowIndex];
|
|
}
|
|
|
|
@end |