[gnome-maps/wip/fix-geoloc: 9/11] MainWindow: more robust track toggle
- From: Mattias Bengtsson <mattiasb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/fix-geoloc: 9/11] MainWindow: more robust track toggle
- Date: Wed, 24 Jul 2013 05:58:32 +0000 (UTC)
commit 328758f5afde52a5aa0337fa04db4c8554cee3be
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date: Wed Jul 24 07:26:22 2013 +0200
MainWindow: more robust track toggle
Make the track user location toggle just represent a GSettingsAction.
This makes the code a bit cleaner and the app a bit more robust.
https://bugzilla.gnome.org/show_bug.cgi?id=704537
src/main-window.ui | 1 +
src/mainWindow.js | 63 ++++++++++++++++++++++++++-------------------------
2 files changed, 33 insertions(+), 31 deletions(-)
---
diff --git a/src/main-window.ui b/src/main-window.ui
index b5082ed..4b622ad 100644
--- a/src/main-window.ui
+++ b/src/main-window.ui
@@ -40,6 +40,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="symbolic-icon-name">find-location-symbolic</property>
+ <property name="action_name">win.track-user-location</property>
</object>
<packing>
<property name="pack_type">start</property>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 7fd2eb1..1410251 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -70,37 +70,21 @@ const MainWindow = new Lang.Class({
this.mapView = new MapView.MapView();
- let trackUserLocation = Application.settings.get_boolean('track-user-location');
-
- let onViewMoved = Lang.bind(this,
- function () {
- if (!this.mapView.userLocationVisible())
- toggle.active = false;
- });
-
- // Disable animation for goto animation on startup only
- let animateGotoUserLocation = !trackUserLocation;
- toggle.connect('toggled', Lang.bind(this,
- function() {
- if (this._onViewMovedId > 0) {
- this.mapView.disconnect(this._onViewMovedId);
- this._onViewMovedId = 0;
- }
-
- if (toggle.active) {
- let goneToUserLocationId = this.mapView.connect('gone-to-user-location', Lang.bind(this,
- function () {
- this.mapView.disconnect(goneToUserLocationId);
- this._onViewMovedId = this.mapView.connect('view-moved', onViewMoved);
- }));
- this.mapView.gotoUserLocation(animateGotoUserLocation);
- if (!animateGotoUserLocation)
- animateGotoUserLocation = true;
- }
-
- Application.settings.set_boolean('track-user-location', toggle.active);
- }));
- toggle.active = trackUserLocation;
+ if(Application.settings.get_boolean('track-user-location'))
+ this.mapView.gotoUserLocation(false);
+
+ this._viewMovedId = 0;
+ this._connectMapMove();
+ this.mapView.connect('going-to-user-location',
+ this._disconnectMapMove.bind(this));
+ this.mapView.connect('gone-to-user-location',
+ this._connectMapMove.bind(this));
+
+ Application.settings.connect('changed::track-user-location', (function() {
+ if(Application.settings.get_boolean('track-user-location')) {
+ this.mapView.gotoUserLocation(true);
+ }
+ }).bind(this));
grid.add(this.mapView);
@@ -127,6 +111,23 @@ const MainWindow = new Lang.Class({
signalHandlers: { activate: this._onMapTypeActivate }
}
], this);
+ this.window.add_action(
+ Application.settings.create_action('track-user-location'));
+ },
+
+ _connectMapMove: function() {
+ if(this._viewMovedId === 0) {
+ this._viewMovedId = this.mapView.connect('view-moved', (function() {
+ if (!this.mapView.userLocationVisible())
+ Application.settings.set_boolean('track-user-location', false);
+ }).bind(this));
+ }
+ },
+ _disconnectMapMove: function() {
+ if(this._viewMovedId !== 0) {
+ this.mapView.disconnect(this._viewMovedId);
+ this._viewMovedId = 0;
+ }
},
_saveWindowGeometry: function() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]