854 lines
43 KiB
Swift
854 lines
43 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.Sidebar
|
|
/// Adaptive sidebar widget.
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="sidebar-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img src="sidebar.png" alt="sidebar">
|
|
/// </picture>
|
|
///
|
|
/// `AdwSidebar` contains [class`SidebarSection`] objects, which in turn contain
|
|
/// [class`SidebarItem`] objects.
|
|
///
|
|
/// To add sections, use [method`Sidebar`.append], [method`Sidebar`.prepend] or
|
|
/// [method`Sidebar`.insert].
|
|
///
|
|
/// To remove sections, use [method`Sidebar`.remove] or
|
|
/// [method`Sidebar`.remove_all].
|
|
///
|
|
/// To inspect the items, use [method`Sidebar`.get_item] or
|
|
/// [property`Sidebar`:items].
|
|
///
|
|
/// To inspect sections themselves, use [method`Sidebar`.get_section] or
|
|
/// [property`Sidebar`:sections].
|
|
///
|
|
/// ## Selection and activation
|
|
///
|
|
/// `AdwSidebar` has zero or one selected items. The index of the item can be
|
|
/// accessed and changed via [property`Sidebar`:selected]. Set it to
|
|
/// [const`Gtk`.INVALID_LIST_POSITION] to remove selection.
|
|
///
|
|
/// Selection cannot be permanently disabled.
|
|
///
|
|
/// [property`Sidebar`:selected-item] can be used to access the selected item.
|
|
///
|
|
/// Connect to the [signal`Sidebar`::activated] signal to run code when an item
|
|
/// has been activated. This can be used to toggle the visible pane when used in
|
|
/// a split view.
|
|
///
|
|
/// See also: [class`ViewSwitcherSidebar`].
|
|
///
|
|
/// ## Modes
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="sidebar-modes-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img src="sidebar-modes.png" alt="sidebar-modes">
|
|
/// </picture>
|
|
///
|
|
/// `AdwSidebar` is adaptive and can act as either a regular sidebar, or a page
|
|
/// of boxed lists.
|
|
///
|
|
/// Use the [property`Sidebar`:mode] to determine its look and behavior.
|
|
///
|
|
/// A typical use case involves using `AdwSidebar` inside the sidebar pane of a
|
|
/// [class`NavigationSplitView`], and switching mode to page whenever it's
|
|
/// collapsed, as follows:
|
|
///
|
|
/// ```xml
|
|
/// <object class="AdwWindow">
|
|
/// <property name="default-width">800</property>
|
|
/// <property name="default-height">600</property>
|
|
/// <child>
|
|
/// <object class="AdwBreakpoint">
|
|
/// <condition>max-width: 400sp</condition>
|
|
/// <setter object="split_view" property="collapsed">True</setter>
|
|
/// <setter object="sidebar" property="mode">page</setter>
|
|
/// </object>
|
|
/// </child>
|
|
/// <property name="content">
|
|
/// <object class="AdwNavigationSplitView" id="split_view">
|
|
/// <property name="sidebar">
|
|
/// <object class="AdwNavigationPage">
|
|
/// <property name="title" translatable="yes">Sidebar</property>
|
|
/// <property name="child">
|
|
/// <object class="AdwToolbarView">
|
|
/// <child type="top">
|
|
/// <object class="AdwHeaderBar"/>
|
|
/// </child>
|
|
/// <property name="content">
|
|
/// <object class="AdwSidebar" id="sidebar">
|
|
/// <!-- Calls adw_navigation_split_view_set_show_content (split_view, TRUE); -->
|
|
/// <signal name="activated" handler="sidebar_activated_cb"/>
|
|
/// <!-- ... -->
|
|
/// </object>
|
|
/// </property>
|
|
/// </object>
|
|
/// </property>
|
|
/// </object>
|
|
/// </property>
|
|
/// <property name="content">
|
|
/// <object class="AdwNavigationPage">
|
|
/// <property name="title" translatable="yes">Content</property>
|
|
/// <property name="child">
|
|
/// <!-- ... -->
|
|
/// </property>
|
|
/// </object>
|
|
/// </property>
|
|
/// </object>
|
|
/// </property>
|
|
/// </object>
|
|
/// ```
|
|
///
|
|
/// When used with [class`OverlaySplitView`], the sidebar should stay in sidebar
|
|
/// mode, as the sidebar pane is still a sidebar when collapsed.
|
|
///
|
|
/// ## Search
|
|
///
|
|
/// `AdwSidebar` supports filtering items via the [property`Sidebar`:filter]
|
|
/// property.
|
|
///
|
|
/// Use [property`Sidebar`:placeholder] to provide an empty state widget. It will
|
|
/// be shown when all items have been filtered out, or the sidebar has no items
|
|
/// otherwise.
|
|
///
|
|
/// ## Context Menu
|
|
///
|
|
/// To create a context menu for the sidebar items, use the
|
|
/// [property`Sidebar`:menu-model] property to provide a menu model, and the
|
|
/// [signal`Sidebar`::setup-menu] signal to set up actions for the given item.
|
|
///
|
|
/// To set or override the menu for just one section, use
|
|
/// [property`SidebarSection`:menu-model] instead.
|
|
///
|
|
/// ## Drag-and-Drop
|
|
///
|
|
/// `AdwSidebar` items can have a drop target for arbitrary content.
|
|
///
|
|
/// Use [method`Sidebar`.setup_drop_target] to set it up, specifying the
|
|
/// supported content types and drag actions, then connect to
|
|
/// [signal`Sidebar`::drop] to handle drops.
|
|
///
|
|
/// In some cases, it may be necessary to determine the used action based on the
|
|
/// dragged content, or the hovered item.
|
|
///
|
|
/// To determine it based on the sidebar item, connect to the
|
|
/// [signal`Sidebar`::drop-enter] signal and return the action from its handler.
|
|
///
|
|
/// To determine it based on the content, set [property`Sidebar`:drop-preload] to
|
|
/// `TRUE`, then connect to [signal`Sidebar`::drop-value-loaded] signal and return
|
|
/// the action from its handler.
|
|
///
|
|
/// In both cases the action will be passed as a parameter to the
|
|
/// [signal`Sidebar`::drop] signal.
|
|
///
|
|
/// Regardless of whether a drop target was set up, dragging content over sidebar
|
|
/// items activates them after a timeout. To disable this behavior for specific
|
|
/// items, set [property`SidebarItem`:drag-motion-activate] to `FALSE` on them.
|
|
///
|
|
/// ## `AdwSidebar` as `GtkBuildable`
|
|
///
|
|
/// `AdwSidebar` allows adding sections as children.
|
|
///
|
|
/// Example of an `AdwSidebar` UI definition:
|
|
///
|
|
/// ```xml
|
|
/// <object class="AdwSidebar">
|
|
/// <child>
|
|
/// <object class="AdwSidebarSection">
|
|
/// <child>
|
|
/// <object class="AdwSidebarItem">
|
|
/// <property name="title" translatable="yes">Recent</property>
|
|
/// <property name="icon-name">document-open-recent-symbolic</property>
|
|
/// </object>
|
|
/// </child>
|
|
/// <child>
|
|
/// <object class="AdwSidebarItem">
|
|
/// <property name="title" translatable="yes">Starred</property>
|
|
/// <property name="icon-name">starred-symbolic</property>
|
|
/// </object>
|
|
/// </child>
|
|
/// </object>
|
|
/// </child>
|
|
/// <child>
|
|
/// <object class="AdwSidebarSection">
|
|
/// <property name="title" translatable="yes">Places</property>
|
|
/// <child>
|
|
/// <object class="AdwSidebarItem">
|
|
/// <property name="title" translatable="yes">Music</property>
|
|
/// <property name="icon-name">folder-music-symbolic</property>
|
|
/// </object>
|
|
/// </child>
|
|
/// <child>
|
|
/// <object class="AdwSidebarItem">
|
|
/// <property name="title" translatable="yes">Pictures</property>
|
|
/// <property name="icon-name">folder-pictures-symbolic</property>
|
|
/// </object>
|
|
/// </child>
|
|
/// <child>
|
|
/// <object class="AdwSidebarItem">
|
|
/// <property name="title" translatable="yes">Videos</property>
|
|
/// <property name="icon-name">folder-videos-symbolic</property>
|
|
/// </object>
|
|
/// </child>
|
|
/// </object>
|
|
/// </child>
|
|
/// <child>
|
|
/// <object class="AdwSidebarSection">
|
|
/// <child>
|
|
/// <object class="AdwSidebarItem">
|
|
/// <property name="title" translatable="yes">Trash</property>
|
|
/// <property name="icon-name">user-trash-symbolic</property>
|
|
/// </object>
|
|
/// </child>
|
|
/// </object>
|
|
/// </child>
|
|
/// </object>
|
|
/// ```
|
|
///
|
|
/// ## CSS nodes
|
|
///
|
|
/// `AdwSidebar` has a main CSS node with the name `sidebar`.
|
|
///
|
|
/// Internally, it's using a [class`Gtk`.ListBox] with the
|
|
/// [`.navigation-sidebar`](style-classes.html`sidebars`) style class in sidebar
|
|
/// mode, or an [class`PreferencesPage`] in page mode.
|
|
///
|
|
/// ## Accessibility
|
|
///
|
|
/// `AdwSidebar` uses the [enum`Gtk`.AccessibleRole.generic] role.
|
|
///
|
|
/// A Portico view that mounts a `Adw.Sidebar`.
|
|
@MainActor public struct Sidebar: View {
|
|
private let make: (MountContext) -> Adw.Sidebar
|
|
private var configure: [(Adw.Sidebar, MountContext) -> Void] = []
|
|
|
|
public var body: Never { fatalError() }
|
|
|
|
// PorticoGen: generateInits(static) | source: Adw.Sidebar.init()
|
|
/// Creates a new `AdwSidebar`.
|
|
///
|
|
/// 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 dropPreload: Whether the drop data should be preloaded on hover.
|
|
/// - Parameter filter: The item filter.
|
|
/// - Parameter menuModel: Context menu model for the items.
|
|
/// - Parameter mode: Determines the sidebar's look and behavior.
|
|
/// - Parameter selected: The index of the currently selected item.
|
|
/// - Parameter placeholder: A `ViewBuilder` closure whose first view is mounted into the `placeholder` slot.
|
|
/// - Parameter onActivated: Invoked when the widget emits the `activated` signal. The closure receives the signal's arguments in order.
|
|
/// - Parameter onDrop: Invoked when the widget emits the `drop` signal. The closure receives the signal's arguments in order. Its return value is forwarded to GTK as the signal's result.
|
|
/// - Parameter onDropEnter: Invoked when the widget emits the `drop-enter` signal. The closure receives the signal's arguments in order. Its return value is forwarded to GTK as the signal's result.
|
|
/// - Parameter onDropValueLoaded: Invoked when the widget emits the `drop-value-loaded` signal. The closure receives the signal's arguments in order. Its return value is forwarded to GTK as the signal's result.
|
|
/// - Parameter onSetupMenu: Invoked when the widget emits the `setup-menu` signal. The closure receives the signal's arguments in order.
|
|
public init(dropPreload: Bool? = nil, filter: Adw.Filter? = nil, menuModel: Adw.MenuModel? = nil, mode: Adw.SidebarMode? = nil, selected: UInt32? = nil, @ViewBuilder placeholder: @escaping () -> [AnyView] = { [] }, onActivated: ((UInt32) -> Void)? = nil, onDrop: ((UInt32, Adw.Value, Adw.DragAction) -> Bool)? = nil, onDropEnter: ((UInt32) -> Adw.DragAction)? = nil, onDropValueLoaded: ((UInt32, Adw.Value) -> Adw.DragAction)? = nil, onSetupMenu: ((Adw.SidebarItem?) -> Void)? = nil) {
|
|
make = { _ in Adw.Sidebar() }
|
|
configure.append { w, ctx in
|
|
if let dropPreload { w.setDropPreload(preload: dropPreload) }
|
|
if let filter { w.setFilter(filter: filter) }
|
|
if let menuModel { w.setMenuModel(menuModel: menuModel) }
|
|
if let mode { w.setMode(mode: mode) }
|
|
if let selected { w.setSelected(selected: selected) }
|
|
if let v = Portico.mountSlotChild(placeholder, ctx, onUpdate: { v in w.setPlaceholder(placeholder: v) }) { w.setPlaceholder(placeholder: v) }
|
|
if let onActivated { ctx.registry.add(w.connectActivated { _, a0 in onActivated(a0) }) }
|
|
if let onDrop { ctx.registry.add(w.connectDrop { _, a0, a1, a2 in onDrop(a0, a1, a2) }) }
|
|
if let onDropEnter { ctx.registry.add(w.connectDropEnter { _, a0 in onDropEnter(a0) }) }
|
|
if let onDropValueLoaded { ctx.registry.add(w.connectDropValueLoaded { _, a0, a1 in onDropValueLoaded(a0, a1) }) }
|
|
if let onSetupMenu { ctx.registry.add(w.connectSetupMenu { _, a0 in onSetupMenu(a0) }) }
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension Sidebar: WidgetView {
|
|
public typealias Target = Adw.Sidebar
|
|
|
|
@_spi(Portico) public func appending(
|
|
_ step: @escaping (Adw.Sidebar, MountContext) -> Void
|
|
) -> Self {
|
|
var c = self
|
|
c.configure.append(step)
|
|
return c
|
|
}
|
|
}
|
|
|
|
@_spi(Portico) extension Sidebar: 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: Adw.Sidebar
|
|
/// Modifiers for `Adw.Sidebar`, available on every Portico view whose
|
|
/// backing widget is `Adw.Sidebar` or one of its subclasses.
|
|
extension WidgetView where Target: Adw.Sidebar {
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Sidebar.setDropPreload(preload:)
|
|
/// Sets whether drop data should be preloaded on hover.
|
|
///
|
|
/// See [property`Gtk`.DropTarget:preload].
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter dropPreload: Whether the drop data should be preloaded on hover.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func dropPreload(_ dropPreload: Bool) -> Self {
|
|
appending { w, _ in
|
|
w.setDropPreload(preload: dropPreload)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Sidebar.setDropPreload(preload:), GObject.Object.connectNotify(detail:_:), Adw.Sidebar.getDropPreload()
|
|
/// Sets whether drop data should be preloaded on hover.
|
|
///
|
|
/// See [property`Gtk`.DropTarget:preload].
|
|
///
|
|
/// 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 dropPreload(_ dropPreload: Portico.Binding<Bool>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, dropPreload, registry: ctx.registry, notifyDetail: "drop-preload",
|
|
read: { [w] in w.getDropPreload() },
|
|
write: { [w] v in w.setDropPreload(preload: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Sidebar.setDropPreload(preload:)
|
|
/// Sets whether drop data should be preloaded on hover.
|
|
///
|
|
/// See [property`Gtk`.DropTarget:preload].
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Sidebar.setDropPreload(preload:)`.
|
|
///
|
|
/// - Parameter dropPreload: Whether the drop data should be preloaded on hover.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func dropPreload(_ dropPreload: @escaping () -> Bool) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setDropPreload(preload: dropPreload()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Sidebar.setFilter(filter:)
|
|
/// Sets the item filter for `self`.
|
|
///
|
|
/// Can be used to implement search within the sidebar.
|
|
///
|
|
/// Use [property`Sidebar`:placeholder] to provide an empty state.
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter filter: The item filter.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func filter(_ filter: Adw.Filter?) -> Self {
|
|
appending { w, _ in
|
|
w.setFilter(filter: filter)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Sidebar.setFilter(filter:), GObject.Object.connectNotify(detail:_:), Adw.Sidebar.getFilter()
|
|
/// Sets the item filter for `self`.
|
|
///
|
|
/// Can be used to implement search within the sidebar.
|
|
///
|
|
/// Use [property`Sidebar`:placeholder] to provide an empty state.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// When `Adw.Filter?` 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 filter(_ filter: Portico.Binding<Adw.Filter?>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, filter, registry: ctx.registry, notifyDetail: "filter",
|
|
read: { [w] in w.getFilter() },
|
|
write: { [w] v in w.setFilter(filter: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.Sidebar.setFilter(filter:), GObject.Object.connectNotify(detail:_:), Adw.Sidebar.getFilter()
|
|
/// Sets the item filter for `self`.
|
|
///
|
|
/// Can be used to implement search within the sidebar.
|
|
///
|
|
/// Use [property`Sidebar`:placeholder] to provide an empty state.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// `Binding` is invariant, so a `Binding<Adw.Filter>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Adw.Filter?>` to be able to clear the property.
|
|
/// When `Adw.Filter` 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.
|
|
/// A `nil` widget value is never written back into the binding.
|
|
///
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func filter(_ filter: Portico.Binding<Adw.Filter>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, filter, registry: ctx.registry, notifyDetail: "filter",
|
|
read: { [w] in w.getFilter() },
|
|
write: { [w] v in w.setFilter(filter: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Sidebar.setFilter(filter:)
|
|
/// Sets the item filter for `self`.
|
|
///
|
|
/// Can be used to implement search within the sidebar.
|
|
///
|
|
/// Use [property`Sidebar`:placeholder] to provide an empty state.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Sidebar.setFilter(filter:)`.
|
|
///
|
|
/// - Parameter filter: The item filter.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func filter(_ filter: @escaping () -> Adw.Filter?) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setFilter(filter: filter()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Sidebar.setMenuModel(menuModel:)
|
|
/// Sets the context menu model for `self`'s items.
|
|
///
|
|
/// When a context menu is shown for an item, it will be constructed from the
|
|
/// provided menu model. Use the [signal`Sidebar`::setup-menu] signal to set up
|
|
/// the menu actions for the particular item.
|
|
///
|
|
/// [property`Sidebar`:menu-model] will be preferred over this model if set.
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter menuModel: Context menu model for the items.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func menuModel(_ menuModel: Adw.MenuModel?) -> Self {
|
|
appending { w, _ in
|
|
w.setMenuModel(menuModel: menuModel)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Sidebar.setMenuModel(menuModel:), GObject.Object.connectNotify(detail:_:), Adw.Sidebar.getMenuModel()
|
|
/// Sets the context menu model for `self`'s items.
|
|
///
|
|
/// When a context menu is shown for an item, it will be constructed from the
|
|
/// provided menu model. Use the [signal`Sidebar`::setup-menu] signal to set up
|
|
/// the menu actions for the particular item.
|
|
///
|
|
/// [property`Sidebar`:menu-model] will be preferred over this model if set.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// When `Adw.MenuModel?` 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 menuModel(_ menuModel: Portico.Binding<Adw.MenuModel?>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, menuModel, registry: ctx.registry, notifyDetail: "menu-model",
|
|
read: { [w] in w.getMenuModel() },
|
|
write: { [w] v in w.setMenuModel(menuModel: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.Sidebar.setMenuModel(menuModel:), GObject.Object.connectNotify(detail:_:), Adw.Sidebar.getMenuModel()
|
|
/// Sets the context menu model for `self`'s items.
|
|
///
|
|
/// When a context menu is shown for an item, it will be constructed from the
|
|
/// provided menu model. Use the [signal`Sidebar`::setup-menu] signal to set up
|
|
/// the menu actions for the particular item.
|
|
///
|
|
/// [property`Sidebar`:menu-model] will be preferred over this model if set.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// `Binding` is invariant, so a `Binding<Adw.MenuModel>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Adw.MenuModel?>` to be able to clear the property.
|
|
/// When `Adw.MenuModel` 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.
|
|
/// A `nil` widget value is never written back into the binding.
|
|
///
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func menuModel(_ menuModel: Portico.Binding<Adw.MenuModel>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, menuModel, registry: ctx.registry, notifyDetail: "menu-model",
|
|
read: { [w] in w.getMenuModel() },
|
|
write: { [w] v in w.setMenuModel(menuModel: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Sidebar.setMenuModel(menuModel:)
|
|
/// Sets the context menu model for `self`'s items.
|
|
///
|
|
/// When a context menu is shown for an item, it will be constructed from the
|
|
/// provided menu model. Use the [signal`Sidebar`::setup-menu] signal to set up
|
|
/// the menu actions for the particular item.
|
|
///
|
|
/// [property`Sidebar`:menu-model] will be preferred over this model if set.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Sidebar.setMenuModel(menuModel:)`.
|
|
///
|
|
/// - Parameter menuModel: Context menu model for the items.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func menuModel(_ menuModel: @escaping () -> Adw.MenuModel?) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setMenuModel(menuModel: menuModel()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Sidebar.setMode(mode:)
|
|
/// Sets `self`'s look and behavior.
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="sidebar-modes-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img src="sidebar-modes.png" alt="sidebar-modes">
|
|
/// </picture>
|
|
///
|
|
/// If set to [enum`Adw`.SidebarMode.sidebar], behaves like a sidebar: with a
|
|
/// sidebar style and a persistent selection.
|
|
///
|
|
/// If set to [enum`Adw`.SidebarMode.page], behaves like a page of boxed lists.
|
|
/// In this mode, the selection is invisible and only tracked to determine the
|
|
/// initially selected item once switched back to sidebar mode.
|
|
///
|
|
/// The page mode is intended to be used with [class`NavigationSplitView`] when
|
|
/// collapsed, as the sidebar pane becomes a page there.
|
|
///
|
|
/// When used with [class`OverlaySplitView`], the sidebar should stay in sidebar
|
|
/// mode, as the sidebar pane is still a sidebar when collapsed.
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter mode: Determines the sidebar's look and behavior.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func mode(_ mode: Adw.SidebarMode) -> Self {
|
|
appending { w, _ in
|
|
w.setMode(mode: mode)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Sidebar.setMode(mode:), GObject.Object.connectNotify(detail:_:), Adw.Sidebar.getMode()
|
|
/// Sets `self`'s look and behavior.
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="sidebar-modes-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img src="sidebar-modes.png" alt="sidebar-modes">
|
|
/// </picture>
|
|
///
|
|
/// If set to [enum`Adw`.SidebarMode.sidebar], behaves like a sidebar: with a
|
|
/// sidebar style and a persistent selection.
|
|
///
|
|
/// If set to [enum`Adw`.SidebarMode.page], behaves like a page of boxed lists.
|
|
/// In this mode, the selection is invisible and only tracked to determine the
|
|
/// initially selected item once switched back to sidebar mode.
|
|
///
|
|
/// The page mode is intended to be used with [class`NavigationSplitView`] when
|
|
/// collapsed, as the sidebar pane becomes a page there.
|
|
///
|
|
/// When used with [class`OverlaySplitView`], the sidebar should stay in sidebar
|
|
/// mode, as the sidebar pane is still a sidebar when collapsed.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// When `Adw.SidebarMode` 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 mode(_ mode: Portico.Binding<Adw.SidebarMode>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, mode, registry: ctx.registry, notifyDetail: "mode",
|
|
read: { [w] in w.getMode() },
|
|
write: { [w] v in w.setMode(mode: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Sidebar.setMode(mode:)
|
|
/// Sets `self`'s look and behavior.
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="sidebar-modes-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img src="sidebar-modes.png" alt="sidebar-modes">
|
|
/// </picture>
|
|
///
|
|
/// If set to [enum`Adw`.SidebarMode.sidebar], behaves like a sidebar: with a
|
|
/// sidebar style and a persistent selection.
|
|
///
|
|
/// If set to [enum`Adw`.SidebarMode.page], behaves like a page of boxed lists.
|
|
/// In this mode, the selection is invisible and only tracked to determine the
|
|
/// initially selected item once switched back to sidebar mode.
|
|
///
|
|
/// The page mode is intended to be used with [class`NavigationSplitView`] when
|
|
/// collapsed, as the sidebar pane becomes a page there.
|
|
///
|
|
/// When used with [class`OverlaySplitView`], the sidebar should stay in sidebar
|
|
/// mode, as the sidebar pane is still a sidebar when collapsed.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Sidebar.setMode(mode:)`.
|
|
///
|
|
/// - Parameter mode: Determines the sidebar's look and behavior.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func mode(_ mode: @escaping () -> Adw.SidebarMode) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setMode(mode: mode()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Sidebar.setPlaceholder(placeholder:)
|
|
/// Sets the placeholder widget for `self`.
|
|
///
|
|
/// This widget will be shown if `self` has no items, or all of its items have
|
|
/// been filtered out by [property`Sidebar`:filter].
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter placeholder: The placeholder widget.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func placeholder(_ placeholder: Adw.Widget?) -> Self {
|
|
appending { w, _ in
|
|
w.setPlaceholder(placeholder: placeholder)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(viewBuilder) | source: Adw.Sidebar.setPlaceholder(placeholder:)
|
|
/// Sets the placeholder widget for `self`.
|
|
///
|
|
/// This widget will be shown if `self` has no items, or all of its items have
|
|
/// been filtered out by [property`Sidebar`:filter].
|
|
///
|
|
/// The closure is evaluated once when the modifier is applied. Its first view is mounted into the slot.
|
|
/// Additional views are ignored; an empty closure leaves the slot unset.
|
|
///
|
|
/// - Parameter placeholder: The placeholder widget.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func placeholder(@ViewBuilder _ placeholder: () -> [AnyView]) -> Self {
|
|
let placeholderViews = placeholder()
|
|
return appending { w, ctx in
|
|
guard let v = placeholderViews.first else { return }
|
|
w.setPlaceholder(placeholder: v.makeWidget(ctx))
|
|
}
|
|
}
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Sidebar.setPlaceholder(placeholder:), GObject.Object.connectNotify(detail:_:), Adw.Sidebar.getPlaceholder()
|
|
/// Sets the placeholder widget for `self`.
|
|
///
|
|
/// This widget will be shown if `self` has no items, or all of its items have
|
|
/// been filtered out by [property`Sidebar`:filter].
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// When `Adw.Widget?` 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 placeholder<W: Gtk.Widget>(_ placeholder: Portico.Binding<W?>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, placeholder, registry: ctx.registry, notifyDetail: "placeholder",
|
|
read: { [w] in w.getPlaceholder() as? W },
|
|
write: { [w] v in w.setPlaceholder(placeholder: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.Sidebar.setPlaceholder(placeholder:), GObject.Object.connectNotify(detail:_:), Adw.Sidebar.getPlaceholder()
|
|
/// Sets the placeholder widget for `self`.
|
|
///
|
|
/// This widget will be shown if `self` has no items, or all of its items have
|
|
/// been filtered out by [property`Sidebar`:filter].
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// `Binding` is invariant, so a `Binding<Adw.Widget>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Adw.Widget?>` to be able to clear the property.
|
|
/// When `Adw.Widget` 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.
|
|
/// A `nil` widget value is never written back into the binding.
|
|
///
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func placeholder<W: Gtk.Widget>(_ placeholder: Portico.Binding<W>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, placeholder, registry: ctx.registry, notifyDetail: "placeholder",
|
|
read: { [w] in w.getPlaceholder() as? W },
|
|
write: { [w] v in w.setPlaceholder(placeholder: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Sidebar.setPlaceholder(placeholder:)
|
|
/// Sets the placeholder widget for `self`.
|
|
///
|
|
/// This widget will be shown if `self` has no items, or all of its items have
|
|
/// been filtered out by [property`Sidebar`:filter].
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Sidebar.setPlaceholder(placeholder:)`.
|
|
///
|
|
/// - Parameter placeholder: The placeholder widget.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func placeholder(_ placeholder: @escaping () -> Adw.Widget?) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setPlaceholder(placeholder: placeholder()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Sidebar.setSelected(selected:)
|
|
/// Selects the item at `selected`.
|
|
///
|
|
/// If set to [const`Gtk`.INVALID_LIST_POSITION], no item is selected.
|
|
///
|
|
/// If [property`Sidebar`:mode] is set to [enum`Adw`.SidebarMode.page], the
|
|
/// selection is invisible, but still tracked, indicating which item will be
|
|
/// selected once the mode is changed to [enum`Adw`.SidebarMode.sidebar].
|
|
///
|
|
/// See also: [property`Sidebar`:selected-item].
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter selected: The index of the currently selected item.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func selected(_ selected: UInt32) -> Self {
|
|
appending { w, _ in
|
|
w.setSelected(selected: selected)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Sidebar.setSelected(selected:), GObject.Object.connectNotify(detail:_:), Adw.Sidebar.getSelected()
|
|
/// Selects the item at `selected`.
|
|
///
|
|
/// If set to [const`Gtk`.INVALID_LIST_POSITION], no item is selected.
|
|
///
|
|
/// If [property`Sidebar`:mode] is set to [enum`Adw`.SidebarMode.page], the
|
|
/// selection is invisible, but still tracked, indicating which item will be
|
|
/// selected once the mode is changed to [enum`Adw`.SidebarMode.sidebar].
|
|
///
|
|
/// See also: [property`Sidebar`:selected-item].
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// When `UInt32` 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 selected(_ selected: Portico.Binding<UInt32>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, selected, registry: ctx.registry, notifyDetail: "selected",
|
|
read: { [w] in w.getSelected() },
|
|
write: { [w] v in w.setSelected(selected: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Sidebar.setSelected(selected:)
|
|
/// Selects the item at `selected`.
|
|
///
|
|
/// If set to [const`Gtk`.INVALID_LIST_POSITION], no item is selected.
|
|
///
|
|
/// If [property`Sidebar`:mode] is set to [enum`Adw`.SidebarMode.page], the
|
|
/// selection is invisible, but still tracked, indicating which item will be
|
|
/// selected once the mode is changed to [enum`Adw`.SidebarMode.sidebar].
|
|
///
|
|
/// See also: [property`Sidebar`:selected-item].
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Sidebar.setSelected(selected:)`.
|
|
///
|
|
/// - Parameter selected: The index of the currently selected item.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func selected(_ selected: @escaping () -> UInt32) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setSelected(selected: selected()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.Sidebar.connectActivated(_:)
|
|
/// Emitted when an item at `index` has been activated.
|
|
///
|
|
/// - Parameter handler: Invoked when the widget emits the `activated` signal. The closure receives the signal's arguments in order.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func onActivated(_ handler: @escaping (UInt32) -> Void) -> Self {
|
|
appending { w, ctx in
|
|
ctx.registry.add(w.connectActivated { _, a0 in handler(a0) })
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.Sidebar.connectDrop(_:)
|
|
/// Emitted when content is dropped onto the item at `index`.
|
|
///
|
|
/// The content must be of one of the types set up via
|
|
/// [method`Sidebar`.setup_drop_target].
|
|
///
|
|
/// See [signal`Gtk`.DropTarget::drop].
|
|
///
|
|
/// - Parameter handler: Invoked when the widget emits the `drop` signal. The closure receives the signal's arguments in order. Its return value is forwarded to GTK as the signal's result.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func onDrop(_ handler: @escaping (UInt32, Adw.Value, Adw.DragAction) -> Bool) -> Self {
|
|
appending { w, ctx in
|
|
ctx.registry.add(w.connectDrop { _, a0, a1, a2 in handler(a0, a1, a2) })
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.Sidebar.connectDropEnter(_:)
|
|
/// Emitted when the pointer enters the item at `index`.
|
|
///
|
|
/// Applications can use this to set their default drop action even when
|
|
/// [property`Sidebar`:drop-preload] is set to `FALSE`.
|
|
///
|
|
/// See [signal`Gtk`.DropTarget::enter].
|
|
///
|
|
/// - Parameter handler: Invoked when the widget emits the `drop-enter` signal. The closure receives the signal's arguments in order. Its return value is forwarded to GTK as the signal's result.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func onDropEnter(_ handler: @escaping (UInt32) -> Adw.DragAction) -> Self {
|
|
appending { w, ctx in
|
|
ctx.registry.add(w.connectDropEnter { _, a0 in handler(a0) })
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.Sidebar.connectDropValueLoaded(_:)
|
|
/// Emitted when the dropped content is preloaded for the item at `index`.
|
|
///
|
|
/// In order for data to be preloaded, [property`Sidebar`:drop-preload]
|
|
/// must be set to `TRUE`.
|
|
///
|
|
/// The content must be of one of the types set up via
|
|
/// [method`Sidebar`.setup_drop_target].
|
|
///
|
|
/// See [property`Gtk`.DropTarget:value].
|
|
///
|
|
/// - Parameter handler: Invoked when the widget emits the `drop-value-loaded` signal. The closure receives the signal's arguments in order. Its return value is forwarded to GTK as the signal's result.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func onDropValueLoaded(_ handler: @escaping (UInt32, Adw.Value) -> Adw.DragAction) -> Self {
|
|
appending { w, ctx in
|
|
ctx.registry.add(w.connectDropValueLoaded { _, a0, a1 in handler(a0, a1) })
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.Sidebar.connectSetupMenu(_:)
|
|
/// Emitted when a context menu is opened or closed for `item`.
|
|
///
|
|
/// If the menu has been closed, `item` will be set to `NULL`.
|
|
///
|
|
/// It can be used to set up menu actions before showing the menu, for example
|
|
/// disable actions not applicable to `item`.
|
|
///
|
|
/// - Parameter handler: Invoked when the widget emits the `setup-menu` signal. The closure receives the signal's arguments in order.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func onSetupMenu(_ handler: @escaping (Adw.SidebarItem?) -> Void) -> Self {
|
|
appending { w, ctx in
|
|
ctx.registry.add(w.connectSetupMenu { _, a0 in handler(a0) })
|
|
}
|
|
}
|
|
|
|
}
|