CtkActionGroup

CtkActionGroup — A group of actions

Functions

Properties

CtkAccelGroup * accel-group Read / Write
char * name Read / Write / Construct Only
gboolean sensitive Read / Write
gboolean visible Read / Write

Signals

void connect-proxy  
void disconnect-proxy  
void post-activate  
void pre-activate  

Types and Values

Object Hierarchy

    GObject
    ╰── CtkActionGroup

Implemented Interfaces

CtkActionGroup implements CtkBuildable.

Includes

#include <ctk/ctk.h>

Description

Actions are organised into groups. An action group is essentially a map from names to CtkAction objects.

All actions that would make sense to use in a particular context should be in a single group. Multiple action groups may be used for a particular user interface. In fact, it is expected that most nontrivial applications will make use of multiple groups. For example, in an application that can edit multiple documents, one group holding global actions (e.g. quit, about, new), and one group per document holding actions that act on that document (eg. save, cut/copy/paste, etc). Each window’s menus would be constructed from a combination of two action groups.

Accelerators

Accelerators are handled by the CTK+ accelerator map. All actions are assigned an accelerator path (which normally has the form <Actions>/group-name/action-name) and a shortcut is associated with this accelerator path. All menuitems and toolitems take on this accelerator path. The CTK+ accelerator map code makes sure that the correct shortcut is displayed next to the menu item.

CtkActionGroup as CtkBuildable

The CtkActionGroup implementation of the CtkBuildable interface accepts CtkAction objects as <child> elements in UI definitions.

Note that it is probably more common to define actions and action groups in the code, since they are directly related to what the code can do.

The CtkActionGroup implementation of the CtkBuildable interface supports a custom <accelerator> element, which has attributes named “key“ and “modifiers“ and allows to specify accelerators. This is similar to the <accelerator> element of CtkWidget, the main difference is that it doesn’t allow you to specify a signal.

A CtkDialog UI definition fragment.

1
2
3
4
5
6
7
8
9
10
<object class="CtkActionGroup" id="actiongroup">
  <child>
      <object class="CtkAction" id="About">
          <property name="name">About</property>
          <property name="stock_id">ctk-about</property>
          <signal handler="about_activate" name="activate"/>
      </object>
      <accelerator key="F1" modifiers="CDK_CONTROL_MASK | CDK_SHIFT_MASK"/>
  </child>
</object>

Functions

ctk_action_group_new ()

CtkActionGroup *
ctk_action_group_new (const gchar *name);

Creates a new CtkActionGroup object. The name of the action group is used when associating keybindings with the actions.

Parameters

name

the name of the action group.

 

Returns

the new CtkActionGroup

Since: 2.4


ctk_action_group_get_name ()

const gchar *
ctk_action_group_get_name (CtkActionGroup *action_group);

Gets the name of the action group.

Parameters

action_group

the action group

 

Returns

the name of the action group.

Since: 2.4


ctk_action_group_get_sensitive ()

gboolean
ctk_action_group_get_sensitive (CtkActionGroup *action_group);

Returns TRUE if the group is sensitive. The constituent actions can only be logically sensitive (see ctk_action_is_sensitive()) if they are sensitive (see ctk_action_get_sensitive()) and their group is sensitive.

Parameters

action_group

the action group

 

Returns

TRUE if the group is sensitive.

Since: 2.4


ctk_action_group_set_sensitive ()

void
ctk_action_group_set_sensitive (CtkActionGroup *action_group,
                                gboolean sensitive);

Changes the sensitivity of action_group

Parameters

action_group

the action group

 

sensitive

new sensitivity

 

Since: 2.4


ctk_action_group_get_visible ()

gboolean
ctk_action_group_get_visible (CtkActionGroup *action_group);

Returns TRUE if the group is visible. The constituent actions can only be logically visible (see ctk_action_is_visible()) if they are visible (see ctk_action_get_visible()) and their group is visible.

Parameters

action_group

the action group

 

Returns

TRUE if the group is visible.

Since: 2.4


ctk_action_group_set_visible ()

void
ctk_action_group_set_visible (CtkActionGroup *action_group,
                              gboolean visible);

Changes the visible of action_group .

Parameters

action_group

the action group

 

visible

new visiblity

 

Since: 2.4


ctk_action_group_get_accel_group ()

CtkAccelGroup *
ctk_action_group_get_accel_group (CtkActionGroup *action_group);

Gets the accelerator group.

Parameters

action_group

a CtkActionGroup

 

Returns

the accelerator group associated with this action group or NULL if there is none.

[transfer none]

Since: 3.6


ctk_action_group_set_accel_group ()

void
ctk_action_group_set_accel_group (CtkActionGroup *action_group,
                                  CtkAccelGroup *accel_group);

