Skip to content

Commit f37edb2

Browse files
committed
Improve documentation, rename file chooser parameter
1 parent 3ee10ee commit f37edb2

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

Sources/PathControl/PathSubmenu.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,26 @@
77

88
import Foundation
99

10-
/// Path control pop-up menu item which can displays a submenu.
10+
/// A pop-up menu item in a path control that displays a submenu of additional path items.
11+
///
12+
/// Use `PathSubmenu` to group related `PathMenuItem`s under a titled submenu entry in the path control menu.
1113
public struct PathSubmenu: PathMenuItemConvertible {
12-
14+
1315
/// Title of menu item and submenu.
1416
public let title: String
15-
17+
1618
let menuItems: [PathMenuItem]
17-
18-
/// Creates a path menu item with given `title` that will display its children items in a submenu.
19+
20+
/// Initializes a submenu with the specified title and content items.
1921
///
2022
/// - Parameters:
21-
/// - title: Title of menu item and submenu.
22-
/// - content: Submenu items builder..
23+
/// - title: The title for the menu item and its submenu.
24+
/// - content: A builder that returns the submenu items to be included under this entry.
2325
public init(title: String, @PathMenuBuilder content: () -> [PathMenuItem]) {
2426
self.title = title
2527
self.menuItems = content()
2628
}
27-
29+
2830
public func asMenuItems() -> [PathMenuItem] {
2931
[
3032
PathMenuItem(type: .item, title: title, action: {}, children: menuItems)

Sources/PathControl/PopUpPathControl.swift

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,37 @@
77

88
import SwiftUI
99

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`.
1114
public struct PopUpPathControl: NSViewRepresentable {
1215

1316
@Binding private var url: URL?
1417
private let transformMenuItems: ([PathMenuItem]) -> [PathMenuItem]
1518

16-
/// Creates a pop-up path control with its content created based on provided builder.
19+
/// Initializes a `PopUpPathControl` with custom menu contents.
1720
///
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+
) {
2128
self._url = url
2229
self.transformMenuItems = content
2330
}
2431

25-
/// Creates a pop-up path control with default contents.
32+
/// Initializes a `PopUpPathControl` with optional file chooser.
2633
///
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) {
2938
self._url = url
3039
self.transformMenuItems = { currentPathItems in
31-
if fileChooser {
40+
if includeFileChooser {
3241
let defaultItems = [
3342
PathMenuItem.fileChooser(),
3443
PathMenuItem(type: .divider, title: "")

Sources/PathControl/StandardPathControl.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77

88
import SwiftUI
99

10-
/// A control for display of a file system path or virtual path information.
10+
/// A SwiftUI wrapper for `NSPathControl` that supports binding to a modifiable URL.
11+
///
12+
/// `StandardPathControl` allows users to display and interact with a file system or virtual path.
13+
/// It supports updating the selected path through a two-way binding.
1114
public struct StandardPathControl: NSViewRepresentable {
1215

1316
@Binding private var url: URL?
1417

15-
/// Creates a standard path control.
18+
/// Initializes a new `StandardPathControl` with a bindable URL.
1619
///
17-
/// - Parameter url: A binding to property that defines the currently-selected url.
20+
/// - Parameter url: A two-way binding to the currently selected URL.
1821
public init(url: Binding<URL?>) {
1922
self._url = url
2023
}
@@ -40,14 +43,16 @@ public struct StandardPathControl: NSViewRepresentable {
4043
}
4144
}
4245

43-
/// A control for display of a file system path or virtual path information.
46+
/// A SwiftUI wrapper for `NSPathControl` with a static, non-editable URL.
47+
///
48+
/// `StandardStaticPathControl` is useful for displaying a read-only file or virtual path in a consistent style.
4449
public struct StandardStaticPathControl: NSViewRepresentable {
4550

4651
private var url: URL
4752

48-
/// Creates a standard path control.
53+
/// Initializes a new `StandardStaticPathControl` with a static URL.
4954
///
50-
/// - Parameter url: A binding to property that defines the currently-selected url.
55+
/// - Parameter url: The URL to display.
5156
public init(url: URL) {
5257
self.url = url
5358
}
@@ -62,5 +67,4 @@ public struct StandardStaticPathControl: NSViewRepresentable {
6267
public func updateNSView(_ nsView: NSPathControl, context: Context) {
6368
nsView.url = url
6469
}
65-
6670
}

0 commit comments

Comments
 (0)