[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 01/02: Use GTK search entry.

noreply at xfce.org noreply at xfce.org
Fri Jan 24 18:50:10 CET 2020


This is an automated email from the git hooks/post-receive script.

g   o   t   t   c   o   d   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-whiskermenu-plugin.

commit ec96b4c0d57c5ad94ce97f2470d9953001098ad6
Author: Graeme Gott <graeme at gottcode.org>
Date:   Fri Jan 24 08:58:30 2020 -0500

    Use GTK search entry.
---
 panel-plugin/search-page.cpp | 40 +++++++++-------------------------------
 panel-plugin/search-page.h   |  7 +++----
 panel-plugin/window.cpp      | 13 +++----------
 3 files changed, 15 insertions(+), 45 deletions(-)

diff --git a/panel-plugin/search-page.cpp b/panel-plugin/search-page.cpp
index 6cd2fe4..267d574 100644
--- a/panel-plugin/search-page.cpp
+++ b/panel-plugin/search-page.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2016, 2019 Graeme Gott <graeme at gottcode.org>
+ * Copyright (C) 2013, 2016, 2019, 2020 Graeme Gott <graeme at gottcode.org>
  *
  * This library is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -37,9 +37,8 @@ SearchPage::SearchPage(Window* window) :
 {
 	view_created();
 
-	g_signal_connect_slot(window->get_search_entry(), "icon-release", &SearchPage::clear_search, this);
-	g_signal_connect_slot(window->get_search_entry(), "key-press-event", &SearchPage::cancel_search, this);
-	g_signal_connect_slot<GtkEntry*>(window->get_search_entry(), "activate", &SearchPage::activate_search, this);
+	g_signal_connect_slot(window->get_search_entry(), "activate", &SearchPage::activate_search, this);
+	g_signal_connect_slot(window->get_search_entry(), "stop-search", &SearchPage::cancel_search, this);
 }
 
 //-----------------------------------------------------------------------------
@@ -188,8 +187,9 @@ void SearchPage::unset_menu_items()
 
 //-----------------------------------------------------------------------------
 
-void SearchPage::activate_search()
+void SearchPage::activate_search(GtkEntry* entry)
 {
+	set_filter(gtk_entry_get_text(entry));
 	GtkTreePath* path = get_view()->get_selected_path();
 	if (path)
 	{
@@ -200,39 +200,17 @@ void SearchPage::activate_search()
 
 //-----------------------------------------------------------------------------
 
-void SearchPage::clear_search(GtkEntry* entry, GtkEntryIconPosition icon_pos, GdkEvent*)
+void SearchPage::cancel_search(GtkSearchEntry* entry)
 {
-	if (icon_pos == GTK_ENTRY_ICON_SECONDARY)
+	const gchar* text = gtk_entry_get_text(GTK_ENTRY(entry));
+	if (!exo_str_is_empty(text))
 	{
-		gtk_entry_set_text(entry, "");
+		gtk_entry_set_text(GTK_ENTRY(entry), "");
 	}
 }
 
 //-----------------------------------------------------------------------------
 
-gboolean SearchPage::cancel_search(GtkWidget* widget, GdkEvent* event)
-{
-	GdkEventKey* key_event = reinterpret_cast<GdkEventKey*>(event);
-	if (key_event->keyval == GDK_KEY_Escape)
-	{
-		GtkEntry* entry = GTK_ENTRY(widget);
-		const gchar* text = gtk_entry_get_text(entry);
-		if ((text != NULL) && (*text != '\0'))
-		{
-			gtk_entry_set_text(entry, "");
-			return true;
-		}
-		else
-		{
-			return false;
-		}
-	}
-
-	return false;
-}
-
-//-----------------------------------------------------------------------------
-
 void SearchPage::view_created()
 {
 	get_view()->set_selection_mode(GTK_SELECTION_BROWSE);
diff --git a/panel-plugin/search-page.h b/panel-plugin/search-page.h
index bd81f63..9927e19 100644
--- a/panel-plugin/search-page.h
+++ b/panel-plugin/search-page.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2015, 2019 Graeme Gott <graeme at gottcode.org>
+ * Copyright (C) 2013, 2015, 2019, 2020 Graeme Gott <graeme at gottcode.org>
  *
  * This library is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -39,9 +39,8 @@ public:
 	void unset_menu_items();
 
 private:
-	void activate_search();
-	void clear_search(GtkEntry* entry, GtkEntryIconPosition icon_pos, GdkEvent*);
-	gboolean cancel_search(GtkWidget* widget, GdkEvent* event);
+	void activate_search(GtkEntry* entry);
+	void cancel_search(GtkSearchEntry* entry);
 	void view_created();
 
 private:
diff --git a/panel-plugin/window.cpp b/panel-plugin/window.cpp
index 7b6c06d..f7c2109 100644
--- a/panel-plugin/window.cpp
+++ b/panel-plugin/window.cpp
@@ -147,10 +147,8 @@ WhiskerMenu::Window::Window(Plugin* plugin) :
 	m_resizer = new ResizerWidget(m_window);
 
 	// Create search entry
-	m_search_entry = GTK_ENTRY(gtk_entry_new());
-	gtk_entry_set_icon_from_icon_name(m_search_entry, GTK_ENTRY_ICON_SECONDARY, "edit-find");
-	gtk_entry_set_icon_activatable(m_search_entry, GTK_ENTRY_ICON_SECONDARY, false);
-	g_signal_connect_slot<GtkEditable*>(m_search_entry, "changed", &Window::search, this);
+	m_search_entry = GTK_ENTRY(gtk_search_entry_new());
+	g_signal_connect_slot<GtkSearchEntry*>(m_search_entry, "search-changed", &Window::search, this);
 
 	// Create favorites
 	m_favorites = new FavoritesPage(this);
@@ -1077,12 +1075,7 @@ void WhiskerMenu::Window::search()
 		text = NULL;
 	}
 
-	// Update search entry icon
-	bool visible = text != NULL;
-	gtk_entry_set_icon_from_icon_name(m_search_entry, GTK_ENTRY_ICON_SECONDARY, !visible ? "edit-find" : "edit-clear");
-	gtk_entry_set_icon_activatable(m_search_entry, GTK_ENTRY_ICON_SECONDARY, visible);
-
-	if (visible)
+	if (text)
 	{
 		// Show search results
 		gtk_stack_set_visible_child_full(m_contents_stack, "search", m_search_cover);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list