Class TabView

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Proxy

@Generated("org.javagi.JavaGI") public final class TabView extends Widget implements Accessible, Buildable, ConstraintTarget

A dynamic tabbed container.

AdwTabView is a container which shows one child at a time. While it provides keyboard shortcuts for switching between pages, it does not provide a visible tab switcher and relies on external widgets for that, such as TabBar, TabOverview and TabButton.

AdwTabView maintains a TabPage object for each page, which holds additional per-page properties. You can obtain the AdwTabPage for a page with getPage(Widget), and as the return value for append(Widget) and other functions for adding children.

AdwTabView only aims to be useful for dynamic tabs in multi-window document-based applications, such as web browsers, file managers, text editors or terminals. It does not aim to replace Notebook for use cases such as tabbed dialogs.

As such, it does not support disabling page reordering or detaching.

AdwTabView adds a number of global page switching and reordering shortcuts. The TabView:shortcuts property can be used to manage them.

See TabViewShortcuts for the list of the available shortcuts. All of the shortcuts are enabled by default.

addShortcuts(Set) and removeShortcuts(Set) can be used to manage shortcuts in a convenient way, for example:

adw_tab_view_remove_shortcuts (view, ADW_TAB_VIEW_SHORTCUT_CONTROL_HOME |
                                     ADW_TAB_VIEW_SHORTCUT_CONTROL_END);

CSS nodes

AdwTabView has a main CSS node with the name tabview.

Accessibility

