[gnome-documents] Ports Dropdown of the Overview Searchbar to GtkPopover



commit 06b7534ec305c1eaa913a331b5a2e419268ae905
Author: Marta Milakovic <marta milakovic gmail com>
Date:   Tue Apr 15 23:32:16 2014 +0200

    Ports Dropdown of the Overview Searchbar to GtkPopover
    
    GtkPopover allows hiding interface elements out of the way.
    The problem of click handling for dropdown menu is solved by using
    GtkPopover.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=725622

 src/mainToolbar.js |    6 +-----
 src/searchbar.js   |   50 +++++++++++++++++---------------------------------
 2 files changed, 18 insertions(+), 38 deletions(-)
---
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index a1ed411..90ea778 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -304,10 +304,6 @@ const OverviewToolbar = new Lang.Class({
     },
 
     createSearchbar: function() {
-        // create the dropdown for the search bar, it's hidden by default
-        let dropdown = new Searchbar.Dropdown();
-        this._overlay.add_overlay(dropdown.widget);
-
-        return new Searchbar.OverviewSearchbar(dropdown);
+        return new Searchbar.OverviewSearchbar();
     }
 });
diff --git a/src/searchbar.js b/src/searchbar.js
index 804e199..d6024c9 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -221,8 +221,11 @@ Signals.addSignalMethods(Searchbar.prototype);
 
 const Dropdown = new Lang.Class({
     Name: 'Dropdown',
+    Extends: Gtk.Popover,
 
-    _init: function() {
+    _init: function(relativeTo) {
+        this.parent({ relative_to: relativeTo,
+                      height_request: 240 });
         this._sourceView = new Manager.BaseView(Application.sourceManager);
         this._typeView = new Manager.BaseView(Application.searchTypeManager);
         this._matchView = new Manager.BaseView(Application.searchMatchManager);
@@ -230,53 +233,31 @@ const Dropdown = new Lang.Class({
         // else?
         // this._categoryView = new Manager.BaseView(Application.searchCategoryManager);
 
-        this._sourceView.connect('item-activated',
-                                 Lang.bind(this, this._onItemActivated));
-        this._typeView.connect('item-activated',
-                               Lang.bind(this, this._onItemActivated));
-        this._matchView.connect('item-activated',
-                                Lang.bind(this, this._onItemActivated));
-
-        let frame = new Gtk.Frame({ shadow_type: Gtk.ShadowType.IN,
-                                    opacity: 0.9 });
-        frame.get_style_context().add_class('documents-dropdown');
-
-        this.widget = new Gtk.Revealer({ halign: Gtk.Align.CENTER,
-                                         valign: Gtk.Align.START });
-        this.widget.add(frame);
-
-        this._grid = new Gtk.Grid({ orientation: Gtk.Orientation.HORIZONTAL });
-        frame.add(this._grid);
+        this._grid = new Gtk.Grid({ orientation: Gtk.Orientation.HORIZONTAL,
+                                    row_homogeneous: true,
+                                    margin: 10 });
+        this.add(this._grid);
 
         this._grid.add(this._sourceView.widget);
         this._grid.add(this._typeView.widget);
         this._grid.add(this._matchView.widget);
         //this._grid.add(this._categoryView.widget);
 
+        this.get_style_context().add_class('documents-dropdown');
         this.hide();
-        this.widget.show_all();
+        this._grid.show_all();
     },
 
     _onItemActivated: function() {
         this.emit('item-activated');
-    },
-
-    show: function() {
-        this.widget.reveal_child = true;
-    },
-
-    hide: function() {
-        this.widget.reveal_child = false;
     }
 });
-Signals.addSignalMethods(Dropdown.prototype);
 
 const OverviewSearchbar = new Lang.Class({
     Name: 'OverviewSearchbar',
     Extends: Searchbar,
 
-    _init: function(dropdown) {
-        this._dropdown = dropdown;
+    _init: function() {
         this._selectAll = Application.application.lookup_action('select-all');
 
         this.parent();
@@ -304,6 +285,8 @@ const OverviewSearchbar = new Lang.Class({
             Lang.bind(this, this._onTagClicked));
         this._searchEntry.connect('tag-button-clicked',
             Lang.bind(this, this._onTagButtonClicked));
+        
+        this._dropdown = new Dropdown(this._searchEntry);
 
         this._sourceTag = new Gd.TaggedEntryTag();
         this._typeTag = new Gd.TaggedEntryTag();
@@ -315,7 +298,7 @@ const OverviewSearchbar = new Lang.Class({
 
         this._searchEntry.connect('destroy', Lang.bind(this,
             function() {
-                this._dropdown.widget.reveal_child = false;
+                this._dropdown.hide();
                 Application.searchController.disconnect(this._searchChangedId);
             }));
 
@@ -327,9 +310,10 @@ const OverviewSearchbar = new Lang.Class({
         this._dropdownButton.connect('toggled', Lang.bind(this,
             function() {
                 let active = this._dropdownButton.get_active();
-                this._dropdown.widget.reveal_child = active;
+                if(active)
+                    this._dropdown.show();
             }));
-        this._dropdown.connect('item-activated', Lang.bind(this,
+        this._dropdown.connect('closed', Lang.bind(this,
             function() {
                 this._dropdownButton.set_active(false);
             }));


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