eagleoneraptor

_initBubbleSignals changes v1

Aug 20th, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     _initSomething: function(object, signal, interval) {
  2.         let sourceId = null;
  3.         let signalId = object.connect(signal, (function() {
  4.             if (sourceId)
  5.                 Mainloop.source_remove(sourceId);
  6.             else
  7.                 this.hideBubble();
  8.  
  9.             sourceId = Mainloop.timeout_add(interval, (function() {
  10.                 this.showBubble();
  11.                 sourceId = null;
  12.             }).bind(this));
  13.         }).bind(this));
  14.  
  15.         Utils.once(this.bubble, 'closed', (function() {
  16.             if (!sourceId)
  17.                 object.disconnect(signalId);
  18.         }).bind(this));
  19.  
  20.         Utils.once(this, 'notify::selected', (function() {
  21.             if (sourceId) {
  22.                 Mainloop.source_remove(sourceId);
  23.                 object.disconnect(signalId);
  24.             }
  25.         }).bind(this));
  26.     },
  27.  
  28.     _initBubbleSignals: function() {
  29.         // This is done to get just one marker selected at any time regardless
  30.         // of the layer to which it belongs so we can get only one visible bubble
  31.         // at any time. We do this for markers in different layers because for
  32.         // markers in the same layer, ChamplainMarkerLayer single selection mode
  33.         // does the job.
  34.         this._mapView.onSetMarkerSelected(this);
  35.  
  36.         let markerSelectedSignalId = this._mapView.connect('marker-selected', (function(mapView, selectedMarker) {
  37.             if (this.get_parent() != selectedMarker.get_parent())
  38.                 this.selected = false;
  39.         }).bind(this));
  40.  
  41.         this._initSomething(this._view, 'notify::zoom-level', 500);
  42.         this._initSomething(this._view, 'notify::size', 0);
  43.  
  44.         let buttonPressSignalId = this._view.connect('button-press-event',
  45.                                                      this.set_selected.bind(this, false));
  46.         let goingToSignalId = this._mapView.connect('going-to',
  47.                                                     this.set_selected.bind(this, false));
  48.         let parentSetSignalId = this.connect('parent-set',
  49.                                              this.set_selected.bind(this, false));
  50.         let dragMotionSignalId = this.connect('drag-motion',
  51.                                               this.set_selected.bind(this, false));
  52.  
  53.         Utils.once(this.bubble, 'closed', (function() {
  54.             this._mapView.disconnect(markerSelectedSignalId);
  55.             this._view.disconnect(buttonPressSignalId);
  56.             this._mapView.disconnect(goingToSignalId);
  57.             this.disconnect(parentSetSignalId);
  58.             this.disconnect(dragMotionSignalId);
  59.  
  60.             this._bubble.destroy();
  61.             delete this._bubble;
  62.         }).bind(this));
  63.     },
Advertisement
Add Comment
Please, Sign In to add comment