[Xfce4-commits] <xfmpc:master> dbbrowser, playlist: Add Clear button in filter entry

Mike Massonnet noreply at xfce.org
Sun Oct 23 17:00:02 CEST 2011


Updating branch refs/heads/master
         to bbb78934f055b7ae466a1ea0fc8638a63a5c3e8a (commit)
       from 36d22ac107e1fb4f23ecd5f1edcb5ff88c5f671e (commit)

commit bbb78934f055b7ae466a1ea0fc8638a63a5c3e8a
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Sun Oct 23 16:59:28 2011 +0200

    dbbrowser, playlist: Add Clear button in filter entry
    
    Added a clear button in order to have a visual component to show it can
    be flushed away in a click (it currently works with the touch Escape).

 src/dbbrowser.vala |   15 +++++++++++++++
 src/playlist.vala  |   14 ++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/src/dbbrowser.vala b/src/dbbrowser.vala
index db32735..cc7bcf8 100644
--- a/src/dbbrowser.vala
+++ b/src/dbbrowser.vala
@@ -108,6 +108,7 @@ namespace Xfmpc {
 			this.search_entry = new Entry ();
 			this.search_entry.set_icon_from_stock (EntryIconPosition.PRIMARY, Gtk.Stock.FIND);
 			this.search_entry.set_icon_activatable (EntryIconPosition.PRIMARY, false);
+			this.search_entry.set_icon_activatable (EntryIconPosition.SECONDARY, true);
 
 			scrolled.add (this.treeview);
 			pack_start (scrolled, true, true, 0);
@@ -126,6 +127,7 @@ namespace Xfmpc {
 			this.search_entry.activate.connect (cb_search_entry_activated);
 			this.search_entry.key_release_event.connect (cb_search_entry_key_released);
 			this.search_entry.changed.connect (cb_search_entry_changed);
+			this.search_entry.icon_release.connect (cb_search_entry_icon_activated);
 
 			this.preferences.notify["song-format"].connect (reload);
 			this.preferences.notify["song-format-custom"].connect (reload);
@@ -457,6 +459,13 @@ namespace Xfmpc {
 		}
 
 		private void cb_search_entry_changed () {
+			if (search_entry.get_text () != "") {
+				search_entry.set_icon_from_stock (EntryIconPosition.SECONDARY, Gtk.Stock.CLEAR);
+			}
+			else {
+				search_entry.set_icon_from_stock (EntryIconPosition.SECONDARY, null);
+			}
+
 			if (this.search_timeout > 0)
 				GLib.Source.remove (search_timeout);
 
@@ -467,5 +476,11 @@ namespace Xfmpc {
 			cb_search_entry_activated ();
 			return false;
 		}
+
+		private void cb_search_entry_icon_activated (Gtk.EntryIconPosition icon_pos, Gdk.Event event) {
+			if (icon_pos != Gtk.EntryIconPosition.SECONDARY)
+				return;
+			search_entry.set_text ("");
+		}
 	}
 }
diff --git a/src/playlist.vala b/src/playlist.vala
index 1558be2..a66d652 100644
--- a/src/playlist.vala
+++ b/src/playlist.vala
@@ -117,6 +117,7 @@ namespace Xfmpc {
 			this.filter_entry = new Entry ();
 			this.filter_entry.set_icon_from_stock (EntryIconPosition.PRIMARY, Gtk.Stock.FIND);
 			this.filter_entry.set_icon_activatable (EntryIconPosition.PRIMARY, false);
+			this.filter_entry.set_icon_activatable (EntryIconPosition.SECONDARY, true);
 
 			scrolled.add (this.treeview);
 			pack_start (scrolled, true, true, 0);
@@ -135,6 +136,7 @@ namespace Xfmpc {
 			this.filter_entry.activate.connect (cb_filter_entry_activated);
 			this.filter_entry.key_release_event.connect (cb_filter_entry_key_released);
 			this.filter_entry.changed.connect (cb_filter_entry_changed);
+			this.filter_entry.icon_release.connect (cb_filter_entry_icon_activated);
 
 			this.preferences.notify["song-format"].connect (cb_playlist_changed);
 			this.preferences.notify["song-format-custom"].connect (cb_playlist_changed);
@@ -347,9 +349,21 @@ namespace Xfmpc {
 		}
 
 		private void cb_filter_entry_changed () {
+			if (filter_entry.get_text () != "") {
+				filter_entry.set_icon_from_stock (EntryIconPosition.SECONDARY, Gtk.Stock.CLEAR);
+			}
+			else {
+				filter_entry.set_icon_from_stock (EntryIconPosition.SECONDARY, null);
+			}
   			this.filter.refilter ();
 		}
 
+		private void cb_filter_entry_icon_activated (Gtk.EntryIconPosition icon_pos, Gdk.Event event) {
+			if (icon_pos != Gtk.EntryIconPosition.SECONDARY)
+				return;
+			filter_entry.set_text ("");
+		}
+
 		/*
 		 * Public
 		 */


More information about the Xfce4-commits mailing list