refactor: don't use NSClassFromString in TouchBar code (#19445)

This commit is contained in:
Milan Burda 2019-07-27 01:20:25 +02:00 committed by Alexey Kuzmin
parent c6bcf49acc
commit 50c7eb58a1

View file

@ -54,8 +54,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
} }
- (NSTouchBar*)touchBarFromItemIdentifiers:(NSMutableArray*)items { - (NSTouchBar*)touchBarFromItemIdentifiers:(NSMutableArray*)items {
base::scoped_nsobject<NSTouchBar> bar( base::scoped_nsobject<NSTouchBar> bar([[NSTouchBar alloc] init]);
[[NSClassFromString(@"NSTouchBar") alloc] init]);
[bar setDelegate:delegate_]; [bar setDelegate:delegate_];
[bar setDefaultItemIdentifiers:items]; [bar setDefaultItemIdentifiers:items];
return bar.autorelease(); return bar.autorelease();
@ -341,8 +340,8 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
return nil; return nil;
mate::PersistentDictionary settings = settings_[s_id]; mate::PersistentDictionary settings = settings_[s_id];
base::scoped_nsobject<NSCustomTouchBarItem> item([[NSClassFromString( base::scoped_nsobject<NSCustomTouchBarItem> item(
@"NSCustomTouchBarItem") alloc] initWithIdentifier:identifier]); [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]);
NSButton* button = [NSButton buttonWithTitle:@"" NSButton* button = [NSButton buttonWithTitle:@""
target:self target:self
action:@selector(buttonAction:)]; action:@selector(buttonAction:)];
@ -391,8 +390,8 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
return nil; return nil;
mate::PersistentDictionary settings = settings_[s_id]; mate::PersistentDictionary settings = settings_[s_id];
base::scoped_nsobject<NSCustomTouchBarItem> item([[NSClassFromString( base::scoped_nsobject<NSCustomTouchBarItem> item(
@"NSCustomTouchBarItem") alloc] initWithIdentifier:identifier]); [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]);
[item setView:[NSTextField labelWithString:@""]]; [item setView:[NSTextField labelWithString:@""]];
[self updateLabel:item withSettings:settings]; [self updateLabel:item withSettings:settings];
return item.autorelease(); return item.autorelease();
@ -421,8 +420,8 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
return nil; return nil;
mate::PersistentDictionary settings = settings_[s_id]; mate::PersistentDictionary settings = settings_[s_id];
base::scoped_nsobject<NSColorPickerTouchBarItem> item([[NSClassFromString( base::scoped_nsobject<NSColorPickerTouchBarItem> item(
@"NSColorPickerTouchBarItem") alloc] initWithIdentifier:identifier]); [[NSColorPickerTouchBarItem alloc] initWithIdentifier:identifier]);
[item setTarget:self]; [item setTarget:self];
[item setAction:@selector(colorPickerAction:)]; [item setAction:@selector(colorPickerAction:)];
[self updateColorPicker:item withSettings:settings]; [self updateColorPicker:item withSettings:settings];
@ -456,8 +455,8 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
return nil; return nil;
mate::PersistentDictionary settings = settings_[s_id]; mate::PersistentDictionary settings = settings_[s_id];
base::scoped_nsobject<NSSliderTouchBarItem> item([[NSClassFromString( base::scoped_nsobject<NSSliderTouchBarItem> item(
@"NSSliderTouchBarItem") alloc] initWithIdentifier:identifier]); [[NSSliderTouchBarItem alloc] initWithIdentifier:identifier]);
[item setTarget:self]; [item setTarget:self];
[item setAction:@selector(sliderAction:)]; [item setAction:@selector(sliderAction:)];
[self updateSlider:item withSettings:settings]; [self updateSlider:item withSettings:settings];
@ -489,8 +488,8 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
return nil; return nil;
mate::PersistentDictionary settings = settings_[s_id]; mate::PersistentDictionary settings = settings_[s_id];
base::scoped_nsobject<NSPopoverTouchBarItem> item([[NSClassFromString( base::scoped_nsobject<NSPopoverTouchBarItem> item(
@"NSPopoverTouchBarItem") alloc] initWithIdentifier:identifier]); [[NSPopoverTouchBarItem alloc] initWithIdentifier:identifier]);
[self updatePopover:item withSettings:settings]; [self updatePopover:item withSettings:settings];
return item.autorelease(); return item.autorelease();
} }
@ -544,9 +543,8 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
} }
} }
} }
return [NSClassFromString(@"NSGroupTouchBarItem") return [NSGroupTouchBarItem groupItemWithIdentifier:identifier
groupItemWithIdentifier:identifier items:generatedItems];
items:generatedItems];
} }
- (void)updateGroup:(NSGroupTouchBarItem*)item - (void)updateGroup:(NSGroupTouchBarItem*)item
@ -571,8 +569,8 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
return nil; return nil;
mate::PersistentDictionary settings = settings_[s_id]; mate::PersistentDictionary settings = settings_[s_id];
base::scoped_nsobject<NSCustomTouchBarItem> item([[NSClassFromString( base::scoped_nsobject<NSCustomTouchBarItem> item(
@"NSCustomTouchBarItem") alloc] initWithIdentifier:identifier]); [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]);
NSSegmentedControl* control = [NSSegmentedControl NSSegmentedControl* control = [NSSegmentedControl
segmentedControlWithLabels:[NSMutableArray array] segmentedControlWithLabels:[NSMutableArray array]
@ -656,15 +654,15 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
return nil; return nil;
mate::PersistentDictionary settings = settings_[s_id]; mate::PersistentDictionary settings = settings_[s_id];
base::scoped_nsobject<NSCustomTouchBarItem> item([[NSClassFromString( base::scoped_nsobject<NSCustomTouchBarItem> item(
@"NSCustomTouchBarItem") alloc] initWithIdentifier:identifier]); [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]);
NSScrubber* scrubber = [[[NSClassFromString(@"NSScrubber") alloc] NSScrubber* scrubber =
initWithFrame:NSZeroRect] autorelease]; [[[NSScrubber alloc] initWithFrame:NSZeroRect] autorelease];
[scrubber registerClass:NSClassFromString(@"NSScrubberTextItemView") [scrubber registerClass:[NSScrubberTextItemView class]
forItemIdentifier:TextScrubberItemIdentifier]; forItemIdentifier:TextScrubberItemIdentifier];
[scrubber registerClass:NSClassFromString(@"NSScrubberImageItemView") [scrubber registerClass:[NSScrubberImageItemView class]
forItemIdentifier:ImageScrubberItemIdentifier]; forItemIdentifier:ImageScrubberItemIdentifier];
scrubber.delegate = self; scrubber.delegate = self;
@ -693,20 +691,20 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
if (selectedStyle == "outline") { if (selectedStyle == "outline") {
scrubber.selectionBackgroundStyle = scrubber.selectionBackgroundStyle =
[NSClassFromString(@"NSScrubberSelectionStyle") outlineOverlayStyle]; [NSScrubberSelectionStyle outlineOverlayStyle];
} else if (selectedStyle == "background") { } else if (selectedStyle == "background") {
scrubber.selectionBackgroundStyle = scrubber.selectionBackgroundStyle =
[NSClassFromString(@"NSScrubberSelectionStyle") roundedBackgroundStyle]; [NSScrubberSelectionStyle roundedBackgroundStyle];
} else { } else {
scrubber.selectionBackgroundStyle = nil; scrubber.selectionBackgroundStyle = nil;
} }
if (overlayStyle == "outline") { if (overlayStyle == "outline") {
scrubber.selectionOverlayStyle = scrubber.selectionOverlayStyle =
[NSClassFromString(@"NSScrubberSelectionStyle") outlineOverlayStyle]; [NSScrubberSelectionStyle outlineOverlayStyle];
} else if (overlayStyle == "background") { } else if (overlayStyle == "background") {
scrubber.selectionOverlayStyle = scrubber.selectionOverlayStyle =
[NSClassFromString(@"NSScrubberSelectionStyle") roundedBackgroundStyle]; [NSScrubberSelectionStyle roundedBackgroundStyle];
} else { } else {
scrubber.selectionOverlayStyle = nil; scrubber.selectionOverlayStyle = nil;
} }