[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 01/02: Add ability to hide menu items. (bug #14816)

noreply at xfce.org noreply at xfce.org
Sat Jan 4 15:00:52 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 0443ee157f5238a7c59bc14d7aa0c3e2698828cb
Author: Graeme Gott <graeme at gottcode.org>
Date:   Tue Jul 23 10:37:05 2019 -0400

    Add ability to hide menu items. (bug #14816)
---
 panel-plugin/launcher.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 panel-plugin/launcher.h   |  2 ++
 panel-plugin/page.cpp     | 15 +++++++++++++++
 panel-plugin/page.h       |  1 +
 4 files changed, 65 insertions(+)

diff --git a/panel-plugin/launcher.cpp b/panel-plugin/launcher.cpp
index 07fe961..879b8d8 100644
--- a/panel-plugin/launcher.cpp
+++ b/panel-plugin/launcher.cpp
@@ -226,6 +226,53 @@ Launcher::~Launcher()
 
 //-----------------------------------------------------------------------------
 
+// Adapted from https://git.xfce.org/xfce/xfce4-appfinder/tree/src/appfinder-window.c#n945
+void Launcher::hide()
+{
+	// Look up the correct relative path
+	const gchar* relpath = NULL;
+	gchar* uri = get_uri();
+	if (uri)
+	{
+		gchar** dirs = xfce_resource_lookup_all(XFCE_RESOURCE_DATA, "applications/");
+		for (guint i = 0; dirs[i] != NULL; i++)
+		{
+			if (g_str_has_prefix(uri + 7, dirs[i]))
+			{
+				relpath = uri + 7 + strlen(dirs[i]) - 13;
+				break;
+			}
+		}
+		g_strfreev(dirs);
+	}
+	if (!relpath)
+	{
+		g_free(uri);
+		return;
+	}
+
+	gchar* path = xfce_resource_save_location(XFCE_RESOURCE_DATA, relpath, false);
+	// I18N: the first %s will be replaced with desktop file path, the second with Hidden=true
+	gchar* message = g_strdup_printf(_("To unhide it you have to manually "
+			"remove the file \"%s\" or open the file and "
+			"remove the line \"%s\"."), path, "Hidden=true");
+	g_free(path);
+
+	if (xfce_dialog_confirm(NULL, NULL, _("Hide Application"), message,
+		_("Are you sure you want to hide \"%s\"?"), m_display_name))
+	{
+		XfceRc* rc = xfce_rc_config_open(XFCE_RESOURCE_DATA, relpath, false);
+		xfce_rc_set_group(rc, G_KEY_FILE_DESKTOP_GROUP);
+		xfce_rc_write_bool_entry(rc, G_KEY_FILE_DESKTOP_KEY_HIDDEN, true);
+		xfce_rc_close(rc);
+	}
+
+	g_free(message);
+	g_free(uri);
+}
+
+//-----------------------------------------------------------------------------
+
 void Launcher::run(GdkScreen* screen) const
 {
 	const gchar* string = garcon_menu_item_get_command(m_item);
diff --git a/panel-plugin/launcher.h b/panel-plugin/launcher.h
index 09e171f..2e34579 100644
--- a/panel-plugin/launcher.h
+++ b/panel-plugin/launcher.h
@@ -117,6 +117,8 @@ public:
 		return garcon_menu_item_get_uri(m_item);
 	}
 
+	void hide();
+
 	void run(GdkScreen* screen) const;
 
 	void run(GdkScreen* screen, DesktopAction* action) const;
diff --git a/panel-plugin/page.cpp b/panel-plugin/page.cpp
index 55f46ee..4528c7f 100644
--- a/panel-plugin/page.cpp
+++ b/panel-plugin/page.cpp
@@ -416,6 +416,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS
 	g_signal_connect_slot<GtkMenuItem*>(menuitem, "activate", &Page::edit_selected, this);
 	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
 
+	menuitem = gtk_menu_item_new_with_label(_("Hide Application"));
+	g_signal_connect_slot<GtkMenuItem*>(menuitem, "activate", &Page::hide_selected, this);
+	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+
 	extend_context_menu(menu);
 
 	gtk_widget_show_all(menu);
@@ -558,6 +562,17 @@ void Page::edit_selected()
 
 //-----------------------------------------------------------------------------
 
+void Page::hide_selected()
+{
+	g_assert(m_selected_launcher != NULL);
+
+	m_window->hide();
+
+	m_selected_launcher->hide();
+}
+
+//-----------------------------------------------------------------------------
+
 void Page::remove_selected_from_favorites()
 {
 	g_assert(m_selected_launcher != NULL);
diff --git a/panel-plugin/page.h b/panel-plugin/page.h
index d00d3b3..7cd22dc 100644
--- a/panel-plugin/page.h
+++ b/panel-plugin/page.h
@@ -75,6 +75,7 @@ private:
 	void add_selected_to_panel();
 	void add_selected_to_favorites();
 	void edit_selected();
+	void hide_selected();
 	void remove_selected_from_favorites();
 	void create_context_menu(GtkTreePath* path, GdkEvent* event);
 	virtual void extend_context_menu(GtkWidget* menu);

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


More information about the Xfce4-commits mailing list