[Xfce4-commits] [apps/xfdashboard] 03/05: Add pop-up menu to menu items in result actors of application search provider in search view

noreply at xfce.org noreply at xfce.org
Fri Oct 27 11:52:19 CEST 2017


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

n   o   m   a   d       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 apps/xfdashboard.

commit dbdc57dcc0c8dac6f433b8c6b91f7272a6fb5358
Author: Stephan Haller <nomad at froevel.de>
Date:   Fri Oct 27 11:21:56 2017 +0200

    Add pop-up menu to menu items in result actors of application search provider in search view
    
    The pop-up menus used at application buttons (result actors of application seaarch provider) in search view is mostly the same as used in quicklaunch, except that the menu items to add or remove the application from quicklaunch are not included.
    
    This commit addresses issue GH #160
---
 data/themes/xfdashboard/xfdashboard.css       |   6 +-
 libxfdashboard/applications-search-provider.c | 163 ++++++++++++++++++++++++++
 2 files changed, 167 insertions(+), 2 deletions(-)

diff --git a/data/themes/xfdashboard/xfdashboard.css b/data/themes/xfdashboard/xfdashboard.css
index b6cb4ae..34a8fd4 100644
--- a/data/themes/xfdashboard/xfdashboard.css
+++ b/data/themes/xfdashboard/xfdashboard.css
@@ -572,14 +572,16 @@ XfdashboardSearchView XfdashboardSearchResultContainer XfdashboardButton:selecte
 }
 
 .popup-menu.popup-menu-source-XfdashboardQuicklaunch,
-.popup-menu.popup-menu-source-XfdashboardApplicationsView
+.popup-menu.popup-menu-source-XfdashboardApplicationsView,
+.popup-menu.popup-menu-source-XfdashboardApplicationsSearchProvider
 {
 	show-title: true;
 	show-title-icon: true;
 }
 
 .popup-menu.popup-menu-source-XfdashboardQuicklaunch XfdashboardLabel.popup-menu-item,
