[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 273/473: Add running arbitrary programs in PATH. Closes #42.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:57:23 CET 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 b6aa55e2fd30e5dad7de4fbcd62058a9fb8396ad
Author: Graeme Gott <graeme at gottcode.org>
Date:   Thu Dec 5 16:43:08 2013 -0500

    Add running arbitrary programs in PATH. Closes #42.
---
 panel-plugin/CMakeLists.txt  |    1 +
 panel-plugin/run-action.cpp  |   86 ++++++++++++++++++++++++++++++++++++++++++
 panel-plugin/run-action.h    |   51 +++++++++++++++++++++++++
 panel-plugin/search-page.cpp |   15 +++++---
 panel-plugin/search-page.h   |    8 +++-
 5 files changed, 155 insertions(+), 6 deletions(-)

diff --git a/panel-plugin/CMakeLists.txt b/panel-plugin/CMakeLists.txt
index 31e6432..120fcdb 100644
--- a/panel-plugin/CMakeLists.txt
+++ b/panel-plugin/CMakeLists.txt
@@ -84,6 +84,7 @@ add_library(whiskermenu MODULE
 	recent-page.cpp
 	register-plugin.c
 	resizer-widget.cpp
+	run-action.cpp
 	search-action.cpp
 	search-page.cpp
 	section-button.cpp
diff --git a/panel-plugin/run-action.cpp b/panel-plugin/run-action.cpp
new file mode 100644
index 0000000..5dc86a6
--- /dev/null
+++ b/panel-plugin/run-action.cpp
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2013 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
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "run-action.h"
+
+#include "query.h"
+#include "settings.h"
+
+#include <libxfce4ui/libxfce4ui.h>
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+RunAction::RunAction()
+{
+	set_icon("gtk-execute");
+}
+
+//-----------------------------------------------------------------------------
+
+void RunAction::run(GdkScreen* screen) const
+{
+	GError* error = NULL;
+	if (xfce_spawn_command_line_on_screen(screen, m_command_line.c_str(), false, false, &error) == false)
+	{
+		xfce_dialog_show_error(NULL, error, _("Failed to execute command \"%s\"."), m_command_line.c_str());
+		g_error_free(error);
+	}
+}
+
+//-----------------------------------------------------------------------------
+
+int RunAction::search(const Query& query)
+{
+	// Check if in PATH
+	bool valid = false;
+
+	gchar** argv;
+	if (g_shell_parse_argv(query.query().c_str(), NULL, &argv, NULL))
+	{
+		gchar* path = g_find_program_in_path(argv[0]);
+		valid = path != NULL;
+		g_free(path);
+		g_strfreev(argv);
+	}
+
+	if (!valid)
+	{
+		return G_MAXINT;
+	}
+
+	m_command_line = query.query();
+
+	// Set item text
+	const gchar* direction = (gtk_widget_get_default_direction() != GTK_TEXT_DIR_RTL) ? "\342\200\216" : "\342\200\217";
+	gchar* display_name = g_strdup_printf(_("Run %s"), m_command_line.c_str());
+	if (wm_settings->launcher_show_description)
+	{
+		set_text(g_markup_printf_escaped("%s<b>%s</b>\n", direction, display_name));
+	}
+	else
+	{
+		set_text(g_markup_printf_escaped("%s%s", direction, display_name));
+	}
+	g_free(display_name);
+
+	// Sort after matches in names and before matches in executables
+	return 9;
+}
+
+//-----------------------------------------------------------------------------
diff --git a/panel-plugin/run-action.h b/panel-plugin/run-action.h
new file mode 100644
index 0000000..b08832c
--- /dev/null
+++ b/panel-plugin/run-action.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2013 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
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef WHISKERMENU_RUN_ACTION_H
+#define WHISKERMENU_RUN_ACTION_H
+
+#include "element.h"
+
+#include <string>
+
+namespace WhiskerMenu
+{
+
+class RunAction : public Element
+{
+public:
+	RunAction();
+
+	enum
+	{
+		Type = 4
+	};
+	int get_type() const
+	{
+		return Type;
+	}
+
+	void run(GdkScreen* screen) const;
+	int search(const Query& query);
+
+private:
+	std::string m_command_line;
+};
+
+}
+
+#endif // WHISKERMENU_RUN_ACTION_H
diff --git a/panel-plugin/search-page.cpp b/panel-plugin/search-page.cpp
index 75c2af3..65e8c87 100644
--- a/panel-plugin/search-page.cpp
+++ b/panel-plugin/search-page.cpp
@@ -56,7 +56,7 @@ void SearchPage::set_filter(const gchar* filter)
 	if (!filter)
 	{
 		m_query.clear();
-		m_matches.resize(0);
+		m_matches.clear();
 		return;
 	}
 
@@ -70,12 +70,17 @@ void SearchPage::set_filter(const gchar* filter)
 	// Reset search results if new search does not start with previous search
 	if (m_query.query().empty() || !g_str_has_prefix(filter, m_query.query().c_str()))
 	{
-		m_matches.resize(0);
+		m_matches.clear();
+		m_matches.push_back(&m_run_action);
 		for (std::vector<Launcher*>::size_type i = 0, end = m_launchers.size(); i < end; ++i)
 		{
 			m_matches.push_back(m_launchers[i]);
 		}
 	}
+	else if (std::find(m_matches.begin(), m_matches.end(), &m_run_action) == m_matches.end())
+	{
+		m_matches.insert(m_matches.begin(), &m_run_action);
+	}
 	m_query.set(query);
 
 	// Create search results
@@ -154,8 +159,8 @@ void SearchPage::set_menu_items(GtkTreeModel* model)
 
 	get_view()->unset_model();
 
-	m_matches.resize(0);
-	m_matches.reserve(m_launchers.size());
+	m_matches.clear();
+	m_matches.reserve(m_launchers.size() + 1);
 }
 
 //-----------------------------------------------------------------------------
@@ -163,7 +168,7 @@ void SearchPage::set_menu_items(GtkTreeModel* model)
 void SearchPage::unset_menu_items()
 {
 	m_launchers.clear();
-	m_matches.resize(0);
+	m_matches.clear();
 	get_view()->unset_model();
 }
 
diff --git a/panel-plugin/search-page.h b/panel-plugin/search-page.h
index 5a88bea..2a4d776 100644
--- a/panel-plugin/search-page.h
+++ b/panel-plugin/search-page.h
@@ -18,9 +18,9 @@
 #ifndef WHISKERMENU_SEARCH_PAGE_H
 #define WHISKERMENU_SEARCH_PAGE_H
 
-#include "launcher.h"
 #include "page.h"
 #include "query.h"
+#include "run-action.h"
 
 #include <string>
 #include <vector>
@@ -45,6 +45,7 @@ private:
 private:
 	Query m_query;
 	std::vector<Launcher*> m_launchers;
+	RunAction m_run_action;
 
 	class Match
 	{
@@ -65,6 +66,11 @@ private:
 			return m_relevancy < match.m_relevancy;
 		}
 
+		bool operator==(const Match& match) const
+		{
+			return m_element == match.m_element;
+		}
+
 		void update(const Query& query)
 		{
 			g_assert(m_element != NULL);

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


More information about the Xfce4-commits mailing list