From 5f97b16361a0a5e600629a67f0c7b82cdf8cf6bd Mon Sep 17 00:00:00 2001
From: Alessandro Bono <shadow@openaliasbox.org>
Date: Tue, 28 Jul 2015 14:04:32 +0200
Subject: [PATCH] searchbar: Use inheritance instead of composition

https://bugzilla.gnome.org/show_bug.cgi?id=752792
---
 src/mainToolbar.js |  2 +-
 src/preview.js     |  4 ++--
 src/searchbar.js   | 41 +++++++++++++++++++----------------------
 3 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index 85e3247..5b5b5de 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -52,7 +52,7 @@ const MainToolbar = new Lang.Class({
 
         this.searchbar = this.createSearchbar();
         if (this.searchbar)
-            this.add(this.searchbar.widget);
+            this.add(this.searchbar);
 
         let loadStartedId = Application.documentManager.connect('load-started', Lang.bind(this,
             function() {
diff --git a/src/preview.js b/src/preview.js
index 06aa4b2..1631be1 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -985,7 +985,7 @@ const PreviewSearchbar = new Lang.Class({
         this._previewView.startSearch(this._searchEntry.get_text());
     },
 
-    show: function() {
+    reveal: function() {
         this.parent();
 
         if (!this._searchEntry.get_text()) {
@@ -997,7 +997,7 @@ const PreviewSearchbar = new Lang.Class({
         this._previewView.startSearch(this._searchEntry.get_text());
     },
 
-    hide: function() {
+    conceal: function() {
         this._previewView.view.find_set_highlight_search(false);
 
         this.searchChangeBlocked = true;
diff --git a/src/searchbar.js b/src/searchbar.js
index ebd61d6..b798406 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -37,18 +37,19 @@ const Utils = imports.utils;
 
 const Searchbar = new Lang.Class({
     Name: 'Searchbar',
+    Extends: Gtk.SearchBar,
 
     _init: function() {
         this.searchChangeBlocked = false;
 
-        this.widget = new Gtk.SearchBar();
+        this.parent();
 
         // subclasses will create this._searchEntry and this._searchContainer
         // GtkWidgets
         this.createSearchWidgets();
 
-        this.widget.add(this._searchContainer);
-        this.widget.connect_entry(this._searchEntry);
+        this.add(this._searchContainer);
+        this.connect_entry(this._searchEntry);
 
         this._searchEntry.connect('search-changed', Lang.bind(this,
             function() {
@@ -57,9 +58,9 @@ const Searchbar = new Lang.Class({
 
                 this.entryChanged();
             }));
-        this.widget.connect('notify::search-mode-enabled', Lang.bind(this,
+        this.connect('notify::search-mode-enabled', Lang.bind(this,
             function() {
-                let searchEnabled = this.widget.search_mode_enabled;
+                let searchEnabled = this.get_search_mode();
                 Application.application.change_action_state('search', GLib.Variant.new('b', searchEnabled));
             }));
 
@@ -68,20 +69,20 @@ const Searchbar = new Lang.Class({
             Lang.bind(this, this._onActionStateChanged));
         this._onActionStateChanged(Application.application, 'search', Application.application.get_action_state('search'));
 
-        this.widget.connect('destroy', Lang.bind(this,
+        this.connect('destroy', Lang.bind(this,
             function() {
                 Application.application.disconnect(searchStateId);
                 Application.application.change_action_state('search', GLib.Variant.new('b', false));
             }));
 
-        this.widget.show_all();
+        this.show_all();
     },
 
     _onActionStateChanged: function(source, actionName, state) {
         if (state.get_boolean())
-            this.show();
+            this.reveal();
         else
-            this.hide();
+            this.conceal();
     },
 
     createSearchWidgets: function() {
@@ -92,30 +93,26 @@ const Searchbar = new Lang.Class({
         log('Error: Searchbar implementations must override entryChanged');
     },
 
-    destroy: function() {
-        this.widget.destroy();
-    },
-
     handleEvent: function(event) {
         // Skip if the search bar is shown and the focus is elsewhere
-        if (this.widget.search_mode_enabled && !this._searchEntry.is_focus)
+        if (this.get_search_mode() && !this._searchEntry.is_focus)
             return false;
 
         let keyval = event.get_keyval()[1];
-        if (this.widget.search_mode_enabled && keyval == Gdk.KEY_Return) {
+        if (this.get_search_mode() && keyval == Gdk.KEY_Return) {
             this.emit('activate-result');
             return true;
         }
 
-        return this.widget.handle_event(event);
+        return this.handle_event(event);
     },
 
-    show: function() {
-        this.widget.search_mode_enabled = true;
+    reveal: function() {
+        this.set_search_mode(true);
     },
 
-    hide: function() {
-        this.widget.search_mode_enabled = false;
+    conceal: function() {
+        this.set_search_mode(false);
 
         // clear all the search properties when hiding the entry
         this._searchEntry.set_text('');
@@ -321,12 +318,12 @@ const OverviewSearchbar = new Lang.Class({
         this.parent();
     },
 
-    show: function() {
+    reveal: function() {
         this._selectAll.enabled = false;
         this.parent();
     },
 
-    hide: function() {
+    conceal: function() {
         this._dropdownButton.set_active(false);
         this._selectAll.enabled = true;
 
-- 
2.1.4