gtkfilechooser: add file copy and cut menu items
This commit is contained in:
parent
bdad1edd93
commit
6594e77f7a
2 changed files with 233 additions and 1 deletions
|
|
@ -4750,6 +4750,8 @@ popup_menu_detach_cb (GtkWidget *attach_widget,
|
|||
|
||||
impl->browse_files_popup_menu = NULL;
|
||||
impl->browse_files_popup_menu_add_shortcut_item = NULL;
|
||||
impl->browse_files_popup_menu_copy_item = NULL;
|
||||
impl->browse_files_popup_menu_cut_item = NULL;
|
||||
impl->browse_files_popup_menu_copy_location_item = NULL;
|
||||
impl->browse_files_popup_menu_rename_item = NULL;
|
||||
impl->browse_files_popup_menu_hidden_files_item = NULL;
|
||||
|
|
@ -4868,6 +4870,211 @@ add_to_shortcuts_cb (GtkMenuItem *item,
|
|||
bookmarks_add_selected_folder (impl);
|
||||
}
|
||||
|
||||
enum {
|
||||
FILE_CLIPBOARD_TARGET_GNOME_COPIED_FILES,
|
||||
FILE_CLIPBOARD_TARGET_URI_LIST,
|
||||
FILE_CLIPBOARD_TARGET_TEXT_PLAIN,
|
||||
FILE_CLIPBOARD_TARGET_KDE_CUT_SELECTION,
|
||||
FILE_CLIPBOARD_TARGET_TDE_CUT_SELECTION,
|
||||
FILE_CLIPBOARD_TARGET_EMPTY
|
||||
};
|
||||
|
||||
struct file_clipboard_data
|
||||
{
|
||||
gchar *gnome_copied_files;
|
||||
gchar *uri_list;
|
||||
gchar *plain_text;
|
||||
gchar *cut_selection;
|
||||
};
|
||||
|
||||
struct file_clipboard_closure
|
||||
{
|
||||
GString *gnome_copied_files;
|
||||
GString *uri_list;
|
||||
GString *plain_text;
|
||||
gboolean first;
|
||||
};
|
||||
|
||||
static const GtkTargetEntry file_clipboard_targets[] = {
|
||||
{ "x-special/gnome-copied-files", 0, FILE_CLIPBOARD_TARGET_GNOME_COPIED_FILES },
|
||||
{ "text/uri-list", 0, FILE_CLIPBOARD_TARGET_URI_LIST },
|
||||
{ "text/plain", 0, FILE_CLIPBOARD_TARGET_TEXT_PLAIN },
|
||||
{ "text/plain;charset=utf-8", 0, FILE_CLIPBOARD_TARGET_TEXT_PLAIN },
|
||||
{ "text/plain;charset=UTF-8", 0, FILE_CLIPBOARD_TARGET_TEXT_PLAIN },
|
||||
{ "UTF8_STRING", 0, FILE_CLIPBOARD_TARGET_TEXT_PLAIN },
|
||||
{ "text/x-moz-url", 0, FILE_CLIPBOARD_TARGET_URI_LIST },
|
||||
{ "application/x-kde4-urilist", 0, FILE_CLIPBOARD_TARGET_URI_LIST },
|
||||
{ "application/x-tde-urilist", 0, FILE_CLIPBOARD_TARGET_URI_LIST },
|
||||
{ "application/x-kde-cutselection", 0, FILE_CLIPBOARD_TARGET_KDE_CUT_SELECTION },
|
||||
{ "application/x-tde-cutselection", 0, FILE_CLIPBOARD_TARGET_TDE_CUT_SELECTION },
|
||||
{ "application/x-tdeio-metadata", 0, FILE_CLIPBOARD_TARGET_EMPTY }
|
||||
};
|
||||
|
||||
static void
|
||||
file_clipboard_data_free (struct file_clipboard_data *data)
|
||||
{
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
g_free (data->gnome_copied_files);
|
||||
g_free (data->uri_list);
|
||||
g_free (data->plain_text);
|
||||
g_free (data->cut_selection);
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
static void
|
||||
file_clipboard_get_cb (GtkClipboard *clipboard,
|
||||
GtkSelectionData *selection_data,
|
||||
guint info,
|
||||
gpointer user_data)
|
||||
{
|
||||
struct file_clipboard_data *data = user_data;
|
||||
const gchar *text;
|
||||
|
||||
switch (info)
|
||||
{
|
||||
case FILE_CLIPBOARD_TARGET_GNOME_COPIED_FILES:
|
||||
text = data->gnome_copied_files;
|
||||
break;
|
||||
|
||||
case FILE_CLIPBOARD_TARGET_TEXT_PLAIN:
|
||||
text = data->plain_text;
|
||||
break;
|
||||
|
||||
case FILE_CLIPBOARD_TARGET_KDE_CUT_SELECTION:
|
||||
case FILE_CLIPBOARD_TARGET_TDE_CUT_SELECTION:
|
||||
text = data->cut_selection;
|
||||
break;
|
||||
|
||||
case FILE_CLIPBOARD_TARGET_EMPTY:
|
||||
text = "";
|
||||
break;
|
||||
|
||||
case FILE_CLIPBOARD_TARGET_URI_LIST:
|
||||
default:
|
||||
text = data->uri_list;
|
||||
break;
|
||||
}
|
||||
|
||||
gtk_selection_data_set (selection_data,
|
||||
gtk_selection_data_get_target (selection_data),
|
||||
8,
|
||||
(const guchar *) text,
|
||||
strlen (text) + (info == FILE_CLIPBOARD_TARGET_URI_LIST ? 1 : 0));
|
||||
}
|
||||
|
||||
static void
|
||||
file_clipboard_clear_cb (GtkClipboard *clipboard,
|
||||
gpointer user_data)
|
||||
{
|
||||
file_clipboard_data_free (user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
file_clipboard_foreach_cb (GtkTreeModel *model,
|
||||
GtkTreePath *path,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
struct file_clipboard_closure *closure = data;
|
||||
GFile *file = NULL;
|
||||
gchar *uri;
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
MODEL_COL_FILE, &file,
|
||||
-1);
|
||||
|
||||
if (file == NULL)
|
||||
return;
|
||||
|
||||
uri = g_file_get_uri (file);
|
||||
|
||||
if (uri)
|
||||
{
|
||||
g_string_append (closure->gnome_copied_files, uri);
|
||||
g_string_append_c (closure->gnome_copied_files, '\n');
|
||||
|
||||
g_string_append (closure->uri_list, uri);
|
||||
g_string_append (closure->uri_list, "\r\n");
|
||||
|
||||
if (!closure->first)
|
||||
g_string_append_c (closure->plain_text, '\n');
|
||||
|
||||
g_string_append (closure->plain_text, uri);
|
||||
closure->first = FALSE;
|
||||
}
|
||||
|
||||
g_free (uri);
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
static void
|
||||
copy_or_cut_files_to_clipboard (GtkFileChooserDefault *impl,
|
||||
gboolean cut)
|
||||
{
|
||||
struct file_clipboard_closure closure;
|
||||
struct file_clipboard_data *data;
|
||||
GtkClipboard *clipboard;
|
||||
|
||||
closure.gnome_copied_files = g_string_new (cut ? "cut\n" : "copy\n");
|
||||
closure.uri_list = g_string_new (NULL);
|
||||
closure.plain_text = g_string_new (NULL);
|
||||
closure.first = TRUE;
|
||||
|
||||
current_selection_selected_foreach (impl,
|
||||
file_clipboard_foreach_cb,
|
||||
&closure);
|
||||
|
||||
if (closure.uri_list->len == 0)
|
||||
{
|
||||
g_string_free (closure.gnome_copied_files, TRUE);
|
||||
g_string_free (closure.uri_list, TRUE);
|
||||
g_string_free (closure.plain_text, TRUE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (closure.gnome_copied_files->len > 0 &&
|
||||
closure.gnome_copied_files->str[closure.gnome_copied_files->len - 1] == '\n')
|
||||
g_string_truncate (closure.gnome_copied_files,
|
||||
closure.gnome_copied_files->len - 1);
|
||||
|
||||
data = g_new0 (struct file_clipboard_data, 1);
|
||||
data->gnome_copied_files = g_string_free (closure.gnome_copied_files, FALSE);
|
||||
data->uri_list = g_string_free (closure.uri_list, FALSE);
|
||||
data->plain_text = g_string_free (closure.plain_text, FALSE);
|
||||
data->cut_selection = g_strdup (cut ? "1" : "0");
|
||||
|
||||
clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (impl->browse_files_current_view),
|
||||
GDK_SELECTION_CLIPBOARD);
|
||||
|
||||
if (gtk_clipboard_set_with_data (clipboard,
|
||||
file_clipboard_targets,
|
||||
G_N_ELEMENTS (file_clipboard_targets),
|
||||
file_clipboard_get_cb,
|
||||
file_clipboard_clear_cb,
|
||||
data))
|
||||
gtk_clipboard_set_can_store (clipboard,
|
||||
file_clipboard_targets,
|
||||
G_N_ELEMENTS (file_clipboard_targets));
|
||||
else
|
||||
file_clipboard_data_free (data);
|
||||
}
|
||||
|
||||
static void
|
||||
copy_files_cb (GtkMenuItem *item,
|
||||
GtkFileChooserDefault *impl)
|
||||
{
|
||||
copy_or_cut_files_to_clipboard (impl, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
cut_files_cb (GtkMenuItem *item,
|
||||
GtkFileChooserDefault *impl)
|
||||
{
|
||||
copy_or_cut_files_to_clipboard (impl, TRUE);
|
||||
}
|
||||
|
||||
struct copy_locations_closure
|
||||
{
|
||||
GString *locations;
|
||||
|
|
@ -5804,10 +6011,24 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl)
|
|||
gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
|
||||
|
||||
|
||||
item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
|
||||
impl->browse_files_popup_menu_copy_item = item;
|
||||
g_signal_connect (item, "activate",
|
||||
G_CALLBACK (copy_files_cb), impl);
|
||||
gtk_widget_show (item);
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
|
||||
|
||||
item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CUT, NULL);
|
||||
impl->browse_files_popup_menu_cut_item = item;
|
||||
g_signal_connect (item, "activate",
|
||||
G_CALLBACK (cut_files_cb), impl);
|
||||
gtk_widget_show (item);
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
|
||||
|
||||
item = gtk_image_menu_item_new_with_mnemonic (_("_Copy Location"));
|
||||
impl->browse_files_popup_menu_copy_location_item = item;
|
||||
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
|
||||
gtk_image_new_from_stock (GTK_STOCK_COPY, GTK_ICON_SIZE_MENU));
|
||||
gtk_image_new_from_stock (GTK_STOCK_JUMP_TO, GTK_ICON_SIZE_MENU));
|
||||
g_signal_connect (item, "activate",
|
||||
G_CALLBACK (copy_location_cb), impl);
|
||||
gtk_widget_show (item);
|
||||
|
|
@ -5930,6 +6151,15 @@ file_list_update_popup_menu (GtkFileChooserDefault *impl)
|
|||
* bookmarks_check_add_sensitivity()
|
||||
*/
|
||||
|
||||
if (impl->browse_files_popup_menu_copy_item)
|
||||
gtk_widget_set_sensitive (impl->browse_files_popup_menu_copy_item,
|
||||
current_selection_count_selected_rows (impl) > 0);
|
||||
|
||||
if (impl->browse_files_popup_menu_cut_item)
|
||||
gtk_widget_set_sensitive (impl->browse_files_popup_menu_cut_item,
|
||||
impl->operation_mode == OPERATION_MODE_BROWSE &&
|
||||
current_selection_count_selected_rows (impl) > 0);
|
||||
|
||||
if (impl->browse_files_popup_menu_copy_location_item)
|
||||
gtk_widget_set_sensitive (impl->browse_files_popup_menu_copy_location_item,
|
||||
current_selection_count_selected_rows (impl) > 0);
|
||||
|
|
|
|||
|
|
@ -195,6 +195,8 @@ struct _GtkFileChooserDefault
|
|||
guint list_tooltip_visible : 1;
|
||||
GtkWidget *browse_files_popup_menu;
|
||||
GtkWidget *browse_files_popup_menu_add_shortcut_item;
|
||||
GtkWidget *browse_files_popup_menu_copy_item;
|
||||
GtkWidget *browse_files_popup_menu_cut_item;
|
||||
GtkWidget *browse_files_popup_menu_copy_location_item;
|
||||
GtkWidget *browse_files_popup_menu_rename_item;
|
||||
GtkWidget *browse_files_popup_menu_hidden_files_item;
|
||||
|
|
|
|||
Loading…
Reference in a new issue