diff options
author | Felipe Kinoshita <kinofhek@gmail.com> | 2023-03-20 20:11:03 +0000 |
---|---|---|
committer | Marcus Lundblad <ml@dfupdate.se> | 2023-03-20 20:11:03 +0000 |
commit | f770faed34ef9397328fb9d3bca025a2ac06c049 (patch) | |
tree | 62ae5ce7402568c1667ffc383964b60aa721b68c /src | |
parent | f88b6bd3e52d5f0e8ec741ab56afe1e0dcdf546b (diff) | |
download | gnome-maps-f770faed34ef9397328fb9d3bca025a2ac06c049.tar.gz |
Make use of Adw.Toast
Diffstat (limited to 'src')
-rw-r--r-- | src/application.js | 9 | ||||
-rw-r--r-- | src/mainWindow.js | 10 | ||||
-rw-r--r-- | src/mapView.js | 20 | ||||
-rw-r--r-- | src/osmAccountDialog.js | 5 | ||||
-rw-r--r-- | src/osmEditDialog.js | 6 | ||||
-rw-r--r-- | src/placeEntry.js | 9 | ||||
-rw-r--r-- | src/sendToDialog.js | 6 | ||||
-rw-r--r-- | src/utils.js | 16 |
8 files changed, 35 insertions, 46 deletions
diff --git a/src/application.js b/src/application.js index d787dea3..d6a0cf50 100644 --- a/src/application.js +++ b/src/application.js @@ -249,8 +249,7 @@ export class Application extends Adw.Application { GeocodeFactory.getGeocoder().search(query, null, null, cancellable, (places, error) => { if (error) { - Utils.showDialog(_("An error has occurred"), - Gtk.MessageType.ERROR, this._mainWindow); + this._mainWindow.showToast(_("An error has occurred")); } else { // clear search entry this._mainWindow.placeEntry.text = ''; @@ -272,16 +271,14 @@ export class Application extends Adw.Application { false); } } else { - Utils.showDialog(_("No results found"), - Gtk.MessageType.INFO, this._mainWindow); + this._mainWindow.showToast(_("No results found")); } } }); } _invalidMapsUri(uri) { - Utils.showDialog(_("Invalid maps: URI: %s").format(uri), - Gtk.MessageType.ERROR, this._mainWindow); + this._mainWindow.showToast(_("Invalid maps: URI: %s").format(uri)); } vfunc_open(files) { diff --git a/src/mainWindow.js b/src/mainWindow.js index c9466248..e99a1414 100644 --- a/src/mainWindow.js +++ b/src/mainWindow.js @@ -134,6 +134,10 @@ export class MainWindow extends Gtk.ApplicationWindow { this.title = _("Maps"); } + showToast(message) { + Utils.showToastInOverlay(message, this._overlay); + } + _createPlaceEntry() { let placeEntry = new PlaceEntry({ mapView: this._mapView, visible: true, @@ -439,8 +443,7 @@ export class MainWindow extends Gtk.ApplicationWindow { Application.geoclue.start(() => { switch(Application.geoclue.state) { case Geoclue.State.FAILED: - message = _("Failed to connect to location service"); - Utils.showDialog(message, Gtk.MessageType.ERROR, this); + this.showToast(_("Failed to connect to location service")); break; case Geoclue.State.DENIED: @@ -634,5 +637,6 @@ GObject.registerClass({ 'grid', 'actionBar', 'actionBarRevealer', - 'placeBarContainer'] + 'placeBarContainer', + 'overlay'] }, MainWindow); diff --git a/src/mapView.js b/src/mapView.js index cc459d29..d7f91e5f 100644 --- a/src/mapView.js +++ b/src/mapView.js @@ -457,7 +457,7 @@ export class MapView extends Gtk.Overlay { } catch(e) { this.setMapType(MapView.MapType.STREET); Application.application.local_tile_path = false; - Utils.showDialog(e.message, Gtk.MessageType.ERROR, this._mainWindow); + this._mainWindow.showToast(e.message); return; } } @@ -498,8 +498,7 @@ export class MapView extends Gtk.Overlay { _onShapeLoad(error, bbox, layer) { if (error) { - let msg = _("Failed to open layer"); - Utils.showDialog(msg, Gtk.MessageType.ERROR, this._mainWindow); + this._mainWindow.showToast(_("Failed to open layer")); } else { bbox.compose(layer.bbox); } @@ -558,8 +557,7 @@ export class MapView extends Gtk.Overlay { } } catch (e) { Utils.debug(e); - let msg = _("Failed to open layer"); - Utils.showDialog(msg, Gtk.MessageType.ERROR, this._mainWindow); + this._mainWindow.showToast(_("Failed to open layer")); } } } @@ -590,8 +588,7 @@ export class MapView extends Gtk.Overlay { this._placeLayer.add_marker(marker); marker.goToAndSelect(true); } catch(e) { - let msg = _("Failed to open GeoURI"); - Utils.showDialog(msg, Gtk.MessageType.ERROR, this._mainWindow); + this._mainWindow.showToast(_("Failed to open GeoURI")); Utils.debug("failed to open GeoURI: %s".format(e.message)); } } @@ -605,7 +602,7 @@ export class MapView extends Gtk.Overlay { this._placeLayer.add_marker(marker); marker.goToAndSelect(true); } else { - Utils.showDialog(error, Gtk.MessageType.ERROR, this._mainWindow); + this._mainWindow.showToast(error); } }); } @@ -1030,9 +1027,7 @@ export class MapView extends Gtk.Overlay { if (place) { this.showPlace(place, true); } else { - let msg = _("Nothing found here!"); - - Utils.showDialog(msg, Gtk.MessageType.INFO, this._mainWindow); + this._mainWindow.showToast(_("Nothing found here!")); } }); } @@ -1091,8 +1086,7 @@ export class MapView extends Gtk.Overlay { dialog.connect('response', (dialog, response) => { dialog.destroy(); if (response === OSMEditDialog.Response.UPLOADED) { - Utils.showDialog(_("Location was added to the map, note that it may take a while before it shows on the map and in search results."), - Gtk.MessageType.INFO, this._mainWindow); + this._mainWindow.showToast(_("Location was added in OpenStreetMap")); } }); } diff --git a/src/osmAccountDialog.js b/src/osmAccountDialog.js index 1e83835d..b7359a40 100644 --- a/src/osmAccountDialog.js +++ b/src/osmAccountDialog.js @@ -126,7 +126,7 @@ export class OSMAccountDialog extends Gtk.Dialog { } } else { if (errorMessage) - Utils.showDialog(errorMessage, Gtk.MessageType.ERROR, this); + Utils.showToastInOverlay(errorMessage, this._overlay); /* switch back to the sign-in view, and show a label indicating that verification failed */ this._errorLabel.visible = true; @@ -154,5 +154,6 @@ GObject.registerClass({ 'verifyButton', 'errorLabel', 'signedInUserLabel', - 'signOutButton'], + 'signOutButton', + 'overlay'], }, OSMAccountDialog); diff --git a/src/osmEditDialog.js b/src/osmEditDialog.js index 32890c5e..82912aa3 100644 --- a/src/osmEditDialog.js +++ b/src/osmEditDialog.js @@ -838,8 +838,7 @@ export class OSMEditDialog extends Gtk.Dialog { this._cancellable, (wikidata) => { if (!wikidata) { - Utils.showDialog(_("Couldn't find Wikidata tag for article"), - Gtk.MessageType.ERROR, this); + Utils.showToastInOverlay(_("Couldn't find Wikidata tag for article"), this._overlay); return; } @@ -996,6 +995,7 @@ GObject.registerClass({ 'typeValueLabel', 'recentTypesLabel', 'recentTypesListBox', - 'headerBar'], + 'headerBar', + 'overlay'], }, OSMEditDialog); diff --git a/src/placeEntry.js b/src/placeEntry.js index 77df0837..19e6024c 100644 --- a/src/placeEntry.js +++ b/src/placeEntry.js @@ -264,8 +264,7 @@ export class PlaceEntry extends Gtk.SearchEntry { location.set_from_uri(this.text); this.place = new Place({ location: location }); } catch(e) { - let msg = _("Failed to parse Geo URI"); - Utils.showDialog(msg, Gtk.MessageType.ERROR, this.get_toplevel()); + this.root.showToast(_("Failed to parse Geo URI")); } parsed = true; @@ -277,8 +276,7 @@ export class PlaceEntry extends Gtk.SearchEntry { if (query) { this.text = query; } else { - let msg = _("Failed to parse Maps URI"); - Utils.showDialog(msg, Gtk.MessageType.ERROR, this.get_toplevel()); + this.root.showToast(_("Failed to parse Maps URI")); } parsed = true; @@ -306,8 +304,7 @@ export class PlaceEntry extends Gtk.SearchEntry { if (place) this.place = place; else - Utils.showDialog(error, - Gtk.MessageType.ERROR, this.get_toplevel()); + this.root.showToast(error); }); /* don't cancel ongoing search, as we have started an async diff --git a/src/sendToDialog.js b/src/sendToDialog.js index f2665417..257df649 100644 --- a/src/sendToDialog.js +++ b/src/sendToDialog.js @@ -178,8 +178,7 @@ export class SendToDialog extends Gtk.Dialog { try { Gio.app_info_launch_default_for_uri(uri, this._getAppLaunchContext()); } catch(e) { - Utils.showDialog(_("Failed to open URI"), Gtk.MessageType.ERROR, - this); + Utils.showToastInOverlay(_("Failed to open URI"), this._overlay); Utils.debug('failed to open URI: %s'.format(e.message)); } @@ -235,7 +234,8 @@ GObject.registerClass({ 'summaryUrl', 'copyButton', 'emailButton', - 'scrolledWindow' ] + 'scrolledWindow', + 'overlay'] }, SendToDialog); export class OpenWithRow extends Gtk.ListBoxRow { diff --git a/src/utils.js b/src/utils.js index 65057b6e..70b74caa 100644 --- a/src/utils.js +++ b/src/utils.js @@ -28,6 +28,7 @@ import GdkPixbuf from 'gi://GdkPixbuf'; import GeocodeGlib from 'gi://GeocodeGlib'; import Gio from 'gi://Gio'; import Gtk from 'gi://Gtk'; +import Adw from 'gi://Adw'; import GWeather from 'gi://GWeather'; const _ = gettext.gettext; @@ -453,17 +454,12 @@ export function isUsingHighContrastTheme() { return themeName === 'HighContrast' || themeName === 'HighContrastInverse'; } -export function showDialog(msg, type, transientFor) { - let messageDialog = - new Gtk.MessageDialog({ transient_for: transientFor, - destroy_with_parent: true, - message_type: type, - buttons: Gtk.ButtonsType.OK, - modal: true, - text: msg }); +export function showToastInOverlay(message, overlay) { + let toast = new Adw.Toast({ + title: message, + }); - messageDialog.connect('response', () => messageDialog.destroy()); - messageDialog.show(); + overlay.add_toast(toast); } let decoder = new TextDecoder('utf-8'); |