diff --git a/thunar/thunar-gtk-extensions.c b/thunar/thunar-gtk-extensions.c index 0555a33e6d1d0b3e265df53b3905020caf029fec..424e328758641fea834203b05d2d0b908e55ee4a 100644 --- a/thunar/thunar-gtk-extensions.c +++ b/thunar/thunar-gtk-extensions.c @@ -205,7 +205,7 @@ popup_menu_realized (GtkWidget *menu, * This method automatically takes over the floating reference of @menu if any and * releases it on return. That means if you created the menu via gtk_menu_new() you'll * not need to take care of destroying the menu later. - * + * **/ void thunar_gtk_menu_run_at_event (GtkMenu *menu, @@ -278,6 +278,26 @@ thunar_gtk_widget_set_tooltip (GtkWidget *widget, +/** + * thunar_gtk_get_focused_widget: + * Return value: (transfer none): currently focused widget or NULL, if there is none. + **/ +GtkWidget* +thunar_gtk_get_focused_widget (void) +{ + GtkApplication *app; + GtkWindow *window; + app = GTK_APPLICATION (g_application_get_default ()); + if (NULL == app) + return NULL; + + window = gtk_application_get_active_window (app); + + return gtk_window_get_focus (window); +} + + + /** * thunar_gtk_mount_operation_new: * @parent : a #GtkWindow or non-toplevel widget. @@ -300,3 +320,46 @@ thunar_gtk_mount_operation_new (gpointer parent) return operation; } + + + +/** + * thunar_gtk_editable_can_cut: + * + * Return value: TRUE if it's possible to cut text off of a GtkEditable. + * FALSE, otherwise. + **/ +gboolean +thunar_gtk_editable_can_cut (GtkEditable *editable) +{ + return gtk_editable_get_editable (editable) && + thunar_gtk_editable_can_copy (editable); +} + + + +/** + * thunar_gtk_editable_can_copy: + * + * Return value: TRUE if it's possible to copy text from a GtkEditable. + * FALSE, otherwise. + **/ +gboolean +thunar_gtk_editable_can_copy (GtkEditable *editable) +{ + return gtk_editable_get_selection_bounds (editable, NULL,NULL); +} + + + +/** + * thunar_gtk_editable_can_paste: + * + * Return value: TRUE if it's possible to paste text to a GtkEditable. + * FALSE, otherwise. + **/ +gboolean +thunar_gtk_editable_can_paste (GtkEditable *editable) +{ + return gtk_editable_get_editable (editable); +} diff --git a/thunar/thunar-gtk-extensions.h b/thunar/thunar-gtk-extensions.h index 74fdf4c2d0a6cd644b52643982c438687571ebd9..178145ff815ca67d549b504566b06c0ccfb1100f 100644 --- a/thunar/thunar-gtk-extensions.h +++ b/thunar/thunar-gtk-extensions.h @@ -40,6 +40,12 @@ GtkWidget *thunar_gtk_menu_thunarx_menu_item_new (GObject GMountOperation *thunar_gtk_mount_operation_new (gpointer parent); +GtkWidget *thunar_gtk_get_focused_widget (void); + +gboolean thunar_gtk_editable_can_cut (GtkEditable *editable); +gboolean thunar_gtk_editable_can_copy (GtkEditable *editable); +gboolean thunar_gtk_editable_can_paste (GtkEditable *editable); + G_GNUC_BEGIN_IGNORE_DEPRECATIONS static inline int diff --git a/thunar/thunar-launcher.c b/thunar/thunar-launcher.c index c9881bfeb09f4f66c4b2b5bb45217b8c9ea28753..7fc8b024e63b436a10c920ba090eb24ff35bf557 100644 --- a/thunar/thunar-launcher.c +++ b/thunar/thunar-launcher.c @@ -1226,6 +1226,7 @@ thunar_launcher_append_menu_item (ThunarLauncher *launcher, { GtkWidget *item = NULL; GtkWidget *submenu; + GtkWidget *focused_widget; gchar *label_text; gchar *tooltip_text; const XfceGtkActionEntry *action_entry = get_action_entry (action); @@ -1395,26 +1396,52 @@ thunar_launcher_append_menu_item (ThunarLauncher *launcher, return item; case THUNAR_LAUNCHER_ACTION_CUT: - show_item = launcher->current_directory_selected == FALSE && - launcher->parent_folder != NULL; - if (!show_item && !force) - return NULL; - tooltip_text = ngettext ("Prepare the selected file to be moved with a Paste command", - "Prepare the selected files to be moved with a Paste command", launcher->n_selected_files); - item = xfce_gtk_image_menu_item_new_from_icon_name (action_entry->menu_item_label_text, tooltip_text, action_entry->accel_path, - action_entry->callback, G_OBJECT (launcher), action_entry->menu_item_icon_name, menu); - gtk_widget_set_sensitive (item, show_item && thunar_file_is_writable (launcher->parent_folder)); + focused_widget = thunar_gtk_get_focused_widget(); + if (focused_widget && GTK_IS_EDITABLE (focused_widget)) + { + item = xfce_gtk_image_menu_item_new_from_icon_name ( + action_entry->menu_item_label_text, + N_ ("Cut the selection"), + action_entry->accel_path, G_CALLBACK (gtk_editable_cut_clipboard), + G_OBJECT (focused_widget), action_entry->menu_item_icon_name, menu); + gtk_widget_set_sensitive (item, thunar_gtk_editable_can_cut (GTK_EDITABLE (focused_widget))); + } + else + { + show_item = launcher->current_directory_selected == FALSE && + launcher->parent_folder != NULL; + if (!show_item && !force) + return NULL; + tooltip_text = ngettext ("Prepare the selected file to be moved with a Paste command", + "Prepare the selected files to be moved with a Paste command", launcher->n_selected_files); + item = xfce_gtk_image_menu_item_new_from_icon_name (action_entry->menu_item_label_text, tooltip_text, action_entry->accel_path, + action_entry->callback, G_OBJECT (launcher), action_entry->menu_item_icon_name, menu); + gtk_widget_set_sensitive (item, show_item && thunar_file_is_writable (launcher->parent_folder)); + } return item; case THUNAR_LAUNCHER_ACTION_COPY: - show_item = launcher->current_directory_selected == FALSE; - if (!show_item && !force) - return NULL; - tooltip_text = ngettext ("Prepare the selected file to be copied with a Paste command", - "Prepare the selected files to be copied with a Paste command", launcher->n_selected_files); - item = xfce_gtk_image_menu_item_new_from_icon_name (action_entry->menu_item_label_text, tooltip_text, action_entry->accel_path, - action_entry->callback, G_OBJECT (launcher), action_entry->menu_item_icon_name, menu); - gtk_widget_set_sensitive (item, show_item); + focused_widget = thunar_gtk_get_focused_widget(); + if (focused_widget && GTK_IS_EDITABLE (focused_widget)) + { + item = xfce_gtk_image_menu_item_new_from_icon_name ( + action_entry->menu_item_label_text, + N_ ("Copy the selection"), + action_entry->accel_path,G_CALLBACK (gtk_editable_copy_clipboard), + G_OBJECT (focused_widget), action_entry->menu_item_icon_name, menu); + gtk_widget_set_sensitive (item, thunar_gtk_editable_can_copy (GTK_EDITABLE (focused_widget))); + } + else + { + show_item = launcher->current_directory_selected == FALSE; + if (!show_item && !force) + return NULL; + tooltip_text = ngettext ("Prepare the selected file to be copied with a Paste command", + "Prepare the selected files to be copied with a Paste command", launcher->n_selected_files); + item = xfce_gtk_image_menu_item_new_from_icon_name (action_entry->menu_item_label_text, tooltip_text, action_entry->accel_path, + action_entry->callback, G_OBJECT (launcher), action_entry->menu_item_icon_name, menu); + gtk_widget_set_sensitive (item, show_item); + } return item; case THUNAR_LAUNCHER_ACTION_PASTE_INTO_FOLDER: @@ -1427,12 +1454,25 @@ thunar_launcher_append_menu_item (ThunarLauncher *launcher, return item; case THUNAR_LAUNCHER_ACTION_PASTE: - if (launcher->single_folder_selected && !launcher->current_directory_selected) - return thunar_launcher_append_menu_item (launcher, menu, THUNAR_LAUNCHER_ACTION_PASTE_INTO_FOLDER, force); - clipboard = thunar_clipboard_manager_get_for_display (gtk_widget_get_display (launcher->widget)); - item = xfce_gtk_menu_item_new_from_action_entry (action_entry, G_OBJECT (launcher), GTK_MENU_SHELL (menu)); - gtk_widget_set_sensitive (item, thunar_clipboard_manager_get_can_paste (clipboard) && thunar_file_is_writable (launcher->current_directory)); - g_object_unref (clipboard); + focused_widget = thunar_gtk_get_focused_widget(); + if (focused_widget && GTK_IS_EDITABLE (focused_widget)) + { + item = xfce_gtk_image_menu_item_new_from_icon_name ( + action_entry->menu_item_label_text, + N_ ("Paste the clipboard"), + action_entry->accel_path,G_CALLBACK (gtk_editable_paste_clipboard), + G_OBJECT (focused_widget), action_entry->menu_item_icon_name, menu); + gtk_widget_set_sensitive (item, thunar_gtk_editable_can_paste (GTK_EDITABLE (focused_widget))); + } + else + { + if (launcher->single_folder_selected && !launcher->current_directory_selected) + return thunar_launcher_append_menu_item (launcher, menu, THUNAR_LAUNCHER_ACTION_PASTE_INTO_FOLDER, force); + clipboard = thunar_clipboard_manager_get_for_display (gtk_widget_get_display (launcher->widget)); + item = xfce_gtk_menu_item_new_from_action_entry (action_entry, G_OBJECT (launcher), GTK_MENU_SHELL (menu)); + gtk_widget_set_sensitive (item, thunar_clipboard_manager_get_can_paste (clipboard) && thunar_file_is_writable (launcher->current_directory)); + g_object_unref (clipboard); + } return item; default: