[gnome-maps/wip/mlundblad/osm-edit-namevariants: 12/12] WIP: osmEditDialog: Implement editing name variants
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/osm-edit-namevariants: 12/12] WIP: osmEditDialog: Implement editing name variants
- Date: Tue, 30 May 2017 21:01:10 +0000 (UTC)
commit 4042d1942247686ce60ec1bf871a85e181ea941a
Author: Marcus Lundblad <ml update uu se>
Date: Thu Mar 23 23:21:16 2017 +0100
WIP: osmEditDialog: Implement editing name variants
data/ui/osm-edit-dialog.ui | 12 ++++
src/osmEditDialog.js | 141 +++++++++++++++++++++++++++++++++++++++++--
2 files changed, 146 insertions(+), 7 deletions(-)
---
diff --git a/data/ui/osm-edit-dialog.ui b/data/ui/osm-edit-dialog.ui
index 1b9fd32..72ccaf0 100644
--- a/data/ui/osm-edit-dialog.ui
+++ b/data/ui/osm-edit-dialog.ui
@@ -148,6 +148,18 @@
</packing>
</child>
<child>
+ <object class="GtkGrid" id="nameVariantsGrid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="row-spacing">12</property>
+ <property name="column-spacing">6</property>
+ <property name="margin">20</property>
+ </object>
+ <packing>
+ <property name="name">name-variants</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkGrid" id="uploadGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
diff --git a/src/osmEditDialog.js b/src/osmEditDialog.js
index 9b9c1b7..b3acfae 100644
--- a/src/osmEditDialog.js
+++ b/src/osmEditDialog.js
@@ -24,6 +24,7 @@ const _ = imports.gettext.gettext;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
+const GnomeDesktop = imports.gi.GnomeDesktop;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Soup = imports.gi.Soup;
@@ -206,6 +207,36 @@ const OSM_FIELDS = [
['zoroastrian', _("Zoroastrianism")]]
}];
+const OSM_NAME_FIELDS = [
+ {
+ name: _("Alternative name"),
+ tag: 'alt_name',
+ type: EditFieldType.TEXT,
+ hint: _("Alternative name by which the feature is known.")
+ },
+ {
+ name: _("Old name"),
+ tag: 'old_name',
+ type: EditFieldType.TEXT,
+ hint: _("Older or historical name.")
+ },
+ {
+ name: _("English name"),
+ tag: 'name:en',
+ type: EditFieldType.TEXT,
+ hint: _("Name of feature in English.")
+ },
+ {
+ /* Translators: this placeholder string should be replaced by a string
+ * representing the translated equivalent to "English name" where
+ * "English" would be replaced by the name of the language translated
+ * into. This tag will be targetted at the user's actual language.
+ */
+ name: _("name-in-localized-language"),
+ tag: 'name:localized',
+ type: EditFieldType.TEXT
+ }];
+
const OSMEditAddress = new Lang.Class({
Name: 'OSMEditAddress',
Extends: Gtk.Grid,
@@ -254,6 +285,7 @@ const OSMEditDialog = new Lang.Class({
'nextButton',
'stack',
'editorGrid',
+ 'nameVariantsGrid',
'commentTextView',
'addFieldPopoverGrid',
'addFieldButton',
@@ -587,7 +619,31 @@ const OSMEditDialog = new Lang.Class({
deleteButton.show();
},
- _addOSMEditLabel: function(fieldSpec) {
+ _onNameVariantsClicked: function() {
+ this._cancelButton.visible = false;
+ this._backButton.visible = true;
+ this._nextButton.visible = false;
+ this._headerBar.title = _("Edit Name Variants");
+ this._stack.visible_child_name = 'name-variants';
+ },
+
+ _addOSMEditNameVariantsButton: function() {
+ let nameVariantsButton = Gtk.Button.new_from_icon_name('go-next-symbolic',
+ Gtk.IconSize.BUTTON);
+ let styleContext = nameVariantsButton.get_style_context();
+
+ nameVariantsButton.tooltip_text = _("Edit name variants");
+ styleContext.add_class('flat');
+ this._editorGrid.attach(nameVariantsButton, 2, this._currentRow, 1, 1);
+
+ nameVariantsButton.connect('clicked', (function() {
+ this._onNameVariantsClicked();
+ }).bind(this));
+
+ nameVariantsButton.show();
+ },
+
+ _createOSMEditLabel: function(fieldSpec) {
let text = fieldSpec.name;
if (fieldSpec.includeHelp) {
let link = _WIKI_BASE + fieldSpec.tag;
@@ -597,6 +653,20 @@ const OSMEditDialog = new Lang.Class({
use_markup: true });
label.halign = Gtk.Align.END;
label.get_style_context().add_class('dim-label');
+
+ return label;
+ },
+
+ _addOSMEditNameVariantLabel: function(fieldSpec, row) {
+ let label = this._createOSMEditLabel(fieldSpec);
+
+ this._nameVariantsGrid.attach(label, 0, row, 1, 1);
+ label.show();
+ },
+
+ _addOSMEditLabel: function(fieldSpec) {
+ let label = this._createOSMEditLabel(fieldSpec);
+
this._editorGrid.attach(label, 0, this._currentRow, 1, 1);
label.show();
},
@@ -610,11 +680,12 @@ const OSMEditDialog = new Lang.Class({
}
},
- _addOSMEditTextEntry: function(fieldSpec, value) {
- this._addOSMEditLabel(fieldSpec);
-
+ _createOSMEditTextEntry: function(fieldSpec, value) {
let entry = new Gtk.Entry();
- entry.text = value;
+
+ if (value)
+ entry.text = value;
+
entry.hexpand = true;
if (fieldSpec.placeHolder)
entry.placeholder_text = fieldSpec.placeHolder;
@@ -633,11 +704,28 @@ const OSMEditDialog = new Lang.Class({
}).bind(this));
}
+ return entry;
+ },
+
+ _addOSMEditNameVariantTextEntry: function(fieldSpec, value, row) {
+ let entry = this._createOSMEditTextEntry(fieldSpec, value);
+
+ this._addOSMEditNameVariantLabel(fieldSpec, row);
+ this._nameVariantsGrid.attach(entry, 1, row, 1, 1);
+ entry.show();
+ },
+
+ _addOSMEditTextEntry: function(fieldSpec, value) {
+ let entry = this._createOSMEditTextEntry(fieldSpec, value);
+
+ this._addOSMEditLabel(fieldSpec);
this._editorGrid.attach(entry, 1, this._currentRow, 1, 1);
entry.show();
- /* TODO: should we allow deleting the name field? */
- this._addOSMEditDeleteButton(fieldSpec);
+ if (fieldSpec.tag === 'name')
+ this._addOSMEditNameVariantsButton();
+ else
+ this._addOSMEditDeleteButton(fieldSpec);
this._currentRow++;
},
@@ -789,6 +877,17 @@ const OSMEditDialog = new Lang.Class({
}
},
+ /* Get a localized title for the "name in user's language" item,
+ * generate it programmatically if no translation is available
+ */
+ _getLocalizedNameTitle: function(title, language) {
+ Utils.debug('get localized name for: ' + language);
+ if (title === 'name-in-localized-language')
+ return GnomeDesktop.get_language_from_locale(language, 'C') + ' name';
+ else
+ return title;
+ },
+
_loadOSMData: function(osmObject) {
this._osmObject = osmObject;
@@ -820,6 +919,34 @@ const OSMEditDialog = new Lang.Class({
}
}
+ for (let i = 0; i < OSM_NAME_FIELDS.length; i++) {
+ let fieldSpec = OSM_NAME_FIELDS[i];
+
+ if (fieldSpec.type === EditFieldType.TEXT) {
+ // special handling for the locale-dependent name tag
+ if (fieldSpec.tag === 'name:localized') {
+ let language = OSMUtils.getLanguageCode();
+
+ if (language === 'en' || language === 'C') {
+ /* skip the localized name for English (or fallback) locale
+ * since we already have a hard-coded English name
+ */
+ continue;
+ } else {
+ // re-write the field-spec
+ fieldSpec.tag = 'name:' + language;
+ fieldSpec.name = this._getLocalizedNameTitle(fieldSpec.name,
+ language);
+ }
+ }
+ let value = osmObject.get_tag(fieldSpec.tag);
+
+ this._addOSMEditNameVariantTextEntry(fieldSpec, value, i);
+ } else {
+ Utils.debug('Only simple text input fields are supported for name variants');
+ }
+ }
+
this._updateAddFieldMenu();
this._updateTypeButton();
this._stack.visible_child_name = 'editor';
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]