[gtk/new-style-menu: 2/2] widget-factory: Add another popover menu example
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/new-style-menu: 2/2] widget-factory: Add another popover menu example
- Date: Wed, 5 Jun 2019 20:09:16 +0000 (UTC)
commit 39bc6f4b91bfac465e77c6148e4b107f83ce2907
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Jun 5 19:36:35 2019 +0000
widget-factory: Add another popover menu example
This one is taken from
https://gitlab.gnome.org/GNOME/gtk/issues/1824
demos/widget-factory/widget-factory.c | 53 ++++++++-
demos/widget-factory/widget-factory.ui | 195 ++++++++++++++++++++++++++++++++-
2 files changed, 245 insertions(+), 3 deletions(-)
---
diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c
index af4a03f733..2ccc659c1b 100644
--- a/demos/widget-factory/widget-factory.c
+++ b/demos/widget-factory/widget-factory.c
@@ -118,6 +118,8 @@ activate_delete (GSimpleAction *action,
GtkWidget *window = user_data;
GtkWidget *infobar;
+ g_print ("Activate action delete\n");
+
if (!on_page (2))
return;
@@ -1634,6 +1636,7 @@ activate (GApplication *app)
} accels[] = {
{ "app.about", { "F1", NULL } },
{ "app.quit", { "<Primary>q", NULL } },
+ { "app.open-in", { "<Primary>n", NULL } },
{ "win.dark", { "<Primary>d", NULL } },
{ "win.search", { "<Primary>s", NULL } },
{ "win.delete", { "Delete", NULL } },
@@ -1921,6 +1924,41 @@ local_options (GApplication *app,
return -1;
}
+static void
+activate_action (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ g_print ("Activate action %s\n", g_action_get_name (G_ACTION (action)));
+}
+
+static void
+select_action (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ g_print ("Set action %s to %s\n",
+ g_action_get_name (G_ACTION (action)),
+ g_variant_get_string (parameter, NULL));
+
+ g_simple_action_set_state (action, parameter);
+}
+
+static void
+toggle_action (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GVariant *state = g_action_get_state (G_ACTION (action));
+
+ g_print ("Toggle action %s to %s\n",
+ g_action_get_name (G_ACTION (action)),
+ g_variant_get_boolean (state) ? "false" : "true");
+
+ g_simple_action_set_state (action,
+ g_variant_new_boolean (!g_variant_get_boolean (state)));
+}
+
int
main (int argc, char *argv[])
{
@@ -1935,7 +1973,20 @@ main (int argc, char *argv[])
{ "beer", NULL, NULL, "false", NULL },
{ "water", NULL, NULL, "true", NULL },
{ "dessert", NULL, "s", "'bars'", NULL },
- { "pay", NULL, "s", NULL, NULL }
+ { "pay", NULL, "s", NULL, NULL },
+ { "print", activate_action, NULL, NULL, NULL },
+ { "share", activate_action, NULL, NULL, NULL },
+ { "labels", activate_action, NULL, NULL, NULL },
+ { "open-in", activate_action, NULL, NULL, NULL },
+ { "cut", activate_action, NULL, NULL, NULL },
+ { "copy", activate_action, NULL, NULL, NULL },
+ { "paste", activate_action, NULL, NULL, NULL },
+ { "pin", toggle_action, NULL, "true", NULL },
+ { "size", select_action, "s", "'medium'", NULL },
+ { "berk", toggle_action, NULL, "true", NULL },
+ { "broni", toggle_action, NULL, "true", NULL },
+ { "drutt", toggle_action, NULL, "true", NULL },
+ { "upstairs", toggle_action, NULL, "true", NULL },
};
gint status;
diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui
index 7cdc6981ae..d34970115f 100644
--- a/demos/widget-factory/widget-factory.ui
+++ b/demos/widget-factory/widget-factory.ui
@@ -2433,11 +2433,12 @@ microphone-sensitivity-medium-symbolic</property>
<property name="spacing">10</property>
<child>
<object class="GtkBox">
- <property name="halign">start</property>
+ <property name="halign">fill</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox" id="lockbox">
- <property name="halign">start</property>
+ <property name="halign">fill</property>
+ <property name="hexpand">1</property>
<property name="spacing">6</property>
<child>
<object class="GtkMenuButton" id="open_menubutton">
@@ -2509,6 +2510,12 @@ microphone-sensitivity-medium-symbolic</property>
<child>
<object class="GtkLockButton" id="lockbutton"/>
</child>
+ <child>
+ <object class="GtkMenuButton">
+ <property name="icon-name">view-more-symbolic</property>
+ <property name="popover">new_style_menu</property>
+ </object>
+ </child>
</object>
</child>
<child>
@@ -3509,4 +3516,188 @@ bad things might happen.</property>
</object>
</child>
</object>
+ <object class="GtkPopoverMenu" id="new_style_menu">
+ <child>
+ <object class="GtkBox">
+ <property name="name">main</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkBox">
+ <property name="halign">fill</property>
+ <child>
+ <object class="GtkModelButton">
+ <property name="icon"><object class="GThemedIcon"><property
name="name">printer-symbolic</property></object></property>
+ <property name="iconic">1</property>
+ <property name="action-name">app.print</property>
+ <property name="hexpand">1</property>
+ <property name="halign">center</property>
+ <style>
+ <class name="circular"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="icon"><object class="GThemedIcon"><property
name="name">emblem-shared-symbolic</property></object></property>
+ <property name="iconic">1</property>
+ <property name="action-name">app.share</property>
+ <property name="hexpand">1</property>
+ <property name="halign">center</property>
+ <style>
+ <class name="circular"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparator"/>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="text">Open in New Window</property>
+ <property name="action-name">app.open-in</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparator"/>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <child>
+ <object class="GtkLabel">
+ <property name="label">Edit</property>
+ <property name="xalign">0</property>
+ <property name="hexpand">1</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="icon"><object class="GThemedIcon"><property
name="name">edit-cut-symbolic</property></object></property>
+ <property name="iconic">1</property>
+ <property name="relief">none</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="icon"><object class="GThemedIcon"><property
name="name">edit-copy-symbolic</property></object></property>
+ <property name="iconic">1</property>
+ <property name="relief">none</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="icon"><object class="GThemedIcon"><property
name="name">edit-paste-symbolic</property></object></property>
+ <property name="iconic">1</property>
+ <property name="relief">none</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparator"/>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="text">Pin</property>
+ <property name="action-name">app.pin</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="text">Select Labels…</property>
+ <property name="action-name">app.labels</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="text">Share…</property>
+ <property name="action-name">app.share</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparator"/>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="text">Basement</property>
+ <property name="menu-name">basement</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparator"/>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="text">Large</property>
+ <property name="action-name">app.size</property>
+ <property name="action-target">'large'</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="text">Medium</property>
+ <property name="action-name">app.size</property>
+ <property name="action-target">'medium'</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="text">Small</property>
+ <property name="action-name">app.size</property>
+ <property name="action-target">'small'</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparator"/>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="text">Move to Trash</property>
+ <property name="action-name">win.delete</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="name">basement</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkModelButton">
+ <property name="text">Basement</property>
+ <property name="inverted">1</property>
+ <property name="menu-name">main</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparator"/>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="text">Berk</property>
+ <property name="action-name">app.berk</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="text">Broni</property>
+ <property name="action-name">app.broni</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="text">Drutt</property>
+ <property name="action-name">app.drutt</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="text">The Thing Upstairs</property>
+ <property name="action-name">app.upstairs</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]