portico/Sources/Portico/Generated/AppChooserButton.swift

332 lines
18 KiB
Swift

// Generated by PorticoGen. DO NOT EDIT. See Sources/PorticoGen to make changes.
import Adw
import Gtk
import Gio
import Gdk
// PorticoGen: generateStruct | source: Gtk.AppChooserButton
/// The `GtkAppChooserButton` lets the user select an application.
///
/// <picture>
/// <source srcset="appchooserbutton-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkAppChooserButton" src="appchooserbutton.png">
/// </picture>
///
/// Initially, a `GtkAppChooserButton` selects the first application
/// in its list, which will either be the most-recently used application
/// or, if [property`Gtk`.AppChooserButton:show-default-item] is `true`, the
/// default application.
///
/// The list of applications shown in a `GtkAppChooserButton` includes
/// the recommended applications for the given content type. When
/// [property`Gtk`.AppChooserButton:show-default-item] is set, the default
/// application is also included. To let the user chooser other applications,
/// you can set the [property`Gtk`.AppChooserButton:show-dialog-item] property,
/// which allows to open a full [class`Gtk`.AppChooserDialog].
///
/// It is possible to add custom items to the list, using
/// [method`Gtk`.AppChooserButton.append_custom_item]. These items cause
/// the [signal`Gtk`.AppChooserButton::custom-item-activated] signal to be
/// emitted when they are selected.
///
/// To track changes in the selected application, use the
/// [signal`Gtk`.AppChooserButton::changed] signal.
///
/// ## CSS nodes
///
/// `GtkAppChooserButton` has a single CSS node with the name appchooserbutton.
///
/// A Portico view that mounts a `Gtk.AppChooserButton`.
@MainActor public struct AppChooserButton: View {
private let make: (MountContext) -> Gtk.AppChooserButton
private var configure: [(Gtk.AppChooserButton, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.AppChooserButton.init(contentType:)
/// Creates a new `GtkAppChooserButton` for applications
/// that can handle content of the given type.
///
/// Applied once at mount; use the `Binding` or closure overload for values that change.
/// Optional value parameters are applied only when non-`nil`; a `nil` argument leaves the widget's own default in place and cannot clear a nullable property - use the matching modifier for that.
///
/// - Parameter contentType: The `contentType` value forwarded to `Gtk.AppChooserButton`.
/// - Parameter heading: The text to show at the top of the dialog that can be opened from the button.
/// - Parameter modal: Whether the app chooser dialog should be modal.
/// - Parameter showDefaultItem: Determines whether the dropdown menu shows the default application on top for the provided content type.
/// - Parameter showDialogItem: Determines whether the dropdown menu shows an item to open a `GtkAppChooserDialog`.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onChanged: Invoked when the widget emits the `changed` signal.
public init(contentType: String, heading: String? = nil, modal: Bool? = nil, showDefaultItem: Bool? = nil, showDialogItem: Bool? = nil, onActivate: (() -> Void)? = nil, onChanged: (() -> Void)? = nil) {
make = { _ in Gtk.AppChooserButton(contentType: contentType) }
configure.append { w, ctx in
if let heading { w.setHeading(heading: heading) }
if let modal { w.setModal(modal: modal) }
if let showDefaultItem { w.setShowDefaultItem(setting: showDefaultItem) }
if let showDialogItem { w.setShowDialogItem(setting: showDialogItem) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onChanged { ctx.registry.add(w.connectChanged { _ in onChanged() }) }
}
}
}
extension AppChooserButton: WidgetView {
public typealias Target = Gtk.AppChooserButton
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.AppChooserButton, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension AppChooserButton: Mountable {
@_spi(Portico) public func mount(_ ctx: MountContext) -> Gtk.Widget {
let w = make(ctx)
for step in configure { step(w, ctx) }
return w
}
}
// PorticoGen: generateModifierExtension | source: Gtk.AppChooserButton
/// Modifiers for `Gtk.AppChooserButton`, available on every Portico view whose
/// backing widget is `Gtk.AppChooserButton` or one of its subclasses.
extension WidgetView where Target: Gtk.AppChooserButton {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.AppChooserButton.setHeading(heading:)
/// Sets the text to display at the top of the dialog.
///
/// If the heading is not set, the dialog displays a default text.
///
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for a value that changes.
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
///
/// - Parameter heading: The text to show at the top of the dialog that can be opened from the button.
/// - Returns: A copy of this view with the modifier applied.
@_disfavoredOverload
public func heading<S: StringProtocol>(_ heading: S) -> Self {
appending { w, _ in
w.setHeading(heading: String(heading))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.AppChooserButton.setHeading(heading:), GObject.Object.connectNotify(detail:_:), Gtk.AppChooserButton.getHeading()
/// Sets the text to display at the top of the dialog.
///
/// If the heading is not set, the dialog displays a default text.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `String` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func heading(_ heading: Portico.Binding<String>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, heading, registry: ctx.registry, notifyDetail: "heading",
read: { [w] in w.getHeading() },
write: { [w] v in w.setHeading(heading: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.AppChooserButton.setHeading(heading:)
/// Sets the text to display at the top of the dialog.
///
/// If the heading is not set, the dialog displays a default text.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.AppChooserButton.setHeading(heading:)`.
///
/// - Parameter heading: The text to show at the top of the dialog that can be opened from the button.
/// - Returns: A copy of this view with the modifier applied.
public func heading(_ heading: @escaping () -> String) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setHeading(heading: heading()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Gtk.AppChooserButton.setHeading(heading:)
/// Sets the text to display at the top of the dialog.
///
/// If the heading is not set, the dialog displays a default text.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Gtk.AppChooserButton.setHeading(heading:)`. A literal with no interpolation is applied once, with no subscription.
///
/// - Parameter heading: The text to show at the top of the dialog that can be opened from the button.
/// - Returns: A copy of this view with the modifier applied.
public func heading(_ heading: Portico.InterpolatedText) -> Self {
appending { w, ctx in
Portico.bindInterpolation(heading, registry: ctx.registry) { [w] v in w.setHeading(heading: v) }
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.AppChooserButton.setModal(modal:)
/// Sets whether the dialog should be modal.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter modal: Whether the app chooser dialog should be modal.
/// - Returns: A copy of this view with the modifier applied.
public func modal(_ modal: Bool) -> Self {
appending { w, _ in
w.setModal(modal: modal)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.AppChooserButton.setModal(modal:), GObject.Object.connectNotify(detail:_:), Gtk.AppChooserButton.getModal()
/// Sets whether the dialog should be modal.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Bool` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func modal(_ modal: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, modal, registry: ctx.registry, notifyDetail: "modal",
read: { [w] in w.getModal() },
write: { [w] v in w.setModal(modal: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.AppChooserButton.setModal(modal:)
/// Sets whether the dialog should be modal.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.AppChooserButton.setModal(modal:)`.
///
/// - Parameter modal: Whether the app chooser dialog should be modal.
/// - Returns: A copy of this view with the modifier applied.
public func modal(_ modal: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setModal(modal: modal()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.AppChooserButton.setShowDefaultItem(setting:)
/// Sets whether the dropdown menu of this button should show the
/// default application for the given content type at top.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter showDefaultItem: Determines whether the dropdown menu shows the default application on top for the provided content type.
/// - Returns: A copy of this view with the modifier applied.
public func showDefaultItem(_ showDefaultItem: Bool) -> Self {
appending { w, _ in
w.setShowDefaultItem(setting: showDefaultItem)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.AppChooserButton.setShowDefaultItem(setting:), GObject.Object.connectNotify(detail:_:), Gtk.AppChooserButton.getShowDefaultItem()
/// Sets whether the dropdown menu of this button should show the
/// default application for the given content type at top.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Bool` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func showDefaultItem(_ showDefaultItem: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, showDefaultItem, registry: ctx.registry, notifyDetail: "show-default-item",
read: { [w] in w.getShowDefaultItem() },
write: { [w] v in w.setShowDefaultItem(setting: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.AppChooserButton.setShowDefaultItem(setting:)
/// Sets whether the dropdown menu of this button should show the
/// default application for the given content type at top.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.AppChooserButton.setShowDefaultItem(setting:)`.
///
/// - Parameter showDefaultItem: Determines whether the dropdown menu shows the default application on top for the provided content type.
/// - Returns: A copy of this view with the modifier applied.
public func showDefaultItem(_ showDefaultItem: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setShowDefaultItem(setting: showDefaultItem()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.AppChooserButton.setShowDialogItem(setting:)
/// Sets whether the dropdown menu of this button should show an
/// entry to trigger a `GtkAppChooserDialog`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter showDialogItem: Determines whether the dropdown menu shows an item to open a `GtkAppChooserDialog`.
/// - Returns: A copy of this view with the modifier applied.
public func showDialogItem(_ showDialogItem: Bool) -> Self {
appending { w, _ in
w.setShowDialogItem(setting: showDialogItem)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.AppChooserButton.setShowDialogItem(setting:), GObject.Object.connectNotify(detail:_:), Gtk.AppChooserButton.getShowDialogItem()
/// Sets whether the dropdown menu of this button should show an
/// entry to trigger a `GtkAppChooserDialog`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Bool` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func showDialogItem(_ showDialogItem: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, showDialogItem, registry: ctx.registry, notifyDetail: "show-dialog-item",
read: { [w] in w.getShowDialogItem() },
write: { [w] v in w.setShowDialogItem(setting: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.AppChooserButton.setShowDialogItem(setting:)
/// Sets whether the dropdown menu of this button should show an
/// entry to trigger a `GtkAppChooserDialog`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.AppChooserButton.setShowDialogItem(setting:)`.
///
/// - Parameter showDialogItem: Determines whether the dropdown menu shows an item to open a `GtkAppChooserDialog`.
/// - Returns: A copy of this view with the modifier applied.
public func showDialogItem(_ showDialogItem: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setShowDialogItem(setting: showDialogItem()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.AppChooserButton.connectActivate(_:)
/// Emitted to when the button is activated.
///
/// The `::activate` signal on `GtkAppChooserButton` is an action signal and
/// emitting it causes the button to pop up its dialog.
///
/// - Parameter handler: Invoked when the widget emits the `activate` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onActivate(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectActivate { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.AppChooserButton.connectChanged(_:)
/// Emitted when the active application changes.
///
/// - Parameter handler: Invoked when the widget emits the `changed` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onChanged(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectChanged { _ in handler() })
}
}
}