It derives from <GtkWidget>.
Adaptive sidebar widget.
<AdwSidebar> contains SidebarSection
objects, which in turn contain SidebarItem objects.
To add sections, use Sidebar.append, Sidebar.prepend or
Sidebar.insert.
To remove sections, use Sidebar.remove or
Sidebar.remove_all.
To inspect the items, use Sidebar.get_item or
Sidebar:items.
To inspect sections themselves, use Sidebar.get_section or
Sidebar:sections.
<AdwSidebar> has zero or one selected items. The
index of the item can be accessed and changed via
Sidebar:selected. Set it to Gtk.INVALID_LIST_POSITION to
remove selection.
Selection cannot be permanently disabled.
Sidebar:selected-item can be used to access the selected item.
Connect to the "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: ViewSwitcherSidebar.
<AdwSidebar> is adaptive and can act as either a
regular sidebar, or a page of boxed lists.
Use the Sidebar:mode to determine its look and behavior.
A typical use case involves using <AdwSidebar>
inside the sidebar pane of a NavigationSplitView, and switching
mode to page whenever it’s collapsed, as follows:
<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 OverlaySplitView, the sidebar should stay in
sidebar mode, as the sidebar pane is still a sidebar when collapsed.
<AdwSidebar> supports filtering items via the
Sidebar:filter property.
Use 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.
To create a context menu for the sidebar items, use the
Sidebar:menu-model property to provide a menu model, and the
"setup-menu" signal to set up actions for the given item.
To set or override the menu for just one section, use
SidebarSection:menu-model instead.
<AdwSidebar> items can have a drop target for
arbitrary content.
Use Sidebar.setup_drop_target to set it up, specifying the
supported content types and drag actions, then connect to "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
"drop-enter" signal and return the action from its handler.
To determine it based on the content, set Sidebar:drop-preload to
TRUE, then connect to "drop-value-loaded" signal and
return the action from its handler.
In both cases the action will be passed as a parameter to the
"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 SidebarItem:drag-motion-activate to
FALSE on them.
<AdwSidebar> allows adding sections as children.
Example of an <AdwSidebar> UI definition:
<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>
<AdwSidebar> has a main CSS node with the name
sidebar.
Internally, it’s using a <GtkListBox> with the
‘.navigation-sidebar‘ style class in sidebar mode, or an
PreferencesPage in page mode.
<AdwSidebar> uses the
Gtk.AccessibleRole.generic role.
Whether the drop data should be preloaded on hover.
See drop-target:preload.
Its value is a boolean.
Set it with (set! (sidebar:drop-preload self) value).
The item filter.
Can be used to implement search within the sidebar.
Use Sidebar:placeholder to provide an empty state.
Its value is a <GtkFilter>, or #f.
Set it with (set! (sidebar:filter self) value).
A list model with the sidebar’s items.
This can be used to keep an up-to-date view.
The model implements <GtkSectionModel>
and creates sections corresponding to the sidebar’s sections.
The model also implements
<GtkSelectionModel> and can be used to
track and change the selection.
To only track sections, use Sidebar:sections instead.
Its value is a <GtkSelectionModel>, or
#f.
It is read only.
Context menu model for the items.
When a context menu is shown for an item, it will be constructed from
the provided menu model. Use the "setup-menu" signal to set up
the menu actions for the particular item.
Sidebar:menu-model will be preferred over this model if set.
Its value is a <GMenuModel>, or #f.
Set it with (set! (sidebar:menu-model self) value).
Determines the sidebar’s look and behavior.
If set to Adw.SidebarMode.sidebar, behaves like a sidebar: with a
sidebar style and a persistent selection.
If set to 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 NavigationSplitView
when collapsed, as the sidebar pane becomes a page there.
When used with OverlaySplitView, the sidebar should stay in
sidebar mode, as the sidebar pane is still a sidebar when collapsed.
Its value is a <AdwSidebarMode> (or, to set
it, one of its symbols).
Set it with (set! (sidebar:mode self) value).
The placeholder widget.
This widget will be shown if the sidebar has no items, or all of its
items have been filtered out by Sidebar:filter.
Its value is a <GtkWidget>, or #f.
Set it with (set! (sidebar:placeholder self) value).
A list model with the sidebar’s sections.
This can be used to keep an up-to-date view.
To track items, use Sidebar:items instead.
Its value is a <GListModel>, or #f.
It is read only.
The index of the currently selected item.
If set to Gtk.INVALID_LIST_POSITION, no item is selected.
If Sidebar:mode is set to Adw.SidebarMode.page, the
selection is invisible, but still tracked, indicating which item will be
selected once the mode is changed to Adw.SidebarMode.sidebar.
See also: Sidebar:selected-item.
Its value is an unsigned 32-bit integer.
Set it with (set! (sidebar:selected self) value).
The currently selected item.
This is a convenience property, equivalent to calling
Sidebar.get_item with Sidebar:selected provided as the
index.
To change selection, use Sidebar:selected.
Its value is a <AdwSidebarItem>, or #f.
It is read only.
Appends section to self.
Passed: a <AdwSidebar>.
a sidebar
Passed: a <AdwSidebarSection>.
a section to append
Gets whether drop data should be preloaded on hover.
Passed: a <AdwSidebar>.
a sidebar
Returned: a boolean.
whether drop data should be preloaded on hover
Gets the item filter for self.
Passed: a <AdwSidebar>.
a sidebar
Returned: a <GtkFilter>, or #f.
the item filter
Gets the item at index within self.
The index starts from 0 at the top of the sidebar, and is same as the
one returned by SidebarItem.get_index.
Can return NULL if index is larger or equal to the number
of items.
Passed: a <AdwSidebar>.
a sidebar
Passed: an unsigned 32-bit integer.
index of the item
Returned: a <AdwSidebarItem>, or #f.
the item at index
Gets a list model with self’s items.
This can be used to keep an up-to-date view.
The model implements <GtkSectionModel>
and creates sections corresponding to the sidebar’s sections.
The model also implements
<GtkSelectionModel> and can be used to
track and change the selection.
To only track sections, use Sidebar:sections instead.
Passed: a <AdwSidebar>.
a sidebar
Returned: a <GtkSelectionModel>.
a model containing the items
Gets the context menu model for self’s items.
Passed: a <AdwSidebar>.
a sidebar
Returned: a <GMenuModel>, or #f.
the context menu model
Gets self’s look and behavior.
Passed: a <AdwSidebar>.
a sidebar
Returned: a <AdwSidebarMode>.
the current mode
Gets the placeholder widget for self.
Passed: a <AdwSidebar>.
a sidebar
Returned: a <GtkWidget>, or #f.
the placeholder widget
Gets the section at index within self.
Can return NULL if index is larger or equal to the number
of sections.
Passed: a <AdwSidebar>.
a sidebar
Passed: an unsigned 32-bit integer.
index of the section
Returned: a <AdwSidebarSection>, or
#f.
the section at index
Gets a list model with self’s sections.
This can be used to keep an up-to-date view.
To track items, use Sidebar:items instead.
Passed: a <AdwSidebar>.
a sidebar
Returned: a <GListModel>.
a model containing the sections
Gets the index of the currently selected item.
See also: Sidebar.get_selected_item.
Passed: a <AdwSidebar>.
a sidebar
Returned: an unsigned 32-bit integer.
index of the currently selected item
Gets the currently selected item.
This is a convenience method, equivalent to calling
Sidebar.get_item with Sidebar:selected provided as the
index.
To change selection, use Sidebar.set_selected.
Passed: a <AdwSidebar>.
a sidebar
Returned: a <AdwSidebarItem>, or #f.
the selected item
Inserts section at position to self.
If position is -1, or larger than the total number of sections in self, the section will be appended to the end.
Passed: a <AdwSidebar>.
a sidebar
Passed: a <AdwSidebarSection>.
a section to insert
Passed: a 32-bit integer.
position to insert section at
Creates a new <AdwSidebar>.
Returned: a <GtkWidget>.
the newly created <AdwSidebar>
Prepends section to self.
Passed: a <AdwSidebar>.
a sidebar
Passed: a <AdwSidebarSection>.
a section to prepend
Removes section from self.
Passed: a <AdwSidebar>.
a sidebar
Passed: a <AdwSidebarSection>.
a section to remove
Removes all sections from self.
Passed: a <AdwSidebar>.
a sidebar
Sets whether drop data should be preloaded on hover.
See drop-target:preload.
Passed: a <AdwSidebar>.
a sidebar
Passed: a boolean.
whether to preload drop data
Sets the item filter for self.
Can be used to implement search within the sidebar.
Use Sidebar:placeholder to provide an empty state.
Passed: a <AdwSidebar>.
a sidebar
Passed, or left out: a <GtkFilter>, or
#f.
the item filter
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 "setup-menu" signal to set up
the menu actions for the particular item.
Sidebar:menu-model will be preferred over this model if set.
Passed: a <AdwSidebar>.
a sidebar
Passed, or left out: a <GMenuModel>, or
#f.
a menu model
Sets self’s look and behavior.
If set to Adw.SidebarMode.sidebar, behaves like a sidebar: with a
sidebar style and a persistent selection.
If set to 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 NavigationSplitView
when collapsed, as the sidebar pane becomes a page there.
When used with OverlaySplitView, the sidebar should stay in
sidebar mode, as the sidebar pane is still a sidebar when collapsed.
Passed: a <AdwSidebar>.
a sidebar
Passed: a <AdwSidebarMode>, or one of its
symbols.
the new mode
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 Sidebar:filter.
Passed: a <AdwSidebar>.
a sidebar
Passed, or left out: a <GtkWidget>, or
#f.
the placeholder widget
Selects the item at selected.
If set to Gtk.INVALID_LIST_POSITION, no item is selected.
If Sidebar:mode is set to Adw.SidebarMode.page, the
selection is invisible, but still tracked, indicating which item will be
selected once the mode is changed to Adw.SidebarMode.sidebar.
See also: Sidebar:selected-item.
Passed: a <AdwSidebar>.
a sidebar
Passed: an unsigned 32-bit integer.
index of the newly selected item
Sets up a drop target on the items.
This allows to drag arbitrary content onto items.
The "drop" signal can be used to handle the drop.
Passed: a <AdwSidebar>.
a sidebar
Passed: a <GdkDragAction>, or a list of its
symbols, or one of them.
the supported actions
Passed: a list or vector, each a class, or a GType number, or #f.
all supported GTypes that can be dropped
Not passed: guile-gi gives the length of types.
number of types
Connect a handler with (connect object sidebar:activated
handler). It is called as (handler self index).
Emitted when an item at index has been activated.
Passed: a <AdwSidebar>.
Passed: an unsigned 32-bit integer.
the item index
Connect a handler with (connect object sidebar:drop handler). It
is called as (handler self index value preferred-action) ⇒
%return.
Emitted when content is dropped onto the item at index.
The content must be of one of the types set up via
Sidebar.setup_drop_target.
See drop-target:drop.
Passed: a <AdwSidebar>.
Passed: an unsigned 32-bit integer.
index of the item the content was dropped onto
Passed: a <GValue>.
the <GValue> being dropped
Passed: a <GdkDragAction>.
the preferred drop action
Returned: a boolean.
whether the drop was accepted
SinceL 1.9
Connect a handler with (connect object sidebar:drop-enter
handler). It is called as (handler self index) ⇒ %return.
Emitted when the pointer enters the item at index.
Applications can use this to set their default drop action even when
Sidebar:drop-preload is set to FALSE.
See drop-target:enter.
Passed: a <AdwSidebar>.
Passed: an unsigned 32-bit integer.
index of the hovered item
Returned: a <GdkDragAction>, or a list of
its symbols, or one of them.
the preferred action for the drop
Connect a handler with (connect object sidebar:drop-value-loaded
handler). It is called as (handler self index value) ⇒ %return.
Emitted when the dropped content is preloaded for the item at index.
In order for data to be preloaded, Sidebar:drop-preload must be
set to TRUE.
The content must be of one of the types set up via
Sidebar.setup_drop_target.
See drop-target:value.
Passed: a <AdwSidebar>.
Passed: an unsigned 32-bit integer.
index of the hovered item
Passed: a <GValue>.
the <GValue> being dropped
Returned: a <GdkDragAction>, or a list of
its symbols, or one of them.
the preferred action for the drop
Connect a handler with (connect object sidebar:setup-menu
handler). It is called as (handler self item).
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.
Passed: a <AdwSidebar>.
Passed: a <AdwSidebarItem>, or #f.
an item in self