Skip to content

Commit 855ee24

Browse files
committed
Keep previous ButtonToolbarItem-based share toolbar item
Standard toolbar items with `isBordered` enabled do not have a view to which the share sheet can be pinned.
1 parent 2ce102c commit 855ee24

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

Vienna/Interfaces/Base.lproj/MainWindowController.xib

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,15 @@
264264
<action selector="getInfo:" target="-1" id="Xvh-S3-PIS"/>
265265
</connections>
266266
</toolbarItem>
267-
<toolbarItem implicitItemIdentifier="2194A0A2-BEF2-4411-AE86-F573CC3E7FFB" explicitItemIdentifier="Share" label="Share" paletteLabel="Share" image="NSShareTemplate" bordered="YES" sizingBehavior="auto" id="YVR-Ym-Do7" customClass="VNAToolbarItem">
267+
<toolbarItem implicitItemIdentifier="2194A0A2-BEF2-4411-AE86-F573CC3E7FFB" explicitItemIdentifier="Share" label="Share" paletteLabel="Share" image="NSShareTemplate" sizingBehavior="auto" id="YVR-Ym-Do7" customClass="VNAButtonToolbarItem">
268+
<button key="view" verticalHuggingPriority="750" id="XcR-k5-Au0">
269+
<rect key="frame" x="6" y="14" width="27" height="23"/>
270+
<autoresizingMask key="autoresizingMask"/>
271+
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="NSShareTemplate" imagePosition="only" alignment="center" lineBreakMode="truncatingTail" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="rk1-Vu-d16">
272+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
273+
<font key="font" metaFont="system"/>
274+
</buttonCell>
275+
</button>
268276
<connections>
269277
<action selector="invokeSharingServicePicker:" target="-1" id="uUn-Rf-hIQ"/>
270278
</connections>

Vienna/Sources/Main window/MainWindowController.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,13 @@ final class MainWindowController: NSWindowController {
216216
}
217217

218218
@IBAction private func invokeSharingServicePicker(_ sender: Any) {
219-
guard sender is NSMenuItem || sender is NSToolbarItem else {
220-
return
221-
}
222-
223-
if let window, let contentView = window.contentView {
219+
// The sender is either the menu item in the main menu, the menu-form
220+
// representation of the toolbar item in label-only mode or the toolbar
221+
// item itself.
222+
if sender is NSMenuItem || sender is NSToolbarItem,
223+
let window,
224+
let contentView = window.contentView
225+
{
224226
let picker = NSSharingServicePicker(items: shareableItems)
225227
picker.delegate = self
226228
// The menu item does not have a view to which the picker could be
@@ -233,6 +235,16 @@ final class MainWindowController: NSWindowController {
233235
let yCoordinate = layoutRect.maxY - 1
234236
let topEdgeRect = NSRect(x: xCoordinate, y: yCoordinate, width: 1, height: 1)
235237
picker.show(relativeTo: topEdgeRect, of: contentView, preferredEdge: .minY)
238+
return
239+
}
240+
241+
// The sender is a button if the user clicked on the toolbar item in
242+
// icon-and-label mode or icon-only mode.
243+
if let button = sender as? NSButton {
244+
let picker = NSSharingServicePicker(items: shareableItems)
245+
picker.delegate = self
246+
picker.show(relativeTo: .zero, of: button, preferredEdge: .minY)
247+
return
236248
}
237249
}
238250

0 commit comments

Comments
 (0)