portico/Sources/Portico/Generated/ShortcutsDialog.swift

158 lines
7.4 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: Adw.ShortcutsDialog
/// A dialog that displays application's keyboard shortcuts.
///
/// <picture>
/// <source srcset="shortcuts-dialog-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="shortcuts-dialog.png" alt="shortcuts-dialog">
/// </picture>
///
/// Shortcuts are grouped into sections, represented by [class`ShortcutsSection`]
/// objects. Each section has one or more items, represented by
/// [class`ShortcutsItem`] objects.
///
/// To add a section to the dialog, use [method`ShortcutsDialog`.add], or add it
/// as a child when using UI files.
///
/// Sections without titles can be used to further subdivide each section into
/// groups.
///
/// Example of an `AdwShortcutsDialog` UI definition:
///
/// ```xml
/// <object class="AdwShortcutsDialog" id="shortcuts_dialog">
/// <child>
/// <object class="AdwShortcutsSection">
/// <property name="title" translatable="yes">General</property>
/// <child>
/// <object class="AdwShortcutsItem">
/// <property name="title" translatable="yes">Open Menu</property>
/// <property name="accelerator">F10</property>
/// </object>
/// </child>
/// <child>
/// <object class="AdwShortcutsItem">
/// <property name="title" translatable="yes">Quit</property>
/// <property name="action-name">app.quit</property>
/// </object>
/// </child>
/// </object>
/// </child>
/// <child>
/// <object class="AdwShortcutsSection">
/// <child>
/// <object class="AdwShortcutsItem">
/// <property name="title" translatable="yes">Move Tab Left</property>
/// <property name="accelerator">&lt;Shift&gt;&lt;Ctrl&gt;Page_Up</property>
/// <property name="direction">ltr</property>
/// </object>
/// </child>
/// <child>
/// <object class="AdwShortcutsItem">
/// <property name="title" translatable="yes">Move Tab Right</property>
/// <property name="accelerator">&lt;Shift&gt;&lt;Ctrl&gt;Page_Down</property>
/// <property name="direction">ltr</property>
/// </object>
/// </child>
/// <child>
/// <object class="AdwShortcutsItem">
/// <property name="title" translatable="yes">Move Tab Right</property>
/// <property name="accelerator">&lt;Shift&gt;&lt;Ctrl&gt;Page_Up</property>
/// <property name="direction">rtl</property>
/// </object>
/// </child>
/// <child>
/// <object class="AdwShortcutsItem">
/// <property name="title" translatable="yes">Move Tab Left</property>
/// <property name="accelerator">&lt;Shift&gt;&lt;Ctrl&gt;Page_Down</property>
/// <property name="direction">rtl</property>
/// </object>
/// </child>
/// </object>
/// </child>
/// </object>
/// ```
///
/// If the `app.quit` action has the <kbd>Ctrl</kbd><kbd>Q</kbd> accelerator
/// associated with it, the result will look as follows:
///
/// <picture>
/// <source srcset="shortcuts-dialog-example-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="shortcuts-dialog-example.png" alt="shortcuts-dialog-example">
/// </picture>
///
/// The recommended way to use `AdwShortcutsDialog` is via [class`Application`]'s
/// automatic resource loading.
///
/// See also: [class`ShortcutLabel`].
///
/// A Portico view that mounts a `Adw.ShortcutsDialog`.
@MainActor public struct ShortcutsDialog: View {
private let make: (MountContext) -> Adw.ShortcutsDialog
private var configure: [(Adw.ShortcutsDialog, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Adw.ShortcutsDialog.init()
/// Creates a new `AdwShortcutsDialog`.
///
/// Applied once at mount; use the `Binding` or closure overload for values that change.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 canClose: Whether the dialog can be closed.
/// - Parameter contentHeight: The height of the dialog's contents.
/// - Parameter contentWidth: The width of the dialog's contents.
/// - Parameter followsContentSize: Whether to size content automatically.
/// - Parameter presentationMode: The dialog's presentation mode.
/// - Parameter title: The title of the dialog.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter defaultWidget: A `ViewBuilder` closure whose first view is mounted into the `defaultWidget` slot.
/// - Parameter focusWidget: A `ViewBuilder` closure whose first view is mounted into the `focusWidget` slot.
/// - Parameter onCloseAttempt: Invoked when the widget emits the `close-attempt` signal.
/// - Parameter onClosed: Invoked when the widget emits the `closed` signal.
public init(canClose: Bool? = nil, contentHeight: Int32? = nil, contentWidth: Int32? = nil, followsContentSize: Bool? = nil, presentationMode: Adw.DialogPresentationMode? = nil, title: String? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, @ViewBuilder defaultWidget: @escaping () -> [AnyView] = { [] }, @ViewBuilder focusWidget: @escaping () -> [AnyView] = { [] }, onCloseAttempt: (() -> Void)? = nil, onClosed: (() -> Void)? = nil) {
make = { _ in Adw.ShortcutsDialog() }
configure.append { w, ctx in
if let canClose { w.setCanClose(canClose: canClose) }
if let contentHeight { w.setContentHeight(contentHeight: contentHeight) }
if let contentWidth { w.setContentWidth(contentWidth: contentWidth) }
if let followsContentSize { w.setFollowsContentSize(followsContentSize: followsContentSize) }
if let presentationMode { w.setPresentationMode(presentationMode: presentationMode) }
if let title { w.setTitle(title: title) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let v = Portico.mountSlotChild(defaultWidget, ctx, onUpdate: { v in w.setDefaultWidget(defaultWidget: v) }) { w.setDefaultWidget(defaultWidget: v) }
if let v = Portico.mountSlotChild(focusWidget, ctx, onUpdate: { v in w.setFocus(focus: v) }) { w.setFocus(focus: v) }
if let onCloseAttempt { ctx.registry.add(w.connectCloseAttempt { _ in onCloseAttempt() }) }
if let onClosed { ctx.registry.add(w.connectClosed { _ in onClosed() }) }
}
}
}
extension ShortcutsDialog: WidgetView {
public typealias Target = Adw.ShortcutsDialog
@_spi(Portico) public func appending(
_ step: @escaping (Adw.ShortcutsDialog, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension ShortcutsDialog: Mountable {
@_spi(Portico) public func mount(_ ctx: MountContext) -> Gtk.Widget {
let w = make(ctx)
for step in configure { step(w, ctx) }
return w
}
}