From 225ccab3d2218fe9d5a4af2da1bbfef73868118e Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Fri, 28 Apr 2017 14:50:58 +1000 Subject: [PATCH 1/3] Add mode prop to segmented touch bar control --- atom/browser/ui/cocoa/atom_touch_bar.mm | 9 +++++++++ lib/browser/api/touch-bar.js | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/atom/browser/ui/cocoa/atom_touch_bar.mm b/atom/browser/ui/cocoa/atom_touch_bar.mm index a21fbc5497a3..b4a30c9950f1 100644 --- a/atom/browser/ui/cocoa/atom_touch_bar.mm +++ b/atom/browser/ui/cocoa/atom_touch_bar.mm @@ -520,6 +520,15 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; else control.segmentStyle = NSSegmentStyleAutomatic; + std::string segmentMode; + settings.Get("mode", &segmentMode); + if (segmentMode == "multiple") + control.trackingMode = NSSegmentSwitchTrackingSelectAny; + else if (segmentMode == "buttons") + control.trackingMode = NSSegmentSwitchTrackingMomentary; + else + control.trackingMode = NSSegmentSwitchTrackingSelectOne; + std::vector segments; settings.Get("segments", &segments); diff --git a/lib/browser/api/touch-bar.js b/lib/browser/api/touch-bar.js index 4bb129449eb9..b2f48d239d7c 100644 --- a/lib/browser/api/touch-bar.js +++ b/lib/browser/api/touch-bar.js @@ -264,11 +264,12 @@ TouchBar.TouchBarSegmentedControl = class TouchBarSegmentedControl extends Touch constructor (config) { super() if (config == null) config = {} - const {segmentStyle, segments, selectedIndex, change} = config + const {segmentStyle, segments, selectedIndex, change, mode} = config this.type = 'segmented_control' this._addLiveProperty('segmentStyle', segmentStyle) this._addLiveProperty('segments', segments || []) this._addLiveProperty('selectedIndex', selectedIndex) + this._addLiveProperty('mode', mode) if (typeof change === 'function') { this.onInteraction = (details) => { From 718dc732ad2e6887b0705a5eca7cc7a98535f9e6 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Wed, 3 May 2017 20:25:50 +1000 Subject: [PATCH 2/3] Add docs and add isSelected arg --- atom/browser/ui/cocoa/atom_touch_bar.mm | 1 + docs/api/touch-bar-segmented-control.md | 7 ++++++- lib/browser/api/touch-bar.js | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/atom/browser/ui/cocoa/atom_touch_bar.mm b/atom/browser/ui/cocoa/atom_touch_bar.mm index b4a30c9950f1..30a3e6643fb8 100644 --- a/atom/browser/ui/cocoa/atom_touch_bar.mm +++ b/atom/browser/ui/cocoa/atom_touch_bar.mm @@ -224,6 +224,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; NSString* item_id = [NSString stringWithFormat:@"%ld", ((NSSegmentedControl*)sender).tag]; base::DictionaryValue details; details.SetInteger("selectedIndex", ((NSSegmentedControl*)sender).selectedSegment); + details.SetBoolean("isSelected", [((NSSegmentedControl*)sender) isSelectedForSegment:((NSSegmentedControl*)sender).selectedSegment]); window_->NotifyTouchBarItemInteraction([item_id UTF8String], details); } diff --git a/docs/api/touch-bar-segmented-control.md b/docs/api/touch-bar-segmented-control.md index 42be09079082..893805dd643c 100644 --- a/docs/api/touch-bar-segmented-control.md +++ b/docs/api/touch-bar-segmented-control.md @@ -21,10 +21,15 @@ Process: [Main](../tutorial/quick-start.md#main-process) * `small-square` - The control is displayed using the small square style. * `separated` - The segments in the control are displayed very close to each other but not touching. + * `mode` String - (Optional) The selection mode of the control: + * `single` - Default. One item selected at a time, selecting one deselects the previously selected item + * `multiple` - Multiple items can be selected at a time + * `buttons` - Make the segments act as buttons, each segment can be pressed and released but never marked as active * `segments` [SegmentedControlSegment[]](structures/segmented-control-segment.md) - An array of segments to place in this control - * `selectedIndex` Integer (Optional) - The index of the currently selected segment, will update automatically with user interaction + * `selectedIndex` Integer (Optional) - The index of the currently selected segment, will update automatically with user interaction. When the mode is multiple will be the last selected item * `change` Function - Called when the user selects a new segment * `selectedIndex` Integer - The index of the segment the user selected + * `isSelected` Boolean - Whether as a result of user selection the segment is selected or not ### Instance Properties diff --git a/lib/browser/api/touch-bar.js b/lib/browser/api/touch-bar.js index b2f48d239d7c..ae0c1f1428b4 100644 --- a/lib/browser/api/touch-bar.js +++ b/lib/browser/api/touch-bar.js @@ -274,7 +274,7 @@ TouchBar.TouchBarSegmentedControl = class TouchBarSegmentedControl extends Touch if (typeof change === 'function') { this.onInteraction = (details) => { this._selectedIndex = details.selectedIndex - change(details.selectedIndex) + change(details.selectedIndex, details.isSelected) } } } From 01b3db3d2f2d7427d3c55951a4906fa1db6e54f6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 4 May 2017 14:15:48 -0700 Subject: [PATCH 3/3] :art: --- docs/api/touch-bar-segmented-control.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/api/touch-bar-segmented-control.md b/docs/api/touch-bar-segmented-control.md index 893805dd643c..986fee4929f8 100644 --- a/docs/api/touch-bar-segmented-control.md +++ b/docs/api/touch-bar-segmented-control.md @@ -22,14 +22,14 @@ Process: [Main](../tutorial/quick-start.md#main-process) * `separated` - The segments in the control are displayed very close to each other but not touching. * `mode` String - (Optional) The selection mode of the control: - * `single` - Default. One item selected at a time, selecting one deselects the previously selected item - * `multiple` - Multiple items can be selected at a time - * `buttons` - Make the segments act as buttons, each segment can be pressed and released but never marked as active - * `segments` [SegmentedControlSegment[]](structures/segmented-control-segment.md) - An array of segments to place in this control - * `selectedIndex` Integer (Optional) - The index of the currently selected segment, will update automatically with user interaction. When the mode is multiple will be the last selected item + * `single` - Default. One item selected at a time, selecting one deselects the previously selected item. + * `multiple` - Multiple items can be selected at a time. + * `buttons` - Make the segments act as buttons, each segment can be pressed and released but never marked as active. + * `segments` [SegmentedControlSegment[]](structures/segmented-control-segment.md) - An array of segments to place in this control. + * `selectedIndex` Integer (Optional) - The index of the currently selected segment, will update automatically with user interaction. When the mode is multiple it will be the last selected item. * `change` Function - Called when the user selects a new segment - * `selectedIndex` Integer - The index of the segment the user selected - * `isSelected` Boolean - Whether as a result of user selection the segment is selected or not + * `selectedIndex` Integer - The index of the segment the user selected. + * `isSelected` Boolean - Whether as a result of user selection the segment is selected or not. ### Instance Properties