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



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

    ContextMenu: Use Templates

 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 094ec99..295d427 100644
--- a/src/contextMenu.js
+++ b/src/contextMenu.js
@@ -22,6 +22,7 @@
 
 const Clutter = imports.gi.Clutter;
 const Geocode = imports.gi.GeocodeGlib;
+const Gtk = imports.gi.Gtk;
 const Mainloop = imports.mainloop;
 
 const Application = imports.application;
@@ -30,19 +31,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) {
@@ -54,7 +55,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]