|
7 | 7 |
|
8 | 8 | import SwiftUI |
9 | 9 |
|
10 | | -/// A control for display of a file system path or virtual path information. |
| 10 | +/// A SwiftUI wrapper for `NSPathControl` in pop-up style, allowing customization of the displayed menu items. |
| 11 | +/// |
| 12 | +/// `PopUpPathControl` enables users to navigate and select a path using a pop-up menu. The contents of the menu |
| 13 | +/// can be customized via a `PathMenuBuilder`. |
11 | 14 | public struct PopUpPathControl: NSViewRepresentable { |
12 | 15 |
|
13 | 16 | @Binding private var url: URL? |
14 | 17 | private let transformMenuItems: ([PathMenuItem]) -> [PathMenuItem] |
15 | 18 |
|
16 | | - /// Creates a pop-up path control with its content created based on provided builder. |
| 19 | + /// Initializes a `PopUpPathControl` with custom menu contents. |
17 | 20 | /// |
18 | | - /// - Parameter url: A binding to property that defines the currently-selected url. |
19 | | - /// - Parameter content: Contents of pop-up menu. |
20 | | - public init(url: Binding<URL?>, @PathMenuBuilder content: @escaping ([PathMenuItem]) -> [PathMenuItem]) { |
| 21 | + /// - Parameters: |
| 22 | + /// - url: A binding to the currently selected URL. |
| 23 | + /// - content: A closure that defines the menu items shown in the pop-up path control. |
| 24 | + public init( |
| 25 | + url: Binding<URL?>, |
| 26 | + @PathMenuBuilder content: @escaping ([PathMenuItem]) -> [PathMenuItem] |
| 27 | + ) { |
21 | 28 | self._url = url |
22 | 29 | self.transformMenuItems = content |
23 | 30 | } |
24 | 31 |
|
25 | | - /// Creates a pop-up path control with default contents. |
| 32 | + /// Initializes a `PopUpPathControl` with optional file chooser. |
26 | 33 | /// |
27 | | - /// - Parameter url: A binding to property that defines the currently-selected url. |
28 | | - public init(url: Binding<URL?>, fileChooser: Bool = true) { |
| 34 | + /// - Parameters: |
| 35 | + /// - url: A binding to the currently selected URL. |
| 36 | + /// - includeFileChooser: Whether to include a standard file chooser item in the menu. Defaults to `true`. |
| 37 | + public init(url: Binding<URL?>, includeFileChooser: Bool = true) { |
29 | 38 | self._url = url |
30 | 39 | self.transformMenuItems = { currentPathItems in |
31 | | - if fileChooser { |
| 40 | + if includeFileChooser { |
32 | 41 | let defaultItems = [ |
33 | 42 | PathMenuItem.fileChooser(), |
34 | 43 | PathMenuItem(type: .divider, title: "") |
|
0 commit comments