Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSRuleEditor: Criteria for new row

Tags:

cocoa

When I hit the "+" button on a row in NSRuleEditor, a new row is created. How can I take influence on the criteria used for that row.

It seems NSRuleEditor defaults to selecting the first criterion sequentially from the list of possible values. I would much rather have the new row match the row where the "+" was clicked.

like image 465
Pierre Bernard Avatar asked Nov 06 '22 18:11

Pierre Bernard


1 Answers

I was able 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];
    }
}
like image 68
Pierre Bernard Avatar answered Nov 12 '22 16:11

Pierre Bernard