mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-29 09:52:03 +00:00
CPTableView: Ignore clicks on control cells in non-editable columns
Previously, clicking a control cell (such as a checkbox) in a non-editable column mutated its value and committed the change because -_hitTest: routed non-text-field control cell mouse-downs to the control without checking whether the column was editable. Matching AppKit, control cells in non-editable columns no longer handle the click, allowing the table view to select the row instead.
This commit is contained in:
1 parent
7e229f5bd7
commit
145138ae8b
2 files changed
+54
No files matched your search
@@ -102,7 +102,21 @@
|
||||
}
|
||||
}
|
||||
else if (!_isViewBased && [aView isKindOfClass:[CPControl class]] && ![aView isKindOfClass:[CPTextField class]])
|
||||
{
|
||||
/*
|
||||
2026-11-25: a click on a checkbox in a column that is not editable changed the value.
|
||||
This branch sent every mouse-down on a control cell, such as a checkbox, to the
|
||||
control and committed its new value, and it did not check the column. As in AppKit,
|
||||
a control cell in a column that is not editable now does not take the click; the
|
||||
table view takes it and selects the row.
|
||||
*/
|
||||
[self getColumn:@ref(column) row:@ref(row) forView:aView];
|
||||
|
||||
if (column === -1 || ![_tableColumns[column] isEditable])
|
||||
return self;
|
||||
|
||||
[aView addObserver:self forKeyPath:@"objectValue" options:CPKeyValueObservingOptionOld | CPKeyValueObservingOptionNew context:"editing"];
|
||||
}
|
||||
|
||||
return aView;
|
||||
}
|
||||
|
||||
@@ -658,6 +658,46 @@ var InteractionDragType = @"InteractionDragType";
|
||||
[self assert:CPNotFound equals:[tableView editedRow]];
|
||||
}
|
||||
|
||||
/*
|
||||
Gives the column a checkbox data view, and checks that a click in row 1 lands on that row's
|
||||
checkbox. -reloadData only schedules the layout that loads the data views, and a click does
|
||||
not force it, so the table is laid out here. Without the layout no checkbox is under the
|
||||
point, and both checkbox tests would pass or fail without a click reaching a checkbox.
|
||||
*/
|
||||
- (void)useCheckBoxDataView
|
||||
{
|
||||
var checkBox = [CPCheckBox checkBoxWithTitle:@""];
|
||||
|
||||
[checkBox setImagePosition:CPImageOnly];
|
||||
[tableColumn setDataView:checkBox];
|
||||
[tableView reloadData];
|
||||
[tableView layoutIfNeeded];
|
||||
|
||||
var rowCheckBox = [tableView viewAtColumn:0 row:1 makeIfNecessary:NO];
|
||||
|
||||
[self assertTrue:[rowCheckBox isKindOfClass:[CPCheckBox class]] message:@"Row 1 must show a checkbox"];
|
||||
[self assertTrue:CGRectContainsPoint([rowCheckBox frame], [self pointInRow:1]) message:@"A click in row 1 must land on its checkbox"];
|
||||
}
|
||||
|
||||
- (void)testAClickOnACheckBoxInAnEditableColumnStoresTheValue
|
||||
{
|
||||
[self useCheckBoxDataView];
|
||||
[self clickRow:1];
|
||||
|
||||
[self assert:1 equals:[dataSource editedValues].length];
|
||||
[self assert:1 equals:[dataSource editedValues][0].row];
|
||||
}
|
||||
|
||||
- (void)testAClickOnACheckBoxInAColumnThatIsNotEditableDoesNotStoreAValue
|
||||
{
|
||||
[tableColumn setEditable:NO];
|
||||
[self useCheckBoxDataView];
|
||||
[self clickRow:1];
|
||||
|
||||
[self assert:0 equals:[dataSource editedValues].length];
|
||||
[self assert:[1] equals:[self selectedRows]];
|
||||
}
|
||||
|
||||
/*
|
||||
Removes the data source and binds the column to an array controller. The table then
|
||||
stores an edited value through its content binding.
|
||||
|
||||
Reference in new issue
Block a user