diff options
Diffstat (limited to 'calendar/gui/e-calendar-table.c')
-rw-r--r-- | calendar/gui/e-calendar-table.c | 111 |
1 files changed, 33 insertions, 78 deletions
diff --git a/calendar/gui/e-calendar-table.c b/calendar/gui/e-calendar-table.c index 483c032438..3903c58888 100644 --- a/calendar/gui/e-calendar-table.c +++ b/calendar/gui/e-calendar-table.c @@ -55,6 +55,7 @@ #include "dialogs/delete-error.h" #include "dialogs/task-editor.h" #include "e-cal-model-tasks.h" +#include "e-cal-selection.h" #include "e-calendar-table.h" #include "e-calendar-view.h" #include "e-cell-date-edit-text.h" @@ -85,20 +86,10 @@ enum { LAST_SIGNAL }; -enum { - TARGET_TYPE_VCALENDAR -}; - -static GtkTargetEntry target_types[] = { - { (gchar *) "text/calendar", 0, TARGET_TYPE_VCALENDAR }, - { (gchar *) "text/x-calendar", 0, TARGET_TYPE_VCALENDAR } -}; - static struct tm e_calendar_table_get_current_time (ECellDateEdit *ecde, gpointer data); static gpointer parent_class; static guint signals[LAST_SIGNAL]; -static GdkAtom clipboard_atom; /* The icons to represent the task. */ #define NUM_ICONS 4 @@ -938,8 +929,6 @@ calendar_table_class_init (ECalendarTableClass *class) NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); } static void @@ -1277,26 +1266,6 @@ e_calendar_table_cut_clipboard (ECalendarTable *cal_table) delete_selected_components (cal_table); } -static void -clipboard_get_calendar_cb (GtkClipboard *clipboard, - GtkSelectionData *selection_data, - guint info, - gpointer data) -{ - gchar *comp_str = (gchar *) data; - - switch (info) { - case TARGET_TYPE_VCALENDAR: - gtk_selection_data_set (selection_data, - gdk_atom_intern (target_types[info].target, FALSE), 8, - (const guchar *) comp_str, - (gint) strlen (comp_str)); - break; - default: - break; - } -} - /* callback for e_table_selected_row_foreach */ static void copy_row_cb (gint model_row, gpointer data) @@ -1351,16 +1320,10 @@ e_calendar_table_copy_clipboard (ECalendarTable *cal_table) etable = e_calendar_table_get_table (cal_table); e_table_selected_row_foreach (etable, copy_row_cb, cal_table); comp_str = icalcomponent_as_ical_string_r (cal_table->tmp_vcal); - clipboard = gtk_widget_get_clipboard (GTK_WIDGET (cal_table), clipboard_atom); - if (!gtk_clipboard_set_with_data ( - clipboard, target_types, G_N_ELEMENTS (target_types), - clipboard_get_calendar_cb, NULL, comp_str)) { - /* no-op */ - } else { - gtk_clipboard_set_can_store ( - clipboard, target_types + 1, - G_N_ELEMENTS (target_types) - 1); - } + + clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + e_clipboard_set_calendar (clipboard, comp_str, -1); + gtk_clipboard_store (clipboard); /* free memory */ icalcomponent_free (cal_table->tmp_vcal); @@ -1449,37 +1412,6 @@ clipboard_get_calendar_data (ECalendarTable *cal_table, const gchar *text) calendar_table_emit_status_message (cal_table, NULL, -1.0); } -static void -clipboard_paste_received_cb (GtkClipboard *clipboard, - GtkSelectionData *selection_data, - gpointer data) -{ - ECalendarTable *cal_table = E_CALENDAR_TABLE (data); - ETable *e_table = e_calendar_table_get_table (cal_table); - GnomeCanvas *canvas = e_table->table_canvas; - GnomeCanvasItem *item = GNOME_CANVAS (canvas)->focused_item; - - if (gtk_clipboard_wait_is_text_available (clipboard) && - GTK_WIDGET_HAS_FOCUS (canvas) && - E_IS_TABLE_ITEM (item) && - E_TABLE_ITEM (item)->editing_col >= 0 && - E_TABLE_ITEM (item)->editing_row >= 0) { - ETableItem *eti = E_TABLE_ITEM (item); - ECellView *cell_view = eti->cell_views[eti->editing_col]; - e_cell_text_paste_clipboard (cell_view, eti->editing_col, eti->editing_row); - } else { - GdkAtom type = selection_data->type; - if (type == gdk_atom_intern (target_types[TARGET_TYPE_VCALENDAR].target, TRUE)) { - gchar *result = NULL; - result = g_strndup ((const gchar *) selection_data->data, - selection_data->length); - clipboard_get_calendar_data (cal_table, result); - g_free (result); - } - } - g_object_unref (cal_table); -} - /** * e_calendar_table_paste_clipboard: * @cal_table: A calendar table. @@ -1490,15 +1422,38 @@ void e_calendar_table_paste_clipboard (ECalendarTable *cal_table) { GtkClipboard *clipboard; + GnomeCanvasItem *item; + ETable *etable; g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - clipboard = gtk_widget_get_clipboard ( - GTK_WIDGET (cal_table), clipboard_atom); + clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); - gtk_clipboard_request_contents ( - clipboard, gdk_atom_intern (target_types[0].target, FALSE), - clipboard_paste_received_cb, g_object_ref (cal_table)); + etable = e_calendar_table_get_table (cal_table); + item = GNOME_CANVAS (etable->table_canvas)->focused_item; + + /* Paste text into a cell being edited. */ + if (gtk_clipboard_wait_is_text_available (clipboard) && + GTK_WIDGET_HAS_FOCUS (etable->table_canvas) && + E_IS_TABLE_ITEM (item) && + E_TABLE_ITEM (item)->editing_col >= 0 && + E_TABLE_ITEM (item)->editing_row >= 0) { + + ETableItem *etable_item = E_TABLE_ITEM (item); + + e_cell_text_paste_clipboard ( + etable_item->cell_views[etable_item->editing_col], + etable_item->editing_col, + etable_item->editing_row); + + /* Paste iCalendar data into the table. */ + } else if (e_clipboard_wait_is_calendar_available (clipboard)) { + gchar *calendar_source; + + calendar_source = e_clipboard_wait_for_calendar (clipboard); + clipboard_get_calendar_data (cal_table, calendar_source); + g_free (calendar_source); + } } static void |