Skip to content

Commit

Permalink
Merge pull request #46 from thirstyice/segment-support
Browse files Browse the repository at this point in the history
Improve support for segmented controls
  • Loading branch information
felixerdy authored Mar 27, 2020
2 parents 9d3abfb + 5182e90 commit bcc4f07
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/touchbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ export default {
let tbev = new TouchbarEditView(EditViewURI)
atom.workspace.open(tbev)
},

doCommand(command) {
var activeElement = (document.activeElement === document.body) ? atom.views.getView(atom.workspace) : document.activeElement
atom.commands.dispatch(activeElement, command);
},
arrayToTouchBarElements(input) {
let elements = typeof input === 'string' ? JSON.parse(input) : input;
let myTouchBarElements = []
Expand All @@ -111,10 +114,7 @@ export default {
myTouchBarElements.push(new TouchBarButton({
label: e.label,
icon: e.icon ? e.icon.indexOf('/') == -1? nativeImage.createFromNamedImage(e.icon, iconColor) : nativeImage.createFromPath(e.icon) : null,
click: () => {
var activeElement = (document.activeElement === document.body) ? atom.views.getView(atom.workspace) : document.activeElement
atom.commands.dispatch(activeElement, e.command);
},
click: () => this.doCommand(e.command),
// apply selected color only when there is one specified in config, otherwise use default color
backgroundColor: (e.color
? e.color
Expand Down Expand Up @@ -186,7 +186,11 @@ export default {
segments: e.elements.map(c => ({
label: c.label,
icon: c.icon ? c.icon.indexOf('/') == -1? nativeImage.createFromNamedImage(c.icon, c.iconColor) : nativeImage.createFromPath(c.icon) : null,
}))
})),
change: (selectedIndex) => {
this.doCommand(e.elements[selectedIndex].command)
},
mode: e.mode
}))
break;

Expand Down

0 comments on commit bcc4f07

Please sign in to comment.