Sets the accelerator group to be used by every action in this group.

Parameters

action_group

a CtkActionGroup

 

accel_group

a CtkAccelGroup to set or NULL.

[allow-none]

Since: 3.6


ctk_action_group_get_action ()

CtkAction *
ctk_action_group_get_action (CtkActionGroup *action_group,
                             const gchar *action_name);

Looks up an action in the action group by name.

Parameters

action_group

the action group

 

action_name

the name of the action

 

Returns

the action, or NULL if no action by that name exists.

[transfer none]

Since: 2.4


ctk_action_group_list_actions ()

GList *
ctk_action_group_list_actions (CtkActionGroup *action_group);

Lists the actions in the action group.

Parameters

action_group

the action group

 

Returns

an allocated list of the action objects in the action group.

[element-type CtkAction][transfer container]

Since: 2.4


ctk_action_group_add_action ()

void
ctk_action_group_add_action (CtkActionGroup *action_group,
                             CtkAction *action);

Adds an action object to the action group. Note that this function does not set up the accel path of the action, which can lead to problems if a user tries to modify the accelerator of a menuitem associated with the action. Therefore you must either set the accel path yourself with ctk_action_set_accel_path(), or use ctk_action_group_add_action_with_accel (..., NULL).

Parameters

action_group

the action group

 

action

an action

 

Since: 2.4


ctk_action_group_add_action_with_accel ()

void
ctk_action_group_add_action_with_accel
                               (CtkActionGroup *action_group,
                                CtkAction *action,
                                const gchar *accelerator);

Adds an action object to the action group and sets up the accelerator.

If accelerator is NULL, attempts to use the accelerator associated with the stock_id of the action.

Accel paths are set to <Actions>/group-name/action-name.

Parameters

action_group

the action group

 

action

the action to add

 

accelerator

the accelerator for the action, in the format understood by ctk_accelerator_parse(), or "" for no accelerator, or NULL to use the stock accelerator.

[allow-none]

Since: 2.4


ctk_action_group_remove_action ()

void
ctk_action_group_remove_action (CtkActionGroup *action_group,
                                CtkAction *action);

Removes an action object from the action group.

Parameters

action_group

the action group

 

action

an action

 

Since: 2.4


ctk_action_group_add_actions ()

void
ctk_action_group_add_actions (CtkActionGroup *action_group,
                              const CtkActionEntry *entries,
                              guint n_entries,
                              gpointer user_data);

This is a convenience function to create a number of actions and add them to the action group.

The “activate” signals of the actions are connected to the callbacks and their accel paths are set to <Actions>/group-name/action-name.

[skip]

Parameters

action_group

the action group

 

entries

an array of action descriptions.

[array length=n_entries]

n_entries

the number of entries

 

user_data

data to pass to the action callbacks

 

Since: 2.4


ctk_action_group_add_actions_full ()

void
ctk_action_group_add_actions_full (CtkActionGroup *action_group,
                                   const CtkActionEntry *entries,
                                   guint n_entries,
                                   gpointer user_data,
                                   GDestroyNotify destroy);

This variant of ctk_action_group_add_actions() adds a GDestroyNotify callback for user_data .

[skip]

Parameters

action_group

the action group

 

entries

an array of action descriptions.

[array length=n_entries]

n_entries

the number of entries

 

user_data

data to pass to the action callbacks

 

destroy

destroy notification callback for user_data .

[nullable]

Since: 2.4


ctk_action_group_add_toggle_actions ()

void
ctk_action_group_add_toggle_actions (CtkActionGroup *action_group,
                                     const CtkToggleActionEntry *entries,
                                     guint n_entries,
                                     gpointer user_data);

This is a convenience function to create a number of toggle actions and add them to the action group.

The “activate” signals of the actions are connected to the callbacks and their accel paths are set to <Actions>/group-name/action-name.

[skip]

Parameters

action_group

the action group

 

entries

an array of toggle action descriptions.

[array length=n_entries]

n_entries

the number of entries

 

user_data

data to pass to the action callbacks

 

Since: 2.4


ctk_action_group_add_toggle_actions_full ()

void
ctk_action_group_add_toggle_actions_full
                               (CtkActionGroup *action_group,
                                const CtkToggleActionEntry *entries,
                                guint n_entries,
                                gpointer user_data,
                                GDestroyNotify destroy);

This variant of ctk_action_group_add_toggle_actions() adds a GDestroyNotify callback for user_data .

[skip]

Parameters

action_group

the action group

 

entries

an array of toggle action descriptions.

[array length=n_entries]

n_entries

the number of entries

 

user_data

data to pass to the action callbacks

 

destroy

destroy notification callback for user_data .

[nullable]

Since: 2.4


