diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index 83139fc..9c0c78d 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -153,6 +153,10 @@ static ThunarFile *thunar_standard_view_get_drop_file (Thu gint x, gint y, GtkTreePath **path_return); +static void thunar_standard_view_add_custom_actions (ThunarStandardView *standard_view, + GList *selected_items, + GList *actions, + const char *subdirectory); static void thunar_standard_view_merge_custom_actions (ThunarStandardView *standard_view, GList *selected_items); static void thunar_standard_view_update_statusbar_text (ThunarStandardView *standard_view); @@ -1586,6 +1590,99 @@ thunar_standard_view_get_drop_file (ThunarStandardView *standard_view, static void +thunar_standard_view_add_custom_actions (ThunarStandardView *standard_view, + GList *selected_items, + GList *actions, + const char *subdirectory) +{ + GList *lp; + + /* add the actions to the UI manager */ + for (lp = actions; lp != NULL; lp = lp->next) + { + GtkWidget *menu = NULL; + GtkMenuItem *menuitem = NULL; + char *path; + GSList *proxies, *proxy; + + /* If a proxy menuitem has been created, get it */ + proxies = gtk_action_get_proxies (GTK_ACTION (lp->data)); + for (proxy = proxies; proxy != NULL; proxy = proxy->next) + { + if (GTK_IS_MENU_ITEM (proxy->data)) + { + menuitem = GTK_MENU_ITEM (proxy->data); + } + } + + if (menuitem != NULL) + { + menu = gtk_menu_item_get_submenu (menuitem); + } + + /* add the action to the action group */ + gtk_action_group_add_action (standard_view->priv->custom_actions, GTK_ACTION (lp->data)); + + /* add the action to the UI manager */ + if (G_LIKELY (selected_items != NULL)) + { + path = g_build_path ("/", "/file-context-menu/placeholder-custom-actions", subdirectory, NULL); + } + else + { + path = g_build_path ("/", "/folder-context-menu/placeholder-custom-actions", subdirectory, NULL); + } + + /* add to the file context menu */ + gtk_ui_manager_add_ui (standard_view->ui_manager, + standard_view->priv->custom_merge_id, + path, + gtk_action_get_name (GTK_ACTION (lp->data)), + gtk_action_get_name (GTK_ACTION (lp->data)), + (menu != NULL) ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM, + FALSE); + + g_free (path); + + /* recursively fill the action group */ + if (menu != NULL) + { + char *subdir; + GList *child_menuitems = NULL; + GList *child_actions = NULL; + GList *mip; + + child_menuitems = gtk_container_get_children (GTK_CONTAINER (menu)); + if (child_menuitems != NULL) + { + /* convert the list of menuitems to a list of actions */ + for (mip = child_menuitems; mip != NULL; mip = mip->next) + { + child_actions = g_list_append (child_actions, gtk_activatable_get_related_action (GTK_ACTIVATABLE (mip->data))); + } + + /* release the reference on the menu items */ + g_list_free (child_menuitems); + } + + subdir = g_build_path ("/", subdirectory, gtk_action_get_name (GTK_ACTION (lp->data)), NULL); + thunar_standard_view_add_custom_actions (standard_view, + selected_items, + child_actions, + subdir); + + g_list_free (child_actions); + g_free (subdir); + } + + /* release the reference on the action */ + g_object_unref (G_OBJECT (lp->data)); + } +} + + + +static void thunar_standard_view_merge_custom_actions (ThunarStandardView *standard_view, GList *selected_items) { @@ -1662,49 +1759,19 @@ thunar_standard_view_merge_custom_actions (ThunarStandardView *standard_view, /* add the actions specified by the menu providers */ if (G_LIKELY (actions != NULL)) - { + { /* allocate the action group and the merge id for the custom actions */ standard_view->priv->custom_actions = gtk_action_group_new ("thunar-standard-view-custom-actions"); standard_view->priv->custom_merge_id = gtk_ui_manager_new_merge_id (standard_view->ui_manager); gtk_ui_manager_insert_action_group (standard_view->ui_manager, standard_view->priv->custom_actions, -1); - /* add the actions to the UI manager */ - for (lp = actions; lp != NULL; lp = lp->next) - { - /* add the action to the action group */ - gtk_action_group_add_action (standard_view->priv->custom_actions, GTK_ACTION (lp->data)); - - /* add the action to the UI manager */ - if (G_LIKELY (selected_items != NULL)) - { - /* add to the file context menu */ - gtk_ui_manager_add_ui (standard_view->ui_manager, - standard_view->priv->custom_merge_id, - "/file-context-menu/placeholder-custom-actions", - gtk_action_get_name (GTK_ACTION (lp->data)), - gtk_action_get_name (GTK_ACTION (lp->data)), - GTK_UI_MANAGER_MENUITEM, FALSE); - } - else - { - /* add to the folder context menu */ - gtk_ui_manager_add_ui (standard_view->ui_manager, - standard_view->priv->custom_merge_id, - "/folder-context-menu/placeholder-custom-actions", - gtk_action_get_name (GTK_ACTION (lp->data)), - gtk_action_get_name (GTK_ACTION (lp->data)), - GTK_UI_MANAGER_MENUITEM, FALSE); - } - - /* release the reference on the action */ - g_object_unref (G_OBJECT (lp->data)); - } + thunar_standard_view_add_custom_actions(standard_view, selected_items, actions, ""); /* be sure to update the UI manager to avoid flickering */ gtk_ui_manager_ensure_update (standard_view->ui_manager); /* cleanup */ - g_list_free (actions); + g_list_free (actions); } }