NSImageView, copy image with CMD/CTR+C

85 views Asked by At

If a NSImageView is Editable and contains an image, it is possible to copy it's content via CMD+C

In my subclass i don't want the Editable property to be YES (cause of cut, drop, etc...) i just want to support the copy, but wasn't able to figure out, what makes the copy work

In my subclass i tried

- (void)copy:(id)sender {

}

- (BOOL)refusesFirstResponder {
    return NO;
}

- (BOOL)respondsToSelector:(SEL)aSelector {

    if (aSelector == @selector(copy:)) {
        return YES;
    }
    return [super respondsToSelector:aSelector];

}

but the copy command from the menu is grayed out and CMD+C doesn't work either (it triggers the menu copy:)

How to add support for copy an NSImageView subclass, which is Editable=NO

1

There are 1 answers

0
Peter Lapisu On

The key was setting the NSImageView as the first responder

[self.view.window makeFirstResponder:self.imageView];

Not sure why it got autoselected when Editable was YES