1.51 <AdwSidebarSection>

Class: <AdwSidebarSection>

It derives from <GObject>.

A section within Sidebar.

<AdwSidebarSection> contains SidebarItem objects.

Section can optionally have a title, set with the SidebarSection:title property. If a title is not set, the section will have a separator in front of it, or just spacing in the Adw.SidebarMode.page mode.

To add items, use SidebarSection.append, SidebarSection.prepend or SidebarSection.insert.

To remove items, use SidebarSection.remove or SidebarSection.remove_all.

To inspect the items, use SidebarSection.get_item or SidebarSection:items.

To get the sidebar the section is in, useSidebarSection:sidebar.

Binding models

<AdwSidebarSection> can show items from a provided <GListModel>, using SidebarSection.bind_model. It works the same way as list-box:bind-model, except the provided function creates an SidebarItem rather than a <GtkListBoxRow>.

While a model is bound, adding or removing items manually is not allowed. Inspecting them is still allowed, but discouraged.

‘AdwSidebarSection‘ as ‘GtkBuildable‘

<AdwSidebarSection> allows adding items as children.

Example of an <AdwSidebarSection> UI definition:

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

Result:

Properties

Property: sidebar-section:items self

A list model with the section’s items.

This can be used to keep an up-to-date view.

Its value is a <GListModel>, or #f.

It is read only.

Property: sidebar-section:menu-model self

Context menu model for the section 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.

If not set, Sidebar:menu-model will be used instead.

Its value is a <GMenuModel>, or #f.

Set it with (set! (sidebar-section:menu-model self) value).

Property: sidebar-section:sidebar self

The sidebar the section is in.

Its value is a <AdwSidebar>, or #f.

It is read only.

Property: sidebar-section:title self

Title of the section.

If set, it will be displayed instead of the separator before the section.

Its value is a string, or #f.

Set it with (set! (sidebar-section:title self) value).

Procedures

Method: sidebar-section:append self item
Method: append self item

Appends item to self.

Cannot be used while a model is bound via SidebarSection.bind_model.

self

Passed: a <AdwSidebarSection>.

a sidebar section

item

Passed: a <AdwSidebarItem>.

an item to append

Method: sidebar-section:bind-model self [model] [create-item-func]
Method: bind-model self [model] [create-item-func]

Binds model to self.

If self was already bound to a model, that previous binding is destroyed.

The contents of self are cleared and then filled with items that represent items from model. self is updated whenever model changes.

If model is NULL, self is left empty.

Calling SidebarSection.prepend, SidebarSection.insert, SidebarSection.append, SidebarSection.remove or SidebarSection.remove_all while a model is bound is not allowed.

Accessing items and modifying them is allowed, but the changes will be erased whenever that part of the model changes, so it’s not recommended.

self

Passed: a <AdwSidebarSection>.

a sidebar section

model

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

the model to be bound

create-item-func

Passed, or left out: a procedure, or #f.

a function that creates SidebarItem for model items, or NULL in case model is also NULL

See AdwSidebarSectionCreateItemFunc for how it is called.

user-data

Not passed: guile-gi supplies it.

user data passed to create-widget-func

user-data-free-func

Not passed: guile-gi supplies it.

function for freeing user-data

See GDestroyNotify for how it is called.

Method: sidebar-section: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 section, and is same as the one returned by SidebarItem.get_section_index.

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

self

Passed: a <AdwSidebarSection>.

a sidebar section

index

Passed: an unsigned 32-bit integer.

index of the item

%return

Returned: a <AdwSidebarItem>, or #f.

the item at index

Method: sidebar-section: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.

self

Passed: a <AdwSidebarSection>.

a sidebar section

%return

Returned: a <GListModel>.

a model containing the items

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

Gets the context menu model for self’s items.

self

Passed: a <AdwSidebarSection>.

a sidebar section

%return

Returned: a <GMenuModel>, or #f.

the context menu model

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

Gets the sidebar self is in.

self

Passed: a <AdwSidebarSection>.

a sidebar section

%return

Returned: a <AdwSidebar>, or #f.

the sidebar of self

Method: sidebar-section:get-title self ⇒ %return
Method: get-title self ⇒ %return

Gets the title of self.

self

Passed: a <AdwSidebarSection>.

a sidebar section

%return

Returned: a string, or #f.

the title

Method: sidebar-section:insert self item position
Method: insert self item position

Inserts item at position to self.

If position is -1, or larger than the total number of items in self, the item will be appended to the end.

Cannot be used while a model is bound via SidebarSection.bind_model.

self

Passed: a <AdwSidebarSection>.

a sidebar section

item

Passed: a <AdwSidebarItem>.

an item to insert

position

Passed: a 32-bit integer.

position to insert item at

Procedure: sidebar-section:new ⇒ %return

Creates a new <AdwSidebarSection>.

%return

Returned: a <AdwSidebarSection>.

the newly created <AdwSidebarSection>

Method: sidebar-section:prepend self item
Method: prepend self item

Prepends item to self.

Cannot be used while a model is bound via SidebarSection.bind_model.

self

Passed: a <AdwSidebarSection>.

a sidebar section

item

Passed: a <AdwSidebarItem>.

an item to prepend

Method: sidebar-section:remove self item
Method: remove self item

Removes item from self.

Cannot be used while a model is bound via SidebarSection.bind_model.

self

Passed: a <AdwSidebarSection>.

a sidebar section

item

Passed: a <AdwSidebarItem>.

an item to remove

Method: sidebar-section:remove-all self
Method: remove-all self

Removes all items from self.

Cannot be used while a model is bound via SidebarSection.bind_model.

self

Passed: a <AdwSidebarSection>.

a sidebar section

Method: sidebar-section: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.

If not set, Sidebar:menu-model will be used instead.

self

Passed: a <AdwSidebarSection>.

a sidebar section

menu-model

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

a menu model

Method: sidebar-section:set-title self [title]
Method: set-title self [title]

Sets the title of self.

If set, it will be displayed instead of the separator before the section.

self

Passed: a <AdwSidebarSection>.

a sidebar section

title

Passed, or left out: a string, or #f.

the title