[gnome-maps/wip/mattiasb/templates: 8/10] ContextMenu: Use Templates



commit 84e30f3b20ddc57a1c1c6e5ea496050930aa090b
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      |   16 ++++++++--------
 2 files changed, 11 insertions(+), 11 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 094ec99..7838f3f 100644
--- a/src/contextMenu.js
+++ b/src/contextMenu.js
@@ -22,27 +22,27 @@
 
 const Clutter = imports.gi.Clutter;
 const Geocode = imports.gi.GeocodeGlib;
+const Gtk = imports.gi.Gtk;
 const Mainloop = imports.mainloop;
 
 const Application = imports.application;
 const Lang = imports.lang;
-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) {
@@ -54,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]