[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 03/05: Use bitmask to sort search results.

noreply at xfce.org noreply at xfce.org
Mon Sep 21 17:42:37 CEST 2015


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

gottcode pushed a commit to branch master
in repository panel-plugins/xfce4-whiskermenu-plugin.

commit 4b14b76a46fa8cc0aae2b28a2d8367a167bd2832
Author: Graeme Gott <graeme at gottcode.org>
Date:   Mon Sep 21 10:28:15 2015 -0400

    Use bitmask to sort search results.
---
 panel-plugin/launcher.cpp   |   18 +++++++-----------
 panel-plugin/query.cpp      |   12 ++++++------
 panel-plugin/run-action.cpp |    2 +-
 3 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/panel-plugin/launcher.cpp b/panel-plugin/launcher.cpp
index d046223..ebe55cc 100644
--- a/panel-plugin/launcher.cpp
+++ b/panel-plugin/launcher.cpp
@@ -278,38 +278,34 @@ void Launcher::run(GdkScreen* screen) const
 
 guint Launcher::search(const Query& query)
 {
+	// Sort matches in names first
 	guint match = query.match(m_search_name);
 	if (match != G_MAXUINT)
 	{
-		if (match > 5)
-		{
-			match += 10;
-		}
-		return match;
+		return match | 0x400;
 	}
 
 	match = query.match(m_search_generic_name);
 	if (match != G_MAXUINT)
 	{
-		match += 10;
-		return match;
+		return match | 0x800;
 	}
 
 	// Sort matches in executables after matches in names
 	match = query.match(m_search_command);
 	if (match != G_MAXUINT)
 	{
-		match += 20;
-		return match;
+		return match | 0x1000;
 	}
 
 	// Sort matches in comments after matches in names
 	match = query.match(m_search_comment);
 	if (match != G_MAXUINT)
 	{
-		match += 30;
+		return match | 0x2000;
 	}
-	return match;
+
+	return G_MAXUINT;
 }
 
 //-----------------------------------------------------------------------------
diff --git a/panel-plugin/query.cpp b/panel-plugin/query.cpp
index cd39346..f2e1da1 100644
--- a/panel-plugin/query.cpp
+++ b/panel-plugin/query.cpp
@@ -67,12 +67,12 @@ unsigned int Query::match(const std::string& haystack) const
 	std::string::size_type pos = haystack.find(m_query);
 	if (pos == 0)
 	{
-		return haystack.length() != m_query.length();
+		return (haystack.length() == m_query.length()) ? 0x4 : 0x8;
 	}
 	// Check if haystack contains query starting at a word boundary
 	else if ((pos != std::string::npos) && is_start_word(haystack, pos))
 	{
-		return 2;
+		return 0x10;
 	}
 
 	if (m_query_words.size() > 1)
@@ -90,7 +90,7 @@ unsigned int Query::match(const std::string& haystack) const
 		}
 		if (search_pos != std::string::npos)
 		{
-			return 3;
+			return 0x20;
 		}
 
 		// Check if haystack contains query as words in any order
@@ -109,14 +109,14 @@ unsigned int Query::match(const std::string& haystack) const
 		}
 		if (found_words == m_query_words.size())
 		{
-			return 4;
+			return 0x40;
 		}
 	}
 
 	// Check if haystack contains query
 	if (pos != std::string::npos)
 	{
-		return 5;
+		return 0x80;
 	}
 
 	// Check if haystack contains query as characters
@@ -149,7 +149,7 @@ unsigned int Query::match(const std::string& haystack) const
 	unsigned int result = UINT_MAX;
 	if (*query_string == 0)
 	{
-		result = characters_start_words ? 6 : 7;
+		result = characters_start_words ? 0x100 : 0x200;
 	}
 
 	return result;
diff --git a/panel-plugin/run-action.cpp b/panel-plugin/run-action.cpp
index 3bdbf83..90d0b4c 100644
--- a/panel-plugin/run-action.cpp
+++ b/panel-plugin/run-action.cpp
@@ -80,7 +80,7 @@ guint RunAction::search(const Query& query)
 	g_free(display_name);
 
 	// Sort after matches in names and before matches in executables
-	return 9;
+	return 0x801;
 }
 
 //-----------------------------------------------------------------------------

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


More information about the Xfce4-commits mailing list