Next: <AdwSidebarItem>, Previous: <AdwShortcutsSection>, Up: Classes   [Index]


1.49 <AdwSidebar> ¶

Class: <AdwSidebar> ¶

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.

Selection and activation ¶

<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.

Modes ¶

<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.

Search ¶

<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.

Context Menu ¶

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.

Drag-and-Drop ¶

<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‘ as ‘GtkBuildable‘ ¶

<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>

CSS nodes ¶

<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.

Accessibility ¶

<AdwSidebar> uses the Gtk.AccessibleRole.generic role.

Properties ¶

Property: sidebar:drop-preload self ¶

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).

Property: sidebar:filter self ¶

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).

Property: sidebar:items self ¶

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.

Property: sidebar:menu-model self ¶

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).

Property: sidebar:mode self ¶

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).

Property: sidebar:placeholder self ¶

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).

Property: sidebar:sections self ¶

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.

Property: sidebar:selected self ¶

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).

Property: sidebar:selected-item self ¶

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.

Procedures ¶

Method: sidebar:append self section ¶
Method: append self section ¶

Appends section to self.

self

Passed: a <AdwSidebar>.

a sidebar

section

Passed: a <AdwSidebarSection>.

a section to append

Method: sidebar:get-drop-preload? self ⇒ %return ¶
Method: get-drop-preload? self ⇒ %return ¶

Gets whether drop data should be preloaded on hover.

self

Passed: a <AdwSidebar>.

a sidebar

%return

Returned: a boolean.

whether drop data should be preloaded on hover

Method: sidebar:get-filter self ⇒ %return ¶
Method: get-filter self ⇒ %return ¶

Gets the item filter for self.

self

Passed: a <AdwSidebar>.

a sidebar

%return

Returned: a <GtkFilter>, or #f.

the item filter

Method: sidebar:get-item self index ⇒ %return ¶
Method: get-item self index ⇒ %return ¶

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.

self

Passed: a <AdwSidebar>.

a sidebar

index

Passed: an unsigned 32-bit integer.

index of the item

%return

Returned: a <AdwSidebarItem>, or #f.

the item at index

Method: sidebar:get-items self ⇒ %return ¶
Method: get-items self ⇒ %return ¶

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.

self

Passed: a <AdwSidebar>.

a sidebar

%return

Returned: a <GtkSelectionModel>.

a model containing the items

Method: sidebar:get-menu-model self ⇒ %return ¶
Method: get-menu-model self ⇒ %return ¶

Gets the context menu model for self’s items.

self

Passed: a <AdwSidebar>.

a sidebar

%return

Returned: a <GMenuModel>, or #f.

the context menu model

Method: sidebar:get-mode self ⇒ %return ¶
Method: get-mode self ⇒ %return ¶

Gets self’s look and behavior.

self

Passed: a <AdwSidebar>.

a sidebar

%return

Returned: a <AdwSidebarMode>.

the current mode

Method: sidebar:get-placeholder self ⇒ %return ¶
Method: get-placeholder self ⇒ %return ¶

Gets the placeholder widget for self.

self

Passed: a <AdwSidebar>.

a sidebar

%return

Returned: a <GtkWidget>, or #f.

the placeholder widget

Method: sidebar:get-section self index ⇒ %return ¶
Method: get-section self index ⇒ %return ¶

Gets the section at index within self.

Can return NULL if index is larger or equal to the number of sections.

self

Passed: a <AdwSidebar>.

a sidebar

index

Passed: an unsigned 32-bit integer.

index of the section

%return

Returned: a <AdwSidebarSection>, or #f.

the section at index

Method: sidebar:get-sections self ⇒ %return ¶
Method: get-sections self ⇒ %return ¶

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.

self

Passed: a <AdwSidebar>.

a sidebar

%return

Returned: a <GListModel>.

a model containing the sections

Method: sidebar:get-selected self ⇒ %return ¶
Method: get-selected self ⇒ %return ¶

Gets the index of the currently selected item.

See also: Sidebar.get_selected_item.

self

Passed: a <AdwSidebar>.

a sidebar

%return

Returned: an unsigned 32-bit integer.

index of the currently selected item

Method: sidebar:get-selected-item self ⇒ %return ¶
Method: get-selected-item self ⇒ %return ¶

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.

self

Passed: a <AdwSidebar>.

a sidebar

%return

Returned: a <AdwSidebarItem>, or #f.

the selected item

Method: sidebar:insert self section position ¶
Method: insert self section position ¶

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.

self

