Commit cbc20c4d authored by Matthias Clasen's avatar Matthias Clasen Committed by Matthias Clasen

Change the XML format: <Root> element is replaced by <ui>, <menu> element

2003-08-28  Matthias Clasen  <maclas@gmx.de>

	* gtk/gtkuimanager.c: Change the XML format:
	<Root> element is replaced by <ui>,
	<menu> element is replaced by <menubar>,
	<submenu> element is replaced by <menu>,
	<dockitem> element is replaced by <toolbar>,
	<popups> element is gone,
	verb attribute is replaced by action,
	name defaults to action or the element name.

	* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
	and GtkRadioActionEntry. GtkActionEntry is simplified by removing
	the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
	further simplified by removing the callback. The user_data can now be
	specified as an argument to gtk_action_group_add_actions(). There is
	a new method gtk_action_group_add_radio_actions(), which is similar
	to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
	and a callback parameter in addition to the user_data. The callback
	is connected to the ::changed signal of the first group member.
	There are _full() variants taking a GDestroyNotify of
	gtk_action_group_add_[radio_]actions().

	* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
	on every member of the radio group when the active member is changed.
	Add an integer property "value", and a getter for the value of "value"
	on the currently active group member.

	* tests/testactions.c:
	* tests/testmerge.c:
	* tests/merge-[123].ui:
	* demos/gtk-demo/appwindow.c: Adjust to these changes.

	* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
