forked from AuroraMiddleware/gtk
example: Port to gtk_application_set_accels_for_action
Instead of hardcoding an accelerator in the ui file, use gtk_application_set_accels_for_action.
This commit is contained in:
parent
25ce82d5b3
commit
b718b95aab
@ -605,12 +605,16 @@ example_app_startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
|
||||
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
|
||||
"app.quit",
|
||||
quit_accels);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
@ -633,7 +637,7 @@ example_app_class_init (ExampleAppClass *class)
|
||||
<para>Our preferences menu item does not do anything yet,
|
||||
but the Quit menu item is fully functional. Note that it
|
||||
can also be activated by the usual Ctrl-Q shortcut. The
|
||||
shortcut was specified in the ui file.
|
||||
shortcut was added with gtk_application_set_accels_for_action().
|
||||
</para>
|
||||
|
||||
<para>The application menu looks like this:</para>
|
||||
|
@ -12,7 +12,6 @@
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Quit</attribute>
|
||||
<attribute name="action">app.quit</attribute>
|
||||
<attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
|
||||
</item>
|
||||
</section>
|
||||
</menu>
|
||||
|
@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
|
||||
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
|
||||
"app.quit",
|
||||
quit_accels);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
|
@ -12,7 +12,6 @@
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Quit</attribute>
|
||||
<attribute name="action">app.quit</attribute>
|
||||
<attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
|
||||
</item>
|
||||
</section>
|
||||
</menu>
|
||||
|
@ -46,12 +46,16 @@ example_app_startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
|
||||
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
|
||||
"app.quit",
|
||||
quit_accels);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
|
@ -12,7 +12,6 @@
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Quit</attribute>
|
||||
<attribute name="action">app.quit</attribute>
|
||||
<attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
|
||||
</item>
|
||||
</section>
|
||||
</menu>
|
||||
|
@ -46,12 +46,16 @@ example_app_startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
|
||||
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
|
||||
"app.quit",
|
||||
quit_accels);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
|
@ -12,7 +12,6 @@
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Quit</attribute>
|
||||
<attribute name="action">app.quit</attribute>
|
||||
<attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
|
||||
</item>
|
||||
</section>
|
||||
</menu>
|
||||
|
@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
|
||||
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
|
||||
"app.quit",
|
||||
quit_accels);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
|
@ -12,7 +12,6 @@
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Quit</attribute>
|
||||
<attribute name="action">app.quit</attribute>
|
||||
<attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
|
||||
</item>
|
||||
</section>
|
||||
</menu>
|
||||
|
@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
|
||||
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
|
||||
"app.quit",
|
||||
quit_accels);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
|
@ -12,7 +12,6 @@
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Quit</attribute>
|
||||
<attribute name="action">app.quit</attribute>
|
||||
<attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
|
||||
</item>
|
||||
</section>
|
||||
</menu>
|
||||
|
@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
|
||||
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
|
||||
"app.quit",
|
||||
quit_accels);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
|
@ -12,7 +12,6 @@
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Quit</attribute>
|
||||
<attribute name="action">app.quit</attribute>
|
||||
<attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
|
||||
</item>
|
||||
</section>
|
||||
</menu>
|
||||
|
@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
|
||||
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
|
||||
"app.quit",
|
||||
quit_accels);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
|
Loading…
Reference in New Issue
Block a user