Passed: a <AdwSidebar>.

a sidebar

section

Passed: a <AdwSidebarSection>.

a section to insert

position

Passed: a 32-bit integer.

position to insert section at

Procedure: sidebar:new ⇒ %return ¶

Creates a new <AdwSidebar>.

%return

Returned: a <GtkWidget>.

the newly created <AdwSidebar>

Method: sidebar:prepend self section ¶
Method: prepend self section ¶

Prepends section to self.

self

Passed: a <AdwSidebar>.

a sidebar

section

Passed: a <AdwSidebarSection>.

a section to prepend

Method: sidebar:remove self section ¶
Method: remove self section ¶

Removes section from self.

self

Passed: a <AdwSidebar>.

a sidebar

section

Passed: a <AdwSidebarSection>.

a section to remove

Method: sidebar:remove-all self ¶
Method: remove-all self ¶

Removes all sections from self.

self

Passed: a <AdwSidebar>.

a sidebar

Method: sidebar:set-drop-preload self preload ¶
Method: set-drop-preload self preload ¶

Sets whether drop data should be preloaded on hover.

See drop-target:preload.

self

Passed: a <AdwSidebar>.

a sidebar

preload

Passed: a boolean.

whether to preload drop data

Method: sidebar:set-filter self [filter] ¶
Method: set-filter self [filter] ¶

Sets the item filter for self.

Can be used to implement search within the sidebar.

Use Sidebar:placeholder to provide an empty state.

self

Passed: a <AdwSidebar>.

a sidebar

filter

Passed, or left out: a <GtkFilter>, or #f.

the item filter

Method: sidebar:set-menu-model self [menu-model] ¶
Method: set-menu-model self [menu-model] ¶

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.

self

Passed: a <AdwSidebar>.

a sidebar

menu-model

Passed, or left out: a <GMenuModel>, or #f.

a menu model

Method: sidebar:set-mode self mode ¶
Method: set-mode self mode ¶

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.

self

Passed: a <AdwSidebar>.

a sidebar

mode

Passed: a <AdwSidebarMode>, or one of its symbols.

the new mode

Method: sidebar:set-placeholder self [placeholder] ¶
Method: set-placeholder self [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 Sidebar:filter.

self

Passed: a <AdwSidebar>.

a sidebar

placeholder

Passed, or left out: a <GtkWidget>, or #f.

the placeholder widget

Method: sidebar:set-selected self selected ¶
Method: set-selected self selected ¶

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.

self

Passed: a <AdwSidebar>.

a sidebar

selected

Passed: an unsigned 32-bit integer.

index of the newly selected item

Method: sidebar:setup-drop-target self actions types ¶
Method: setup-drop-target self actions types ¶

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.

self

Passed: a <AdwSidebar>.

a sidebar

actions

Passed: a <GdkDragAction>, or a list of its symbols, or one of them.

the supported actions

types

Passed: a list or vector, each a class, or a GType number, or #f.

all supported GTypes that can be dropped

n-types

Not passed: guile-gi gives the length of types.

number of types

Signals ¶

Signal: sidebar:activated ¶

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.

self

Passed: a <AdwSidebar>.

index

Passed: an unsigned 32-bit integer.

the item index

Signal: sidebar:drop ¶

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.

self

Passed: a <AdwSidebar>.

index

Passed: an unsigned 32-bit integer.

index of the item the content was dropped onto

value

Passed: a <GValue>.

the <GValue> being dropped

preferred-action

Passed: a <GdkDragAction>.

the preferred drop action

%return

Returned: a boolean.

whether the drop was accepted

SinceL 1.9

Signal: sidebar:drop-enter ¶

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.

self

Passed: a <AdwSidebar>.

index

Passed: an unsigned 32-bit integer.

index of the hovered item

%return

Returned: a <GdkDragAction>, or a list of its symbols, or one of them.

the preferred action for the drop

Signal: sidebar:drop-value-loaded ¶

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.

self

Passed: a <AdwSidebar>.

index

Passed: an unsigned 32-bit integer.

index of the hovered item

value

Passed: a <GValue>.

the <GValue> being dropped

%return

Returned: a <GdkDragAction>, or a list of its symbols, or one of them.

the preferred action for the drop

Signal: sidebar:setup-menu ¶

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.

self

Passed: a <AdwSidebar>.

item

Passed: a <AdwSidebarItem>, or #f.

an item in self


Next: <AdwSidebarItem>, Previous: <AdwShortcutsSection>, Up: Classes   [Index]