[gnome-maps/wip/routing2: 6/9] more sidebar work
- From: Mattias Bengtsson <mattiasb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/routing2: 6/9] more sidebar work
- Date: Sun, 8 Jun 2014 22:52:12 +0000 (UTC)
commit 15171b6bafb18d2aded9fa8157895630b1289e8d
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date: Sun May 25 19:10:38 2014 +0100
more sidebar work
src/application.js | 2 +-
src/mainWindow.js | 2 +-
src/sidebar.js | 182 ++++++++++++++++++++++++++++------------------------
src/sidebar.ui | 50 +++++++-------
4 files changed, 125 insertions(+), 111 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index ef4aac3..259d08d 100644
--- a/src/application.js
+++ b/src/application.js
@@ -35,7 +35,7 @@ const GLib = imports.gi.GLib;
const Main = imports.main;
const Format = imports.format;
const Geoclue = imports.geoclue;
-// const GeocodeService = imports.geocode;
+const GeocodeService = imports.geocodeService;
const MainWindow = imports.mainWindow;
const Notification = imports.notification;
const NotificationManager = imports.notificationManager;
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 4c84d65..ad8f92d 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -300,7 +300,7 @@ const MainWindow = new Lang.Class({
let [mapType, len] = value.get_string();
this.mapView.setMapType(MapView.MapType[mapType]);
},
-
+
_onToggleSidebarActivate: function(action) {
let newState = !action.get_state().get_boolean();
action.set_state(GLib.Variant.new('b', newState));
diff --git a/src/sidebar.js b/src/sidebar.js
index 99f5e4f..003eeda 100644
--- a/src/sidebar.js
+++ b/src/sidebar.js
@@ -21,115 +21,129 @@
* Mattias Bengtsson <mattias jc bengtsson gmail com>
*/
-const Lang = imports.lang;
-const Gtk = imports.gi.Gtk;
-const GLib = imports.gi.GLib;
+const Geocode = imports.gi.GeocodeGlib;
+const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
+const Gtk = imports.gi.Gtk;
+const Lang = imports.lang;
const Application = imports.application;
-const PlaceStore = imports.placeStore;
+const PlaceStore = imports.placeStore;
const SearchPopup = imports.searchPopup;
-const Utils = imports.utils;
+const Utils = imports.utils;
const Sidebar = new Lang.Class({
Name: 'Sidebar',
Extends: Gtk.Revealer,
_init: function() {
- this.parent({ name: "sidebar",
- visible: true,
- transition_type: Gtk.RevealerTransitionType.SLIDE_LEFT,
+ this.parent({ visible: true,
+ transition_type: Gtk.RevealerTransitionType.SLIDE_LEFT,
transition_duration: 400,
- halign: Gtk.Align.END,
- valign: Gtk.Align.FILL
+ halign: Gtk.Align.END,
+ valign: Gtk.Align.FILL
});
- this._ui = Utils.getUIObject('sidebar', [ 'form',
- 'instruction-list-scrolled',
- 'instruction-list',
- 'to-entry',
- 'from-entry',
- 'to-completion',
- 'from-completion',
- 'mode-pedestrian-toggle',
- 'mode-bike-toggle',
- 'mode-car-toggle']);
-
- this._ui.instructionList.connect('row-activated', (function(list, row) {
+ let ui = Utils.getUIObject('sidebar', [ 'grid',
+ 'instruction-list-scrolled',
+ 'instruction-list',
+ 'from-completion',
+ 'to-completion',
+ 'mode-pedestrian-toggle',
+ 'mode-bike-toggle',
+ 'mode-car-toggle']);
+
+ ui.instructionList.connect('row-activated', (function(list, row) {
this.emit('instruction-selected', row.instruction);
}).bind(this));
- this._initCompletion(this._ui.toCompletion);
- this._initCompletion(this._ui.fromCompletion);
-
- this._initSearchEntries();
-
- this.add(this._ui.form);
- },
-
- _initCompletion: function(completion) {
- completion.model = Application.placeStore;
- completion.set_match_func(PlaceStore.completionMatchFunc);
- completion.connect('match-selected',
- this._onPlaceSelected.bind(this));
+ ui.grid.attach(this._createEntry("from", ui.fromCompletion),
+ 1, 0, 1, 1);
+ ui.grid.attach(this._createEntry("to", ui.toCompletion),
+ 1, 1, 1, 1);
+ this.add(ui.grid);
},
- _initSearchEntries: function() {
- this._fromPopover = new SearchPopup.SearchPopup(this._ui.fromEntry, 5);
- this._fromPopover.connect('selected',
- this._onSearchPopupSelected.bind(this));
- this._ui.fromEntry.connect('activate', this._onSearchActivate.bind(this));
+ _createEntry: function(propName, completion) {
+ completion.model = Application.placeStore;
+ completion.match_func = PlaceStore.completionMatchFunc;
+
+ let entry = new PlaceEntry({ visible: true,
+ hexpand: true,
+ completion: completion });
+ entry.bind_property("place",
+ Application.routeService.query, propName,
+ GObject.BindingFlags.BIDIRECTIONAL);
+ return entry;
+ }
+});
- this._toPopover = new SearchPopup.SearchPopup(this._ui.toEntry, 5);
- this._toPopover.connect('selected',
- this._onSearchPopupSelected.bind(this));
- this._ui.toEntry.connect('activate', this._onSearchActivate.bind(this));
+const PlaceEntry = new Lang.Class({
+ Name: 'PlaceEntry',
+ Extends: Gtk.Entry,
+ Properties: {
+ place: GObject.ParamSpec.object('place',
+ '',
+ '',
+ GObject.ParamFlags.READABLE |
+ GObject.ParamFlags.WRITABLE,
+ Geocode.Place)
},
- _onPlaceSelected: function(completion, model, iter) {
- let entry;
- let place = model.get_value(iter, PlaceStore.Columns.PLACE);
-
- if (completion === this._ui.fromCompletion) {
- entry = this._ui.fromEntry;
- this._fromPlace = place;
- } else {
- entry = this._ui.toEntry;
- this._toPlace = place;
- }
- entry.text = place.name;
-
- return true;
+ _init: function(props) {
+ this.parent(props);
+
+ // this.bind_property_full_with_closures("place",
+ // this, "text",
+ // GObject.BindingFlags.DEFAULT,
+ // function(place) {
+ // log("binding-to:" + place.name);
+ // return place.name;
+ // },
+ // function(text) {
+ // return text;
+ // }); //TODO: will this work?
+
+ let popover = this._createPopover();
+
+ this.connect('activate', this._onActivate.bind(this, popover));
+
+ this.completion.connect('match-selected', (function(c, model, iter) {
+ log("match:selected");
+ this.place = model.get_value(iter, PlaceStore.Columns.PLACE);
+ this.text = this.place.name;
+ return true;
+ }).bind(this));
},
- _onSearchPopupSelected: function(popover, place) {
- let entry;
-
- if (popover === this._fromPopover) {
- entry = this._ui.fromEntry;
- this._fromPlace = place;
- } else {
- entry = this._ui.toEntry;
- this._toPlace = place;
- }
- entry.text = place.name;
- popover.hide();
- },
+ _createPopover: function() {
+ let popover = new SearchPopup.SearchPopup(this, 5);
- _onSearchActivate: function(entry) {
- let searchString = entry.get_text();
+ popover.connect('selected', (function(place) {
+ this.place = place;
+ this.text = place.name;
+ popover.hide();
+ }).bind(this));
- if (searchString.length > 0) {
- let popover = (entry === this._ui.toEntry)
- ? this._toPopover
- : this._fromPopover;
+ return popover;
+ },
+ _onActivate: function(popover) {
+ log("activated, text is: " + this.text);
+ log(popover);
+ if (this.text.length > 0) {
popover.showSpinner();
- Application.geocodeService.search(searchString, null, function(places) {
- if (places === null)
- popover.hide();
-
- popover.update(places, searchString);
- popover.showResult();
- });
+ Application
+ .application
+ ._mainWindow
+ .mapView
+ .geocodeSearch(this.text, (function(places) {
+ if (places === null) {
+ popover.hide();
+ log(places);
+ }
+ popover.updateResult(places, this.text);
+ popover.showResult();
+ }).bind(this));
}
}
});
diff --git a/src/sidebar.ui b/src/sidebar.ui
index c17e6ea..ad9a2ac 100644
--- a/src/sidebar.ui
+++ b/src/sidebar.ui
@@ -40,7 +40,7 @@
</attributes>
</child>
</object>
- <object class="GtkGrid" id="form">
+ <object class="GtkGrid" id="grid">
<property name="name">sidebar-form</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -157,30 +157,30 @@
<property name="top_attach">1</property>
</packing>
</child>
- <child>
- <object class="GtkEntry" id="to-entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hexpand">True</property>
- <property name="completion">to-completion</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="from-entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hexpand">True</property>
- <property name="completion">from-completion</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- </packing>
- </child>
+ <!-- <child> -->
+ <!-- <object class="GtkEntry" id="to-entry"> -->
+ <!-- <property name="visible">True</property> -->
+ <!-- <property name="can_focus">True</property> -->
+ <!-- <property name="hexpand">True</property> -->
+ <!-- <property name="completion">to-completion</property> -->
+ <!-- </object> -->
+ <!-- <packing> -->
+ <!-- <property name="left_attach">1</property> -->
+ <!-- <property name="top_attach">1</property> -->
+ <!-- </packing> -->
+ <!-- </child> -->
+ <!-- <child> -->
+ <!-- <object class="GtkEntry" id="from-entry"> -->
+ <!-- <property name="visible">True</property> -->
+ <!-- <property name="can_focus">True</property> -->
+ <!-- <property name="hexpand">True</property> -->
+ <!-- <property name="completion">from-completion</property> -->
+ <!-- </object> -->
+ <!-- <packing> -->
+ <!-- <property name="left_attach">1</property> -->
+ <!-- <property name="top_attach">0</property> -->
+ <!-- </packing> -->
+ <!-- </child> -->
<child>
<object class="GtkLabel" id="from-label">
<property name="visible">True</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]