-.popup-menu.popup-menu-source-XfdashboardApplicationsView XfdashboardLabel.popup-menu-item
+.popup-menu.popup-menu-source-XfdashboardApplicationsView XfdashboardLabel.popup-menu-item,
+.popup-menu.popup-menu-source-XfdashboardApplicationsSearchProvider XfdashboardLabel.popup-menu-item
 {
 	icon-size: 16;
 	text-justify: left;
diff --git a/libxfdashboard/applications-search-provider.c b/libxfdashboard/applications-search-provider.c
index 6fe61a2..3eaf219 100644
--- a/libxfdashboard/applications-search-provider.c
+++ b/libxfdashboard/applications-search-provider.c
@@ -36,6 +36,11 @@
 #include <libxfdashboard/application-button.h>
 #include <libxfdashboard/application.h>
 #include <libxfdashboard/drag-action.h>
+#include <libxfdashboard/click-action.h>
+#include <libxfdashboard/popup-menu.h>
+#include <libxfdashboard/popup-menu-item-button.h>
+#include <libxfdashboard/popup-menu-item-separator.h>
+#include <libxfdashboard/application-tracker.h>
 #include <libxfdashboard/utils.h>
 #include <libxfdashboard/enums.h>
 #include <libxfdashboard/compat.h>
@@ -714,6 +719,159 @@ static void _xfdashboard_applications_search_provider_on_application_removed(Xfd
 	priv->allApps=xfdashboard_application_database_get_all_applications(priv->appDB);
 }
 
+/* User selected to open a new window or to launch that application at pop-up menu */
+static void _xfdashboard_applications_search_provider_on_popup_menu_item_launch(XfdashboardPopupMenuItem *inMenuItem,
+																			gpointer inUserData)
+{
+	GAppInfo							*appInfo;
+	XfdashboardApplicationTracker		*appTracker;
+	GIcon								*gicon;
+	const gchar							*iconName;
+
+	g_return_if_fail(XFDASHBOARD_IS_POPUP_MENU_ITEM(inMenuItem));
+	g_return_if_fail(G_IS_APP_INFO(inUserData));
+
+	appInfo=G_APP_INFO(inUserData);
+	iconName=NULL;
+
+	/* Get icon of application */
+	gicon=g_app_info_get_icon(appInfo);
+	if(gicon) iconName=g_icon_to_string(gicon);
+
+	/* Check if we should launch that application or to open a new window */
+	appTracker=xfdashboard_application_tracker_get_default();
+	if(!xfdashboard_application_tracker_is_running_by_app_info(appTracker, appInfo))
+	{
+		GAppLaunchContext			*context;
+		GError						*error;
+
+		/* Create context to start application at */
+		context=xfdashboard_create_app_context(NULL);
+
+		/* Try to launch application */
+		error=NULL;
+		if(!g_app_info_launch(appInfo, NULL, context, &error))
+		{
+			/* Show notification about failed application launch */
+			xfdashboard_notify(CLUTTER_ACTOR(inMenuItem),
+								iconName,
+								_("Launching application '%s' failed: %s"),
+								g_app_info_get_display_name(appInfo),
+								(error && error->message) ? error->message : _("unknown error"));
+			g_warning(_("Launching application '%s' failed: %s"),
+						g_app_info_get_display_name(appInfo),
+						(error && error->message) ? error->message : _("unknown error"));
+			if(error) g_error_free(error);
+		}
+			else
+			{
+				/* Show notification about successful application launch */
+				xfdashboard_notify(CLUTTER_ACTOR(inMenuItem),
+									iconName,
+									_("Application '%s' launched"),
+									g_app_info_get_display_name(appInfo));
+
+				/* Emit signal for successful application launch */
+				g_signal_emit_by_name(xfdashboard_application_get_default(), "application-launched", appInfo);
+
+				/* Quit application */
+				xfdashboard_application_suspend_or_quit(NULL);
+			}
+
+		/* Release allocated resources */
+		g_object_unref(context);
+	}
+
+	/* Release allocated resources */
+	g_object_unref(appTracker);
+	g_object_unref(gicon);
+}
+
+/* A right-click might have happened on an application icon */
+static void _xfdashboard_applications_search_provider_on_popup_menu(XfdashboardApplicationsSearchProvider *self,
+																	ClutterActor *inActor,
+																	gpointer inUserData)
+{
+	XfdashboardApplicationButton				*button;
+	XfdashboardClickAction						*action;
+
+	g_return_if_fail(XFDASHBOARD_IS_APPLICATIONS_SEARCH_PROVIDER(self));
+	g_return_if_fail(XFDASHBOARD_IS_APPLICATION_BUTTON(inActor));
+	g_return_if_fail(XFDASHBOARD_IS_CLICK_ACTION(inUserData));
+
+	button=XFDASHBOARD_APPLICATION_BUTTON(inActor);
+	action=XFDASHBOARD_CLICK_ACTION(inUserData);
+
+	/* Check if right button was used when the application button was clicked */
+	if(xfdashboard_click_action_get_button(action)==XFDASHBOARD_CLICK_ACTION_RIGHT_BUTTON)
+	{
+		ClutterActor							*popup;
+		ClutterActor							*menuItem;
+		GAppInfo								*appInfo;
+		XfdashboardApplicationTracker			*appTracker;
+		gchar									*sourceStyleClass;
+
+		/* Get app info for application button as it is needed most the time */
+		appInfo=xfdashboard_application_button_get_app_info(button);
+		if(!appInfo)
+		{
+			g_critical(_("No application information available for clicked application button."));
+			return;
+		}
+
+		/* Create pop-up menu */
+		popup=xfdashboard_popup_menu_new();
+		xfdashboard_popup_menu_set_destroy_on_cancel(XFDASHBOARD_POPUP_MENU(popup), TRUE);
+		xfdashboard_popup_menu_set_title(XFDASHBOARD_POPUP_MENU(popup), g_app_info_get_display_name(appInfo));
+		xfdashboard_popup_menu_set_title_gicon(XFDASHBOARD_POPUP_MENU(popup), g_app_info_get_icon(appInfo));
+
+		/* Add each open window to pop-up of application */
+		if(xfdashboard_application_button_add_popup_menu_items_for_windows(button, XFDASHBOARD_POPUP_MENU(popup))>0)
+		{
+			/* Add a separator to split windows from other actions in pop-up menu */
+			menuItem=xfdashboard_popup_menu_item_separator_new();
+			clutter_actor_set_x_expand(menuItem, TRUE);
+			xfdashboard_popup_menu_add_item(XFDASHBOARD_POPUP_MENU(popup), XFDASHBOARD_POPUP_MENU_ITEM(menuItem));
+		}
+
+		/* Add menu item to launch application if it is not running */
+		appTracker=xfdashboard_application_tracker_get_default();
+		if(!xfdashboard_application_tracker_is_running_by_app_info(appTracker, appInfo))
+		{
+			menuItem=xfdashboard_popup_menu_item_button_new();
+			xfdashboard_label_set_text(XFDASHBOARD_LABEL(menuItem), _("Launch"));
+			clutter_actor_set_x_expand(menuItem, TRUE);
+			xfdashboard_popup_menu_add_item(XFDASHBOARD_POPUP_MENU(popup), XFDASHBOARD_POPUP_MENU_ITEM(menuItem));
+
+			g_signal_connect(menuItem,
+								"activated",
+								G_CALLBACK(_xfdashboard_applications_search_provider_on_popup_menu_item_launch),
+								appInfo);
+		}
+		g_object_unref(appTracker);
+
+		/* Add application actions */
+		if(xfdashboard_application_button_add_popup_menu_items_for_actions(button, XFDASHBOARD_POPUP_MENU(popup))>0)
+		{
+			/* Add a separator to split windows from other actions in pop-up menu */
+			menuItem=xfdashboard_popup_menu_item_separator_new();
+			clutter_actor_set_x_expand(menuItem, TRUE);
+			xfdashboard_popup_menu_add_item(XFDASHBOARD_POPUP_MENU(popup), XFDASHBOARD_POPUP_MENU_ITEM(menuItem));
+		}
+
+		/* Set style class as pop-up menu has no source set to create style
+		 * class automatically because this class is not derived from an actor
+		 * class.
+		 */
+		sourceStyleClass=g_strdup_printf("popup-menu-source-%s", G_OBJECT_TYPE_NAME(self));
+		xfdashboard_stylable_add_class(XFDASHBOARD_STYLABLE(popup), sourceStyleClass);
+		g_free(sourceStyleClass);
+
+		/* Activate pop-up menu */
+		xfdashboard_popup_menu_activate(XFDASHBOARD_POPUP_MENU(popup));
+	}
+}
+
 /* Drag of an menu item begins */
 static void _xfdashboard_applications_search_provider_on_drag_begin(ClutterDragAction *inAction,
 																	ClutterActor *inActor,
@@ -1124,6 +1282,7 @@ static ClutterActor* _xfdashboard_applications_search_provider_create_result_act
 	XfdashboardApplicationsSearchProvider			*self;
 	XfdashboardApplicationsSearchProviderPrivate	*priv;
 	ClutterActor									*actor;
+	ClutterAction									*clickAction;
 	ClutterAction									*dragAction;
 	GAppInfo										*appInfo;
 
@@ -1148,6 +1307,10 @@ static ClutterActor* _xfdashboard_applications_search_provider_create_result_act
 	actor=xfdashboard_application_button_new_from_app_info(appInfo);
 	clutter_actor_show(actor);
 
+	clickAction=xfdashboard_click_action_new();
+	g_signal_connect_swapped(clickAction, "clicked", G_CALLBACK(_xfdashboard_applications_search_provider_on_popup_menu), self);
+	clutter_actor_add_action(actor, clickAction);
+
 	dragAction=xfdashboard_drag_action_new();
 	clutter_drag_action_set_drag_threshold(CLUTTER_DRAG_ACTION(dragAction), -1, -1);
 	clutter_actor_add_action(actor, dragAction);

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


More information about the Xfce4-commits mailing list