NSRuleEditor: criteria for a new line

When I click the "+" button on a line in NSRuleEditor, a new line is created. How can I influence the criteria used for this line.

It seems that NSRuleEditor, by default, selects the first criterion sequentially from a list of possible values. I would prefer the new line to match the line where "+" was pressed.

+5
source share
1 answer

I managed to fake it by subclassing a private method:

- (void)_addOptionFromSlice:(id)slice ofRowType:(unsigned int)type
{
    int rowIndex = [(NSRuleEditorViewSlice*)slice rowIndex];

    NSArray *criteriaForRow = [self criteriaForRow:rowIndex];
    NSArray *displayValuesForRow = [self displayValuesForRow:rowIndex];

    self.template = [NSArray arrayWithObjects:criteriaForRow, displayValuesForRow, nil];

    [super _addOptionFromSlice:slice ofRowType:type];
}

- (void)insertRowAtIndex:(NSInteger)rowIndex withType:(NSRuleEditorRowType)rowType asSubrowOfRow:(NSInteger)parentRow animate:(BOOL)shouldAnimate
{
    [super insertRowAtIndex:rowIndex withType:rowType asSubrowOfRow:parentRow animate:shouldAnimate];

    NSArray *template = self.template;

    if (template != nil) {
        [self setCriteria:[template objectAtIndex:0] andDisplayValues:[template objectAtIndex:1] forRowAtIndex:rowIndex];
    }
}
+2
source

All Articles