Commit 4e3aece0 authored by Sumaid Syed's avatar Sumaid Syed Committed by Sumaid
Browse files

contextMenu : Add new option 'Create a favorite'

Context Menu gives the option to mark any location as favorite with the user given name.
ZoomDialog also takes description as parameter, to be used for favorite option also.
Favorites which are added through newly added context menu option don't
get loaded in next session of maps.
Comment the part which checks for id attribute of place before loading favorites in
next section. 'id' attribute doesn't get used anywhere.

closes GNOME/gnome-maps#144
parent 745e75e8
Pipeline #54922 failed with stages
in 11 minutes and 33 seconds
......@@ -5,6 +5,7 @@
<file preprocess="xml-stripblanks">ui/check-in-dialog.ui</file>
<file preprocess="xml-stripblanks">ui/context-menu.ui</file>
<file preprocess="xml-stripblanks">ui/export-view-dialog.ui</file>
<file preprocess="xml-stripblanks">ui/favorite-edit-dialog.ui</file>
<file preprocess="xml-stripblanks">ui/favorites-popover.ui</file>
<file preprocess="xml-stripblanks">ui/instruction-row.ui</file>
<file preprocess="xml-stripblanks">ui/layers-popover.ui</file>
......
......@@ -37,5 +37,12 @@
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="createFavorite">
<property name="name">create-favorite</property>
<property name="label" translatable="yes">Create a favorite</property>
<property name="visible">True</property>
</object>
</child>
</template>
</interface>
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.12"/>
<template class="Gjs_FavoriteEditDialog" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="type">popup</property>
<property name="type_hint">dialog</property>
<property name="width_request">500</property>
<property name="height_request">200</property>
<child internal-child="vbox">
<object class="GtkBox" id="contentArea">
<child>
<object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<property name="transition_type">crossfade</property>
<child>
<object class="GtkGrid" id="loadingGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkSpinner" id="loadingSpinner">
<property name="height_request">32</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="active">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="name">loading</property>
</packing>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="margin">20</property>
<child>
<object class="GtkGrid" id="editorGrid">
<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-bottom">12</property>
</object>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="vexpand">True</property>
<property name="valign">GTK_ALIGN_END</property>
</object>
</child>
</object>
<packing>
<property name="name">editor</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar" id="headerBar">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="show-close-button">False</property>
<property name="title" translatable="yes" context="dialog title">Edit on OpenStreetMap</property>
<child>
<object class="GtkButton" id="cancelButton">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="pack-type">start</property>
</packing>
</child>
<child>
<object class="GtkButton" id="saveButton">
<property name="label" translatable="yes">Save</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<style>
<class name="default"/>
</style>
</object>
<packing>
<property name="pack-type">end</property>
</packing>
</child>
</object>
</child>
</template>
</interface>
......@@ -11,9 +11,9 @@
<object class="GtkBox" id="contentArea">
<property name="visible">True</property>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="descriptionLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Zoom in to add location!</property>
<property name="label" translatable="yes"></property>
</object>
</child>
</object>
......
......@@ -32,7 +32,9 @@ const Location = imports.location;
const OSMAccountDialog = imports.osmAccountDialog;
const OSMEdit = imports.osmEdit;
const OSMEditDialog = imports.osmEditDialog;
const FavoriteEditDialog = imports.favoriteEditDialog;
const Place = imports.place;
const PlaceStore = imports.placeStore;
const RouteQuery = imports.routeQuery;
const Utils = imports.utils;
const ZoomInDialog = imports.zoomInDialog;
......@@ -43,7 +45,8 @@ var ContextMenu = GObject.registerClass({
'geoURIItem',
'exportItem',
'addOSMLocationItem',
'routeItem' ],
'routeItem',
'createFavorite' ],
}, class ContextMenu extends Gtk.Menu {
_init(params) {
this._mapView = params.mapView;
......@@ -67,6 +70,8 @@ var ContextMenu = GObject.registerClass({
this._onAddOSMLocationActivated.bind(this));
this._routeItem.connect('activate',
this._onRouteActivated.bind(this));
this._createFavorite.connect('activate',
this._onCreateFavoriteActivated.bind(this));
Application.routeQuery.connect('notify::points',
this._routingUpdate.bind(this));
this._routeItem.visible = false;
......@@ -135,6 +140,35 @@ var ContextMenu = GObject.registerClass({
});
}
_onCreateFavoriteActivated() {
if (this._mapView.view.get_zoom_level() < FavoriteEditDialog.MIN_ADD_LOCATION_ZOOM_LEVEL) {
let zoomInDialog =
new ZoomInDialog.ZoomInDialog({
longitude: this._longitude,
latitude: this._latitude,
view: this._mapView.view,
transient_for: this._mainWindow,
description: 'Zoom in to mark a location as favorite!',
modal: true
});
zoomInDialog.connect('response', () => zoomInDialog.destroy());
zoomInDialog.show_all();
return;
}
let dialog = new FavoriteEditDialog.FavoriteEditDialog({
transient_for: this._mainWindow,
modal: true,
latitude: this._latitude,
longitude: this._longitude
});
dialog.show();
dialog.connect('response', (dialog) => {
dialog.destroy();
});
}
_onGeoURIActivated() {
let location = new Location.Location({ latitude: this._latitude,
longitude: this._longitude,
......@@ -161,7 +195,7 @@ var ContextMenu = GObject.registerClass({
return;
}
this._addOSMLocation();
}
......@@ -174,7 +208,8 @@ var ContextMenu = GObject.registerClass({
latitude: this._latitude,
view: this._mapView.view,
transient_for: this._mainWindow,
modal: true });
description: 'Zoom in to add location!',
modal: true, });
zoomInDialog.connect('response', () => zoomInDialog.destroy());
zoomInDialog.show_all();
......
/* -*- 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
*
*/
const _ = imports.gettext.gettext;
const Geocode = imports.gi.GeocodeGlib;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Soup = imports.gi.Soup;
const Application = imports.application;
const Maps = imports.gi.GnomeMaps;
const Place = imports.place;
const PlaceStore = imports.placeStore;
const Location = imports.location;
const Utils = imports.utils;
var MIN_ADD_LOCATION_ZOOM_LEVEL = 16;
var Response = {
UPLOADED: 0,
CANCELLED: 2,
ERROR: 3
};
var FavoriteEditDialog = GObject.registerClass({
Template: 'resource:///org/gnome/Maps/ui/favorite-edit-dialog.ui',
InternalChildren: ['cancelButton',
'saveButton',
'stack',
'editorGrid',
'headerBar'],
}, class FavoriteEditDialog extends Gtk.Dialog {
_init(params) {
this._latitude = params.latitude;
delete params.latitude;
this._longitude = params.longitude;
delete params.longitude;
this._location = new Location.Location({
latitude: this._latitude,
longitude: this._longitude,
accuracy: 0
});
this._place = new Place.Place({ location: this._location });
/* This is a construct-only property and cannot be set by GtkBuilder */
params.use_header_bar = true;
super._init(params);
let label = new Gtk.Label({
label: 'Name',
use_markup: true
});
label.halign = Gtk.Align.END;
label.get_style_context().add_class('dim-label');
this._editorGrid.attach(label, 0, 1, 1, 1);
label.show();
let entry = new Gtk.Entry();
entry.hexpand = true;
entry.connect('changed', () => {
this._place.name = entry.text;
this._saveButton.sensitive = true;
});
this._editorGrid.attach(entry, 1, 1, 1, 1);
entry.show();
entry.grab_focus();
this._stack.visible_child_name = 'editor';
this._saveButton.connect('clicked', () => this._onSaveClicked());
this._cancelButton.connect('clicked', () => this._onCancelClicked());
this._headerBar.title = C_("dialog title", "Mark as favorite");
}
_onSaveClicked() {
let placeStore = Application.placeStore;
if (!placeStore.exists(this._place, null)) {
placeStore.addPlace(this._place,
PlaceStore.PlaceType.FAVORITE);
}
this.response(Response.CANCELLED);
}
_onCancelClicked() {
this.response(Response.CANCELLED);
}
});
......@@ -11,6 +11,7 @@
<file>epaf.js</file>
<file>exportViewDialog.js</file>
<file>facebookBackend.js</file>
<file>favoriteEditDialog.js</file>
<file>favoritesPopover.js</file>
<file>foursquareBackend.js</file>
<file>foursquareGoaAuthorizer.js</file>
......
......@@ -107,7 +107,9 @@ class Place extends Geocode.Place {
}
get uniqueID() {
return this.osm_type + '-' + this.osm_id;
if (this.osm_type)
return this.osm_type + '-' + this.osm_id;
return 'user-defined' + this.location.longitude + '-' + this.location.latitude;
}
set population(v) {
......
......@@ -91,7 +91,7 @@ class PlaceStore extends Gtk.ListStore {
_addFavorite(place) {
if (!place.store)
return;
if (this.exists(place, PlaceType.FAVORITE)) {
return;
}
......@@ -170,8 +170,8 @@ class PlaceStore extends Gtk.ListStore {
// We expect exception to be thrown in this line when parsing
// gnome-maps 3.14 or below place stores since the "place"
// key is not present.
if (!place.id)
return;
//if (!place.id)
// return;
let p;
if (type === PlaceType.RECENT_ROUTE) {
......
......@@ -28,7 +28,8 @@ const OSMEdit = imports.osmEdit;
var ZoomInDialog = GObject.registerClass({
Template: 'resource:///org/gnome/Maps/ui/zoom-in-dialog.ui',
InternalChildren: [ 'cancelButton',
'zoomInButton'],
'zoomInButton',
'descriptionLabel'],
}, class ZoomInDialog extends Gtk.Dialog {
_init(params) {
......@@ -38,12 +39,16 @@ var ZoomInDialog = GObject.registerClass({
delete params.longitude;
this._view = params.view;
delete params.view;
let description = params.description;
delete params.description;
/* This is a construct-only property and cannot be set by GtkBuilder */
params.use_header_bar = true;
super._init(params);
this._descriptionLabel.label = description;
this._zoomInButton.connect('clicked', () => this._onZoomIn());
this._cancelButton.connect('clicked', () => this._onCancel());
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment