About all my projects
Gnome::Gtk4::ApplicationWindow

Gnome::Gtk4::ApplicationWindow

Description

Gnome::Gtk4::ApplicationWindow is a Gnome::Gtk4::Window subclass that integrates with Gnome::Gtk4::Application.

Notably, Gnome::Gtk4::ApplicationWindow can handle an application menubar.

This class implements the Gnome::Gio::R-ActionGroup and Gnome::Gio::R-ActionMap interfaces, to let you add window-specific actions that will be exported by the associated Gnome::Gtk4::Application, together with its application-wide actions. Window-specific actions are prefixed with the “win.” prefix and application-wide actions are prefixed with the “app.” prefix. Actions must be addressed with the prefixed name when referring to them from a Gnome::Gio::MenuModel.

Note that widgets that are placed inside a Gnome::Gtk4::ApplicationWindow can also activate these actions, if they implement the Gnome::Gtk4::R-Actionable interface.

The settings gtk-shell-shows-app-menu defined in Gnome::Gtk4::Settings and gtk-shell-shows-menubar defined in Gnome::Gtk4::Settings tell GTK whether the desktop environment is showing the application menu and menubar models outside the application as part of the desktop shell. For instance, on OS X, both menus will be displayed remotely; on Windows neither will be.

If the desktop environment does not display the menubar, then Gnome::Gtk4::ApplicationWindow will automatically show a menubar for it. This behaviour can be overridden with the show-menubar property. If the desktop environment does not display the application menu, then it will automatically be included in the menubar or in the windows client-side decorations.

See Gnome::Gtk4::PopoverMenu for information about the XML language used by Gnome::Gtk4::Builder for menu models.

See also: .set-menubar() in class Gnome::Gtk4::Application.

A GtkApplicationWindow with a menubar

The code sample below shows how to set up a Gnome::Gtk4::ApplicationWindow with a menu bar defined on the Gnome::Gtk4::Application:

my Gnome::Gtk4::Application $app .= new-application( "org.gtk.test", 0);
my Gnome::Gtk4::Builder $builder .= from-string( q:to/EOUI/, -1);
  <interface>
    <menu id='menubar'>
      <submenu>
        <attribute name='label' translatable='yes'>_Edit</attribute>
        <item>
          <attribute name='label' translatable='yes'>_Copy</attribute>
          <attribute name='action'>win.copy</attribute>
        </item>
        <item>
          <attribute name='label' translatable='yes'>_Paste</attribute>
          <attribute name='action'>win.paste</attribute>
        </item>
      </submenu>
    </menu>
  </interface>
  EOUI

my Gnome::Gio::MenuModel $menubar = $builder.get-object("menubar);
$app.set-menubar($menubar);
$builder.clear-object

# ...
my Gnome::Gtk4::Widget $window .= new-application-window($app);

Class initialization

new

:native-object

Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.

multi method new ( N-Object :$native-object! )

new-applicationwindow

Creates a new Gnome::Gtk4::ApplicationWindow.

method new-applicationwindow ( N-Object() $application --> Gnome::Gtk4::ApplicationWindow \)
  • $application; a Gnome::Gtk4::Application.

Methods

get-help-overlay

Gets the Gnome::Gtk4::ShortcutsWindow that is associated with $window.

See .set-help-overlay().

method get-help-overlay (--> N-Object )

Return value; the help overlay associated with $window.

get-id

Returns the unique ID of the window.

If the window has not yet been added to a B<Gnome::Gtk4::Application>, returns B<0>.
method get-id (--> UInt )

Return value; the unique ID for $window, or 0 if the window has not yet been added to a Gnome::Gtk4::Application.

get-show-menubar

Returns whether the window will display a menubar for the app menu and menubar as needed.

method get-show-menubar (--> Bool )

Return value; True if $window will display a menubar when needed.

set-help-overlay

Associates a shortcuts window with the application window.

Additionally, sets up an action with the name win.show-help-overlay to present it. $window takes responsibility for destroying $help-overlay.

method set-help-overlay ( N-Object() $help-overlay )
  • $help-overlay; a Gnome::Gtk4::ShortcutsWindow.

set-show-menubar

Sets whether the window will display a menubar for the app menu and menubar as needed.

method set-show-menubar ( Bool() $show-menubar )
  • $show-menubar; whether to show a menubar when needed.