osx - NSTableView editable header and double click in table Cell -
implemented nstableview editable headers in this stackoverflow question. works fine, except double-clicking in table edit cells. no longer works.
i suspect happens because of nstableview setdoubleaction:
bit being set custom method, , method becomes handler double click events in table (code sample original question follows):
-(void)setuptableheader:(id)table { nsarray *columns = [table tablecolumns]; nsenumerator *cols = [columns objectenumerator]; nstablecolumn *col = nil; nbetableheadercell *iheadercell; while (col = [cols nextobject]) { iheadercell = [[nbetableheadercell alloc] inittextcell:[[col headercell] stringvalue]]; [col setheadercell:iheadercell]; [[col headercell] seteditable:yes]; [iheadercell release]; } [table settarget:self]; [table setdoubleaction:@selector(doubleclickintableview:)]; // < bit }
my question is, how 1 go restoring double click functionality editing table cells?
thank you.
found answer shortly after preparing question , thought q&a.
in doubleclickintableview:
method, there check make sure header cell clicked. so, enough extend check else clause , implement editcolumn:row:withevent:select:
there:
-(void)doubleclickintableview:(id)sender { nsinteger row = [sender clickedrow]; nsinteger column = [sender clickedcolumn]; if(row == -1&& column >= 0) { nstablecolumn *tablecolumn = [[sender tablecolumns] objectatindex:column]; nstableheaderview *headerview = [sender headerview]; yctableheadercell *headercell = [tablecolumn headercell]; nswindow *window = [[nsapplication sharedapplication] mainwindow]; id celleditor = [window fieldeditor:yes forobject:sender]; [headercell sethighlighted:yes]; [headercell selectwithframe:[headerview headerrectofcolumn:column] inview:headerview editor:celleditor delegate:headercell start:0 length:headercell.stringvalue.length]; [celleditor setbackgroundcolor:[nscolor whitecolor]]; [celleditor setdrawsbackground:yes]; } // bit below. else if(row >= 0 && column >= 0) { [sender editcolumn:column row:row withevent:nil select:true]; } }
Comments
Post a Comment