gem-graph-client/docs/GTK-docs/gnome-dev-documentation/developer.gnome.org/documentation/tutorials/actions.html

799 lines
84 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html class="no-js">
<head><meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="color-scheme" content="light dark"><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<link rel="index" title="Index" href="../genindex.html" /><link rel="search" title="Search" href="../search.html" /><link rel="next" title="Menus" href="menus.html" /><link rel="prev" title="Dealing With Deprecations" href="deprecations.html" />
<meta name="generator" content="sphinx-4.3.0, furo 2022.06.21"/>
<title>Actions - GNOME Developer Documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/styles/furo.css?digest=40978830699223671f4072448e654b5958f38b89" />
<link rel="stylesheet" type="text/css" href="../_static/tabs.css" />
<link rel="stylesheet" type="text/css" href="../_static/styles/furo-extensions.css?digest=30d1aed668e5c3a91c3e3bf6a60b675221979f0e" />
<link rel="stylesheet" type="text/css" href="../_static/gnome.css" />
<style>
body {
--color-code-background: #f8f8f8;
--color-code-foreground: black;
--color-brand-primary: #4a86cf;
--color-brand-content: #4a86cf;
}
@media not print {
body[data-theme="dark"] {
--color-code-background: #202020;
--color-code-foreground: #d0d0d0;
}
@media (prefers-color-scheme: dark) {
body:not([data-theme="light"]) {
--color-code-background: #202020;
--color-code-foreground: #d0d0d0;
}
}
}
</style></head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id="svg-toc" viewBox="0 0 24 24">
<title>Contents</title>
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024">
<path d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 0 0 0 13.8z"/>
</svg>
</symbol>
<symbol id="svg-menu" viewBox="0 0 24 24">
<title>Menu</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-menu">
<line x1="3" y1="12" x2="21" y2="12"></line>
<line x1="3" y1="6" x2="21" y2="6"></line>
<line x1="3" y1="18" x2="21" y2="18"></line>
</svg>
</symbol>
<symbol id="svg-arrow-right" viewBox="0 0 24 24">
<title>Expand</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-chevron-right">
<polyline points="9 18 15 12 9 6"></polyline>
</svg>
</symbol>
<symbol id="svg-sun" viewBox="0 0 24 24">
<title>Light mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather-sun">
<circle cx="12" cy="12" r="5"></circle>
<line x1="12" y1="1" x2="12" y2="3"></line>
<line x1="12" y1="21" x2="12" y2="23"></line>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
<line x1="1" y1="12" x2="3" y2="12"></line>
<line x1="21" y1="12" x2="23" y2="12"></line>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
</svg>
</symbol>
<symbol id="svg-moon" viewBox="0 0 24 24">
<title>Dark mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-moon">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z" />
</svg>
</symbol>
<symbol id="svg-sun-half" viewBox="0 0 24 24">
<title>Auto light/dark mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-shadow">
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
<circle cx="12" cy="12" r="9" />
<path d="M13 12h5" />
<path d="M13 15h4" />
<path d="M13 18h1" />
<path d="M13 9h4" />
<path d="M13 6h1" />
</svg>
</symbol>
</svg>
<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
<label class="overlay sidebar-overlay" for="__navigation"></label>
<label class="overlay toc-overlay" for="__toc"></label>
<div class="page">
<header class="mobile-header">
<div class="header-left">
<label class="nav-overlay-icon" for="__navigation">
<i class="icon"><svg><use href="#svg-menu"></use></svg></i>
</label>
</div>
<div class="header-center">
<a href="../index.html"><div class="brand">GNOME Developer Documentation</div></a>
</div>
<div class="header-right">
<label class="toc-overlay-icon toc-header-icon" for="__toc">
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
</label>
</div>
</header>
<aside class="sidebar-drawer">
<div class="sidebar-container">
<div class="sidebar-sticky"><a class="sidebar-brand" href="../index.html">
<span class="sidebar-brand-text">GNOME Developer Documentation</span>
</a><form class="sidebar-search-container" method="get" action="../search.html" role="search">
<input class="sidebar-search" placeholder=Search name="q" aria-label="Search">
<input type="hidden" name="check_keywords" value="yes">
<input type="hidden" name="area" value="default">
</form>
<div id="searchbox"></div><div class="sidebar-scroll"><div class="sidebar-tree">
<p class="caption" role="heading"><span class="caption-text">Contents</span></p>
<ul class="current">
<li class="toctree-l1 has-children"><a class="reference internal" href="../introduction.html">Platform Introduction</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2 has-children"><a class="reference internal" href="../introduction/components.html">Platform Components</a><input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" role="switch" type="checkbox"/><label for="toctree-checkbox-2"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../introduction/overview/libraries.html">Libraries</a></li>
<li class="toctree-l3"><a class="reference internal" href="../introduction/overview/services.html">Services</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../introduction/languages.html">Programming Languages</a></li>
<li class="toctree-l2"><a class="reference internal" href="../introduction/builder.html">GNOME Builder</a></li>
<li class="toctree-l2"><a class="reference internal" href="../introduction/flatpak.html">Flatpak</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../guidelines.html">Guidelines</a><input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" role="switch" type="checkbox"/><label for="toctree-checkbox-3"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2 has-children"><a class="reference internal" href="../guidelines/programming.html">Programming Guidelines</a><input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" role="switch" type="checkbox"/><label for="toctree-checkbox-4"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/programming/coding-style.html">C Coding Style</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/programming/memory-management.html">Managing Memory</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/programming/writing-good-code.html">The Importance of Writing Good Code</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/programming/optimizing.html">Optimizing GNOME Applications</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/programming/namespacing.html">Namespacing</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/programming/introspection.html">Introspection</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../guidelines/accessibility.html">Accessibility</a><input class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" role="switch" type="checkbox"/><label for="toctree-checkbox-5"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/accessibility/coding-guidelines.html">Coding Guidelines for Supporting Accessibility</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/accessibility/custom-widgets.html">Making Custom Components Accessible</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../guidelines/localization.html">Localization</a><input class="toctree-checkbox" id="toctree-checkbox-6" name="toctree-checkbox-6" role="switch" type="checkbox"/><label for="toctree-checkbox-6"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/localization/practices.html">Best Practices for Localization</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../guidelines/maintainer.html">Maintainer Guidelines</a><input class="toctree-checkbox" id="toctree-checkbox-7" name="toctree-checkbox-7" role="switch" type="checkbox"/><label for="toctree-checkbox-7"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/maintainer/api-stability.html">API Stability</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/maintainer/parallel-installability.html">Parallel Installability</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/maintainer/integrating.html">Integrating with GNOME</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../guidelines/devel-docs.html">Developer Documentation Style Guidelines</a></li>
</ul>
</li>
<li class="toctree-l1 current has-children"><a class="reference internal" href="../tutorials.html">Tutorials</a><input checked="" class="toctree-checkbox" id="toctree-checkbox-8" name="toctree-checkbox-8" role="switch" type="checkbox"/><label for="toctree-checkbox-8"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul class="current">
<li class="toctree-l2 has-children"><a class="reference internal" href="beginners.html">Beginners Tutorials</a><input class="toctree-checkbox" id="toctree-checkbox-9" name="toctree-checkbox-9" role="switch" type="checkbox"/><label for="toctree-checkbox-9"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3 has-children"><a class="reference internal" href="beginners/getting_started.html">Getting Started</a><input class="toctree-checkbox" id="toctree-checkbox-10" name="toctree-checkbox-10" role="switch" type="checkbox"/><label for="toctree-checkbox-10"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l4"><a class="reference internal" href="beginners/getting_started/content_view.html">Adding A Content View</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/getting_started/opening_files.html">Loading Content From A File</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/getting_started/cursor_position.html">Showing The Cursor Position</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/getting_started/saving_files.html">Saving The Content To A File</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/getting_started/saving_state.html">Saving The Application State</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/getting_started/adding_toasts.html">Notifying The User With Toasts</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/getting_started/dark_mode.html">Forcing The Dark Color Scheme</a></li>
</ul>
</li>
<li class="toctree-l3 has-children"><a class="reference internal" href="beginners/components.html">UI components</a><input class="toctree-checkbox" id="toctree-checkbox-11" name="toctree-checkbox-11" role="switch" type="checkbox"/><label for="toctree-checkbox-11"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/window.html">Windows</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/image.html">Images</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/label.html">Labels</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/button.html">Buttons</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/box.html">Boxes</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/stack.html">Stacks</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/leaflet.html">Leaflets</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/toggle.html">Toggles</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/check_box.html">Check Boxes</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/radio_button.html">Radio Buttons</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/spin_button.html">Spin Buttons</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/link_button.html">Link Buttons</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/switch.html">Switches</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/menu_button.html">Menu Buttons</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/entry.html">Entries</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/password_entry.html">Password Entries</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/message_dialog.html">Messages</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/file_dialog.html">File Dialogs</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/spinner.html">Spinners</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/level_bar.html">Level Bars</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="application-id.html">Application ID</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html">Using GtkApplication</a></li>
<li class="toctree-l2"><a class="reference internal" href="save-state.html">Saving and Loading Window State</a></li>
<li class="toctree-l2"><a class="reference internal" href="notifications.html">Using Notifications</a></li>
<li class="toctree-l2"><a class="reference internal" href="themed-icons.html">Themed Icons</a></li>
<li class="toctree-l2"><a class="reference internal" href="deprecations.html">Dealing With Deprecations</a></li>
<li class="toctree-l2 current current-page"><a class="current reference internal" href="#">Actions</a></li>
<li class="toctree-l2"><a class="reference internal" href="menus.html">Menus</a></li>
<li class="toctree-l2"><a class="reference internal" href="search-provider.html">Writing a Search Provider</a></li>
<li class="toctree-l2"><a class="reference internal" href="pre-and-post-conditions.html">Pre- and Post-Conditions</a></li>
<li class="toctree-l2"><a class="reference internal" href="main-contexts.html">Main Contexts</a></li>
<li class="toctree-l2"><a class="reference internal" href="lists.html">Using GLib Lists</a></li>
<li class="toctree-l2"><a class="reference internal" href="threading.html">Threading</a></li>
<li class="toctree-l2"><a class="reference internal" href="asynchronous-programming.html">Asynchronous Programming</a></li>
<li class="toctree-l2"><a class="reference internal" href="drag-and-drop.html">Drag and Drop</a></li>
<li class="toctree-l2"><a class="reference internal" href="widget-templates.html">Widget Templates</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
</aside>
<main class="main">
<div class="content">
<article role="main">
<label class="toc-overlay-icon toc-content-icon" for="__toc">
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
</label>
<section id="actions">
<h1>Actions<a class="headerlink" href="#actions" title="Permalink to this headline">#</a></h1>
<p>A <code class="docutils literal notranslate"><span class="pre">GAction</span></code> is a representation of a single user-interesting action in an application.</p>
<p>To use <code class="docutils literal notranslate"><span class="pre">GAction</span></code> you should be using <a class="reference internal" href="application.html"><span class="doc">GtkApplication</span></a>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Its possible to use <code class="docutils literal notranslate"><span class="pre">GAction</span></code> without <code class="docutils literal notranslate"><span class="pre">GtkApplication</span></code> but this is not
discussed here.</p>
</div>
<section id="what-it-is-what-it-isn-t">
<h2>What it is, what it isnt<a class="headerlink" href="#what-it-is-what-it-isn-t" title="Permalink to this headline">#</a></h2>
<p>A <code class="docutils literal notranslate"><span class="pre">GAction</span></code> is essentially a way to tell the toolkit about a piece of
functionality in your program, and to give it a name.</p>
<p>Actions are purely functional. They do not contain any presentational information.</p>
<p>An action has four pieces of information associated with it:</p>
<ul class="simple">
<li><p>a <strong>name</strong> as an identifier (usually all-lowercase, untranslated English string)</p></li>
<li><p>an <strong>enabled</strong> flag indicating if the action can be activated or not (like “sensitive”)</p></li>
<li><p>an optional <strong>state</strong> value, for stateful actions (like a boolean for toggles)</p></li>
<li><p>an optional <strong>parameter</strong> type, used when activating the action</p></li>
</ul>
<p>An action supports two operations:</p>
<ul class="simple">
<li><p>activation, invoked with an optional parameter (of the correct type, see
above)</p></li>
<li><p>state change request, invoked with a new requested state value (of the
correct type). Only supported for stateful actions.</p></li>
</ul>
<p>Here are some rules about an action:</p>
<ul class="simple">
<li><p>the <strong>name</strong> is immutable (in the sense that it will never change) and it
is never <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p></li>
<li><p>the <strong>enabled</strong> flag can change</p></li>
<li><p>the <strong>parameter</strong> type is immutable</p></li>
<li><p>the <strong>parameter type</strong> is optional: it can be <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
<ul>
<li><p>if the parameter type is <code class="docutils literal notranslate"><span class="pre">NULL</span></code> then action activation must be done
without a parameter (ie: a <code class="docutils literal notranslate"><span class="pre">NULL</span></code> GVariant pointer)</p></li>
<li><p>if the parameter type is non <code class="docutils literal notranslate"><span class="pre">NULL</span></code> then the parameter must have this
type</p></li>
</ul>
</li>
<li><p>the <strong>state</strong> can change, but it cannot change type</p>
<ul>
<li><p>if the action was stateful when it was created, it will always have a
state and it will always have exactly the same type (such as boolean
or string)</p></li>
<li><p>if the action was stateless when it was created, it can never have a state</p></li>
</ul>
</li>
<li><p>you can only request <strong>state changes</strong> on stateful actions and it is only
possible to request that the state change to a value of the same type as the
existing state</p></li>
</ul>
<p>An action does <strong>not</strong> have any of the following:</p>
<ul class="simple">
<li><p>a label</p></li>
<li><p>an icon</p></li>
<li><p>a way of creating a widget corresponding to it</p></li>
<li><p>any other sort of presentational information</p></li>
</ul>
</section>
<section id="action-state-and-parameters">
<h2>Action state and parameters<a class="headerlink" href="#action-state-and-parameters" title="Permalink to this headline">#</a></h2>
<p>Most actions in your application will be stateless actions with no parameters.
These typically appear as menu items with no special decoration. An example is
“quit”.</p>
<p>Stateful actions are used to represent an action which has a closely-associated
state of some kind. A good example is a “fullscreen” action. For this case,
youd expect to see a checkmark next to the menu item when the fullscreen option
is active. This is usually called a toggle action, and it has a boolean state.
By convention, toggle actions have no parameter type for activation: activating
the action always toggles the state.</p>
<p>Another common case is to have an action representing a enumeration of possible
values of a given type (typically string). This is often called a radio action
and is usually represented in the user interface with radio buttons or radio
menu items, or sometimes a combobox. A good example is “text-justify” with
possible values “left”, “center”, and “right”. By convention, these types of
actions have a parameter type equal to their state type, and activating them
with a particular parameter value is equivalent to changing their state to that
value.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This approach to handling radio buttons is different than many other action
systems. With <code class="docutils literal notranslate"><span class="pre">GAction</span></code>, there is only one action for “text-justify” and
“left”, “center” and “right” are possible states on that action. There are
not three separate “justify-left”, “justify-center” and “justify-right”
actions.</p>
</div>
<p>The final common type of action is a stateless action with a parameter. This is
typically used for actions like “open-bookmark” where the parameter to the
action would be the identifier of the bookmark to open.</p>
</section>
<section id="action-target-and-detailed-names">
<h2>Action target and detailed names<a class="headerlink" href="#action-target-and-detailed-names" title="Permalink to this headline">#</a></h2>
<p>Because some types of actions cannot be invoked without a parameter, it is often
important to specify a parameter when referring to the action from a place where
it will be invoked (such as from a radio button that sets the state to a
particular value or from a menu item that opens a specific bookmark). From these
contexts, the value used for the action parameter is typically called the target
of the action.</p>
<p>Even though toggle actions have a state, they do not have a parameter.
Therefore, a target value is not needed when referring to them they will
always be toggled on activation.</p>
<p>Most APIs that allow using a <code class="docutils literal notranslate"><span class="pre">GAction</span></code> (such as <code class="docutils literal notranslate"><span class="pre">GMenuModel</span></code> and
<code class="docutils literal notranslate"><span class="pre">GtkActionable</span></code>) allow use of detailed action names. This is a convenient way
of specifying an action name and an action target with a single string.</p>
<p>In the case that the action target is a string with no unusual characters (ie:
only alpha-numeric, plus - and .) then you can use a detailed action name of
the form <code class="docutils literal notranslate"><span class="pre">justify::left</span></code> to specify the justify action with a target of left.</p>
<p>In the case that the action target is not a string, or contains unusual
characters, you can use the more general format <code class="docutils literal notranslate"><span class="pre">action-name(5)</span></code>, where the “5”
here is any valid text-format <code class="docutils literal notranslate"><span class="pre">GVariant</span></code> (ie: a string that can be parsed by
<code class="docutils literal notranslate"><span class="pre">g_variant_parse()</span></code>). Another example is <code class="docutils literal notranslate"><span class="pre">open-bookmark('http://gnome.org/')</span></code>.</p>
<p>You can convert between detailed action names and split-out action names and
target values using <code class="docutils literal notranslate"><span class="pre">g_action_parse_detailed_action_name()</span></code> and
<code class="docutils literal notranslate"><span class="pre">g_action_print_detailed_action_name()</span></code> but usually you will not need to. Most
APIs will provide both ways of specifying actions with targets.</p>
</section>
<section id="action-scopes">
<h2>Action scopes<a class="headerlink" href="#action-scopes" title="Permalink to this headline">#</a></h2>
<p>Actions are always scoped to a particular object on which they operate.</p>
<p>GTK allows you to create any number of scopes for actions, but will always have
two predefined scopes available:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">app</span></code>, for actions global to the application</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">win</span></code>, for actions tied to an application window</p></li>
</ul>
<p>Actions scoped to windows should be the actions that specifically impact that
window. These are actions like “fullscreen” and “close”, or in the case that a
window contains a document, “save” and “print”.</p>
<p>Actions that impact the application as a whole rather than one specific window
are scoped to the application. These are actions like “about” and “preferences”.</p>
<p>If a particular action is scoped to a window then it is scoped to a specific
window. Another way of saying this: if your application has a “fullscreen”
action that applies to windows and it has three windows, then it will have three
fullscreen actions: one for each window.</p>
<p>Having a separate action per-window allows for each window to have a separate
state for each instance of the action as well as being able to control the
enabled state of the action on a per-window basis.</p>
<p>Actions are added to their relevant scope (application or window) using the
<code class="docutils literal notranslate"><span class="pre">GActionMap</span></code> interface.</p>
</section>
<section id="gactionmap">
<h2><code class="docutils literal notranslate"><span class="pre">GActionMap</span></code><a class="headerlink" href="#gactionmap" title="Permalink to this headline">#</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">GActionMap</span></code> is an interface exposing a mapping of action names to actions. It
is implemented by <code class="docutils literal notranslate"><span class="pre">GtkApplication</span></code> and <code class="docutils literal notranslate"><span class="pre">GtkApplicationWindow</span></code>. Actions can
be added, removed, or looked up.</p>
<div class="sphinx-tabs docutils container">
<div aria-label="Tabbed content" class="closeable" role="tablist"><button aria-controls="panel-0-Qw==" aria-selected="true" class="sphinx-tabs-tab code-tab group-tab" id="tab-0-Qw==" name="Qw==" role="tab" tabindex="0">C</button><button aria-controls="panel-0-UHl0aG9u" aria-selected="false" class="sphinx-tabs-tab code-tab group-tab" id="tab-0-UHl0aG9u" name="UHl0aG9u" role="tab" tabindex="-1">Python</button><button aria-controls="panel-0-VmFsYQ==" aria-selected="false" class="sphinx-tabs-tab code-tab group-tab" id="tab-0-VmFsYQ==" name="VmFsYQ==" role="tab" tabindex="-1">Vala</button><button aria-controls="panel-0-SmF2YVNjcmlwdA==" aria-selected="false" class="sphinx-tabs-tab code-tab group-tab" id="tab-0-SmF2YVNjcmlwdA==" name="SmF2YVNjcmlwdA==" role="tab" tabindex="-1">JavaScript</button></div><div aria-labelledby="tab-0-Qw==" class="sphinx-tabs-panel code-tab group-tab" id="panel-0-Qw==" name="Qw==" role="tabpanel" tabindex="0"><div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="kt">void</span><span class="w"> </span><span class="nf">g_action_map_add_action</span><span class="w"> </span><span class="p">(</span><span class="n">GActionMap</span><span class="w"> </span><span class="o">*</span><span class="n">action_map</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="n">GAction</span><span class="w"> </span><span class="o">*</span><span class="n">action</span><span class="p">);</span><span class="w"></span>
<span class="kt">void</span><span class="w"> </span><span class="nf">g_action_map_remove_action</span><span class="w"> </span><span class="p">(</span><span class="n">GActionMap</span><span class="w"> </span><span class="o">*</span><span class="n">action_map</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">gchar</span><span class="w"> </span><span class="o">*</span><span class="n">action_name</span><span class="p">);</span><span class="w"></span>
<span class="n">GAction</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nf">g_action_map_lookup_action</span><span class="w"> </span><span class="p">(</span><span class="n">GActionMap</span><span class="w"> </span><span class="o">*</span><span class="n">action_map</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">gchar</span><span class="w"> </span><span class="o">*</span><span class="n">action_name</span><span class="p">);</span><span class="w"></span>
</pre></div>
</div>
</div><div aria-labelledby="tab-0-UHl0aG9u" class="sphinx-tabs-panel code-tab group-tab" hidden="true" id="panel-0-UHl0aG9u" name="UHl0aG9u" role="tabpanel" tabindex="0"><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">ActionMap</span><span class="p">:</span>
<span class="k">def</span> <span class="nf">add_action</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">action</span><span class="p">:</span> <span class="n">Gio</span><span class="o">.</span><span class="n">Action</span><span class="p">):</span>
<span class="k">pass</span>
<span class="k">def</span> <span class="nf">remove_action</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">action_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
<span class="k">pass</span>
<span class="k">def</span> <span class="nf">lookup_action</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">action_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Gio</span><span class="o">.</span><span class="n">Action</span><span class="p">:</span>
<span class="k">pass</span>
</pre></div>
</div>
</div><div aria-labelledby="tab-0-VmFsYQ==" class="sphinx-tabs-panel code-tab group-tab" hidden="true" id="panel-0-VmFsYQ==" name="VmFsYQ==" role="tabpanel" tabindex="0"><div class="highlight-vala notranslate"><div class="highlight"><pre><span></span><span class="kd">public</span><span class="w"> </span><span class="kd">interface</span><span class="w"> </span><span class="nc">ActionMap</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="n">add_action</span><span class="w"> </span><span class="p">(</span><span class="n">GLib</span><span class="p">.</span><span class="n">Action</span><span class="w"> </span><span class="n">action</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="n">remove_action</span><span class="w"> </span><span class="p">(</span><span class="kt">string</span><span class="w"> </span><span class="n">action_name</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="n">GLib</span><span class="p">.</span><span class="n">Action</span><span class="w"> </span><span class="n">lookup_action</span><span class="w"> </span><span class="p">(</span><span class="kt">string</span><span class="w"> </span><span class="n">action_name</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>
</div>
</div><div aria-labelledby="tab-0-SmF2YVNjcmlwdA==" class="sphinx-tabs-panel code-tab group-tab" hidden="true" id="panel-0-SmF2YVNjcmlwdA==" name="SmF2YVNjcmlwdA==" role="tabpanel" tabindex="0"><div class="highlight-js notranslate"><div class="highlight"><pre><span></span><span class="nx">action_map</span><span class="p">.</span><span class="nx">add_action</span><span class="p">(</span><span class="nx">action</span><span class="p">);</span><span class="w"> </span><span class="c1">// GLib.Action</span><span class="w"></span>
<span class="nx">action_map</span><span class="p">.</span><span class="nx">remove_action</span><span class="p">(</span><span class="nx">action_name</span><span class="p">);</span><span class="w"> </span><span class="c1">// string</span><span class="w"></span>
<span class="nx">action_map</span><span class="p">.</span><span class="nx">lookup_action</span><span class="p">(</span><span class="nx">action_name</span><span class="p">);</span><span class="w"> </span><span class="c1">// string</span><span class="w"></span>
</pre></div>
</div>
</div></div>
<p>If you want to insert several actions at the same time, it is typically faster
and easier to use <code class="docutils literal notranslate"><span class="pre">GActionEntry</span></code>.</p>
<p>When referring to actions on a <code class="docutils literal notranslate"><span class="pre">GActionMap</span></code> only the name of the action itself
is used (ie: “quit”, not “app.quit”). The “app.quit” form is only used when
referring to actions from places like a <code class="docutils literal notranslate"><span class="pre">GMenu</span></code> or <code class="docutils literal notranslate"><span class="pre">GtkActionable</span></code> widget
where the scope of the action is not already known. Because youre using the
<code class="docutils literal notranslate"><span class="pre">GtkApplication</span></code> or <code class="docutils literal notranslate"><span class="pre">GtkApplicationWindow</span></code> as the <code class="docutils literal notranslate"><span class="pre">GActionMap</span></code> it is clear
which object your action is scoped to, so the prefix is not needed.</p>
</section>
<section id="gsimpleaction-vs-gaction">
<h2><code class="docutils literal notranslate"><span class="pre">GSimpleAction</span></code> vs <code class="docutils literal notranslate"><span class="pre">GAction</span></code><a class="headerlink" href="#gsimpleaction-vs-gaction" title="Permalink to this headline">#</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">GAction</span></code> is an interface with several implementations. The one that you are
most likely to use directly is <code class="docutils literal notranslate"><span class="pre">GSimpleAction</span></code>.</p>
<p>A good way to think about the split between <code class="docutils literal notranslate"><span class="pre">GAction</span></code> and <code class="docutils literal notranslate"><span class="pre">GSimpleAction</span></code> is
that <code class="docutils literal notranslate"><span class="pre">GAction</span></code> is the “consumer interface” and <code class="docutils literal notranslate"><span class="pre">GSimpleAction</span></code> is the
“provider interface”. The <code class="docutils literal notranslate"><span class="pre">GAction</span></code> interface provides the functions that are
consumed by users/callers/displayers of the action (such as menus and widgets).
The <code class="docutils literal notranslate"><span class="pre">GSimpleAction</span></code> interface is only accessed by the code that provides the
implementation for the action itself.</p>
<p>Note that <code class="docutils literal notranslate"><span class="pre">GActionMap</span></code> takes a <code class="docutils literal notranslate"><span class="pre">GAction</span></code>. Your action will only be
“consumed” as a result of you putting it in a <code class="docutils literal notranslate"><span class="pre">GActionMap</span></code>.</p>
<p>Compare:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">GAction</span></code> has a function for checking if an action is enabled
(<code class="docutils literal notranslate"><span class="pre">g_action_get_enabled()</span></code>) but only the <code class="docutils literal notranslate"><span class="pre">GSimpleAction</span></code> API can enable or
disable an action (<code class="docutils literal notranslate"><span class="pre">g_simple_action_set_enabled()</span></code>).</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">GAction</span></code> has a function to query the state of the action
(<code class="docutils literal notranslate"><span class="pre">g_action_get_state()</span></code>) and request changes to it
(<code class="docutils literal notranslate"><span class="pre">g_action_change_state()</span></code>) but only <code class="docutils literal notranslate"><span class="pre">GSimpleAction</span></code> has the API to directly
set the state value (<code class="docutils literal notranslate"><span class="pre">g_simple_action_set_state()</span></code>).</p></li>
</ul>
<p>If you want to provide a custom <code class="docutils literal notranslate"><span class="pre">GAction</span></code> implementation then you can have
your own mechanism to control access to state setting and enabled. The GSettings
<code class="docutils literal notranslate"><span class="pre">GAction</span></code> implementation, for example, gets its state directly from the value
in GSettings and is enabled according to lockdown in effect on the key. It is
not possible to directly modify these values in any way (although it is possible
to indirectly affect the state by changing the value of the setting, if you have
permission to do so).</p>
</section>
<section id="using-gsimpleaction">
<h2>Using <code class="docutils literal notranslate"><span class="pre">GSimpleAction</span></code><a class="headerlink" href="#using-gsimpleaction" title="Permalink to this headline">#</a></h2>
<p>If you are implementing actions, probably you will do it with <code class="docutils literal notranslate"><span class="pre">GSimpleAction</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">GSimpleAction</span></code> has two interesting signals: <code class="docutils literal notranslate"><span class="pre">activate</span></code> and
<code class="docutils literal notranslate"><span class="pre">change-state</span></code>. These correspond directly to <code class="docutils literal notranslate"><span class="pre">g_action_activate()</span></code> and
<code class="docutils literal notranslate"><span class="pre">g_action_change_state()</span></code>. You will almost certainly need to connect a handler
to the activate signal in order to handle the action being activated. The signal
handler takes a GVariant parameter which is the parameter that was passed to
<code class="docutils literal notranslate"><span class="pre">g_action_activate()</span></code>.</p>
<p>If your action is stateful, you may also want to connect a change-state handler
to deal with state change requests. If your action is stateful and you do not
connect a handler for the change-state signal then the default is that all state
change requests will always change the state to the requested value. Even if you
always want the state to be set to the requested value, you will probably want
to connect a handler so that you can take some action in response to the state
being changed.</p>
<p>The default behaviour of setting the state in response to
<code class="docutils literal notranslate"><span class="pre">g_action_change_state()</span></code> is disabled when connecting a handler to
change-state. You therefore need to be sure to call
<code class="docutils literal notranslate"><span class="pre">g_simple_action_set_state()</span></code> from your handler if you actually want the state
to change.</p>
<p>A convenient way to bulk-create all the <code class="docutils literal notranslate"><span class="pre">GSimpleActions</span></code> you need to add to a
<code class="docutils literal notranslate"><span class="pre">GActionMap</span></code> is to use a <code class="docutils literal notranslate"><span class="pre">GActionEntry</span></code> array and
<code class="docutils literal notranslate"><span class="pre">g_action_map_add_action_entries()</span></code>:</p>
<div class="sphinx-tabs docutils container">
<div aria-label="Tabbed content" class="closeable" role="tablist"><button aria-controls="panel-1-Qw==" aria-selected="true" class="sphinx-tabs-tab code-tab group-tab" id="tab-1-Qw==" name="Qw==" role="tab" tabindex="0">C</button><button aria-controls="panel-1-VmFsYQ==" aria-selected="false" class="sphinx-tabs-tab code-tab group-tab" id="tab-1-VmFsYQ==" name="VmFsYQ==" role="tab" tabindex="-1">Vala</button></div><div aria-labelledby="tab-1-Qw==" class="sphinx-tabs-panel code-tab group-tab" id="panel-1-Qw==" name="Qw==" role="tabpanel" tabindex="0"><div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">static</span><span class="w"> </span><span class="n">GActionEntry</span><span class="w"> </span><span class="n">app_entries</span><span class="p">[]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s">&quot;preferences&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">preferences_activated</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="w"> </span><span class="p">},</span><span class="w"></span>
<span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s">&quot;quit&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">quit_activated</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">};</span><span class="w"></span>
<span class="k">static</span><span class="w"> </span><span class="kt">void</span><span class="w"></span>
<span class="nf">example_app_startup</span><span class="w"> </span><span class="p">(</span><span class="n">GApplication</span><span class="w"> </span><span class="o">*</span><span class="n">app</span><span class="p">)</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="c1">// ...</span>
<span class="w"> </span><span class="n">g_action_map_add_action_entries</span><span class="w"> </span><span class="p">(</span><span class="n">G_ACTION_MAP</span><span class="w"> </span><span class="p">(</span><span class="n">app</span><span class="p">),</span><span class="w"></span>
<span class="w"> </span><span class="n">app_entries</span><span class="p">,</span><span class="w"> </span><span class="n">G_N_ELEMENTS</span><span class="w"> </span><span class="p">(</span><span class="n">app_entries</span><span class="p">),</span><span class="w"></span>
<span class="w"> </span><span class="n">app</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="c1">// ...</span>
<span class="p">}</span><span class="w"></span>
</pre></div>
</div>
</div><div aria-labelledby="tab-1-VmFsYQ==" class="sphinx-tabs-panel code-tab group-tab" hidden="true" id="panel-1-VmFsYQ==" name="VmFsYQ==" role="tabpanel" tabindex="0"><div class="highlight-vala notranslate"><div class="highlight"><pre><span></span><span class="kd">public</span><span class="w"> </span><span class="kd">class</span><span class="w"> </span><span class="nc">Example</span><span class="p">.</span><span class="n">App</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="n">GLib</span><span class="p">.</span><span class="n">Application</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="kd">private</span><span class="w"> </span><span class="n">ActionEntry</span><span class="w"> </span><span class="n">app_entries</span><span class="p">[]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s">&quot;preferences&quot;</span><span class="p">,</span><span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="n">preferences_activated</span><span class="w"> </span><span class="p">},</span><span class="w"></span>
<span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s">&quot;quit&quot;</span><span class="p">,</span><span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="n">quit_activated</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w"> </span><span class="p">};</span><span class="w"></span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">override</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="n">startup</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="c1">// ...</span>
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="n">add_action_entries</span><span class="w"> </span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="n">app_entries</span><span class="p">,</span><span class="w"> </span><span class="k">this</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="c1">// ...</span>
<span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w"> </span><span class="kd">private</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="n">preferences_activated</span><span class="w"> </span><span class="p">(</span><span class="n">SimpleAction</span><span class="w"> </span><span class="n">action</span><span class="p">,</span><span class="w"> </span><span class="n">Variant</span><span class="o">?</span><span class="w"> </span><span class="n">parameter</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="c1">// ...</span>
<span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w"> </span><span class="kd">private</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="n">quit_activated</span><span class="w"> </span><span class="p">(</span><span class="n">SimpleAction</span><span class="w"> </span><span class="n">action</span><span class="p">,</span><span class="w"> </span><span class="n">Variant</span><span class="o">?</span><span class="w"> </span><span class="n">parameter</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="c1">// ...</span>
<span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>
</div>
</div></div>
</section>
<section id="other-kinds-of-actions">
<h2>Other kinds of actions<a class="headerlink" href="#other-kinds-of-actions" title="Permalink to this headline">#</a></h2>
<p>Besides <code class="docutils literal notranslate"><span class="pre">GSimpleAction</span></code>, GIO provides some other implementations of
<code class="docutils literal notranslate"><span class="pre">GAction</span></code>. One is <code class="docutils literal notranslate"><span class="pre">GSettingsAction</span></code>, which wraps a GSettings key with an
action that represents the value of the setting and lets you set the key to a
new value when activated. Another is <code class="docutils literal notranslate"><span class="pre">GPropertyAction</span></code>, which similarly
wraps a GObject property.</p>
<p>Both <code class="docutils literal notranslate"><span class="pre">GSettingsAction</span></code> and <code class="docutils literal notranslate"><span class="pre">GPropertyAction</span></code> implement toggle-on-activate
behaviour for boolean states - note that <code class="docutils literal notranslate"><span class="pre">GSimpleAction</span></code> does not, you have
to implement an activate handler yourself for that.</p>
</section>
<section id="adding-actions-to-your-gtkapplication">
<h2>Adding actions to your GtkApplication<a class="headerlink" href="#adding-actions-to-your-gtkapplication" title="Permalink to this headline">#</a></h2>
<p>You can add a <code class="docutils literal notranslate"><span class="pre">GAction</span></code> to anything implementing the <code class="docutils literal notranslate"><span class="pre">GActionMap</span></code> interface,
including <code class="docutils literal notranslate"><span class="pre">GtkApplication</span></code>. This is done with <code class="docutils literal notranslate"><span class="pre">g_action_map_add_action()</span></code>
and <code class="docutils literal notranslate"><span class="pre">g_action_map_add_action_entries()</span></code>.</p>
<p>Typically, you will want to do this during the startup phase of your
application.</p>
<p>Its possible to add or remove actions at any time, but doing it before startup
is wasteful in case the application is a remote instance (and will just exit
anyway). It is also possible to dynamically add and remove actions any time
after startup, when the application is running.</p>
</section>
<section id="adding-actions-to-your-gtkapplicationwindow">
<h2>Adding actions to your GtkApplicationWindow<a class="headerlink" href="#adding-actions-to-your-gtkapplicationwindow" title="Permalink to this headline">#</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">GtkApplicationWindow</span></code> also implements <code class="docutils literal notranslate"><span class="pre">GActionMap</span></code>. You will typically
want to add most actions to your window when it is constructed. It is possible
to add and remove actions at any time while the window exists.</p>
<p>For example:</p>
<div class="sphinx-tabs docutils container">
<div aria-label="Tabbed content" class="closeable" role="tablist"><button aria-controls="panel-2-Qw==" aria-selected="true" class="sphinx-tabs-tab code-tab group-tab" id="tab-2-Qw==" name="Qw==" role="tab" tabindex="0">C</button><button aria-controls="panel-2-UHl0aG9u" aria-selected="false" class="sphinx-tabs-tab code-tab group-tab" id="tab-2-UHl0aG9u" name="UHl0aG9u" role="tab" tabindex="-1">Python</button><button aria-controls="panel-2-VmFsYQ==" aria-selected="false" class="sphinx-tabs-tab code-tab group-tab" id="tab-2-VmFsYQ==" name="VmFsYQ==" role="tab" tabindex="-1">Vala</button><button aria-controls="panel-2-SmF2YVNjcmlwdA==" aria-selected="false" class="sphinx-tabs-tab code-tab group-tab" id="tab-2-SmF2YVNjcmlwdA==" name="SmF2YVNjcmlwdA==" role="tab" tabindex="-1">JavaScript</button></div><div aria-labelledby="tab-2-Qw==" class="sphinx-tabs-panel code-tab group-tab" id="panel-2-Qw==" name="Qw==" role="tabpanel" tabindex="0"><div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">static</span><span class="w"> </span><span class="kt">void</span><span class="w"></span>
<span class="nf">on_save_activate</span><span class="w"> </span><span class="p">(</span><span class="n">GAction</span><span class="w"> </span><span class="o">*</span><span class="n">action</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="n">GVariant</span><span class="w"> </span><span class="o">*</span><span class="n">param</span><span class="p">)</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="n">g_print</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;You are welcome&quot;</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">static</span><span class="w"> </span><span class="kt">void</span><span class="w"></span>
<span class="nf">on_app_activate</span><span class="w"> </span><span class="p">(</span><span class="n">GApplication</span><span class="w"> </span><span class="o">*</span><span class="n">app</span><span class="p">)</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="n">GtkWidget</span><span class="w"> </span><span class="o">*</span><span class="n">window</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">gtk_application_window_new</span><span class="w"> </span><span class="p">(</span><span class="n">GTK_APPLICATION</span><span class="w"> </span><span class="p">(</span><span class="n">app</span><span class="p">));</span><span class="w"></span>
<span class="w"> </span><span class="n">gtk_window_present</span><span class="w"> </span><span class="p">(</span><span class="n">GTK_WINDOW</span><span class="w"> </span><span class="p">(</span><span class="n">window</span><span class="p">));</span><span class="w"></span>
<span class="w"> </span><span class="n">GAction</span><span class="w"> </span><span class="o">*</span><span class="n">action</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">g_simple_action_new</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;save&quot;</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="n">g_signal_connect</span><span class="w"> </span><span class="p">(</span><span class="n">action</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;activate&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">G_CALLBACK</span><span class="w"> </span><span class="p">(</span><span class="n">on_save_activate</span><span class="p">),</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="n">g_action_map_add_action</span><span class="w"> </span><span class="p">(</span><span class="n">G_ACTION_MAP</span><span class="w"> </span><span class="p">(</span><span class="n">window</span><span class="p">),</span><span class="w"> </span><span class="n">action</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="n">GtkWidget</span><span class="w"> </span><span class="o">*</span><span class="n">button</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">gtk_button_new_with_label</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;Save&quot;</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="n">gtk_window_set_child</span><span class="w"> </span><span class="p">(</span><span class="n">GTK_WINDOW</span><span class="w"> </span><span class="p">(</span><span class="n">window</span><span class="p">),</span><span class="w"> </span><span class="n">button</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="n">gtk_actionable_set_action_name</span><span class="w"> </span><span class="p">(</span><span class="n">GTK_ACTIONABLE</span><span class="w"> </span><span class="p">(</span><span class="n">button</span><span class="p">),</span><span class="w"> </span><span class="s">&quot;win.save&quot;</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="c1">// ...</span>
<span class="kt">int</span><span class="w"></span>
<span class="nf">main</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">argc</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">argv</span><span class="p">[])</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="n">GtkApplication</span><span class="w"> </span><span class="o">*</span><span class="n">app</span><span class="w"> </span><span class="o">=</span><span class="w"></span>
<span class="w"> </span><span class="n">gtk_application_new</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;com.example.App&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">G_APPLICATION_FLAGS_NONE</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="n">g_signal_connect</span><span class="w"> </span><span class="p">(</span><span class="n">app</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;activate&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">G_CALLBACK</span><span class="w"> </span><span class="p">(</span><span class="n">on_app_activate</span><span class="p">),</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">g_application_run</span><span class="w"> </span><span class="p">(</span><span class="n">G_APPLICATION</span><span class="w"> </span><span class="p">(</span><span class="n">app</span><span class="p">),</span><span class="w"> </span><span class="n">argc</span><span class="p">,</span><span class="w"> </span><span class="n">argv</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>
</div>
</div><div aria-labelledby="tab-2-UHl0aG9u" class="sphinx-tabs-panel code-tab group-tab" hidden="true" id="panel-2-UHl0aG9u" name="UHl0aG9u" role="tabpanel" tabindex="0"><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">gi.repository</span> <span class="kn">import</span> <span class="n">Gio</span><span class="p">,</span> <span class="n">Gtk</span>
<span class="k">def</span> <span class="nf">on_save_activate</span><span class="p">(</span><span class="n">action</span><span class="p">,</span> <span class="n">_</span><span class="p">):</span>
<span class="nb">print</span> <span class="s2">&quot;You are welcome&quot;</span>
<span class="k">def</span> <span class="nf">on_app_activate</span><span class="p">(</span><span class="n">app</span><span class="p">):</span>
<span class="n">window</span> <span class="o">=</span> <span class="n">Gtk</span><span class="o">.</span><span class="n">ApplicationWindow</span><span class="p">(</span><span class="n">application</span><span class="o">=</span><span class="n">app</span><span class="p">)</span>
<span class="n">window</span><span class="o">.</span><span class="n">present</span><span class="p">()</span>
<span class="n">action</span> <span class="o">=</span> <span class="n">Gio</span><span class="o">.</span><span class="n">SimpleAction</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;save&quot;</span><span class="p">)</span>
<span class="n">action</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s2">&quot;activate&quot;</span><span class="p">,</span> <span class="n">on_save_activate</span><span class="p">)</span>
<span class="n">window</span><span class="o">.</span><span class="n">add_action</span><span class="p">(</span><span class="n">action</span><span class="p">)</span>
<span class="n">button</span> <span class="o">=</span> <span class="n">Gtk</span><span class="o">.</span><span class="n">Button</span><span class="p">(</span><span class="n">label</span><span class="o">=</span><span class="s2">&quot;Save&quot;</span><span class="p">)</span>
<span class="n">window</span><span class="o">.</span><span class="n">set_child</span><span class="p">(</span><span class="n">button</span><span class="p">)</span>
<span class="n">button</span><span class="o">.</span><span class="n">set_action_name</span><span class="p">(</span><span class="s2">&quot;win.save&quot;</span><span class="p">)</span>
<span class="n">app</span> <span class="o">=</span> <span class="n">Gtk</span><span class="o">.</span><span class="n">Application</span><span class="p">()</span>
<span class="n">app</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s2">&quot;activate&quot;</span><span class="p">,</span> <span class="n">on_app_activate</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">run</span><span class="p">([])</span>
</pre></div>
</div>
</div><div aria-labelledby="tab-2-VmFsYQ==" class="sphinx-tabs-panel code-tab group-tab" hidden="true" id="panel-2-VmFsYQ==" name="VmFsYQ==" role="tabpanel" tabindex="0"><div class="highlight-vala notranslate"><div class="highlight"><pre><span></span><span class="kd">public</span><span class="w"> </span><span class="kd">class</span><span class="w"> </span><span class="nc">Example</span><span class="p">.</span><span class="n">App</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="n">Gtk</span><span class="p">.</span><span class="n">Application</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="n">App</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="n">Object</span><span class="w"> </span><span class="p">(</span><span class="n">application_id</span><span class="o">:</span><span class="w"> </span><span class="s">&quot;com.example.App&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="n">flags</span><span class="o">:</span><span class="w"> </span><span class="n">ApplicationFlags</span><span class="p">.</span><span class="n">FLAGS_NONE</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">override</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="n">activate</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="kd">var</span><span class="w"> </span><span class="n">window</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Gtk</span><span class="p">.</span><span class="n">ApplicationWindow</span><span class="w"> </span><span class="p">(</span><span class="k">this</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="n">window</span><span class="p">.</span><span class="n">present</span><span class="w"> </span><span class="p">();</span><span class="w"></span>
<span class="w"> </span><span class="kd">var</span><span class="w"> </span><span class="n">action</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">SimpleAction</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;save&quot;</span><span class="p">,</span><span class="w"> </span><span class="nb">null</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="n">action</span><span class="p">.</span><span class="n">activate</span><span class="p">.</span><span class="n">connect</span><span class="w"> </span><span class="p">(()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="n">stdout</span><span class="p">.</span><span class="n">printf</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;You are welcome</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="p">});</span><span class="w"></span>
<span class="w"> </span><span class="n">window</span><span class="p">.</span><span class="n">add_action</span><span class="w"> </span><span class="p">(</span><span class="n">action</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="kd">var</span><span class="w"> </span><span class="n">button</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Gtk</span><span class="p">.</span><span class="n">Button</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;Save&quot;</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="n">window</span><span class="p">.</span><span class="n">child</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">button</span><span class="p">;</span><span class="w"></span>
<span class="w"> </span><span class="n">button</span><span class="p">.</span><span class="n">action_name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;win.save&quot;</span><span class="p">;</span><span class="w"></span>
<span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">main</span><span class="w"> </span><span class="p">(</span><span class="kt">string</span><span class="p">[]</span><span class="w"> </span><span class="n">args</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="kd">var</span><span class="w"> </span><span class="n">app</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Example</span><span class="p">.</span><span class="n">App</span><span class="w"> </span><span class="p">();</span><span class="w"></span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">app</span><span class="p">.</span><span class="n">run</span><span class="w"> </span><span class="p">(</span><span class="n">args</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>
</div>
</div><div aria-labelledby="tab-2-SmF2YVNjcmlwdA==" class="sphinx-tabs-panel code-tab group-tab" hidden="true" id="panel-2-SmF2YVNjcmlwdA==" name="SmF2YVNjcmlwdA==" role="tabpanel" tabindex="0"><div class="highlight-js notranslate"><div class="highlight"><pre><span></span><span class="k">import</span><span class="w"> </span><span class="nx">Gtk</span><span class="w"> </span><span class="kr">from</span><span class="w"> </span><span class="s2">&quot;gi://Gtk?version=4.0&quot;</span><span class="p">;</span><span class="w"></span>
<span class="k">import</span><span class="w"> </span><span class="nx">Adw</span><span class="w"> </span><span class="kr">from</span><span class="w"> </span><span class="s2">&quot;gi://Adw?version=1&quot;</span><span class="p">;</span><span class="w"></span>
<span class="k">import</span><span class="w"> </span><span class="nx">Gio</span><span class="w"> </span><span class="kr">from</span><span class="w"> </span><span class="s2">&quot;gi://Gio&quot;</span><span class="p">;</span><span class="w"></span>
<span class="kd">function</span><span class="w"> </span><span class="nx">on_save_activate</span><span class="p">(</span><span class="nx">action</span><span class="p">,</span><span class="w"> </span><span class="nx">param</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;You are welcome&quot;</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="kd">function</span><span class="w"> </span><span class="nx">on_app_activate</span><span class="p">(</span><span class="nx">app</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="kd">const</span><span class="w"> </span><span class="nb">window</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ow">new</span><span class="w"> </span><span class="nx">Gtk</span><span class="p">.</span><span class="nx">ApplicationWindow</span><span class="p">({</span><span class="w"> </span><span class="nx">application</span><span class="w"> </span><span class="p">});</span><span class="w"></span>
<span class="w"> </span><span class="nb">window</span><span class="p">.</span><span class="nx">present</span><span class="p">();</span><span class="w"></span>
<span class="w"> </span><span class="kd">const</span><span class="w"> </span><span class="nx">action</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ow">new</span><span class="w"> </span><span class="nx">Gio</span><span class="p">.</span><span class="nx">SimpleAction</span><span class="p">({</span><span class="w"> </span><span class="nx">name</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;save&quot;</span><span class="w"> </span><span class="p">});</span><span class="w"></span>
<span class="w"> </span><span class="nx">action</span><span class="p">.</span><span class="nx">connect</span><span class="p">(</span><span class="s2">&quot;activate&quot;</span><span class="p">,</span><span class="w"> </span><span class="nx">on_save_activate</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="nb">window</span><span class="p">.</span><span class="nx">add_action</span><span class="p">(</span><span class="nx">action</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="kd">const</span><span class="w"> </span><span class="nx">button</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ow">new</span><span class="w"> </span><span class="nx">Gtk</span><span class="p">.</span><span class="nx">Button</span><span class="p">({</span><span class="w"> </span><span class="nx">label</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;Save&quot;</span><span class="w"> </span><span class="p">});</span><span class="w"></span>
<span class="w"> </span><span class="nb">window</span><span class="p">.</span><span class="nx">set_child</span><span class="p">(</span><span class="nx">button</span><span class="p">);</span><span class="w"></span>
<span class="w"> </span><span class="nx">button</span><span class="p">.</span><span class="nx">set_action_name</span><span class="p">(</span><span class="s2">&quot;win.save&quot;</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="kd">const</span><span class="w"> </span><span class="nx">application</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ow">new</span><span class="w"> </span><span class="nx">Gtk</span><span class="p">.</span><span class="nx">Application</span><span class="p">();</span><span class="w"></span>
<span class="nx">application</span><span class="p">.</span><span class="nx">connect</span><span class="p">(</span><span class="s2">&quot;activate&quot;</span><span class="p">,</span><span class="w"> </span><span class="nx">on_app_activate</span><span class="p">);</span><span class="w"></span>
<span class="nx">application</span><span class="p">.</span><span class="nx">run</span><span class="p">([]);</span><span class="w"></span>
</pre></div>
</div>
</div></div>
</section>
<section id="accelerators-keybindings-for-actions">
<h2>Accelerators (keybindings) for actions<a class="headerlink" href="#accelerators-keybindings-for-actions" title="Permalink to this headline">#</a></h2>
<p>Use <code class="docutils literal notranslate"><span class="pre">gtk_application_add_accelerator()</span></code> inside your applications startup
implementation. For example:</p>
<div class="sphinx-tabs docutils container">
<div aria-label="Tabbed content" class="closeable" role="tablist"><button aria-controls="panel-3-Qw==" aria-selected="true" class="sphinx-tabs-tab code-tab group-tab" id="tab-3-Qw==" name="Qw==" role="tab" tabindex="0">C</button><button aria-controls="panel-3-UHl0aG9u" aria-selected="false" class="sphinx-tabs-tab code-tab group-tab" id="tab-3-UHl0aG9u" name="UHl0aG9u" role="tab" tabindex="-1">Python</button><button aria-controls="panel-3-VmFsYQ==" aria-selected="false" class="sphinx-tabs-tab code-tab group-tab" id="tab-3-VmFsYQ==" name="VmFsYQ==" role="tab" tabindex="-1">Vala</button><button aria-controls="panel-3-SmF2YVNjcmlwdA==" aria-selected="false" class="sphinx-tabs-tab code-tab group-tab" id="tab-3-SmF2YVNjcmlwdA==" name="SmF2YVNjcmlwdA==" role="tab" tabindex="-1">JavaScript</button></div><div aria-labelledby="tab-3-Qw==" class="sphinx-tabs-panel code-tab group-tab" id="panel-3-Qw==" name="Qw==" role="tabpanel" tabindex="0"><div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">gtk_application_set_accels_for_action</span><span class="w"> </span><span class="p">(</span><span class="n">app</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;win.new_tab&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="p">[])</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w"> </span><span class="s">&quot;&lt;Control&gt;&lt;Shift&gt;T&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="p">});</span><span class="w"></span>
</pre></div>
</div>
</div><div aria-labelledby="tab-3-UHl0aG9u" class="sphinx-tabs-panel code-tab group-tab" hidden="true" id="panel-3-UHl0aG9u" name="UHl0aG9u" role="tabpanel" tabindex="0"><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">set_accels_for_action</span><span class="p">(</span><span class="s2">&quot;win.new_tab&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;&lt;Control&gt;&lt;Shift&gt;T&quot;</span><span class="p">])</span>
</pre></div>
</div>
</div><div aria-labelledby="tab-3-VmFsYQ==" class="sphinx-tabs-panel code-tab group-tab" hidden="true" id="panel-3-VmFsYQ==" name="VmFsYQ==" role="tabpanel" tabindex="0"><div class="highlight-vala notranslate"><div class="highlight"><pre><span></span><span class="k">this</span><span class="p">.</span><span class="n">set_accels_for_action</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;win.new_tab&quot;</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s">&quot;&lt;Control&gt;&lt;Shift&gt;T&quot;</span><span class="p">,</span><span class="w"> </span><span class="nb">null</span><span class="w"> </span><span class="p">});</span><span class="w"></span>
</pre></div>
</div>
</div><div aria-labelledby="tab-3-SmF2YVNjcmlwdA==" class="sphinx-tabs-panel code-tab group-tab" hidden="true" id="panel-3-SmF2YVNjcmlwdA==" name="SmF2YVNjcmlwdA==" role="tabpanel" tabindex="0"><div class="highlight-js notranslate"><div class="highlight"><pre><span></span><span class="nx">app</span><span class="p">.</span><span class="nx">set_accels_for_action</span><span class="p">(</span><span class="s2">&quot;win.new_tab&quot;</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="s2">&quot;&lt;Control&gt;&lt;Shift&gt;T&quot;</span><span class="p">]);</span><span class="w"></span>
</pre></div>
</div>
</div></div>
</section>
<section id="what-can-be-done-with-actions">
<h2>What can be done with actions<a class="headerlink" href="#what-can-be-done-with-actions" title="Permalink to this headline">#</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">GActions</span></code> that you add to your application or window can be used in
several different ways.</p>
<ul class="simple">
<li><p>used with GMenu</p></li>
<li><p>used with GtkActionable widgets</p></li>
<li><p>used with shortcuts</p></li>
<li><p>remotely activated from a remote GApplication instance (only for
application actions)</p></li>
<li><p>listed as “Additional application actions” in desktop files (only for
application actions)</p></li>
<li><p>remotely activated from other D-Bus callers (such as Ubuntus HUD)</p></li>
<li><p>used with GNotification notifications (only for application actions)</p></li>
</ul>
</section>
</section>
</article>
<footer>
<div class="related-pages">
<a class="next-page" href="menus.html">
<div class="page-info">
<div class="context">
<span>Next</span>
</div>
<div class="title">Menus</div>
</div>
<svg><use href="#svg-arrow-right"></use></svg>
</a>
<a class="prev-page" href="deprecations.html">
<svg><use href="#svg-arrow-right"></use></svg>
<div class="page-info">
<div class="context">
<span>Previous</span>
</div>
<div class="title">Dealing With Deprecations</div>
</div>
</a>
</div>
</footer>
</div>
<aside class="toc-drawer">
<div class="toc-sticky toc-scroll">
<div class="toc-title-container">
<span class="toc-title">
Contents
</span>
</div>
<div class="toc-tree-container">
<div class="toc-tree">
<ul>
<li><a class="reference internal" href="#">Actions</a><ul>
<li><a class="reference internal" href="#what-it-is-what-it-isn-t">What it is, what it isnt</a></li>
<li><a class="reference internal" href="#action-state-and-parameters">Action state and parameters</a></li>
<li><a class="reference internal" href="#action-target-and-detailed-names">Action target and detailed names</a></li>
<li><a class="reference internal" href="#action-scopes">Action scopes</a></li>
<li><a class="reference internal" href="#gactionmap"><code class="docutils literal notranslate"><span class="pre">GActionMap</span></code></a></li>
<li><a class="reference internal" href="#gsimpleaction-vs-gaction"><code class="docutils literal notranslate"><span class="pre">GSimpleAction</span></code> vs <code class="docutils literal notranslate"><span class="pre">GAction</span></code></a></li>
<li><a class="reference internal" href="#using-gsimpleaction">Using <code class="docutils literal notranslate"><span class="pre">GSimpleAction</span></code></a></li>
<li><a class="reference internal" href="#other-kinds-of-actions">Other kinds of actions</a></li>
<li><a class="reference internal" href="#adding-actions-to-your-gtkapplication">Adding actions to your GtkApplication</a></li>
<li><a class="reference internal" href="#adding-actions-to-your-gtkapplicationwindow">Adding actions to your GtkApplicationWindow</a></li>
<li><a class="reference internal" href="#accelerators-keybindings-for-actions">Accelerators (keybindings) for actions</a></li>
<li><a class="reference internal" href="#what-can-be-done-with-actions">What can be done with actions</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</aside>
</main>
</div><script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/scripts/furo.js"></script>
<script src="../_static/tabs.js"></script>
</body>
</html>