Commit 005a67c5 authored by Alexander Schwinn's avatar Alexander Schwinn
Browse files

re-introduce support for thunarx (Bug #16654)

parent 91d970c7
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -142,8 +142,6 @@ thunar_SOURCES = \
	thunar-location-entry.h						\
	thunar-menu.c						\
	thunar-menu.h						\
	thunar-menu-util.c						\
	thunar-menu-util.h						\
	thunar-notify.c							\
	thunar-notify.h							\
	thunar-navigator.c						\
+2 −2
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@
#include <thunar/thunar-dialogs.h>
#include <thunar/thunar-dnd.h>
#include <thunar/thunar-gtk-extensions.h>
#include <thunar/thunar-menu-util.h>
#include <thunar/thunar-private.h>


@@ -154,7 +153,8 @@ G_GNUC_END_IGNORE_DEPRECATIONS
          if (G_UNLIKELY (items != NULL))
            {
              /* add menu items for all items */
              thunar_menu_util_add_items_to_menu (menu, items);
              for (lp = items; lp != NULL; lp = lp->next)
                thunar_gtk_menu_thunarx_menu_item_new (lp->data, GTK_MENU_SHELL (menu));
              g_list_free (items);

              /* append another separator */
+60 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include <thunar/thunar-private.h>
#include <thunar/thunar-util.h>

#include <thunarx/thunarx.h>

#include <libxfce4ui/libxfce4ui.h>

@@ -98,6 +99,65 @@ thunar_gtk_label_set_a11y_relation (GtkLabel *label,



/**
 * thunar_gtk_menu_thunarx_menu_item_new:
 * @thunarx_menu_item   : a #ThunarxMenuItem
 * @menu_to_append_item : #GtkMenuShell on which the item should be appended, or NULL
 *
 * method to create a #GtkMenuItem from a #ThunarxMenuItem and append it to the passed #GtkMenuShell
 * This method will as well add all sub-items in case the passed #ThunarxMenuItem is a submenu
 *
 * Return value: (transfer full): The new #GtkImageMenuItem.
 **/
GtkWidget*
thunar_gtk_menu_thunarx_menu_item_new (GObject      *thunarx_menu_item,
                                       GtkMenuShell *menu_to_append_item)
{
  gchar        *name, *label_text, *tooltip_text, *icon_name, *accel_path;
  gboolean      sensitive;
  GtkWidget    *gtk_menu_item;
  ThunarxMenu  *thunarx_menu;
  GList        *children;
  GList        *lp;
  GtkWidget    *submenu;

  g_return_val_if_fail (THUNARX_IS_MENU_ITEM (thunarx_menu_item), NULL);

  g_object_get (G_OBJECT (thunarx_menu_item),
                "name", &name,
                "label", &label_text,
                "tooltip", &tooltip_text,
                "icon", &icon_name,
                "sensitive", &sensitive,
                "menu", &thunarx_menu,
                NULL);

  accel_path = g_strconcat ("<Actions>/ThunarActions/", name, NULL);
  gtk_menu_item = xfce_gtk_image_menu_item_new_from_icon_name (label_text, tooltip_text, accel_path,
                                                               G_CALLBACK (thunarx_menu_item_activate),
                                                               G_OBJECT (thunarx_menu_item), icon_name, menu_to_append_item);

  /* recursively add submenu items if any */
  if (gtk_menu_item != NULL && thunarx_menu != NULL)
  {
    children = thunarx_menu_get_items (thunarx_menu);
    submenu = gtk_menu_new ();
    for (lp = children; lp != NULL; lp = lp->next)
      thunar_gtk_menu_thunarx_menu_item_new (lp->data, GTK_MENU_SHELL (submenu));
    gtk_menu_item_set_submenu (GTK_MENU_ITEM (gtk_menu_item), submenu);
    thunarx_menu_item_list_free (children);
  }
  g_free (name);
  g_free (accel_path);
  g_free (label_text);
  g_free (tooltip_text);
  g_free (icon_name);

  return gtk_menu_item;
}



/**
 * thunar_gtk_menu_run:
 * @menu : a #GtkMenu.
+2 −0
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ void thunar_gtk_menu_run_at_event (GtkMenu
void             thunar_gtk_widget_set_tooltip                (GtkWidget          *widget,
                                                               const gchar        *format,
                                                               ...) G_GNUC_PRINTF (2, 3);
GtkWidget       *thunar_gtk_menu_thunarx_menu_item_new        (GObject            *thunarx_menu_item,
                                                               GtkMenuShell       *menu_to_append_item);

GMountOperation *thunar_gtk_mount_operation_new               (gpointer            parent);

+122 −0
Original line number Diff line number Diff line
@@ -1896,6 +1896,128 @@ thunar_launcher_action_duplicate (ThunarLauncher *launcher)



/**
 * thunar_launcher_append_custom_actions:
 * @launcher : a #ThunarLauncher instance
 * @menu : #GtkMenuShell on which the custom actions should be appended
 *
 * Will append all custom actions which match the file-type to the provided #GtkMenuShell
 *
 * Return value: TRUE if any custom action was added
 **/
gboolean
thunar_launcher_append_custom_actions (ThunarLauncher *launcher,
                                       GtkMenuShell   *menu)
{
  gboolean                uca_added = FALSE;
  GtkWidget              *window;
  GtkWidget              *gtk_menu_item;
  ThunarxProviderFactory *provider_factory;
  GList                  *providers;
  GList                  *thunarx_menu_items = NULL;
  GList                  *lp_provider;
  GList                  *lp_item;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);
  _thunar_return_val_if_fail (GTK_IS_MENU (menu), FALSE);

  /* determine the toplevel window we belong to */
  window = gtk_widget_get_toplevel (launcher->widget);

  /* load the menu providers from the provider factory */
  provider_factory = thunarx_provider_factory_get_default ();
  providers = thunarx_provider_factory_list_providers (provider_factory, THUNARX_TYPE_MENU_PROVIDER);
  g_object_unref (provider_factory);

  if (G_UNLIKELY (providers == NULL))
    return FALSE;

  /* This may occur when the thunar-window is build */
  if (G_UNLIKELY (launcher->selected_files == NULL))
    return FALSE;

  /* load the menu items offered by the menu providers */
  for (lp_provider = providers; lp_provider != NULL; lp_provider = lp_provider->next)
    {
      if (launcher->single_folder_selected)
        thunarx_menu_items = thunarx_menu_provider_get_folder_menu_items (lp_provider->data, window, THUNARX_FILE_INFO (launcher->single_folder));
      else
        thunarx_menu_items = thunarx_menu_provider_get_file_menu_items (lp_provider->data, window, launcher->selected_files);
      for (lp_item = thunarx_menu_items; lp_item != NULL; lp_item = lp_item->next)
        {
          gtk_menu_item = thunar_gtk_menu_thunarx_menu_item_new (lp_item->data, menu);

          /* Each thunarx_menu_item will be destroyed together with its related gtk_menu_item*/
          g_signal_connect_swapped (G_OBJECT (gtk_menu_item), "destroy", G_CALLBACK (g_object_unref), lp_item->data);
          uca_added = TRUE;
        }
      g_list_free (thunarx_menu_items);
    }
  g_list_free_full (providers, g_object_unref);
  return uca_added;
}



gboolean
thunar_launcher_check_uca_key_activation (ThunarLauncher *launcher,
                                          GdkEventKey    *key_event)
{
  GtkWidget              *window;
  ThunarxProviderFactory *provider_factory;
  GList                  *providers;
  GList                  *thunarx_menu_items = NULL;
  GList                  *lp_provider;
  GList                  *lp_item;
  GtkAccelKey             uca_key;
  gchar                  *name, *accel_path;
  gboolean                uca_activated = FALSE;

  /* determine the toplevel window we belong to */
  window = gtk_widget_get_toplevel (launcher->widget);

  /* load the menu providers from the provider factory */
  provider_factory = thunarx_provider_factory_get_default ();
  providers = thunarx_provider_factory_list_providers (provider_factory, THUNARX_TYPE_MENU_PROVIDER);
  g_object_unref (provider_factory);

  if (G_UNLIKELY (providers == NULL))
    return uca_activated;

  /* load the menu items offered by the menu providers */
  for (lp_provider = providers; lp_provider != NULL; lp_provider = lp_provider->next)
    {
      if (launcher->single_folder_selected)
        thunarx_menu_items = thunarx_menu_provider_get_folder_menu_items (lp_provider->data, window, THUNARX_FILE_INFO (launcher->single_folder));
      else
        thunarx_menu_items = thunarx_menu_provider_get_file_menu_items (lp_provider->data, window, launcher->selected_files);
      for (lp_item = thunarx_menu_items; lp_item != NULL; lp_item = lp_item->next)
        {
          g_object_get (G_OBJECT (lp_item->data), "name", &name, NULL);
          accel_path = g_strconcat ("<Actions>/ThunarActions/", name, NULL);
          if (gtk_accel_map_lookup_entry (accel_path, &uca_key) == TRUE)
            {
              if (key_event->keyval == uca_key.accel_key)
                {
                  if ((key_event->state & gtk_accelerator_get_default_mod_mask ()) == uca_key.accel_mods)
                    {
                      thunarx_menu_item_activate (lp_item->data);
                      uca_activated = TRUE;
                    }
                }
            }
          g_free (name);
          g_free (accel_path);
          g_object_unref (lp_item->data);
        }
      g_list_free (thunarx_menu_items);
    }
  g_list_free_full (providers, g_object_unref);
  return uca_activated;
}



static void
thunar_launcher_rename_error (ExoJob    *job,
                              GError    *error,
Loading