[gnome-weather] Add selection menu



commit 14d8b0f5ef5ce95e2c20f12e5a6338bf9941b9b6
Author: Paolo Borelli <pborelli gnome org>
Date:   Mon Mar 11 21:49:39 2013 +0100

    Add selection menu
    
    Add the selection menu with "Select All" and "Select None".
    
    https://bugzilla.gnome.org/show_bug.cgi?id=695567

 data/window.ui |   13 +++++++++++++
 src/main.js    |    3 +++
 src/window.js  |   35 +++++++++++++++++++++++++++++++----
 3 files changed, 47 insertions(+), 4 deletions(-)
---
diff --git a/data/window.ui b/data/window.ui
index d07d5ff..d068db4 100644
--- a/data/window.ui
+++ b/data/window.ui
@@ -1,6 +1,19 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
+  <menu id="selection-menu">
+    <section>
+      <item>
+        <attribute name="action">win.select-all</attribute>
+        <attribute name="label" translatable="yes">Select All</attribute>
+        <attribute name="accel">&lt;Primary&gt;a</attribute>
+      </item>
+      <item>
+        <attribute name="action">win.select-none</attribute>
+        <attribute name="label" translatable="yes">Select None</attribute>
+      </item>
+    </section>
+  </menu>
   <object class="GtkGrid" id="main-panel">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
diff --git a/src/main.js b/src/main.js
index 8435071..2a878df 100644
--- a/src/main.js
+++ b/src/main.js
@@ -74,6 +74,9 @@ const Application = new Lang.Class({
                             callback: this._onQuit }]);
 
         this._initAppMenu();
+
+        this.add_accelerator("Escape", "win.exit-selection-mode", null);
+        this.add_accelerator("<Primary>a", "win.select-all", null);
     },
 
     vfunc_activate: function() {
diff --git a/src/window.js b/src/window.js
index dcfc366..d08a815 100644
--- a/src/window.js
+++ b/src/window.js
@@ -105,7 +105,13 @@ const MainWindow = new Lang.Class({
                          [{ name: 'new',
                             callback: this._newLocation },
                           { name: 'about',
-                            callback: this._showAbout }]);
+                            callback: this._showAbout },
+                          { name: 'exit-selection-mode',
+                            callback: this._exitSelectionMode },
+                          { name: 'select-all',
+                            callback: this._selectAll },
+                          { name: 'select-none',
+                            callback: this._selectNone }]);
 
         let builder = new Gtk.Builder();
         builder.add_from_resource('/org/gnome/weather/window.ui');
@@ -131,6 +137,14 @@ const MainWindow = new Lang.Class({
         let selectDone = builder.get_object('done-button');
         this._pageWidgets[Page.WORLD].push(selectDone);
 
+        let selectionMenu = builder.get_object("selection-menu");
+
+        this._selectionMenuButton = new Gd.HeaderMenuButton(
+            { label: _("Click on items to select them"),
+              menu_model: selectionMenu,
+            });
+        this._selectionMenuButton.get_style_context().add_class("selection-menu");
+
         this._stack = new Gd.Stack({ transition_type: Gd.StackTransitionType.CROSSFADE });
 
         this._cityView = new City.WeatherView({ hexpand: true,
@@ -156,10 +170,10 @@ const MainWindow = new Lang.Class({
 
             if (mode) {
                 this._header.get_style_context().add_class('selection-mode');
-                this._header.set_title(_("Click on locations to select them"));
+                this._header.set_custom_title(this._selectionMenuButton);
             } else {
                 this._header.get_style_context().remove_class('selection-mode');
-                this._header.set_title(null);
+                this._header.set_custom_title(null);
             }
         }));
 
@@ -192,7 +206,7 @@ const MainWindow = new Lang.Class({
                 this._selectionToolbar.fadeOut();
             }
 
-            this._header.set_title(label);
+            this._selectionMenuButton.set_label(label);
         }));
 
         this.add(grid);
@@ -297,6 +311,19 @@ const MainWindow = new Lang.Class({
         dialog.show_all();
     },
 
+    _exitSelectionMode: function() {
+        this._worldView.selection_mode = false;
+    },
+
+    _selectAll: function() {
+        this._worldView.selection_mode = true;
+        this._worldView.select_all();
+    },
+
+    _selectNone: function() {
+        this._worldView.unselect_all();
+    },
+
     _showAbout: function() {
         let artists = [ 'Jakub Steiner <jimmac gmail com>',
                         'Pink Sherbet Photography (D. Sharon Pruitt)',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]