AdwTabView uses the Gtk.AccessibleRole.tab-panel role for the tab pages which are the accessible parent objects of the child widgets.

  • Constructor Details

    • TabView

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

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

    • getType

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

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

      protected TabView 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 Widget
      Returns:
      the instance as if it were its parent type
    • addPage

      public TabPage addPage(Widget child, @Nullable TabPage parent)

      Adds child to this TabView with parent as the parent.

      This function can be used to automatically position new pages, and to select the correct page when this page is closed while being selected (see closePage(TabPage)).

      If parent is NULL, this function is equivalent to append(Widget).

      Parameters:
      child - a widget to add
      parent - a parent page for child
      Returns:
      the page object representing child
    • addShortcuts

      public void addShortcuts(Set<TabViewShortcuts> shortcuts)

      Adds shortcuts for self.

      See TabView:shortcuts for details.

      Parameters:
      shortcuts - the shortcuts to add
      Since:
      1.2
    • addShortcuts

      public void addShortcuts(TabViewShortcuts... shortcuts)

      Adds shortcuts for self.

      See TabView:shortcuts for details.

      Parameters:
      shortcuts - the shortcuts to add
      Since:
      1.2
    • append

      public TabPage append(Widget child)
      Inserts child as the last non-pinned page.
      Parameters:
      child - a widget to add
      Returns:
      the page object representing child
    • appendPinned

      public TabPage appendPinned(Widget child)
      Inserts child as the last pinned page.
      Parameters:
      child - a widget to add
      Returns:
      the page object representing child
    • closeOtherPages

      public void closeOtherPages(TabPage page)
      Requests to close all pages other than page.
      Parameters:
      page - a page of this TabView
    • closePage

      public void closePage(TabPage page)

      Requests to close page.

      Calling this function will result in the TabView::close-page signal being emitted for page. Closing the page can then be confirmed or denied via closePageFinish(TabPage, boolean).

      If the page is waiting for a closePageFinish(TabPage, boolean) call, this function will do nothing.

      The default handler for TabView::close-page will immediately confirm closing the page if it's non-pinned, or reject it if it's pinned. This behavior can be changed by registering your own handler for that signal.

      If page was selected, another page will be selected instead:

      If the TabPage:parent value is NULL, the next page will be selected when possible, or if the page was already last, the previous page will be selected instead.

      If it's not NULL, the previous page will be selected if it's a descendant (possibly indirect) of the parent. If both the previous page and the parent are pinned, the parent will be selected instead.

      Parameters:
      page - a page of this TabView
    • closePageFinish

      public void closePageFinish(TabPage page, boolean confirm)

      Completes a closePage(TabPage) call for page.

      If confirm is TRUE, page will be closed. If it's FALSE, it will be reverted to its previous state and closePage(TabPage) can be called for it again.

      This function should not be called unless a custom handler for TabView::close-page is used.

      Parameters:
      page - a page of this TabView
      confirm - whether to confirm or deny closing page
    • closePagesAfter

      public void closePagesAfter(TabPage page)
      Requests to close all pages after page.
      Parameters:
      page - a page of this TabView
    • closePagesBefore

      public void closePagesBefore(TabPage page)
      Requests to close all pages before page.
      Parameters:
      page - a page of this TabView
    • getDefaultIcon

      public Icon getDefaultIcon()
      Gets the default icon of self.
      Returns:
      the default icon of self.
    • getIsTransferringPage

      public boolean getIsTransferringPage()

      Whether a page is being transferred.

      The corresponding property will be set to TRUE when a drag-n-drop tab transfer starts on any AdwTabView, and to FALSE after it ends.

      During the transfer, children cannot receive pointer input and a tab can be safely dropped on the tab view.

      Returns:
      whether a page is being transferred
    • getMenuModel

      public @Nullable MenuModel getMenuModel()
      Gets the tab context menu model for self.
      Returns:
      the tab context menu model for this TabView
    • getNPages

      public int getNPages()
      Gets the number of pages in self.
      Returns:
      the number of pages in this TabView
    • getNPinnedPages

      public int getNPinnedPages()

      Gets the number of pinned pages in self.

      See setPagePinned(TabPage, boolean).

      Returns:
      the number of pinned pages in this TabView
    • getNthPage

      public TabPage getNthPage(int position)
      Gets the TabPage representing the child at position.
      Parameters:
      position - the index of the page in self, starting from 0
      Returns:
      the page object at position
    • getPage

      public TabPage getPage(Widget child)
      Gets the TabPage object representing child.
      Parameters:
      child - a child in this TabView
      Returns:
      the page object for child
    • getPagePosition

      public int getPagePosition(TabPage page)
      Finds the position of page in self, starting from 0.
      Parameters:
      page - a page of this TabView
      Returns:
      the position of page in this TabView
    • getPages

      public SelectionModel getPages()

      Returns a ListModel that contains the pages of self.

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

      The model implements SectionModel, with one section for pinned pages and one for the rest of the pages.

      It also implements SelectionModel and can be used to track and change the selected page.

      Returns:
      a GtkSelectionModel for the pages of this TabView
    • getSelectedPage

      public @Nullable TabPage getSelectedPage()
      Gets the currently selected page in self.
      Returns:
      the selected page
    • getShortcuts

      public Set<TabViewShortcuts> getShortcuts()
      Gets the enabled shortcuts for self.
      Returns:
      the shortcut mask
      Since:
      1.2
    • insert

      public TabPage insert(Widget child, int position)

      Inserts a non-pinned page at position.

      It's an error to try to insert a page before a pinned page, in that case insertPinned(Widget, int) should be used instead.

      Parameters:
      child - a widget to add
      position - the position to add child at, starting from 0
      Returns:
      the page object representing child
    • insertPinned

      public TabPage insertPinned(Widget child, int position)

      Inserts a pinned page at position.

      It's an error to try to insert a pinned page after a non-pinned page, in that case insert(Widget, int) should be used instead.

      Parameters:
      child - a widget to add
      position - the position to add child at, starting from 0
      Returns:
      the page object representing child
    • invalidateThumbnails

      public void invalidateThumbnails()

      Invalidates thumbnails for all pages in self.

      This is a convenience method, equivalent to calling TabPage.invalidateThumbnail() on each page.

      Since:
      1.3
    • prepend

      public TabPage prepend(Widget child)
      Inserts child as the first non-pinned page.
      Parameters:
      child - a widget to add
      Returns:
      the page object representing child
    • prependPinned

      public TabPage prependPinned(Widget child)
      Inserts child as the first pinned page.
      Parameters:
      child - a widget to add
      Returns:
      the page object representing child
    • removeShortcuts

      public void removeShortcuts(Set<TabViewShortcuts> shortcuts)

      Removes shortcuts from self.

      See TabView:shortcuts for details.

      Parameters:
      shortcuts - the shortcuts to remove
      Since:
      1.2
    • removeShortcuts

      public void removeShortcuts(TabViewShortcuts... shortcuts)

      Removes shortcuts from self.

      See TabView:shortcuts for details.

      Parameters:
      shortcuts - the shortcuts to remove
      Since:
      1.2
    • reorderBackward

      public boolean reorderBackward(TabPage page)
      Reorders page to before its previous page if possible.
      Parameters:
      page - a page of this TabView
      Returns:
      whether page was moved
    • reorderFirst

      public boolean reorderFirst(TabPage page)
      Reorders page to the first possible position.
      Parameters:
      page - a page of this TabView
      Returns:
      whether page was moved
    • reorderForward

      public boolean reorderForward(TabPage page)
      Reorders page to after its next page if possible.
      Parameters:
      page - a page of this TabView
      Returns:
      whether page was moved
    • reorderLast

      public boolean reorderLast(TabPage page)
      Reorders page to the last possible position.
      Parameters:
      page - a page of this TabView
      Returns:
      whether page was moved
    • reorderPage

      public boolean reorderPage(TabPage page, int position)

      Reorders page to position.

      It's a programmer error to try to reorder a pinned page after a non-pinned one, or a non-pinned page before a pinned one.

      Parameters:
      page - a page of this TabView
      position - the position to insert the page at, starting at 0
      Returns:
      whether page was moved
    • selectNextPage

      public boolean selectNextPage()

      Selects the page after the currently selected page.

      If the last page was already selected, this function does nothing.

      Returns:
      whether the selected page was changed
    • selectPreviousPage

      public boolean selectPreviousPage()

      Selects the page before the currently selected page.

      If the first page was already selected, this function does nothing.

      Returns:
      whether the selected page was changed
    • setDefaultIcon

      public void setDefaultIcon(Icon defaultIcon)

      Sets the default page icon for self.

      If a page doesn't provide its own icon via TabPage:icon, a default icon may be used instead for contexts where having an icon is necessary.

      TabBar will use default icon for pinned tabs in case the page is not loading, doesn't have an icon and an indicator. Default icon is never used for tabs that aren't pinned.

      TabOverview will use default icon for pages with missing thumbnails.

      By default, the adw-tab-icon-missing-symbolic icon is used.

      Parameters:
      defaultIcon - the default icon
    • setMenuModel

      public void setMenuModel(@Nullable MenuModel menuModel)

      Sets the tab context menu model for self.

      When a context menu is shown for a tab, it will be constructed from the provided menu model. Use the TabView::setup-menu signal to set up the menu actions for the particular tab.

      Parameters:
      menuModel - a menu model
    • setPagePinned

      public void setPagePinned(TabPage page, boolean pinned)

      Pins or unpins page.

      Pinned pages are guaranteed to be placed before all non-pinned pages; at any given moment the first TabView:n-pinned-pages pages in this TabView are guaranteed to be pinned.

      When a page is pinned or unpinned, it's automatically reordered: pinning a page moves it after other pinned pages; unpinning a page moves it before other non-pinned pages.

      Pinned pages can still be reordered between each other.

      TabBar will display pinned pages in a compact form, never showing the title or close button, and only showing a single icon, selected in the following order:

      1. TabPage:indicator-icon
      2. A spinner if TabPage:loading is TRUE
      3. TabPage:icon
      4. TabView:default-icon

      TabOverview will not show a thumbnail for pinned pages, and replace the close button with an unpin button. Unlike AdwTabBar, it will still display the page's title, icon and indicator separately.

      Pinned pages cannot be closed by default, see TabView::close-page for how to override that behavior.

      Changes the value of the TabPage:pinned property.

      Parameters:
      page - a page of this TabView
      pinned - whether page should be pinned
    • setSelectedPage

      public void setSelectedPage(TabPage selectedPage)
      Sets the currently selected page in self.
      Parameters:
      selectedPage - a page in this TabView
    • setShortcuts

      public void setShortcuts(Set<TabViewShortcuts> shortcuts)

      Sets the enabled shortcuts for self.

      See TabViewShortcuts for the list of the available shortcuts. All of the shortcuts are enabled by default.

      addShortcuts(Set) and removeShortcuts(Set) provide a convenient way to manage individual shortcuts.

      Parameters:
      shortcuts - the new shortcuts
      Since:
      1.2
    • setShortcuts

      public void setShortcuts(TabViewShortcuts... shortcuts)

      Sets the enabled shortcuts for self.

      See TabViewShortcuts for the list of the available shortcuts. All of the shortcuts are enabled by default.

      addShortcuts(Set) and removeShortcuts(Set) provide a convenient way to manage individual shortcuts.

      Parameters:
      shortcuts - the new shortcuts
      Since:
      1.2
    • transferPage

      public void transferPage(TabPage page, TabView otherView, int position)

      Transfers page from this TabView to otherView.

      The page object will be reused.

      It's a programmer error to try to insert a pinned page after a non-pinned one, or a non-pinned page before a pinned one.

      Parameters:
      page - a page of this TabView
      otherView - the tab view to transfer the page to
      position - the position to insert the page at, starting at 0
    • onClosePage

      Emitted after closePage(TabPage) has been called for page.

      The handler is expected to call closePageFinish(TabPage, boolean) to confirm or reject the closing.

      The default handler will immediately confirm closing for non-pinned pages, or reject it for pinned pages, equivalent to the following example:

      static gboolean
      close_page_cb (AdwTabView *view,
                     AdwTabPage *page,
                     gpointer    user_data)
      {
        adw_tab_view_close_page_finish (view, page, !adw_tab_page_get_pinned (page));
      
        return GDK_EVENT_STOP;
      }
      

      The closePageFinish(TabPage, boolean) call doesn't have to happen inside the handler, so can be used to do asynchronous checks before confirming the closing.

      A typical reason to connect to this signal is to show a confirmation dialog for closing a tab.

      The signal handler should return Gdk.EVENT_STOP to stop propagation or Gdk.EVENT_PROPAGATE to invoke the default handler.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitClosePage

      public boolean emitClosePage(@Nullable TabPage page)
      Emits the "close-page" signal. See onClosePage(TabView.ClosePageCallback).
    • onCreateWindow

      Emitted when a tab should be transferred into a new window.

      This can happen after a tab has been dropped on desktop.

      The signal handler is expected to create a new window, position it as needed and return its AdwTabView that the page will be transferred into.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitCreateWindow

      public TabView emitCreateWindow()
      Emits the "create-window" signal. See onCreateWindow(TabView.CreateWindowCallback).
    • onIndicatorActivated

      Emitted after the indicator icon on page has been activated.

      See TabPage:indicator-icon and TabPage:indicator-activatable.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitIndicatorActivated

      public void emitIndicatorActivated(@Nullable TabPage page)
      Emits the "indicator-activated" signal. See onIndicatorActivated(TabView.IndicatorActivatedCallback).
    • onPageAttached

      Emitted when a page has been created or transferred to self.

      A typical reason to connect to this signal would be to connect to page signals for things such as updating window title.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitPageAttached

      public void emitPageAttached(@Nullable TabPage page, int position)
      Emits the "page-attached" signal. See onPageAttached(TabView.PageAttachedCallback).
    • onPageDetached

      Emitted when a page has been removed or transferred to another view.

      A typical reason to connect to this signal would be to disconnect signal handlers connected in the TabView::page-attached handler.

      It is important not to try and destroy the page child in the handler of this function as the child might merely be moved to another window; use child dispose handler for that or do it in sync with your closePageFinish(TabPage, boolean) calls.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitPageDetached

      public void emitPageDetached(@Nullable TabPage page, int position)
      Emits the "page-detached" signal. See onPageDetached(TabView.PageDetachedCallback).
    • onPageReordered

      Emitted after page has been reordered to position.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitPageReordered

      public void emitPageReordered(@Nullable TabPage page, int position)
      Emits the "page-reordered" signal. See onPageReordered(TabView.PageReorderedCallback).
    • onSetupMenu

      Emitted when a context menu is opened or closed for page.

      If the menu has been closed, page 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 page.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitSetupMenu

      public void emitSetupMenu(@Nullable TabPage page)
      Emits the "setup-menu" signal. See onSetupMenu(TabView.SetupMenuCallback).
    • builder

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