[gnome-maps/wip/drag-n-drop: 1/2] Introduce RouteEntry module
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/drag-n-drop: 1/2] Introduce RouteEntry module
- Date: Thu, 27 Nov 2014 09:14:09 +0000 (UTC)
commit e0919541833144b66d4148a3567632a01b55066f
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Thu Nov 27 04:10:02 2014 -0500
Introduce RouteEntry module
data/gnome-maps.css | 12 ++--
src/gnome-maps.data.gresource.xml | 2 +-
src/gnome-maps.js.gresource.xml | 1 +
src/route-entry.ui | 62 ++++++++++++++++++++++
src/route-via-row.ui | 66 ++++++++++++++---------
src/routeEntry.js | 93 +++++++++++++++++++++++++++++++++
src/sidebar.js | 102 ++++++++++++++----------------------
src/sidebar.ui | 80 +----------------------------
8 files changed, 245 insertions(+), 173 deletions(-)
---
diff --git a/data/gnome-maps.css b/data/gnome-maps.css
index 629d5a6..d655e3a 100644
--- a/data/gnome-maps.css
+++ b/data/gnome-maps.css
@@ -29,27 +29,27 @@
font-weight: bold;
}
-#via-grid-container {
+#sidebar-entry-list {
background-color: transparent;
}
-#via-grid-container .list-row:hover {
+#sidebar-entry-list .list-row:hover {
background-color: transparent;
}
-#via-grid-container .list-row:focus {
+#sidebar-entry-list .list-row:focus {
outline: 0;
}
-#via-grid-container > GtkLabel {
+#sidebar-entry-list > GtkLabel {
padding-right: 6px;
}
-#via-grid-container > GtkLabel:dir(rtl) {
+#sidebar-entry-list > GtkLabel:dir(rtl) {
padding-left: 6px;
}
-#via-grid-container .transportation-mode-button > GtkImage {
+#sidebar-entry-list .transportation-mode-button > GtkImage {
padding-left: 7px;
padding-right: 7px;
padding-top: 4px;
diff --git a/src/gnome-maps.data.gresource.xml b/src/gnome-maps.data.gresource.xml
index 0512a79..b19a625 100644
--- a/src/gnome-maps.data.gresource.xml
+++ b/src/gnome-maps.data.gresource.xml
@@ -12,7 +12,7 @@
<file preprocess="xml-stripblanks">context-menu.ui</file>
<file preprocess="xml-stripblanks">layers-popover.ui</file>
<file preprocess="xml-stripblanks">notification.ui</file>
- <file preprocess="xml-stripblanks">route-via-row.ui</file>
+ <file preprocess="xml-stripblanks">route-entry.ui</file>
<file preprocess="xml-stripblanks">map-bubble.ui</file>
<file preprocess="xml-stripblanks">search-result-bubble.ui</file>
<file preprocess="xml-stripblanks">share-dialog.ui</file>
diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
index ce962cc..b06b5da 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -26,6 +26,7 @@
<file>placeListRow.js</file>
<file>placeStore.js</file>
<file>route.js</file>
+ <file>routeEntry.js</file>
<file>routeQuery.js</file>
<file>routeService.js</file>
<file>searchPopup.js</file>
diff --git a/src/route-entry.ui b/src/route-entry.ui
new file mode 100644
index 0000000..0615e37
--- /dev/null
+++ b/src/route-entry.ui
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.10"/>
+ <template class="Gjs_RouteEntry" parent="GtkGrid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">horizontal</property>
+ <property name="hexpand">False</property>
+ <child>
+ <object class="GtkEventBox" id="iconEventBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImage" id="icon">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin-end">8</property>
+ <property name="margin-start">13</property>
+ <property name="width-request">16</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkGrid" id="entryGrid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkGrid" id="buttonGrid">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkButton" id="button">
+ <property name="visible">False</property>
+ <property name="no_show_all">True</property>
+ <property name="can-focus">True</property>
+ <property name="valign">center</property>
+ <property name="height-request">31</property>
+ <property name="margin-start">4</property>
+ <property name="margin-end">10</property>
+ <child>
+ <object class="GtkImage" id="buttonImage">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkGrid" id="buttonPlaceHolder">
+ <property name="visible">False</property>
+ <property name="no_show_all">True</property>
+ <property name="margin_start">5</property>
+ <property name="margin_end">12</property>
+ <property name="width-request">31</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/route-via-row.ui b/src/route-via-row.ui
index a46eb37..bb44bde 100644
--- a/src/route-via-row.ui
+++ b/src/route-via-row.ui
@@ -1,37 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.10"/>
- <object class="GtkGrid" id="via-grid">
+ <object class="GtkEventBox" id="via-event-box">
<property name="visible">True</property>
- <property name="orientation">horizontal</property>
- <property name="hexpand">False</property>
+ <property name="can_focus">False</property>
<child>
- <object class="GtkImage" id="via-image">
+ <object class="GtkGrid" id="via-grid">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="margin-end">21</property>
- <property name="width-request">16</property>
- </object>
- </child>
- <child>
- <object class="GtkGrid" id="via-entry-grid">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="hexpand">True</property>
- </object>
- </child>
- <child>
- <object class="GtkButton" id="via-remove-button">
- <property name="visible">True</property>
- <property name="can-focus">True</property>
- <property name="valign">center</property>
- <property name="height-request">31</property>
- <property name="margin-start">4</property>
- <property name="margin-end">10</property>
+ <property name="orientation">horizontal</property>
+ <property name="hexpand">False</property>
+ <child>
+ <object class="GtkEventBox" id="via-icon-event-box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImage" id="via-image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin-end">8</property>
+ <property name="margin-start">13</property>
+ <property name="width-request">16</property>
+ <property name="icon-name">maps-point-end-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkGrid" id="via-entry-grid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ </object>
+ </child>
<child>
- <object class="GtkImage" id="via-remove-image">
+ <object class="GtkButton" id="via-remove-button">
<property name="visible">True</property>
- <property name="icon-name">list-remove-symbolic</property>
+ <property name="can-focus">True</property>
+ <property name="valign">center</property>
+ <property name="height-request">31</property>
+ <property name="margin-start">4</property>
+ <property name="margin-end">10</property>
+ <child>
+ <object class="GtkImage" id="via-remove-image">
+ <property name="visible">True</property>
+ <property name="icon-name">list-remove-symbolic</property>
+ </object>
+ </child>
</object>
</child>
</object>
diff --git a/src/routeEntry.js b/src/routeEntry.js
new file mode 100644
index 0000000..add85c5
--- /dev/null
+++ b/src/routeEntry.js
@@ -0,0 +1,93 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Jonas Danielsson <jonas threetimestwo org>
+ */
+
+const GObject = imports.gi.GObject;
+const Gtk = imports.gi.Gtk;
+const Lang = imports.lang;
+
+const Application = imports.application;
+const PlaceEntry = imports.placeEntry;
+
+const Type = {
+ FROM: 0,
+ TO: 1,
+ VIA: 2
+};
+
+const RouteEntry = new Lang.Class({
+ Name: 'RouteEntry',
+ Extends: Gtk.Grid,
+ Template: 'resource:///org/gnome/maps/route-entry.ui',
+ Children: [ 'iconEventBox' ],
+ InternalChildren: [ 'entryGrid',
+ 'icon',
+ 'button',
+ 'buttonImage',
+ 'buttonPlaceHolder'],
+
+ _init: function(params) {
+ this._type = params.type;
+ delete params.type;
+
+ this._point = params.point;
+ delete params.point;
+
+ this._mapView = params.mapView;
+ delete params.mapView;
+
+ this.parent(params);
+
+ this.entry = new PlaceEntry.PlaceEntry({ visible: true,
+ can_focus: true,
+ hexpand: true,
+ receives_default: true,
+ mapView: this._mapView,
+ parseOnFocusOut: true,
+ maxChars: 15 });
+ this.entry.bind_property('place',
+ this._point, 'place',
+ GObject.BindingFlags.BIDIRECTIONAL);
+ this._entryGrid.add(this.entry);
+
+ switch(this._type) {
+ case Type.FROM:
+ this._buttonImage.icon_name = 'list-add-symbolic';
+ this._icon.icon_name = 'maps-point-start-symbolic';
+ this._button.show();
+ break;
+ case Type.VIA:
+ this._buttonImage.icon_name = 'list-remove-symbolic';
+ this._button.show();
+ break;
+ case Type.TO:
+ this._icon.icon_name = 'maps-point-end-symbolic';
+ this._buttonPlaceHolder.show();
+ break;
+ }
+ },
+
+ get button() {
+ return this._button;
+ },
+
+ get point() {
+ return this._point;
+ }
+});
diff --git a/src/sidebar.js b/src/sidebar.js
index 5434c53..8695f32 100644
--- a/src/sidebar.js
+++ b/src/sidebar.js
@@ -27,7 +27,7 @@ const Lang = imports.lang;
const _ = imports.gettext.gettext;
const Application = imports.application;
-const PlaceEntry = imports.placeEntry;
+const RouteEntry = imports.routeEntry;
const RouteQuery = imports.routeQuery;
const Utils = imports.utils;
@@ -70,7 +70,7 @@ const Sidebar = new Lang.Class({
this.get_style_context().add_class('maps-sidebar');
let ui = Utils.getUIObject('sidebar', [ 'sidebar',
- 'via-grid-container',
+ 'entry-list',
'instruction-list-scrolled',
'instruction-stack',
'instruction-spinner',
@@ -79,12 +79,10 @@ const Sidebar = new Lang.Class({
'mode-bike-toggle',
'mode-car-toggle',
'time-info',
- 'distance-info',
- 'from-entry-grid',
- 'to-entry-grid',
- 'via-add-button']);
+ 'distance-info' ]);
this._mapView = mapView;
+ this._entryList = ui.entryList;
this._viaGridContainer = ui.viaGridContainer;
this._instructionList = ui.instructionList;
this._instructionStack = ui.instructionStack;
@@ -98,24 +96,12 @@ const Sidebar = new Lang.Class({
this._initTransportationToggles(ui.modePedestrianToggle,
ui.modeBikeToggle,
ui.modeCarToggle);
+ this._initQuerySignals(ui.viaGridContainer);
let query = Application.routeService.query;
query.addPoint(0);
- let fromEntry = this._initRouteEntry(ui.fromEntryGrid, 0);
-
query.addPoint(1);
- this._initRouteEntry(ui.toEntryGrid, 1);
-
- this._initQuerySignals(ui.viaGridContainer);
-
- this.bind_property('child-revealed',
- fromEntry, 'has_focus',
- GObject.BindingFlags.DEFAULT);
-
- ui.viaAddButton.connect('clicked', (function() {
- query.addPoint(-1);
- }).bind(this));
this.add(ui.sidebar);
},
@@ -153,55 +139,45 @@ const Sidebar = new Lang.Class({
_initQuerySignals: function(listbox) {
let query = Application.routeService.query;
- // Do nothing for the From and To points.
query.connect('point-added', (function(obj, point, index) {
- if (index !== 0 && index !== query.points.length - 1)
- this._createViaRow(listbox, index);
+ this._createRouteEntry(index, point);
}).bind(this));
query.connect('point-removed', (function(obj, point, index) {
- let row = listbox.get_row_at_index(index - 1);
+ let row = this._entryList.get_row_at_index(index);
row.destroy();
}).bind(this));
},
- _createPlaceEntry: function() {
- return new PlaceEntry.PlaceEntry({ visible: true,
- can_focus: true,
- hexpand: true,
- receives_default: true,
- mapView: this._mapView,
- parseOnFocusOut: true,
- maxChars: 15 });
- },
-
- _createViaRow: function(listbox, index) {
- let ui = Utils.getUIObject('route-via-row', [ 'via-grid',
- 'via-remove-button',
- 'via-entry-grid' ]);
- let insertIndex = index - 1;
- let entry = this._createPlaceEntry();
-
- this._initRouteEntry(ui.viaEntryGrid, index);
- listbox.insert(ui.viaGrid, insertIndex);
-
- ui.viaRemoveButton.connect('clicked', function() {
- let row = ui.viaGrid.get_parent();
- let pointIndex = row.get_index();
- Application.routeService.query.removePoint(pointIndex + 1);
- });
- },
-
- _initRouteEntry: function(container, pointIndex) {
- let entry = this._createPlaceEntry();
- container.add(entry);
-
- let point = Application.routeService.query.points[pointIndex];
- entry.bind_property('place',
- point, 'place',
- GObject.BindingFlags.BIDIRECTIONAL);
+ _createRouteEntry: function(index, point) {
+ let type;
+ if (index === 0)
+ type = RouteEntry.Type.FROM;
+ else if (index === this._entryList.get_children().length)
+ type = RouteEntry.Type.TO;
+ else
+ type = RouteEntry.Type.VIA;
+
+ let routeEntry = new RouteEntry.RouteEntry({ type: type,
+ point: point,
+ mapView: this._mapView });
+ this._entryList.insert(routeEntry, index);
+
+ if (type === RouteEntry.Type.FROM) {
+ routeEntry.button.connect('clicked', (function() {
+ let lastIndex = this._entryList.get_children().length;
+ Application.routeService.query.addPoint(lastIndex - 1);
+ }).bind(this));
- return entry;
+ this.bind_property('child-revealed',
+ routeEntry.entry, 'has_focus',
+ GObject.BindingFlags.DEFAULT);
+ } else if (type === RouteEntry.Type.VIA) {
+ routeEntry.button.connect('clicked', function() {
+ let row = routeEntry.get_parent();
+ Application.routeService.query.removePoint(row.get_index());
+ });
+ }
},
_initInstructionList: function() {
@@ -211,9 +187,11 @@ const Sidebar = new Lang.Class({
route.connect('reset', (function() {
this._clearInstructions();
this._instructionStack.visible_child = this._instructionWindow;
- this._viaGridContainer.get_children().forEach((function(row) {
- query.removePoint(row.get_index() + 1);
- }).bind(this));
+
+ let length = this._entryList.get_children().length;
+ for (let index = 1; index < (length - 1); index++) {
+ query.removePoint(index);
+ }
}).bind(this));
query.connect('notify', (function() {
diff --git a/src/sidebar.ui b/src/sidebar.ui
index 2a19d40..15fc36b 100644
--- a/src/sidebar.ui
+++ b/src/sidebar.ui
@@ -90,90 +90,14 @@
</object>
</child>
<child>
- <object class="GtkGrid" id="from-grid">
- <property name="visible">True</property>
- <property name="orientation">horizontal</property>
- <property name="margin_top">12</property>
- <property name="hexpand">False</property>
- <child>
- <object class="GtkImage" id="from-image">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="margin-start">15</property>
- <property name="margin-end">8</property>
- <property name="width-request">16</property>
- <property name="icon-name">maps-point-start-symbolic</property>
- </object>
- </child>
- <child>
- <object class="GtkGrid" id="from-entry-grid">
- <property name="visible">True</property>
- <property name="hexpand">True</property>
- <property name="can_focus">False</property>
- </object>
- </child>
- <child>
- <object class="GtkButton" id="via-add-button">
- <property name="visible">True</property>
- <property name="can-focus">True</property>
- <property name="valign">center</property>
- <property name="margin-start">4</property>
- <property name="margin-end">12</property>
- <property name="height-request">31</property>
- <property name="width-request">31</property>
- <child>
- <object class="GtkImage" id="via-add-image">
- <property name="visible">True</property>
- <property name="icon-name">list-add-symbolic</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkListBox" id="via-grid-container">
- <property name="name">via-grid-container</property>
+ <object class="GtkListBox" id="entry-list">
+ <property name="name">sidebar-entry-list</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection-mode">GTK_SELECTION_NONE</property>
</object>
</child>
<child>
- <object class="GtkGrid" id="to-grid">
- <property name="visible">True</property>
- <property name="orientation">horizontal</property>
- <property name="vexpand">False</property>
- <property name="hexpand">False</property>
- <child>
- <object class="GtkImage" id="to-image">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="margin-start">15</property>
- <property name="margin-end">8</property>
- <property name="width-request">16</property>
- <property name="icon-name">maps-point-end-symbolic</property>
- </object>
- </child>
- <child>
- <object class="GtkGrid" id="to-entry-grid">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="hexpand">True</property>
- </object>
- </child>
- <child>
- <object class="GtkGrid" id="to-placeholder-grid">
- <property name="visible">True</property>
- <property name="can-focus">True</property>
- <property name="margin-end">19</property>
- <property name="height-request">31</property>
- <property name="width-request">31</property>
- </object>
- </child>
- </object>
- </child>
- <child>
<object class="GtkGrid" id="sidebar-route-info-wrapper">
<property name="visible">True</property>
<property name="hexpand">False</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]