nsresponder - Cocoa: Forward actions (copy:, paste: etc.) up to the responder chain -


i have subclass of nsoutlineview implements copy:, paste:, cut: etc. also, nsdocument subclass implements these same methods.

when outline view in responder chain (is first responder or parent view of it), copy/paste events intercepted nsoutlineview subclass. want, depending on context catch of these messages, or let them propagate , caught nsdocument subclass.

what want basically:

- (void)copy:(id)sender {     // if copy paste enabled     if ([self iscopypasteenabled]) {         [[nspasteboard generalpasteboard] clearcontents];         [[nspasteboard generalpasteboard] writeobjects:self.selecteditems];         return;     }      // if copy paste disabled     // ... forward copy: message next responder,     // nsdocument or whatever } 

i've tried many tricks, none successful:

  • [[self nextresponder] copy:sender] doesn't work because next responder may not implement copy:
  • [super copy:sender] same here, super doesn't implement copy:
  • [nsapp sendaction:anaction to:nil from:sender] nice send action first responder. if used inside action

sure manually loop on responder chain until find responds copy: or directly call copy: on current document, i'm looking right way of doing it.

many in advance!

this should work:

[[self nextresponder] trytoperform:_cmd with:sender]; 

there's problem, though: presence of responder in responder chain implements -copy: will, in , of itself, cause copy menu item enabled if wouldn't otherwise if object weren't in chain or didn't implement -copy:. object disable item using -validatemenuitem: or -validateuserinterfaceitem:, nontrivial enable if , if there's potential target chain , target enable item.

a different approach make search responder implements action method skip outline view if disable pasteboard support. override -respondstoselector:. if selector 1 of pasteboard operations , pasteboard support disabled, return false though class implement it. is, lie , claim object doesn't respond selectors. other selector, or if pasteboard support on, call through super , return returns.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -