Class SidebarSection

All Implemented Interfaces:
Buildable, Proxy

@Generated("org.javagi.JavaGI") public final class SidebarSection extends GObject implements Buildable

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 append(SidebarItem), prepend(SidebarItem) or insert(SidebarItem, int).

To remove items, use remove(SidebarItem) or removeAll().

To inspect the items, use getItem(int) or SidebarSection:items.

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

Binding models

AdwSidebarSection can show items from a provided ListModel, using bindModel(ListModel, SidebarSectionCreateItemFunc). It works the same way as ListBox#bindModel, except the provided function creates an SidebarItem rather than a ListBoxRow.

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:

sidebar-section
Since:
1.9
  • Constructor Details

    • SidebarSection

      public SidebarSection(MemorySegment address)
      Create a SidebarSection instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • SidebarSection

      public SidebarSection()
      Create a new SidebarSection.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the SidebarSection class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected SidebarSection asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • append

      public void append(SidebarItem item)

      Appends item to self.

      Cannot be used while a model is bound via bindModel(ListModel, SidebarSectionCreateItemFunc).

      Parameters:
      item - an item to append
      Since:
      1.9
    • bindModel

      public void bindModel(@Nullable ListModel model, @Nullable SidebarSectionCreateItemFunc createItemFunc)

      Binds model to self.

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

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

      If model is NULL, this SidebarSection is left empty.

      Calling prepend(SidebarItem), insert(SidebarItem, int), append(SidebarItem), remove(SidebarItem) or removeAll() 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.

      Parameters:
      model - the model to be bound
      createItemFunc - a function that creates SidebarItem for model items, or NULL in case model is also NULL
      Since:
      1.9
    • getItem

      public @Nullable SidebarItem getItem(int index)

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

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

      Parameters:
      index - index of the item
      Returns:
      the item at index
      Since:
      1.9
    • getItems

      public ListModel getItems()

      Gets a list model with self's items.

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

      Returns:
      a model containing the items
      Since:
      1.9
    • getMenuModel

      public @Nullable MenuModel getMenuModel()
      Gets the context menu model for self's items.
      Returns:
      the context menu model
      Since:
      1.9
    • getSidebar

      public @Nullable Sidebar getSidebar()
      Gets the sidebar this SidebarSection is in.
      Returns:
      the sidebar of this SidebarSection
      Since:
      1.9
    • getTitle

      public @Nullable String getTitle()
      Gets the title of self.
      Returns:
      the title
      Since:
      1.9
    • insert

      public void insert(SidebarItem item, int 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 bindModel(ListModel, SidebarSectionCreateItemFunc).

      Parameters:
      item - an item to insert
      position - position to insert item at
      Since:
      1.9
    • prepend

      public void prepend(SidebarItem item)

      Prepends item to self.

      Cannot be used while a model is bound via bindModel(ListModel, SidebarSectionCreateItemFunc).

      Parameters:
      item - an item to prepend
      Since:
      1.9
    • remove

      public void remove(SidebarItem item)

      Removes item from self.

      Cannot be used while a model is bound via bindModel(ListModel, SidebarSectionCreateItemFunc).

      Parameters:
      item - an item to remove
      Since:
      1.9
    • removeAll

      public void removeAll()

      Removes all items from self.

      Cannot be used while a model is bound via bindModel(ListModel, SidebarSectionCreateItemFunc).

      Since:
      1.9
    • setMenuModel

      public void setMenuModel(@Nullable MenuModel 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 Sidebar::setup-menu signal to set up the menu actions for the particular item.

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

      Parameters:
      menuModel - a menu model
      Since:
      1.9
    • setTitle

      public void setTitle(@Nullable String title)

      Sets the title of self.

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

      Parameters:
      title - the title
      Since:
      1.9
    • builder

      public static SidebarSection.Builder<? extends SidebarSection.Builder> builder()
      A SidebarSection.Builder object constructs a SidebarSection with the specified properties. Use the various set...() methods to set properties, and finish construction with SidebarSection.Builder.build().
      Returns:
      the builder object