aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui
diff options
context:
space:
mode:
authorSuman Manjunath <msuman@src.gnome.org>2008-12-08 14:40:17 +0800
committerSuman Manjunath <msuman@src.gnome.org>2008-12-08 14:40:17 +0800
commit1eba7c5d8d740185a48b007e51acc16e4eebaf47 (patch)
tree0b4e3c60577455f23b22be7b088250a6e1e0103f /calendar/gui
parent3059297cddb1838ad733600efa1185bcb7ddde2f (diff)
downloadgsoc2013-evolution-1eba7c5d8d740185a48b007e51acc16e4eebaf47.tar.gz
gsoc2013-evolution-1eba7c5d8d740185a48b007e51acc16e4eebaf47.tar.zst
gsoc2013-evolution-1eba7c5d8d740185a48b007e51acc16e4eebaf47.zip
Patch from Hiroyuki Ikezoe <poincare@ikezoe.net> ** Fix for bug #350725 (Copy/Paste support in day/week views).
svn path=/trunk/; revision=36841
Diffstat (limited to 'calendar/gui')
-rw-r--r--calendar/gui/e-calendar-view.c102
-rw-r--r--calendar/gui/e-calendar-view.h1
-rw-r--r--calendar/gui/e-day-view.c177
-rw-r--r--calendar/gui/e-week-view.c189
4 files changed, 314 insertions, 155 deletions
diff --git a/calendar/gui/e-calendar-view.c b/calendar/gui/e-calendar-view.c
index d54c2808ec..aee65cae19 100644
--- a/calendar/gui/e-calendar-view.c
+++ b/calendar/gui/e-calendar-view.c
@@ -80,7 +80,6 @@ static void e_calendar_view_set_property (GObject *object, guint property_id, co
static void e_calendar_view_destroy (GtkObject *object);
static void open_event_with_flags (ECalendarView *cal_view, ECal *client, icalcomponent *icalcomp, guint32 flags);
-static GdkAtom clipboard_atom = GDK_NONE;
extern ECompEditorRegistry *comp_editor_registry;
/* Property IDs */
@@ -106,6 +105,17 @@ static guint e_calendar_view_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (ECalendarView, e_calendar_view, GTK_TYPE_TABLE)
+enum TargetType{
+ TARGET_TYPE_VCALENDAR
+};
+
+static GtkTargetEntry target_types[] = {
+ { "text/x-calendar", 0, TARGET_TYPE_VCALENDAR },
+ { "text/calendar", 0, TARGET_TYPE_VCALENDAR }
+};
+
+static guint n_target_types = G_N_ELEMENTS (target_types);
+
static void
e_calendar_view_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
@@ -165,6 +175,7 @@ e_calendar_view_class_init (ECalendarViewClass *klass)
klass->get_visible_time_range = NULL;
klass->update_query = NULL;
klass->open_event = e_calendar_view_open_event;
+ klass->paste_text = NULL;
g_object_class_install_property (gobject_class, PROP_MODEL,
g_param_spec_object ("model", NULL, NULL, E_TYPE_CAL_MODEL,
@@ -234,11 +245,6 @@ e_calendar_view_class_init (ECalendarViewClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
- /* clipboard atom */
- if (!clipboard_atom)
- clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE);
-
-
/*
* Key bindings
*/
@@ -711,6 +717,34 @@ e_calendar_view_cut_clipboard (ECalendarView *cal_view)
g_list_free (selected);
}
+static void
+clipboard_clear_calendar_cb (GtkClipboard *clipboard,
+ gpointer data)
+{
+ g_free (data);
+}
+
+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,
+ selection_data->target,
+ 8,
+ (const guchar *) comp_str,
+ (gint) strlen (comp_str));
+ break;
+ default:
+ break;
+ }
+}
+
void
e_calendar_view_copy_clipboard (ECalendarView *cal_view)
{
@@ -719,6 +753,7 @@ e_calendar_view_copy_clipboard (ECalendarView *cal_view)
icalcomponent *vcal_comp;
icalcomponent *new_icalcomp;
ECalendarViewEvent *event;
+ GtkClipboard *clipboard;
g_return_if_fail (E_IS_CALENDAR_VIEW (cal_view));
@@ -752,19 +787,25 @@ e_calendar_view_copy_clipboard (ECalendarView *cal_view)
}
/* copy the VCALENDAR to the clipboard */
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (cal_view), GDK_SELECTION_CLIPBOARD);
comp_str = icalcomponent_as_ical_string (vcal_comp);
- gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (cal_view), clipboard_atom),
- (const gchar *) comp_str,
- strlen (comp_str));
+
+ if (!gtk_clipboard_set_with_data (clipboard, target_types, n_target_types,
+ clipboard_get_calendar_cb,
+ clipboard_clear_calendar_cb,
+ comp_str)) {
+ g_free (comp_str);
+ } else {
+ gtk_clipboard_set_can_store (clipboard, target_types + 1, n_target_types - 1);
+ }
/* free memory */
icalcomponent_free (vcal_comp);
- g_free (comp_str);
g_list_free (selected);
}
static void
-clipboard_get_text_cb (GtkClipboard *clipboard, const gchar *text, ECalendarView *cal_view)
+clipboard_get_calendar_data (ECalendarView *cal_view, const gchar *text)
{
icalcomponent *icalcomp;
icalcomponent_kind kind;
@@ -840,13 +881,48 @@ clipboard_get_text_cb (GtkClipboard *clipboard, const gchar *text, ECalendarView
e_calendar_view_set_status_message (cal_view, NULL, -1);
}
+static void
+e_calendar_view_paste_text (ECalendarView *cal_view)
+{
+ g_return_if_fail (E_IS_CALENDAR_VIEW (cal_view));
+
+ if (E_CALENDAR_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->paste_text)
+ E_CALENDAR_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->paste_text (cal_view);
+}
+
+static void
+clipboard_paste_received_cb (GtkClipboard *clipboard,
+ GtkSelectionData *selection_data,
+ gpointer data)
+{
+ if (gtk_clipboard_wait_is_text_available (clipboard)) {
+ e_calendar_view_paste_text (E_CALENDAR_VIEW (data));
+ } 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 (E_CALENDAR_VIEW (data), result);
+ g_free (result);
+ }
+ }
+ g_object_unref (data);
+}
+
void
e_calendar_view_paste_clipboard (ECalendarView *cal_view)
{
+ GtkClipboard *clipboard;
+
g_return_if_fail (E_IS_CALENDAR_VIEW (cal_view));
- gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (cal_view), clipboard_atom),
- (GtkClipboardTextReceivedFunc) clipboard_get_text_cb, cal_view);
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (cal_view), GDK_SELECTION_CLIPBOARD);
+ g_object_ref (cal_view);
+
+ gtk_clipboard_request_contents (clipboard,
+ gdk_atom_intern (target_types[TARGET_TYPE_VCALENDAR].target, FALSE),
+ clipboard_paste_received_cb, cal_view);
}
static void
diff --git a/calendar/gui/e-calendar-view.h b/calendar/gui/e-calendar-view.h
index 320d911d24..ef74cdcfdb 100644
--- a/calendar/gui/e-calendar-view.h
+++ b/calendar/gui/e-calendar-view.h
@@ -112,6 +112,7 @@ struct _ECalendarViewClass {
gboolean (* get_visible_time_range) (ECalendarView *cal_view, time_t *start_time, time_t *end_time);
void (* update_query) (ECalendarView *cal_view);
void (* open_event) (ECalendarView *cal_view);
+ void (* paste_text) (ECalendarView *cal_view);
};
GType e_calendar_view_get_type (void);
diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c
index 2943b6dcd5..7d54f83cbf 100644
--- a/calendar/gui/e-day-view.c
+++ b/calendar/gui/e-day-view.c
@@ -153,6 +153,7 @@ static GList *e_day_view_get_selected_events (ECalendarView *cal_view);
static gboolean e_day_view_get_selected_time_range (ECalendarView *cal_view, time_t *start_time, time_t *end_time);
static void e_day_view_set_selected_time_range (ECalendarView *cal_view, time_t start_time, time_t end_time);
static gboolean e_day_view_get_visible_time_range (ECalendarView *cal_view, time_t *start_time, time_t *end_time);
+static void e_day_view_paste_text (ECalendarView *day_view);
static void e_day_view_update_query (EDayView *day_view);
static void e_day_view_goto_start_of_work_day (EDayView *day_view);
static void e_day_view_goto_end_of_work_day (EDayView *day_view);
@@ -467,6 +468,7 @@ e_day_view_class_init (EDayViewClass *class)
view_class->get_selected_time_range = e_day_view_get_selected_time_range;
view_class->set_selected_time_range = e_day_view_set_selected_time_range;
view_class->get_visible_time_range = e_day_view_get_visible_time_range;
+ view_class->paste_text = e_day_view_paste_text;
/* init the accessibility support for e_day_view */
e_day_view_a11y_init ();
@@ -4722,16 +4724,13 @@ e_day_view_event_sort_func (const void *arg1,
}
static gboolean
-e_day_view_do_key_press (GtkWidget *widget, GdkEventKey *event)
+e_day_view_add_new_event_in_selected_range (EDayView *day_view, GdkEventKey *key_event)
{
- EDayView *day_view;
icalcomponent *icalcomp;
ECal *ecal;
ECalModel *model;
ECalComponent *comp;
gint day, event_num;
- guint keyval;
- gboolean stop_emission;
time_t dtstart, dtend;
ECalComponentDateTime start_dt, end_dt;
struct icaltimetype start_tt, end_tt;
@@ -4739,6 +4738,80 @@ e_day_view_do_key_press (GtkWidget *widget, GdkEventKey *event)
AddEventData add_event_data;
gboolean read_only = TRUE;
+ /* Check if the client is read only */
+ model = e_calendar_view_get_model (E_CALENDAR_VIEW (day_view));
+ ecal = e_cal_model_get_default_client (model);
+ if (!e_cal_is_read_only (ecal, &read_only, NULL) || read_only)
+ return FALSE;
+
+ icalcomp = e_cal_model_create_component_with_defaults (model);
+ if (!icalcomp)
+ return FALSE;
+
+ uid = icalcomponent_get_uid (icalcomp);
+
+ comp = e_cal_component_new ();
+ e_cal_component_set_icalcomponent (comp, icalcomp);
+
+ e_day_view_get_selected_time_range ((ECalendarView *) day_view, &dtstart, &dtend);
+
+ start_tt = icaltime_from_timet_with_zone (dtstart, FALSE,
+ e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
+
+ end_tt = icaltime_from_timet_with_zone (dtend, FALSE,
+ e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
+
+ if (day_view->selection_in_top_canvas) {
+ start_dt.tzid = NULL;
+ start_tt.is_date = 1;
+ end_tt.is_date = 1;
+
+ /* Editor default in day/work-week view - top canvas */
+ e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_TRANSPARENT);
+ } else {
+ start_dt.tzid = icaltimezone_get_tzid (e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
+
+ /* Editor default in day/work-week view - main canvas */
+ e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_OPAQUE);
+ }
+
+ start_dt.value = &start_tt;
+ end_dt.value = &end_tt;
+ end_dt.tzid = start_dt.tzid;
+ e_cal_component_set_dtstart (comp, &start_dt);
+ e_cal_component_set_dtend (comp, &end_dt);
+
+ e_cal_component_set_categories (
+ comp, e_calendar_view_get_default_category (E_CALENDAR_VIEW (day_view)));
+
+ /* We add the event locally and start editing it. We don't send it
+ to the server until the user finishes editing it. */
+ add_event_data.day_view = day_view;
+ add_event_data.comp_data = NULL;
+ e_day_view_add_event (comp, dtstart, dtend, &add_event_data);
+ e_day_view_check_layout (day_view);
+ gtk_widget_queue_draw (day_view->top_canvas);
+ gtk_widget_queue_draw (day_view->main_canvas);
+
+ if (!e_day_view_find_event_from_uid (day_view, ecal, uid, NULL, &day, &event_num)) {
+ g_warning ("Couldn't find event to start editing.\n");
+ g_object_unref (comp);
+ return FALSE;
+ }
+
+ e_day_view_start_editing_event (day_view, day, event_num, key_event);
+
+ g_object_unref (comp);
+ return TRUE;
+}
+
+static gboolean
+e_day_view_do_key_press (GtkWidget *widget, GdkEventKey *event)
+{
+ EDayView *day_view;
+ guint keyval;
+ gboolean stop_emission;
+
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (E_IS_DAY_VIEW (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
@@ -4862,12 +4935,6 @@ e_day_view_do_key_press (GtkWidget *widget, GdkEventKey *event)
return FALSE;
}
- /* Check if the client is read only */
- model = e_calendar_view_get_model (E_CALENDAR_VIEW (day_view));
- ecal = e_cal_model_get_default_client (model);
- if (!e_cal_is_read_only (ecal, &read_only, NULL) || read_only)
- return FALSE;
-
/* We only want to start an edit with a return key or a simple
character. */
if ((keyval != GDK_Return) &&
@@ -4878,64 +4945,7 @@ e_day_view_do_key_press (GtkWidget *widget, GdkEventKey *event)
return FALSE;
}
- /* Add a new event covering the selected range */
- icalcomp = e_cal_model_create_component_with_defaults (model);
- if (!icalcomp)
- return FALSE;
- uid = icalcomponent_get_uid (icalcomp);
-
- comp = e_cal_component_new ();
- e_cal_component_set_icalcomponent (comp, icalcomp);
-
- e_day_view_get_selected_time_range ((ECalendarView *) day_view, &dtstart, &dtend);
-
- start_tt = icaltime_from_timet_with_zone (dtstart, FALSE,
- e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
-
- end_tt = icaltime_from_timet_with_zone (dtend, FALSE,
- e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
-
- if (day_view->selection_in_top_canvas) {
- start_dt.tzid = NULL;
- start_tt.is_date = 1;
- end_tt.is_date = 1;
-
- /* Editor default in day/work-week view - top canvas */
- e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_TRANSPARENT);
- } else {
- start_dt.tzid = icaltimezone_get_tzid (e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
-
- /* Editor default in day/work-week view - main canvas */
- e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_OPAQUE);
- }
-
- start_dt.value = &start_tt;
- end_dt.value = &end_tt;
- end_dt.tzid = start_dt.tzid;
- e_cal_component_set_dtstart (comp, &start_dt);
- e_cal_component_set_dtend (comp, &end_dt);
-
- e_cal_component_set_categories (
- comp, e_calendar_view_get_default_category (E_CALENDAR_VIEW (day_view)));
-
- /* We add the event locally and start editing it. We don't send it
- to the server until the user finishes editing it. */
- add_event_data.day_view = day_view;
- add_event_data.comp_data = NULL;
- e_day_view_add_event (comp, dtstart, dtend, &add_event_data);
- e_day_view_check_layout (day_view);
- gtk_widget_queue_draw (day_view->top_canvas);
- gtk_widget_queue_draw (day_view->main_canvas);
-
- if (e_day_view_find_event_from_uid (day_view, ecal, uid, NULL, &day, &event_num)) {
- e_day_view_start_editing_event (day_view, day, event_num, event);
- } else {
- g_warning ("Couldn't find event to start editing.\n");
- }
-
- g_object_unref (comp);
-
- return TRUE;
+ return e_day_view_add_new_event_in_selected_range (day_view, event);
}
static gboolean
@@ -7839,3 +7849,34 @@ e_day_view_get_num_events_selected (EDayView *day_view)
return (day_view->editing_event_day != -1) ? 1 : 0;
}
+
+static void
+e_day_view_paste_text (ECalendarView *cal_view)
+{
+ EDayView *day_view;
+ EDayViewEvent *event;
+
+ g_return_if_fail (E_IS_DAY_VIEW (cal_view));
+
+ day_view = E_DAY_VIEW (cal_view);
+
+ if (day_view->editing_event_num == -1 &&
+ !e_day_view_add_new_event_in_selected_range (day_view, NULL))
+ return;
+
+ if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT) {
+ event = &g_array_index (day_view->long_events,
+ EDayViewEvent,
+ day_view->editing_event_num);
+ } else {
+ event = &g_array_index (day_view->events[day_view->editing_event_day],
+ EDayViewEvent,
+ day_view->editing_event_num);
+ }
+
+ if (event->canvas_item &&
+ E_IS_TEXT (event->canvas_item) &&
+ E_TEXT (event->canvas_item)->editing) {
+ e_text_paste_clipboard (E_TEXT (event->canvas_item));
+ }
+}
diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c
index 87bb60095f..e752f6d55e 100644
--- a/calendar/gui/e-week-view.c
+++ b/calendar/gui/e-week-view.c
@@ -114,6 +114,7 @@ static GList *e_week_view_get_selected_events (ECalendarView *cal_view);
static gboolean e_week_view_get_selected_time_range (ECalendarView *cal_view, time_t *start_time, time_t *end_time);
static void e_week_view_set_selected_time_range (ECalendarView *cal_view, time_t start_time, time_t end_time);
static gboolean e_week_view_get_visible_time_range (ECalendarView *cal_view, time_t *start_time, time_t *end_time);
+static void e_week_view_paste_text (ECalendarView *week_view);
static void e_week_view_update_query (EWeekView *week_view);
static void e_week_view_draw_shadow (EWeekView *week_view);
@@ -225,6 +226,7 @@ e_week_view_class_init (EWeekViewClass *class)
view_class->get_selected_time_range = e_week_view_get_selected_time_range;
view_class->set_selected_time_range = e_week_view_set_selected_time_range;
view_class->get_visible_time_range = e_week_view_get_visible_time_range;
+ view_class->paste_text = e_week_view_paste_text;
/* init the accessibility support for e_week_view */
e_week_view_a11y_init ();
@@ -3926,23 +3928,103 @@ e_week_view_cursor_key_right (EWeekView *week_view, GnomeCalendarViewType view_t
}
static gboolean
-e_week_view_do_key_press (GtkWidget *widget, GdkEventKey *event)
+e_week_view_add_new_event_in_selected_range (EWeekView *week_view, const gchar *initial_text)
{
- EWeekView *week_view;
ECal *ecal;
ECalModel *model;
ECalComponent *comp;
icalcomponent *icalcomp;
gint event_num;
- gchar *initial_text;
ECalComponentDateTime date;
struct icaltimetype itt;
time_t dtstart, dtend;
const char *uid;
AddEventData add_event_data;
- guint keyval;
gboolean read_only = TRUE;
+ EWeekViewEvent *wvevent;
+ EWeekViewEventSpan *span;
+
+ /* Check if the client is read only */
+ model = e_calendar_view_get_model (E_CALENDAR_VIEW (week_view));
+ ecal = e_cal_model_get_default_client (model);
+ if (!e_cal_is_read_only (ecal, &read_only, NULL) || read_only)
+ return FALSE;
+
+ /* Add a new event covering the selected range. */
+ icalcomp = e_cal_model_create_component_with_defaults (e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)));
+ if (!icalcomp)
+ return FALSE;
+ uid = icalcomponent_get_uid (icalcomp);
+
+ comp = e_cal_component_new ();
+ e_cal_component_set_icalcomponent (comp, icalcomp);
+
+ dtstart = week_view->day_starts[week_view->selection_start_day];
+ dtend = week_view->day_starts[week_view->selection_end_day + 1];
+
+ date.value = &itt;
+ date.tzid = NULL;
+
+ /* We use DATE values now, so we don't need the timezone. */
+ /*date.tzid = icaltimezone_get_tzid (e_calendar_view_get_timezone (E_CALENDAR_VIEW (week_view)));*/
+
+ *date.value = icaltime_from_timet_with_zone (dtstart, TRUE,
+ e_calendar_view_get_timezone (E_CALENDAR_VIEW (week_view)));
+ e_cal_component_set_dtstart (comp, &date);
+
+ *date.value = icaltime_from_timet_with_zone (dtend, TRUE,
+ e_calendar_view_get_timezone (E_CALENDAR_VIEW (week_view)));
+ e_cal_component_set_dtend (comp, &date);
+
+ /* Editor default in week/month view */
+ e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_TRANSPARENT);
+
+ e_cal_component_set_categories (
+ comp, e_calendar_view_get_default_category (E_CALENDAR_VIEW (week_view)));
+
+ /* We add the event locally and start editing it. We don't send it
+ to the server until the user finishes editing it. */
+ add_event_data.week_view = week_view;
+ add_event_data.comp_data = NULL;
+ e_week_view_add_event (comp, dtstart, dtend, TRUE, &add_event_data);
+ e_week_view_check_layout (week_view);
+ gtk_widget_queue_draw (week_view->main_canvas);
+
+ if (!e_week_view_find_event_from_uid (week_view, ecal, uid, NULL, &event_num)) {
+ g_warning ("Couldn't find event to start editing.\n");
+ g_object_unref (comp);
+ return FALSE;
+ }
+
+ wvevent = &g_array_index (week_view->events, EWeekViewEvent,
+ event_num);
+ span = &g_array_index (week_view->spans, EWeekViewEventSpan,
+ wvevent->spans_index + 0);
+
+ /* If the event can't be fit on the screen, don't try to edit it. */
+ if (!span->text_item) {
+ e_week_view_foreach_event_with_uid (week_view, uid,
+ e_week_view_remove_event_cb, NULL);
+ g_object_unref (comp);
+ return FALSE;
+ } else {
+ e_week_view_start_editing_event (week_view, event_num, 0,
+ (gchar *) initial_text);
+ }
+
+ g_object_unref (comp);
+
+ return TRUE;
+}
+
+static gboolean
+e_week_view_do_key_press (GtkWidget *widget, GdkEventKey *event)
+{
+ EWeekView *week_view;
+ gchar *initial_text;
+ guint keyval;
gboolean stop_emission;
+ gboolean ret_val;
GnomeCalendarViewType view_type;
g_return_val_if_fail (widget != NULL, FALSE);
@@ -4018,12 +4100,6 @@ e_week_view_do_key_press (GtkWidget *widget, GdkEventKey *event)
if (week_view->selection_start_day == -1)
return FALSE;
- /* Check if the client is read only */
- model = e_calendar_view_get_model (E_CALENDAR_VIEW (week_view));
- ecal = e_cal_model_get_default_client (model);
- if (!e_cal_is_read_only (ecal, &read_only, NULL) || read_only)
- return FALSE;
-
/* We only want to start an edit with a return key or a simple
character. */
if (event->keyval == GDK_Return) {
@@ -4036,74 +4112,12 @@ e_week_view_do_key_press (GtkWidget *widget, GdkEventKey *event)
} else
initial_text = e_utf8_from_gtk_event_key (widget, event->keyval, event->string);
- /* Add a new event covering the selected range. */
- icalcomp = e_cal_model_create_component_with_defaults (e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)));
- if (!icalcomp)
- return FALSE;
- uid = icalcomponent_get_uid (icalcomp);
-
- comp = e_cal_component_new ();
- e_cal_component_set_icalcomponent (comp, icalcomp);
-
- dtstart = week_view->day_starts[week_view->selection_start_day];
- dtend = week_view->day_starts[week_view->selection_end_day + 1];
-
- date.value = &itt;
- date.tzid = NULL;
-
- /* We use DATE values now, so we don't need the timezone. */
- /*date.tzid = icaltimezone_get_tzid (e_calendar_view_get_timezone (E_CALENDAR_VIEW (week_view)));*/
-
- *date.value = icaltime_from_timet_with_zone (dtstart, TRUE,
- e_calendar_view_get_timezone (E_CALENDAR_VIEW (week_view)));
- e_cal_component_set_dtstart (comp, &date);
-
- *date.value = icaltime_from_timet_with_zone (dtend, TRUE,
- e_calendar_view_get_timezone (E_CALENDAR_VIEW (week_view)));
- e_cal_component_set_dtend (comp, &date);
-
- /* Editor default in week/month view */
- e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_TRANSPARENT);
-
- e_cal_component_set_categories (
- comp, e_calendar_view_get_default_category (E_CALENDAR_VIEW (week_view)));
-
- /* We add the event locally and start editing it. We don't send it
- to the server until the user finishes editing it. */
- add_event_data.week_view = week_view;
- add_event_data.comp_data = NULL;
- e_week_view_add_event (comp, dtstart, dtend, TRUE, &add_event_data);
- e_week_view_check_layout (week_view);
- gtk_widget_queue_draw (week_view->main_canvas);
-
- if (e_week_view_find_event_from_uid (week_view, ecal, uid, NULL, &event_num)) {
- EWeekViewEvent *wvevent;
- EWeekViewEventSpan *span;
-
- wvevent = &g_array_index (week_view->events, EWeekViewEvent,
- event_num);
- span = &g_array_index (week_view->spans, EWeekViewEventSpan,
- wvevent->spans_index + 0);
-
- /* If the event can't be fit on the screen, don't try to edit it. */
- if (!span->text_item) {
- e_week_view_foreach_event_with_uid (week_view, uid,
- e_week_view_remove_event_cb, NULL);
- } else {
- e_week_view_start_editing_event (week_view, event_num, 0,
- initial_text);
- }
-
- } else {
- g_warning ("Couldn't find event to start editing.\n");
- }
+ ret_val = e_week_view_add_new_event_in_selected_range (week_view, initial_text);
if (initial_text)
g_free (initial_text);
- g_object_unref (comp);
-
- return TRUE;
+ return ret_val;
}
static gint
@@ -4359,3 +4373,30 @@ e_week_view_is_jump_button_visible (EWeekView *week_view, gint day)
return week_view->jump_buttons[day]->object.flags & GNOME_CANVAS_ITEM_VISIBLE;
return FALSE;
}
+
+static void
+e_week_view_paste_text (ECalendarView *cal_view)
+{
+ EWeekViewEvent *event;
+ EWeekViewEventSpan *span;
+ EWeekView *week_view;
+
+ g_return_if_fail (E_IS_WEEK_VIEW (cal_view));
+
+ week_view = E_WEEK_VIEW (cal_view);
+
+ if (week_view->editing_event_num == -1 &&
+ !e_week_view_add_new_event_in_selected_range (week_view, NULL))
+ return;
+
+ event = &g_array_index (week_view->events, EWeekViewEvent,
+ week_view->editing_event_num);
+ span = &g_array_index (week_view->spans, EWeekViewEventSpan,
+ event->spans_index + week_view->editing_span_num);
+
+ if (span->text_item &&
+ E_IS_TEXT (span->text_item) &&
+ E_TEXT (span->text_item)->editing) {
+ e_text_paste_clipboard (E_TEXT (span->text_item));
+ }
+}