ctk_action_group_add_radio_actions ()

void
ctk_action_group_add_radio_actions (CtkActionGroup *action_group,
                                    const CtkRadioActionEntry *entries,
                                    guint n_entries,
                                    gint value,
                                    GCallback on_change,
                                    gpointer user_data);

This is a convenience routine to create a group of radio actions and add them to the action group.

The “changed” signal of the first radio action is connected to the on_change callback and the accel paths of the actions are set to <Actions>/group-name/action-name.

[skip]

Parameters

action_group

the action group

 

entries

an array of radio action descriptions.

[array length=n_entries]

n_entries

the number of entries

 

value

the value of the action to activate initially, or -1 if no action should be activated

 

on_change

the callback to connect to the changed signal

 

user_data

data to pass to the action callbacks

 

Since: 2.4


ctk_action_group_add_radio_actions_full ()

void
ctk_action_group_add_radio_actions_full
                               (CtkActionGroup *action_group,
                                const CtkRadioActionEntry *entries,
                                guint n_entries,
                                gint value,
                                GCallback on_change,
                                gpointer user_data,
                                GDestroyNotify destroy);

This variant of ctk_action_group_add_radio_actions() adds a GDestroyNotify callback for user_data .

[skip]

Parameters

action_group

the action group

 

entries

an array of radio action descriptions.

[array length=n_entries]

n_entries

the number of entries

 

value

the value of the action to activate initially, or -1 if no action should be activated

 

on_change

the callback to connect to the changed signal

 

user_data

data to pass to the action callbacks

 

destroy

destroy notification callback for user_data

 

Since: 2.4


CtkTranslateFunc ()

gchar *
(*CtkTranslateFunc) (const gchar *path,
                     gpointer func_data);

The function used to translate messages in e.g. CtkIconFactory and CtkActionGroup.

Parameters

path

The id of the message. In CtkActionGroup this will be a label or tooltip from a CtkActionEntry.

 

func_data

user data passed in when registering the function.

[closure]

Returns

the translated message


ctk_action_group_set_translate_func ()

void
ctk_action_group_set_translate_func (CtkActionGroup *action_group,
                                     CtkTranslateFunc func,
                                     gpointer data,
                                     GDestroyNotify notify);

Sets a function to be used for translating the label and tooltip of CtkActionEntrys added by ctk_action_group_add_actions().

If you’re using gettext(), it is enough to set the translation domain with ctk_action_group_set_translation_domain().

Parameters

action_group

a CtkActionGroup

 

func

a CtkTranslateFunc

 

data

data to be passed to func and notify

 

notify

a GDestroyNotify function to be called when action_group is destroyed and when the translation function is changed again

 

Since: 2.4


ctk_action_group_set_translation_domain ()

void
ctk_action_group_set_translation_domain
                               (CtkActionGroup *action_group,
                                const gchar *domain);

Sets the translation domain and uses g_dgettext() for translating the label and tooltip of CtkActionEntrys added by ctk_action_group_add_actions().

If you’re not using gettext() for localization, see ctk_action_group_set_translate_func().

Parameters

action_group

a CtkActionGroup

 

domain

the translation domain to use for g_dgettext() calls, or NULL to use the domain set with textdomain().

[allow-none]

Since: 2.4


ctk_action_group_translate_string ()

const gchar *
ctk_action_group_translate_string (CtkActionGroup *action_group,
                                   const gchar *string);

Translates a string using the function set with ctk_action_group_set_translate_func(). This is mainly intended for language bindings.

Parameters

action_group

a CtkActionGroup

 

string

a string

 

Returns

the translation of string

Since: 2.6

Types and Values

struct CtkActionGroup

struct CtkActionGroup;

struct CtkActionGroupClass

struct CtkActionGroupClass {
  GObjectClass parent_class;

  CtkAction *(* get_action) (CtkActionGroup *action_group,
                             const gchar    *action_name);
};

Members

get_action ()

Looks up an action in the action group by name.

 

struct CtkActionEntry

struct CtkActionEntry {
  const gchar     *name;
  const gchar     *stock_id;
  const gchar     *label;
  const gchar     *accelerator;
  const gchar     *tooltip;
  GCallback  callback;
};

CtkActionEntry structs are used with ctk_action_group_add_actions() to construct actions.

Members

const gchar *name;

The name of the action.

 

const gchar *stock_id;

The stock id for the action, or the name of an icon from the icon theme.

 

const gchar *label;

The label for the action. This field should typically be marked for translation, see ctk_action_group_set_translation_domain(). If label is NULL, the label of the stock item with id stock_id is used.

 

const gchar *accelerator;

The accelerator for the action, in the format understood by ctk_accelerator_parse().

 

const gchar *tooltip;

