Support setting the initial/available colors
This commit is contained in:
parent
f9dd91d54d
commit
f153d08297
3 changed files with 26 additions and 4 deletions
|
@ -245,7 +245,7 @@ static NSTouchBarItemIdentifier SliderIdentifier = @"com.electron.touchbar.slide
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTouchBarItem*)makeColorPickerForID:(NSString*)id
|
- (NSTouchBarItem*)makeColorPickerForID:(NSString*)id
|
||||||
withIdentifier:(NSString*)identifier {
|
withIdentifier:(NSString*)identifier {
|
||||||
std::string s_id([id UTF8String]);
|
std::string s_id([id UTF8String]);
|
||||||
if (![self hasItemWithID:s_id]) return nil;
|
if (![self hasItemWithID:s_id]) return nil;
|
||||||
|
|
||||||
|
@ -253,6 +253,25 @@ static NSTouchBarItemIdentifier SliderIdentifier = @"com.electron.touchbar.slide
|
||||||
NSColorPickerTouchBarItem* item = [[NSClassFromString(@"NSColorPickerTouchBarItem") alloc] initWithIdentifier:identifier];
|
NSColorPickerTouchBarItem* item = [[NSClassFromString(@"NSColorPickerTouchBarItem") alloc] initWithIdentifier:identifier];
|
||||||
item.target = self;
|
item.target = self;
|
||||||
item.action = @selector(colorPickerAction:);
|
item.action = @selector(colorPickerAction:);
|
||||||
|
|
||||||
|
std::string selectedColor;
|
||||||
|
if (settings.Get("selectedColor", &selectedColor)) {
|
||||||
|
item.color = [self colorFromHexColorString:selectedColor];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> colors;
|
||||||
|
if (settings.Get("availableColors", &colors) && colors.size() > 0) {
|
||||||
|
NSColorList* color_list = [[[NSColorList alloc] initWithName:identifier] autorelease];
|
||||||
|
for (size_t i = 0; i < colors.size(); ++i) {
|
||||||
|
[color_list insertColor:[self colorFromHexColorString:colors[i]]
|
||||||
|
key:base::SysUTF8ToNSString(colors[i])
|
||||||
|
atIndex:i];
|
||||||
|
}
|
||||||
|
item.colorList = color_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
item.showsAlpha = NO;
|
||||||
|
|
||||||
[self updateColorPicker:item withSettings:settings];
|
[self updateColorPicker:item withSettings:settings];
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,7 @@ static const NSTouchBarItemIdentifier NSTouchBarItemIdentifierOtherItemsProxy =
|
||||||
@property SEL action;
|
@property SEL action;
|
||||||
@property(weak) id target;
|
@property(weak) id target;
|
||||||
@property(copy) NSColor *color;
|
@property(copy) NSColor *color;
|
||||||
|
@property(strong) NSColorList *colorList;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const {EventEmitter} = require('events')
|
const {EventEmitter} = require('events')
|
||||||
|
|
||||||
let itemIdIncrementor = 1
|
let nextItemID = 1
|
||||||
|
|
||||||
class TouchBar extends EventEmitter {
|
class TouchBar extends EventEmitter {
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ class TouchBar extends EventEmitter {
|
||||||
class TouchBarItem extends EventEmitter {
|
class TouchBarItem extends EventEmitter {
|
||||||
constructor (config) {
|
constructor (config) {
|
||||||
super()
|
super()
|
||||||
this.id = `${itemIdIncrementor++}`
|
this.id = `${nextItemID++}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +113,8 @@ TouchBar.ColorPicker = class TouchBarColorPicker extends TouchBarItem {
|
||||||
constructor (config) {
|
constructor (config) {
|
||||||
super(config)
|
super(config)
|
||||||
this.type = 'colorpicker'
|
this.type = 'colorpicker'
|
||||||
|
this.availableColors = config.availableColors
|
||||||
|
this.selectedColor = config.selectedColor
|
||||||
|
|
||||||
const {change} = config
|
const {change} = config
|
||||||
if (typeof change === 'function') {
|
if (typeof change === 'function') {
|
||||||
|
@ -151,7 +153,7 @@ TouchBar.Label = class TouchBarLabel extends TouchBarItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TouchBar.PopOver = class TouchBarPopOver extends TouchBarItem {
|
TouchBar.Popover = class TouchBarPopover extends TouchBarItem {
|
||||||
constructor (config) {
|
constructor (config) {
|
||||||
super(config)
|
super(config)
|
||||||
this.type = 'popover'
|
this.type = 'popover'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue