[gnome-weather] window: add a selection toolbar with a delete action
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-weather] window: add a selection toolbar with a delete action
- Date: Tue, 5 Mar 2013 22:24:48 +0000 (UTC)
commit 1c667c9ecfe4d536c496a01fc3af1bcff0d2f68d
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue Mar 5 13:46:46 2013 -0500
window: add a selection toolbar with a delete action
https://bugzilla.gnome.org/show_bug.cgi?id=695241
src/window.js | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 83 insertions(+), 1 deletions(-)
---
diff --git a/src/window.js b/src/window.js
index 5c3920e..58a2b53 100644
--- a/src/window.js
+++ b/src/window.js
@@ -19,6 +19,9 @@
const City = imports.city;
const World = imports.world;
+const Gettext = imports.gettext;
+const Tweener = imports.tweener.tweener;
+
function makeTitle(location) {
let city = location;
if (location.get_level() == GWeather.LocationLevel.WEATHER_STATION)
@@ -40,6 +43,63 @@ const Page = {
CITY: 1
};
+const _SELECTION_TOOLBAR_DEFAULT_WIDTH = 300;
+
+const SelectionToolbar = new Lang.Class({
+ Name: 'SelectionToolbar',
+ Extends: Gtk.Toolbar,
+
+ _init: function(worldView) {
+ this._worldView = worldView;
+
+ this.parent({ show_arrow: false,
+ halign: Gtk.Align.CENTER,
+ valign: Gtk.Align.END,
+ margin_bottom: 40,
+ icon_size: Gtk.IconSize.LARGE_TOOLBAR,
+ opacity: 0 });
+ this.get_style_context().add_class('osd');
+ this.set_size_request(_SELECTION_TOOLBAR_DEFAULT_WIDTH, -1);
+
+ this._box = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL });
+ let item = new Gtk.ToolItem({ child: this._box });
+ item.set_expand(true);
+ this.insert(item, -1);
+
+ let button = new Gtk.Button({ label: _("Delete"),
+ hexpand: true });
+ this._box.add(button);
+
+ button.connect('clicked', Lang.bind(this, function() {
+ let items = this._worldView.get_selection();
+ let model = this._worldView.get_model();
+
+ items.forEach(function(itemPath) {
+ let [res, iter] = model.get_iter(itemPath);
+ if (res)
+ model.removeLocation(iter);
+ });
+ }));
+ },
+
+ fadeIn: function() {
+ this.show_all();
+ Tweener.addTween(this, { opacity: 1,
+ time: 0.30,
+ transition: 'easeOutQuad' });
+ },
+
+ fadeOut: function() {
+ Tweener.addTween(this, { opacity: 0,
+ time: 0.30,
+ transition: 'easeOutQuad',
+ onComplete: function() {
+ this.hide();
+ },
+ onCompleteScope: this });
+ }
+});
+
const MainWindow = new Lang.Class({
Name: 'MainWindow',
Extends: Gtk.ApplicationWindow,
@@ -126,7 +186,29 @@ const MainWindow = new Lang.Class({
GObject.BindingFlags.SYNC_CREATE);
this._stack.set_visible_child(this._worldView);
- grid.add(this._stack);
+
+ this._overlay = new Gtk.Overlay();
+ this._overlay.add(this._stack);
+ grid.add(this._overlay);
+
+ this._selectionToolbar = new SelectionToolbar(this._worldView);
+ this._overlay.add_overlay(this._selectionToolbar);
+
+ this._worldView.connect('view-selection-changed', Lang.bind(this, function() {
+ let items = this._worldView.get_selection();
+ let label = _("Click on locations to select them");
+
+ if (items.length > 0) {
+ label = Gettext.ngettext("%d selected",
+ "%d selected",
+ items.length).format(items.length);
+ this._selectionToolbar.fadeIn();
+ } else {
+ this._selectionToolbar.fadeOut();
+ }
+
+ this._header.set_title(label);
+ }));
this.add(grid);
grid.show_all();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]