The tooltip for the action. This field should typically be marked for translation, see ctk_action_group_set_translation_domain().

 

GCallback callback;

The function to call when the action is activated.

 

struct CtkToggleActionEntry

struct CtkToggleActionEntry {
  const gchar     *name;
  const gchar     *stock_id;
  const gchar     *label;
  const gchar     *accelerator;
  const gchar     *tooltip;
  GCallback  callback;
  gboolean   is_active;
};

CtkToggleActionEntry structs are used with ctk_action_group_add_toggle_actions() to construct toggle actions.

Members

const gchar *name;

The name of the action.

 

const gchar *stock_id;

The stock id for the action, or the name of an icon from the icon theme.

 

const gchar *label;

The label for the action. This field should typically be marked for translation, see ctk_action_group_set_translation_domain().

 

const gchar *accelerator;

The accelerator for the action, in the format understood by ctk_accelerator_parse().

 

const gchar *tooltip;

The tooltip for the action. This field should typically be marked for translation, see ctk_action_group_set_translation_domain().

 

GCallback callback;

The function to call when the action is activated.

 

gboolean is_active;

The initial state of the toggle action.

 

struct CtkRadioActionEntry

struct CtkRadioActionEntry {
  const gchar *name;
  const gchar *stock_id;
  const gchar *label;
  const gchar *accelerator;
  const gchar *tooltip;
  gint   value;

};

CtkRadioActionEntry structs are used with ctk_action_group_add_radio_actions() to construct groups of radio actions.

Members

const gchar *name;

The name of the action.

 

const gchar *stock_id;

The stock id for the action, or the name of an icon from the icon theme.

 

const gchar *label;

The label for the action. This field should typically be marked for translation, see ctk_action_group_set_translation_domain().

 

const gchar *accelerator;

The accelerator for the action, in the format understood by ctk_accelerator_parse().

 

const gchar *tooltip;

The tooltip for the action. This field should typically be marked for translation, see ctk_action_group_set_translation_domain().

 

gint value;

The value to set on the radio action. See ctk_radio_action_get_current_value().

 

Property Details

The “accel-group” property

  “accel-group”              CtkAccelGroup *

The accelerator group the actions of this group should use.

Owner: CtkActionGroup

Flags: Read / Write


The “name” property

  “name”                     char *

A name for the action.

Owner: CtkActionGroup

Flags: Read / Write / Construct Only

Default value: NULL


The “sensitive” property

  “sensitive”                gboolean

Whether the action group is enabled.

Owner: CtkActionGroup

Flags: Read / Write

Default value: TRUE


The “visible” property

  “visible”                  gboolean

Whether the action group is visible.

Owner: CtkActionGroup

Flags: Read / Write

Default value: TRUE

Signal Details

The “connect-proxy” signal

void
user_function (CtkActionGroup *action_group,
               CtkAction      *action,
               CtkWidget      *proxy,
               gpointer        user_data)

The ::connect-proxy signal is emitted after connecting a proxy to an action in the group. Note that the proxy may have been connected to a different action before.

This is intended for simple customizations for which a custom action class would be too clumsy, e.g. showing tooltips for menuitems in the statusbar.

CtkUIManager proxies the signal and provides global notification just before any action is connected to a proxy, which is probably more convenient to use.

Parameters

action_group

the group

 

action

the action

 

proxy

the proxy

 

user_data

user data set when the signal handler was connected.

 

Since: 2.4


The “disconnect-proxy” signal

void
user_function (CtkActionGroup *action_group,
               CtkAction      *action,
               CtkWidget      *proxy,
               gpointer        user_data)

The ::disconnect-proxy signal is emitted after disconnecting a proxy from an action in the group.

CtkUIManager proxies the signal and provides global notification just before any action is connected to a proxy, which is probably more convenient to use.

Parameters

action_group

the group

 

action

the action

 

proxy

the proxy

 

user_data

user data set when the signal handler was connected.

 

Since: 2.4


The “post-activate” signal

void
user_function (CtkActionGroup *action_group,
               CtkAction      *action,
               gpointer        user_data)

The ::post-activate signal is emitted just after the action in the action_group is activated

This is intended for CtkUIManager to proxy the signal and provide global notification just after any action is activated.

Parameters

action_group

the group

 

action

the action

 

user_data

user data set when the signal handler was connected.

 

Since: 2.4


The “pre-activate” signal

void
user_function (CtkActionGroup *action_group,
               CtkAction      *action,
               gpointer        user_data)

The ::pre-activate signal is emitted just before the action in the action_group is activated

This is intended for CtkUIManager to proxy the signal and provide global notification just before any action is activated.

Parameters

action_group

the group

 

action

the action

 

user_data

user data set when the signal handler was connected.

 

Since: 2.4