forked from compnerd/swift-win32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContextMenuConfiguration.swift
51 lines (41 loc) · 1.79 KB
/
ContextMenuConfiguration.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* Copyright © 2020 Saleem Abdulrasool <[email protected]>
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
**/
import class Foundation.NSUUID
import protocol Foundation.NSCopying
public class ContextMenuConfiguration {
/// Creating the Menu Configuration Object
/// Returns the custom view controller to use when previewing your content.
public typealias ContextMenuContentPreviewProvider = () -> ViewController?
/// Returns an action-based contextual menu, optionally incorporating the
/// system-suggested actions.
public typealias ContextMenuActionProvider = ([MenuElement]) -> Menu?
/// Creates a menu configuration object with the specified action and preview
/// providers.
public convenience init(identifier: NSCopying?,
previewProvider: ContextMenuContentPreviewProvider?,
actionProvider: ContextMenuActionProvider? = nil) {
// TODO(compnerd) fill out the default preview provider
self.init(identifier: identifier ?? NSUUID(),
previewProvider: previewProvider ?? { return nil },
actionProvider: actionProvider)
}
private init(identifier: NSCopying,
previewProvider: @escaping ContextMenuContentPreviewProvider,
actionProvider: ContextMenuActionProvider?) {
self.identifier = identifier
self.previewProvider = previewProvider
self.actionProvider = actionProvider
}
/// Getting the Configuration Identifier
/// The unique identifier for this configuration object.
public let identifier: NSCopying
private var previewProvider: ContextMenuContentPreviewProvider
private var actionProvider: ContextMenuActionProvider?
internal func provideActions() -> Menu? {
actionProvider?([]) // TODO suggest default actions
}
}