[gnome-maps] ContextMenu: Use Templates



commit 8ca738fc248ce1433506f18f3075290688f5ad98
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Tue Mar 24 01:54:02 2015 +0100

    ContextMenu: Use Templates
    
    https://bugzilla.gnome.org/show_bug.cgi?id=740647

 data/ui/context-menu.ui |    6 +++---
 src/contextMenu.js      |   15 ++++++++-------
 2 files changed, 11 insertions(+), 10 deletions(-)
---
diff --git a/data/ui/context-menu.ui b/data/ui/context-menu.ui
index 126c6f5..fa5bc3d 100644
--- a/data/ui/context-menu.ui
+++ b/data/ui/context-menu.ui
@@ -1,14 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <object class= "GtkMenu" id="context-menu">
+  <template class="Gjs_ContextMenu" parent="GtkMenu">
     <property name="visible">False</property>
     <child>
-      <object class="GtkMenuItem" id="whats-here-item">
+      <object class="GtkMenuItem" id="whatsHereItem">
         <property name="name">whats-here-item</property>
         <property name="label" translatable="yes">What’s here?</property>
         <property name="visible">True</property>
       </object>
     </child>
-  </object>
+  </template>
 </interface>
diff --git a/src/contextMenu.js b/src/contextMenu.js
index 8f6368f..58722e0 100644
--- a/src/contextMenu.js
+++ b/src/contextMenu.js
@@ -21,6 +21,7 @@
 
 const Clutter = imports.gi.Clutter;
 const Geocode = imports.gi.GeocodeGlib;
+const Gtk = imports.gi.Gtk;
 const Mainloop = imports.mainloop;
 
 const Application = imports.application;
@@ -29,19 +30,19 @@ const Utils = imports.utils;
 
 const ContextMenu = new Lang.Class({
     Name: 'ContextMenu',
+    Extends: Gtk.Menu,
+    Template: 'resource:///org/gnome/Maps/ui/context-menu.ui',
+    InternalChildren: [ 'whatsHereItem' ],
 
     _init: function(mapView) {
         this._mapView = mapView;
-
-        let ui = Utils.getUIObject('context-menu', [ 'context-menu',
-                                                     'whats-here-item' ]);
-        this._menu = ui.contextMenu;
+        this.parent();
 
         this._mapView.view.connect('button-release-event',
                                    this._onButtonReleaseEvent.bind(this));
 
-        ui.whatsHereItem.connect('activate',
-                                 this._onWhatsHereActivated.bind(this));
+        this._whatsHereItem.connect('activate',
+                                    this._onWhatsHereActivated.bind(this));
     },
 
     _onButtonReleaseEvent: function(actor, event) {
@@ -53,7 +54,7 @@ const ContextMenu = new Lang.Class({
         if (button === Clutter.BUTTON_SECONDARY) {
             Mainloop.idle_add((function() {
                 // Need idle to avoid Clutter dead-lock on re-entrance
-                this._menu.popup(null, null, null, button, event.get_time());
+                this.popup(null, null, null, button, event.get_time());
             }).bind(this));
         }
     },


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]