static gboolean _on_click_item (GtkWidget *pWidget, GdkEventButton* pButton, CDQuickBrowserItem *pItem) { g_return_val_if_fail (pItem != NULL, FALSE); GldiModuleInstance *myApplet = pItem->pApplet; CD_APPLET_ENTER; if (pButton->button == 3) // right click { gchar *cUri = g_filename_to_uri (pItem->cPath, NULL, NULL); g_return_val_if_fail (cUri != NULL, FALSE); GtkWidget *pMenu = gldi_menu_new (NULL); GList *pApps = cairo_dock_fm_list_apps_for_file (cUri); if (pApps != NULL) { GtkWidget *pSubMenu = CD_APPLET_ADD_SUB_MENU_WITH_IMAGE (D_("Open with"), pMenu, GLDI_ICON_NAME_OPEN); cd_quick_browser_free_apps_list (myApplet); GList *a; gchar **pAppInfo; gchar *cIconPath; for (a = pApps; a != NULL; a = a->next) { pAppInfo = a->data; if (pAppInfo[2] != NULL) cIconPath = cairo_dock_search_icon_s_path (pAppInfo[2], cairo_dock_search_icon_size (GTK_ICON_SIZE_MENU)); else cIconPath = NULL; gpointer *data = g_new (gpointer, 2); data[0] = pItem; data[1] = pAppInfo[1]; myData.pAppList = g_list_prepend (myData.pAppList, data); // to save the exec command CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (pAppInfo[0], cIconPath, _cd_launch_with, pSubMenu, data); g_free (cIconPath); g_free (pAppInfo[0]); g_free (pAppInfo[2]); g_free (pAppInfo); } g_list_free (pApps); } CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (D_("Open parent folder"), GLDI_ICON_NAME_DIRECTORY, _cd_open_parent, pMenu, pItem); CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (D_("Copy the location"), GLDI_ICON_NAME_COPY, _cd_copy_location, pMenu, pItem); gtk_widget_show_all (pMenu); gtk_menu_popup (GTK_MENU (pMenu), NULL, NULL, NULL, // popup on mouse. NULL, 1, gtk_get_current_event_time ()); g_free (cUri); CD_APPLET_LEAVE (TRUE); // do not remove quick_browser menu now } CD_APPLET_LEAVE (FALSE); }
static gboolean _on_click_module_tree_view (GtkTreeView *pTreeView, GdkEventButton* pButton, gpointer data) { //g_print ("%s ()\n", __func__); if ((pButton->button == 3 && pButton->type == GDK_BUTTON_RELEASE) // right-click || (pButton->button == 1 && pButton->type == GDK_2BUTTON_PRESS)) // double-click { cd_debug ("%s ()", __func__); // get the current selected line. GtkTreeSelection *pSelection = gtk_tree_view_get_selection (pTreeView); GtkTreeModel *pModel; GtkTreeIter iter; if (! gtk_tree_selection_get_selected (pSelection, &pModel, &iter)) return FALSE; gchar *cName = NULL, *cUri = NULL; guint id = 0; gtk_tree_model_get (pModel, &iter, CD_MODEL_NAME, &cName, CD_MODEL_URI, &cUri, CD_MODEL_ID, &id, -1); //launch or build the menu. gboolean bIsAppli = (strncmp (cUri, "application://", 14) == 0); if (pButton->button == 1) // double-click { if (bIsAppli) // an appli -> run it { gchar *tmp = strrchr (cUri, '.'); // remove the '.desktop' if (tmp) *tmp = '\0'; cairo_dock_launch_command (cUri+14); } else // a file -> open it { cairo_dock_fm_launch_uri (cUri); } g_free (cUri); } else // right-click { GtkWidget *pMenu = gldi_menu_new (NULL); g_free (myData.cCurrentUri); myData.cCurrentUri = cUri; if (!bIsAppli) { GList *pApps = cairo_dock_fm_list_apps_for_file (cUri); if (pApps != NULL) { GtkWidget *pSubMenu = CD_APPLET_ADD_SUB_MENU_WITH_IMAGE (D_("Open with"), pMenu, GLDI_ICON_NAME_OPEN); cd_folders_free_apps_list (myApplet); GList *a; gchar **pAppInfo; gchar *cIconPath; for (a = pApps; a != NULL; a = a->next) { pAppInfo = a->data; myData.pAppList = g_list_prepend (myData.pAppList, pAppInfo[1]); if (pAppInfo[2] != NULL) cIconPath = cairo_dock_search_icon_s_path (pAppInfo[2], cairo_dock_search_icon_size (GTK_ICON_SIZE_MENU)); else cIconPath = NULL; CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (pAppInfo[0], cIconPath, _cd_launch_with, pSubMenu, pAppInfo[1]); g_free (cIconPath); g_free (pAppInfo[0]); g_free (pAppInfo[2]); g_free (pAppInfo); } g_list_free (pApps); } CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (D_("Open parent folder"), GLDI_ICON_NAME_DIRECTORY, _cd_open_parent, pMenu, NULL); CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (D_("Copy the location"), GLDI_ICON_NAME_COPY, _cd_copy_location, pMenu, NULL); } CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (D_("Delete this event"), GLDI_ICON_NAME_REMOVE, _cd_delete_event, pMenu, GUINT_TO_POINTER (id)); gtk_widget_show_all (pMenu); gtk_menu_popup (GTK_MENU (pMenu), NULL, NULL, NULL, // popup on mouse. NULL, 1, gtk_get_current_event_time ()); } } return FALSE; }
static void _take_screenshot (CDScreenshotOptions *pOptions) { g_free (myData.cCurrentUri); myData.cCurrentUri = _make_screenshot (pOptions ? pOptions->bActiveWindow : FALSE, pOptions ? pOptions->cFolder : NULL, pOptions ? pOptions->cName : NULL); if (myData.cCurrentUri) { // demands the attention; it helps localizing the menu and it shows the icon if the dock is hidden. if (myData.bFromShortkey) { CD_APPLET_DEMANDS_ATTENTION ("pulse", 1000); } // pop up the menu GtkWidget *pMenu = gldi_menu_new (myIcon); CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (D_("Copy the location"), GLDI_ICON_NAME_COPY, _cd_copy_location, pMenu, NULL); CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (D_("Open"), GLDI_ICON_NAME_FILE, _cd_open, pMenu, NULL); if (myData.pAppList == NULL) { /* It's always a .png file always made by Cairo * ==> no need to recreate the list, to search for icons, etc. * But we have to use the right icon and then reverse the list */ myData.pAppList = cairo_dock_fm_list_apps_for_file (myData.cCurrentUri); GList *a; gchar **pAppInfo; // name, icon, cmd gchar *cIconPath; for (a = myData.pAppList; a != NULL; a = a->next) { pAppInfo = a->data; if (pAppInfo[2] != NULL) { cIconPath = cairo_dock_search_icon_s_path (pAppInfo[2], cairo_dock_search_icon_size (GTK_ICON_SIZE_MENU)); g_free (pAppInfo[2]); pAppInfo[2] = cIconPath; } } myData.pAppList = g_list_reverse (myData.pAppList); // it's normal, we received a reversed list } if (myData.pAppList) { GtkWidget *pSubMenu = CD_APPLET_ADD_SUB_MENU_WITH_IMAGE (D_("Open with"), pMenu, GLDI_ICON_NAME_OPEN); GList *pItem; gchar **pAppInfo; for (pItem = myData.pAppList; pItem != NULL; pItem = g_list_next (pItem)) { pAppInfo = pItem->data; CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (pAppInfo[0], pAppInfo[2], _cd_launch_with, pSubMenu, pAppInfo[1]); } } CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (D_("Open parent folder"), GLDI_ICON_NAME_DIRECTORY, _cd_open_parent, pMenu, NULL); CD_APPLET_POPUP_MENU_ON_MY_ICON (pMenu); gtk_menu_shell_select_first (GTK_MENU_SHELL (pMenu), FALSE); // must be done here, after the menu has been realized. // when the menu disappear, set the icon back to normal. g_signal_connect (G_OBJECT (pMenu), "deactivate", G_CALLBACK (_on_menu_deactivated), NULL); } else // show an error message { gldi_dialog_show_temporary_with_icon (D_("Unable to take a screenshot"), myIcon, myContainer, 7000, MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE); } }
if (passed==FALSE) { crypt_show_notification_dialog (D_("Operation failed.")); } else { g_ptr_array_remove (myData.pStashArray, data); crypt_free_stashitem (data); crypt_show_notification_dialog (D_("Stash removed. Note actual encfs folder still remain at the disk.")); } } CD_APPLET_LEAVE(); } //\___________ Define here the entries you want to add to the menu when the user right-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons. The menu where you can add your entries is available throught the macro CD_APPLET_MY_MENU; you can add sub-menu to it if you want. CD_APPLET_ON_BUILD_MENU_BEGIN GtkWidget *pSubMenu = CD_APPLET_ADD_SUB_MENU_WITH_IMAGE (D_("Delete stash ..."), CD_APPLET_MY_MENU, GTK_STOCK_DELETE); for (int i=0; i < myData.pStashArray->len; i++) { CryptItem *pStashItem = NULL; pStashItem = g_ptr_array_index (myData.pStashArray, i); if (pStashItem) { if (pStashItem->bIsMounted == TRUE) { CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (pStashItem->cVisibleName, GTK_STOCK_YES, _cd_crypt_delete_stash_item, pSubMenu, pStashItem); } else { CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (pStashItem->cVisibleName, GTK_STOCK_NO, _cd_crypt_delete_stash_item, pSubMenu, pStashItem); } } } CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Import stash"), GTK_STOCK_INDEX, _cd_crypt_import_stash, CD_APPLET_MY_MENU); CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Create new stash"), GTK_STOCK_NEW, _cd_crypt_create_new_stash, CD_APPLET_MY_MENU);