[virt-tools-list] [PATCH virt-viewer 3/4] window: use dynamically generated menu

Marc-André Lureau marcandre.lureau at gmail.com
Mon Jul 22 17:51:58 UTC 2013


Remove the static Glade menu in favour of the one generated dynamically
already used for the toolbar.
---
 src/virt-viewer-window.c |  33 +++++++++-
 src/virt-viewer.xml      | 168 -----------------------------------------------
 2 files changed, 31 insertions(+), 170 deletions(-)

diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index cd30910..6702365 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -195,6 +195,33 @@ virt_viewer_window_dispose (GObject *object)
 }
 
 static void
+rebuild_combo_menu(GObject    *gobject G_GNUC_UNUSED,
+                   GParamSpec *pspec G_GNUC_UNUSED,
+                   gpointer    user_data)
+{
+    VirtViewerWindow *self = user_data;
+    GtkWidget *menu;
+
+    menu = GTK_WIDGET(gtk_builder_get_object(self->priv->builder, "menu-send"));
+    gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu),
+                              GTK_WIDGET(virt_viewer_window_get_keycombo_menu(self)));
+    gtk_widget_set_sensitive(menu, FALSE);
+}
+
+static void
+virt_viewer_window_constructed(GObject *object)
+{
+    VirtViewerWindowPrivate *priv = VIRT_VIEWER_WINDOW(object)->priv;
+
+    if (G_OBJECT_CLASS(virt_viewer_window_parent_class)->constructed)
+        G_OBJECT_CLASS(virt_viewer_window_parent_class)->constructed(object);
+
+    g_signal_connect(priv->app, "notify::enable-accel",
+                     G_CALLBACK(rebuild_combo_menu), object);
+    rebuild_combo_menu(NULL, NULL, object);
+}
+
+static void
 virt_viewer_window_class_init (VirtViewerWindowClass *klass)
 {
     GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -204,6 +231,7 @@ virt_viewer_window_class_init (VirtViewerWindowClass *klass)
     object_class->get_property = virt_viewer_window_get_property;
     object_class->set_property = virt_viewer_window_set_property;
     object_class->dispose = virt_viewer_window_dispose;
+    object_class->constructed = virt_viewer_window_constructed;
 
     g_object_class_install_property(object_class,
                                     PROP_SUBTITLE,
@@ -602,9 +630,8 @@ virt_viewer_window_get_keycombo_menu(VirtViewerWindow *self)
         virt_viewer_menu_add_combo(self, menu, keyCombos[i].keys, keyCombos[i].label);
     }
 
-    gtk_menu_attach_to_widget(menu, GTK_WIDGET(priv->window), NULL);
     gtk_widget_show_all(GTK_WIDGET(menu));
-    return g_object_ref_sink(menu);
+    return menu;
 }
 
 void
@@ -724,6 +751,8 @@ virt_viewer_window_toolbar_send_key(GtkWidget *button G_GNUC_UNUSED,
                                     VirtViewerWindow *self)
 {
     GtkMenu *menu = virt_viewer_window_get_keycombo_menu(self);
+    gtk_menu_attach_to_widget(menu, GTK_WIDGET(self->priv->window), NULL);
+    g_object_ref_sink(menu);
     gtk_menu_popup(menu, NULL, NULL, keycombo_menu_location, self,
                    0, gtk_get_current_event_time());
     g_object_unref(menu);
diff --git a/src/virt-viewer.xml b/src/virt-viewer.xml
index cce1f0d..ca5d136 100644
--- a/src/virt-viewer.xml
+++ b/src/virt-viewer.xml
@@ -210,174 +210,6 @@
                 <property name="use_action_appearance">False</property>
                 <property name="label" translatable="yes">_Send key</property>
                 <property name="use_underline">True</property>
-                <child type="submenu">
-                  <object class="GtkMenu" id="menu5">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-cad">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">Ctrl+Alt+_Del</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-cab">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">Ctrl+Alt+_Backspace</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkSeparatorMenuItem" id="separatormenuitem2">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-caf1">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">Ctrl+Alt+F_1</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-caf2">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">Ctrl+Alt+F_2</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-caf3">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">Ctrl+Alt+F_3</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-caf4">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">Ctrl+Alt+F_4</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-caf5">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">Ctrl+Alt+F_5</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-caf6">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">Ctrl+Alt+F_6</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-caf7">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">Ctrl+Alt+F_7</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-caf8">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">Ctrl+Alt+F_8</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-caf9">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">Ctrl+Alt+F_9</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-caf10">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">Ctrl+Alt+F1_0</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-caf11">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">Ctrl+Alt+F11</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-caf12">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">Ctrl+Alt+F12</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkSeparatorMenuItem" id="separatormenuitem3">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="menu-send-print">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="label" translatable="yes">_PrintScreen</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="virt_viewer_window_menu_send" swapped="no"/>
-                      </object>
-                    </child>
-                  </object>
-                </child>
               </object>
             </child>
             <child>
-- 
1.8.3.rc1.49.g8d97506




More information about the virt-tools-list mailing list