parent bebc663c
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 Anders Carlsson <andersca@gnome.org>
* demos/gtk-demo/appwindow.c (do_appwindow): Focus the
......
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 Anders Carlsson <andersca@gnome.org>
* demos/gtk-demo/appwindow.c (do_appwindow): Focus the
......
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 Anders Carlsson <andersca@gnome.org>
* demos/gtk-demo/appwindow.c (do_appwindow): Focus the
......
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 Anders Carlsson <andersca@gnome.org>
* demos/gtk-demo/appwindow.c (do_appwindow): Focus the
......
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 Anders Carlsson <andersca@gnome.org>
* demos/gtk-demo/appwindow.c (do_appwindow): Focus the
......
......@@ -32,106 +32,143 @@ activate_action (GtkAction *action)
gtk_widget_show (dialog);
}
static void
activate_radio_action (GtkAction *action, GtkRadioAction *current)
{
const gchar *name = gtk_action_get_name (GTK_ACTION (current));
const gchar *typename = G_OBJECT_TYPE_NAME (GTK_ACTION (current));
gboolean active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current));
gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
if (active)
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE,
"You activated radio action: \"%s\" of type \"%s\".\nCurrent value: %d",
name, typename, value);
/* Close dialog on user response */
g_signal_connect (dialog,
"response",
G_CALLBACK (gtk_widget_destroy),
NULL);
gtk_widget_show (dialog);
}
}
static GtkActionGroupEntry entries[] = {
{ "FileMenu", "_File" }, /* name, label */
{ "PreferencesMenu", "_Preferences" }, /* name, label */
{ "ColorMenu", "_Color" }, /* name, label */
{ "ShapeMenu", "_Shape" }, /* name, label */
{ "HelpMenu", "_Help" }, /* name, label */
{ "New", "_New", /* name, label */
GTK_STOCK_NEW, "<control>N", /* stock_id, accelerator */
"Create a new file", /* tooltip */
static GtkActionEntry entries[] = {
{ "FileMenu", NULL, "_File" }, /* name, stock id, label */
{ "PreferencesMenu", NULL, "_Preferences" }, /* name, stock id, label */
{ "ColorMenu", NULL, "_Color" }, /* name, stock id, label */
{ "ShapeMenu", NULL, "_Shape" }, /* name, stock id, label */
{ "HelpMenu", NULL, "_Help" }, /* name, stock id, label */
{ "New", GTK_STOCK_NEW, /* name, stock id */
"_New", "<control>N", /* label, accelerator */
"Create a new file", /* tooltip */
G_CALLBACK (activate_action) },
{ "Open", "_Open", /* name, label */
GTK_STOCK_OPEN, "<control>O", /* stock_id, accelerator */
"Open a file", /* tooltip */
{ "Open", GTK_STOCK_OPEN, /* name, stock id */
"_Open","<control>O", /* label, accelerator */
"Open a file", /* tooltip */
G_CALLBACK (activate_action) },
{ "Save", GTK_STOCK_SAVE, /* name, stock id */
"_Save","<control>S", /* label, accelerator */
"Save current file", /* tooltip */
G_CALLBACK (activate_action) },
{ "Save", "_Save", /* name, label */
GTK_STOCK_SAVE, "<control>S", /* stock_id, accelerator */
"Save current file", /* tooltip */
{ "SaveAs", GTK_STOCK_SAVE, /* name, stock id */
"Save _As...", NULL, /* label, accelerator */
"Save to a file", /* tooltip */
G_CALLBACK (activate_action) },
{ "SaveAs", "Save _As...", /* name, label */
GTK_STOCK_SAVE, NULL, /* stock_id, accelerator */
"Save to a file", /* tooltip */
{ "Quit", GTK_STOCK_QUIT, /* name, stock id */
"_Quit", "<control>Q", /* label, accelerator */
"Quit", /* tooltip */
G_CALLBACK (activate_action) },
{ "Quit", "_Quit", /* name, label */
GTK_STOCK_QUIT, "<control>Q", /* stock_id, accelerator */
"Quit", /* tooltip */
{ "About", NULL, /* name, stock id */
"_About", "<control>A", /* label, accelerator */
"About", /* tooltip */
G_CALLBACK (activate_action) },
{ "Red", "_Red", /* name, label */
NULL, "<control>R", /* stock_id, accelerator */
"Blood", /* tooltip */
G_CALLBACK (activate_action), NULL,
GTK_ACTION_RADIO }, /* entry type */
{ "Green", "_Green", /* name, label */
NULL, "<control>G", /* stock_id, accelerator */
"Grass", /* tooltip */
G_CALLBACK (activate_action), NULL,
GTK_ACTION_RADIO, "Red" }, /* entry type, radio group */
{ "Blue", "_Blue", /* name, label */
NULL, "<control>B", /* stock_id, accelerator */
"Sky", /* tooltip */
G_CALLBACK (activate_action), NULL,
GTK_ACTION_RADIO, "Red" }, /* entry type, radio group */
{ "Square", "_Square", /* name, label */
NULL, "<control>S", /* stock_id, accelerator */
"Square", /* tooltip */
G_CALLBACK (activate_action), NULL,
GTK_ACTION_RADIO }, /* entry type */
{ "Rectangle", "_Rectangle", /* name, label */
NULL, "<control>R", /* stock_id, accelerator */
"Rectangle", /* tooltip */
G_CALLBACK (activate_action), NULL,
GTK_ACTION_RADIO, "Square" }, /* entry type, radio group */
{ "Oval", "_Oval", /* name, label */
NULL, "<control>O", /* stock_id, accelerator */
"Egg", /* tooltip */
G_CALLBACK (activate_action), NULL,
GTK_ACTION_RADIO, "Square" }, /* entry type, radio group */
{ "About", "_About", /* name, label */
NULL, "<control>A", /* stock_id, accelerator */
"About", /* tooltip */
G_CALLBACK (activate_action) },
{ "Logo", NULL, /* name, label */
"demo-gtk-logo", NULL, /* stock_id, accelerator */
"GTK+", /* tooltip */
{ "Logo", "demo-gtk-logo", /* name, stock id */
NULL, NULL, /* label, accelerator */
"GTK+", /* tooltip */
G_CALLBACK (activate_action) },
};
static guint n_entries = G_N_ELEMENTS (entries);
enum {
COLOR_RED,
COLOR_GREEN,
COLOR_BLUE
};
static GtkRadioActionEntry color_entries[] = {
{ "Red", NULL, /* name, stock id */
"_Red", "<control>R", /* label, accelerator */
"Blood", COLOR_RED }, /* tooltip, value */
{ "Green", NULL, /* name, stock id */
"_Green", "<control>G", /* label, accelerator */
"Grass", COLOR_GREEN }, /* tooltip, value */
{ "Blue", NULL, /* name, stock id */
"_Blue", "<control>B", /* label, accelerator */
"Sky", COLOR_BLUE }, /* tooltip, value */
};
static guint n_color_entries = G_N_ELEMENTS (color_entries);
enum {
SHAPE_SQUARE,
SHAPE_RECTANGLE,
SHAPE_OVAL,
};
static GtkRadioActionEntry shape_entries[] = {
{ "Square", NULL, /* name, stock id */
"_Square", "<control>S", /* label, accelerator */
"Square", SHAPE_SQUARE }, /* tooltip, value */
{ "Rectangle", NULL, /* name, stock id */
"_Rectangle", "<control>R", /* label, accelerator */
"Rectangle", SHAPE_RECTANGLE }, /* tooltip, value */
{ "Oval", NULL, /* name, stock id */
"_Oval", "<control>O", /* label, accelerator */
"Egg", SHAPE_OVAL }, /* tooltip, value */
};
static guint n_shape_entries = G_N_ELEMENTS (shape_entries);
static const gchar *ui_info =
"<ui>"
" <menubar name='MenuBar'>"
" <menu name='FileMenu'>"
" <menuitem name='New'/>"
" <menuitem name='Open'/>"
" <menuitem name='Save'/>"
" <menuitem name='SaveAs'/>"
" <separator name='Sep1'/>"
" <menuitem name='Quit'/>"
" <menu action='FileMenu'>"
" <menuitem action='New'/>"
" <menuitem action='Open'/>"
" <menuitem action='Save'/>"
" <menuitem action='SaveAs'/>"
" <separator/>"
" <menuitem action='Quit'/>"
" </menu>"
" <menu name='PreferencesMenu'>"
" <menu name='ColorMenu'>"
" <menuitem name='Red'/>"
" <menuitem name='Green'/>"
" <menuitem name='Blue'/>"
" <menu action='PreferencesMenu'>"
" <menu action='ColorMenu'>"
" <menuitem action='Red'/>"
" <menuitem action='Green'/>"
" <menuitem action='Blue'/>"
" </menu>"
" <menu name='ShapeMenu'>"
" <menuitem name='Square'/>"
" <menuitem name='Rectangle'/>"
" <menuitem name='Oval'/>"
" <menu action='ShapeMenu'>"
" <menuitem action='Square'/>"
" <menuitem action='Rectangle'/>"
" <menuitem action='Oval'/>"
" </menu>"
" </menu>"
" <menu name='HelpMenu'>"
" <menuitem name='About'/>"
" <menu action='HelpMenu'>"
" <menuitem action='About'/>"
" </menu>"
" </menubar>"
" <toolbar name='ToolBar'>"
" <toolitem name='Open'/>"
" <toolitem name='Quit'/>"
" <separator name='Sep1'/>"
" <toolitem name='Logo'/>"
" <toolbar name='ToolBar'>"
" <toolitem action='Open'/>"
" <toolitem action='Quit'/>"
" <separator action='Sep1'/>"
" <toolitem action='Logo'/>"
" </toolbar>"
"</ui>";
......@@ -288,7 +325,11 @@ do_appwindow (void)
*/
action_group = gtk_action_group_new ("AppWindowActions");
gtk_action_group_add_actions (action_group, entries, n_entries);
gtk_action_group_add_actions (action_group, entries, n_entries, NULL);
gtk_action_group_add_radio_actions (action_group, color_entries, n_color_entries,
G_CALLBACK (activate_radio_action), NULL);
gtk_action_group_add_radio_actions (action_group, shape_entries, n_shape_entries,
G_CALLBACK (activate_radio_action), NULL);
action = gtk_action_group_get_action (action_group, "Red");
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
......
......@@ -280,6 +280,7 @@ gtk_action_group_list_actions (GtkActionGroup *action_group)
* @action_group: the action group
* @entries: an array of action descriptions
* @n_entries: the number of entries
* @user_data: data to pass to the action callbacks
*
* This is a convenience routine to create a number of actions and add
* them to the action group. Each member of the array describes an
......@@ -288,9 +289,36 @@ gtk_action_group_list_actions (GtkActionGroup *action_group)
* Since: 2.4
*/
void
gtk_action_group_add_actions (GtkActionGroup *action_group,
GtkActionGroupEntry *entries,
guint n_entries)
gtk_action_group_add_actions (GtkActionGroup *action_group,
GtkActionEntry *entries,
guint n_entries,
gpointer user_data)
{
gtk_action_group_add_actions_full (action_group,
entries, n_entries,
user_data, NULL);
}
/**
* gtk_action_group_add_actions_full:
* @action_group: the action group
* @entries: an array of action descriptions
* @n_entries: the number of entries
* @user_data: data to pass to the action callbacks
* @destroy: destroy notification callback for @user_data
*
* This variant of gtk_action_group_add_actions() adds a #GDestroyNotify
* callback for @user_data.
*
* Since: 2.4
*/
void
gtk_action_group_add_actions_full (GtkActionGroup *action_group,
GtkActionEntry *entries,
guint n_entries,
gpointer user_data,
GDestroyNotify destroy)
{
guint i;
GtkTranslateFunc translate_func;
......@@ -309,20 +337,10 @@ gtk_action_group_add_actions (GtkActionGroup *action_group,
gchar *label;
gchar *tooltip;
switch (entries[i].entry_type) {
case GTK_ACTION_NORMAL:
action_type = GTK_TYPE_ACTION;
break;
case GTK_ACTION_TOGGLE:
if (entries[i].is_toggle)
action_type = GTK_TYPE_TOGGLE_ACTION;
break;
case GTK_ACTION_RADIO:
action_type = GTK_TYPE_RADIO_ACTION;
break;
default:
g_warning ("unsupported action type");
else
action_type = GTK_TYPE_ACTION;
}
if (translate_func)
{
......@@ -342,27 +360,118 @@ gtk_action_group_add_actions (GtkActionGroup *action_group,
"stock_id", entries[i].stock_id,
NULL);
if (entries[i].entry_type == GTK_ACTION_RADIO &&
entries[i].extra_data != NULL)
if (entries[i].callback)
g_signal_connect_data (action, "activate",
entries[i].callback,
user_data, (GClosureNotify)destroy, 0);
/* set the accel path for the menu item */
accel_path = g_strconcat ("<Actions>/", action_group->private_data->name, "/",
entries[i].name, NULL);
if (entries[i].accelerator)
{
GtkAction *radio_action;
GSList *group;
radio_action =
gtk_action_group_get_action (GTK_ACTION_GROUP (action_group),
entries[i].extra_data);
if (radio_action)
{
group = gtk_radio_action_get_group (GTK_RADIO_ACTION (radio_action));
gtk_radio_action_set_group (GTK_RADIO_ACTION (action), group);
}
else
g_warning (G_STRLOC " could not look up `%s'", entries[i].extra_data);
guint accel_key = 0;
GdkModifierType accel_mods;
gtk_accelerator_parse (entries[i].accelerator, &accel_key,
&accel_mods);
if (accel_key)
gtk_accel_map_add_entry (accel_path, accel_key, accel_mods);
}
if (entries[i].callback)
g_signal_connect (action, "activate",
entries[i].callback, entries[i].user_data);
gtk_action_set_accel_path (action, accel_path);
g_free (accel_path);
gtk_action_group_add_action (action_group, action);
g_object_unref (action);
}
}
/**
* gtk_action_group_add_radio_actions:
* @action_group: the action group
* @entries: an array of radio action descriptions
* @n_entries: the number of entries
* @on_change: the callback to connect to the changed signal
* @user_data: data to pass to the action callbacks
*
* This is a convenience routine to create a group of radio actions and
* add them to the action group. Each member of the array describes a
* radio action to create.
*
* Since: 2.4
*
**/
void
gtk_action_group_add_radio_actions (GtkActionGroup *action_group,
GtkRadioActionEntry *entries,
guint n_entries,
GCallback on_change,
gpointer user_data)
{
gtk_action_group_add_radio_actions_full (action_group,
entries, n_entries,
on_change, user_data, NULL);
}
void
gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group,
GtkRadioActionEntry *entries,
guint n_entries,
GCallback on_change,
gpointer user_data,
GDestroyNotify destroy)
{
guint i;
GtkTranslateFunc translate_func;
gpointer translate_data;
GtkRadioAction *radio_action;
g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
translate_func = action_group->private_data->translate_func;
translate_data = action_group->private_data->translate_data;
for (i = 0; i < n_entries; i++)
{
GtkAction *action;
gchar *accel_path;
gchar *label;
gchar *tooltip;
if (translate_func)
{
label = translate_func (entries[i].label, translate_data);
tooltip = translate_func (entries[i].tooltip, translate_data);
}
else
{
label = entries[i].label;
tooltip = entries[i].tooltip;
}
action = g_object_new (GTK_TYPE_RADIO_ACTION,
"name", entries[i].name,
"label", label,
"tooltip", tooltip,
"stock_id", entries[i].stock_id,
"value", entries[i].value,
NULL);
if (i == 0)
{
radio_action = GTK_RADIO_ACTION (action);
if (on_change)
g_signal_connect_data (radio_action, "changed",
on_change, user_data,
(GClosureNotify)destroy, 0);
}
else
{
GSList *group = gtk_radio_action_get_group (radio_action);
gtk_radio_action_set_group (GTK_RADIO_ACTION (action), group);
}
/* set the accel path for the menu item */
accel_path = g_strconcat ("<Actions>/", action_group->private_data->name, "/",
......@@ -380,7 +489,7 @@ gtk_action_group_add_actions (GtkActionGroup *action_group,
gtk_action_set_accel_path (action, accel_path);
g_free (accel_path);
gtk_action_group_add_action (action_group, action);
g_object_unref (action);
}
......@@ -431,7 +540,7 @@ dgettext_swapped (const gchar *msgid,
* @domain: the translation domain to use for dgettext() calls
*
* Sets the translation domain and uses dgettext() for translating the
* @label and @tooltip of #GtkActionGroupEntry<!-- -->s added by
* @label and @tooltip of #GtkActionEntry<!-- -->s added by
* gtk_action_group_add_actions().
*
* If you're not using gettext() for localization, see
......
......@@ -43,7 +43,8 @@
typedef struct _GtkActionGroup GtkActionGroup;
typedef struct _GtkActionGroupPrivate GtkActionGroupPrivate;
typedef struct _GtkActionGroupClass GtkActionGroupClass;
typedef struct _GtkActionGroupEntry GtkActionGroupEntry;
typedef struct _GtkActionEntry GtkActionEntry;
typedef struct _GtkRadioActionEntry GtkRadioActionEntry;
struct _GtkActionGroup
{
......@@ -68,26 +69,28 @@ struct _GtkActionGroupClass
void (*_gtk_reserved4) (void);
};
typedef enum
{
GTK_ACTION_NORMAL,
GTK_ACTION_TOGGLE,
GTK_ACTION_RADIO
} GtkActionGroupEntryType;
struct _GtkActionGroupEntry
struct _GtkActionEntry
{
gchar *name;
gchar *label;
gchar *stock_id;
gchar *label;
gchar *accelerator;
gchar *tooltip;
GCallback callback;
gpointer user_data;
GtkActionGroupEntryType entry_type;
gchar *extra_data;
gboolean is_toggle;
};
struct _GtkRadioActionEntry
{
gchar *name;
gchar *stock_id;
gchar *label;
gchar *accelerator;
gchar *tooltip;
gint value;
};
GType gtk_action_group_get_type (void);
......@@ -103,9 +106,26 @@ void gtk_action_group_add_action (GtkActionGroup *action_grou
void gtk_action_group_remove_action (GtkActionGroup *action_group,
GtkAction *action);
void gtk_action_group_add_actions (GtkActionGroup *action_group,
GtkActionGroupEntry *entries,
guint n_entries);
void gtk_action_group_add_actions (GtkActionGroup *action_group,
GtkActionEntry *entries,
guint n_entries,
gpointer user_data);
void gtk_action_group_add_radio_actions (GtkActionGroup *action_group,
GtkRadioActionEntry *entries,
guint n_entries,
GCallback on_change,
gpointer user_data);
void gtk_action_group_add_actions_full (GtkActionGroup *action_group,
GtkActionEntry *entries,
guint n_entries,
gpointer user_data,
GDestroyNotify destroy);
void gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group,
GtkRadioActionEntry *entries,
guint n_entries,
GCallback on_change,
gpointer user_data,
GDestroyNotify destroy);
void gtk_action_group_set_translate_func (GtkActionGroup *action_group,
GtkTranslateFunc func,
......
......@@ -31,17 +31,43 @@
#include <config.h>
#include "gtkradioaction.h"
#include "gtkradiomenuitem.h"
#include "gtktoggleactionprivate.h"
#include "gtkintl.h"