Index: calendar/gui/tasks-control.c
===================================================================
--- calendar/gui/tasks-control.c	(revision 37274)
+++ calendar/gui/tasks-control.c	(working copy)
@@ -43,6 +43,7 @@
 #include "evolution-shell-component-utils.h"
 #include "e-util/e-menu.h"
 #include "e-cal-menu.h"
+#include "e-cal-component-preview.h"
 #include "e-util/e-menu.h"
 #include "itip-utils.h"
 
@@ -96,11 +97,19 @@ static void tasks_control_view_preview	 
 						const char *state,
 						void *data);
 
+struct focus_changed_data {
+	BonoboControl *control;
+	ETasks *tasks;
+};
+
+static gboolean tasks_control_focus_changed (GtkWidget *widget, GdkEventFocus *event, struct focus_changed_data *fc_data);
+
 BonoboControl *
 tasks_control_new (void)
 {
 	BonoboControl *control;
-	GtkWidget *tasks;
+	GtkWidget *tasks, *preview;
+	struct focus_changed_data *fc_data;
 
 	tasks = e_tasks_new ();
 	if (!tasks)
@@ -116,6 +125,15 @@ tasks_control_new (void)
 
 	g_signal_connect (control, "activate", G_CALLBACK (tasks_control_activate_cb), tasks);
 
+	fc_data = g_new0 (struct focus_changed_data, 1);
+	fc_data->control = control;
+	fc_data->tasks = E_TASKS (tasks);
+
+	preview = e_cal_component_preview_get_html (E_CAL_COMPONENT_PREVIEW (e_tasks_get_preview (fc_data->tasks)));
+	g_object_set_data_full (G_OBJECT (preview), "tasks-ctrl-fc-data", fc_data, g_free);
+	g_signal_connect (preview, "focus-in-event", G_CALLBACK (tasks_control_focus_changed), fc_data);
+	g_signal_connect (preview, "focus-out-event", G_CALLBACK (tasks_control_focus_changed), fc_data);
+
 	return control;
 }
 
@@ -160,11 +178,13 @@ sensitize_items(BonoboUIComponent *uic, 
 	}
 }
 
+#define E_CAL_TASKS_PREVIEW_ACTIVE (1<<31)
+
 static struct _tasks_sensitize_item tasks_sensitize_table[] = {
 	{ "TasksOpenTask", E_CAL_MENU_SELECT_ONE },
-	{ "TasksCut", E_CAL_MENU_SELECT_ANY | E_CAL_MENU_SELECT_EDITABLE },
+	{ "TasksCut", E_CAL_MENU_SELECT_ANY | E_CAL_MENU_SELECT_EDITABLE | E_CAL_TASKS_PREVIEW_ACTIVE },
 	{ "TasksCopy", E_CAL_MENU_SELECT_ANY },
-	{ "TasksPaste", E_CAL_MENU_SELECT_EDITABLE },
+	{ "TasksPaste", E_CAL_MENU_SELECT_EDITABLE | E_CAL_TASKS_PREVIEW_ACTIVE },
 	{ "TasksDelete", E_CAL_MENU_SELECT_ANY | E_CAL_MENU_SELECT_EDITABLE },
 	{ "TasksMarkComplete", E_CAL_MENU_SELECT_ANY | E_CAL_MENU_SELECT_EDITABLE | E_CAL_MENU_SELECT_NOTCOMPLETE},
 	{ "TasksPurge",  E_CAL_MENU_SELECT_EDITABLE },
@@ -188,6 +208,7 @@ tasks_control_sensitize_commands (Bonobo
 	GPtrArray *events;
 	GSList *selected = NULL, *l = NULL;
 	ECalendarTable *cal_table;
+	GtkWidget *preview;
 
 	uic = bonobo_control_get_ui_component (control);
 	g_return_if_fail (uic != NULL);
@@ -214,6 +235,12 @@ tasks_control_sensitize_commands (Bonobo
 	if (ecal)
 		e_cal_is_read_only (ecal, &read_only, NULL);
 
+	preview = e_cal_component_preview_get_html (E_CAL_COMPONENT_PREVIEW (e_tasks_get_preview (tasks)));
+	if (preview && GTK_WIDGET_VISIBLE (preview) && GTK_WIDGET_HAS_FOCUS (preview))
+		t->target.mask = t->target.mask | E_CAL_TASKS_PREVIEW_ACTIVE;
+	else
+		t->target.mask = t->target.mask & (~E_CAL_TASKS_PREVIEW_ACTIVE);
+
 	sensitize_items (uic, tasks_sensitize_table, t->target.mask);
 	e_menu_update_target ((EMenu *)menu, (EMenuTarget *)t);
 }
@@ -229,6 +256,16 @@ selection_changed_cb (ETasks *tasks, int
 	tasks_control_sensitize_commands (control, tasks, n_selected);
 }
 
+static gboolean
+tasks_control_focus_changed (GtkWidget *widget, GdkEventFocus *event, struct focus_changed_data *fc_data)
+{
+	g_return_val_if_fail (fc_data != NULL, FALSE);
+
+	tasks_control_sensitize_commands (fc_data->control, fc_data->tasks, -1);
+
+	return FALSE;
+}
+
 static BonoboUIVerb verbs [] = {
 	BONOBO_UI_VERB ("TasksOpenTask", tasks_control_open_task_cmd),
 	BONOBO_UI_VERB ("TasksNewTask", tasks_control_new_task_cmd),
@@ -379,10 +416,19 @@ tasks_control_copy_cmd                  
 {
 	ETasks *tasks;
 	ECalendarTable *cal_table;
+	GtkWidget *preview;
 
 	tasks = E_TASKS (data);
-	cal_table = e_tasks_get_calendar_table (tasks);
-	e_calendar_table_copy_clipboard (cal_table);
+
+
+	preview = e_cal_component_preview_get_html (E_CAL_COMPONENT_PREVIEW (e_tasks_get_preview (tasks)));
+	if (preview && GTK_WIDGET_VISIBLE (preview) && GTK_WIDGET_HAS_FOCUS (preview)) {
+		/* copy selected text in a preview when that's shown and focused */
+		gtk_html_copy (GTK_HTML (preview));
+	} else {
+		cal_table = e_tasks_get_calendar_table (tasks);
+		e_calendar_table_copy_clipboard (cal_table);
+	}
 }
 
 static void
Index: calendar/gui/e-memos.c
===================================================================
--- calendar/gui/e-memos.c	(revision 37274)
+++ calendar/gui/e-memos.c	(working copy)
@@ -1222,3 +1222,18 @@ e_memos_get_calendar_table (EMemos *memo
 	priv = memos->priv;
 	return E_MEMO_TABLE (priv->memos_view);
 }
+
+/**
+ * e_memos_get_preview:
+ * @memos: A memos widget.
+ *
+ * Queries the #ECalComponentMemoPreview contained in a memos widget.
+ **/
+GtkWidget *
+e_memos_get_preview (EMemos *memos)
+{
+	g_return_val_if_fail (memos != NULL, NULL);
+	g_return_val_if_fail (E_IS_MEMOS (memos), NULL);
+
+	return memos->priv->preview;
+}
Index: calendar/gui/e-memos.h
===================================================================
--- calendar/gui/e-memos.h	(revision 37274)
+++ calendar/gui/e-memos.h	(working copy)
@@ -82,5 +82,6 @@ void e_memos_setup_view_menus (EMemos *m
 void e_memos_discard_view_menus (EMemos *memos);
 
 EMemoTable *e_memos_get_calendar_table (EMemos *memos);
+GtkWidget  *e_memos_get_preview (EMemos *memos);
 
 #endif /* _E_MEMOS_H_ */
Index: calendar/gui/e-tasks.c
===================================================================
--- calendar/gui/e-tasks.c	(revision 37274)
+++ calendar/gui/e-tasks.c	(working copy)
@@ -1563,3 +1563,18 @@ e_tasks_get_calendar_table (ETasks *task
 	priv = tasks->priv;
 	return E_CALENDAR_TABLE (priv->tasks_view);
 }
+
+/**
+ * e_tasks_get_preview:
+ * @tasks: A tasks widget.
+ *
+ * Queries the #ECalComponentPreview contained in a tasks widget.
+ **/
+GtkWidget *
+e_tasks_get_preview (ETasks *tasks)
+{
+	g_return_val_if_fail (tasks != NULL, NULL);
+	g_return_val_if_fail (E_IS_TASKS (tasks), NULL);
+
+	return tasks->priv->preview;
+}
Index: calendar/gui/e-tasks.h
===================================================================
--- calendar/gui/e-tasks.h	(revision 37274)
+++ calendar/gui/e-tasks.h	(working copy)
@@ -87,5 +87,6 @@ void e_tasks_discard_view_menus (ETasks 
 
 struct _ECalMenu *e_tasks_get_tasks_menu (ETasks *tasks);
 ECalendarTable *e_tasks_get_calendar_table (ETasks *tasks);
+GtkWidget *e_tasks_get_preview (ETasks *tasks);
 
 #endif /* _E_TASKS_H_ */
Index: calendar/gui/memos-control.c
===================================================================
--- calendar/gui/memos-control.c	(revision 37274)
+++ calendar/gui/memos-control.c	(working copy)
@@ -35,12 +35,14 @@
 #include <e-util/e-icon-factory.h>
 #include <e-util/e-print.h>
 #include <e-util/e-util-private.h>
+#include <gtkhtml/gtkhtml.h>
 
 #include "calendar-config.h"
 #include "e-memos.h"
 #include "e-memo-table.h"
 #include "print.h"
 #include "memos-control.h"
+#include "e-cal-component-memo-preview.h"
 #include "evolution-shell-component-utils.h"
 
 #define FIXED_MARGIN                            .05
@@ -74,13 +76,19 @@ static void memos_control_print_preview_
 						 gpointer		 data,
 						 const char		*path);
 
+struct focus_changed_data {
+	BonoboControl *control;
+	EMemos *memos;
+};
 
+static gboolean memos_control_focus_changed (GtkWidget *widget, GdkEventFocus *event, struct focus_changed_data *fc_data);
 
 BonoboControl *
 memos_control_new (void)
 {
 	BonoboControl *control;
-	GtkWidget *memos;
+	GtkWidget *memos, *preview;
+	struct focus_changed_data *fc_data;
 
 	memos = e_memos_new ();
 	if (!memos)
@@ -96,6 +104,15 @@ memos_control_new (void)
 
 	g_signal_connect (control, "activate", G_CALLBACK (memos_control_activate_cb), memos);
 
+	fc_data = g_new0 (struct focus_changed_data, 1);
+	fc_data->control = control;
+	fc_data->memos = E_MEMOS (memos);
+
+	preview = e_cal_component_memo_preview_get_html (E_CAL_COMPONENT_MEMO_PREVIEW (e_memos_get_preview (fc_data->memos)));
+	g_object_set_data_full (G_OBJECT (preview), "memos-ctrl-fc-data", fc_data, g_free);
+	g_signal_connect (preview, "focus-in-event", G_CALLBACK (memos_control_focus_changed), fc_data);
+	g_signal_connect (preview, "focus-out-event", G_CALLBACK (memos_control_focus_changed), fc_data);
+
 	return control;
 }
 
@@ -122,9 +139,10 @@ void
 memos_control_sensitize_commands (BonoboControl *control, EMemos *memos, int n_selected)
 {
 	BonoboUIComponent *uic;
-	gboolean read_only = TRUE;
+	gboolean read_only = TRUE, preview_active;
 	ECal *ecal;
 	ECalModel *model;
+	GtkWidget *preview;
 
 	uic = bonobo_control_get_ui_component (control);
 	g_return_if_fail (uic != NULL);
@@ -132,6 +150,9 @@ memos_control_sensitize_commands (Bonobo
 	if (bonobo_ui_component_get_container (uic) == CORBA_OBJECT_NIL)
 		return;
 
+	preview = e_cal_component_memo_preview_get_html (E_CAL_COMPONENT_MEMO_PREVIEW (e_memos_get_preview (memos)));
+	preview_active = preview && GTK_WIDGET_VISIBLE (preview) && GTK_WIDGET_HAS_FOCUS (preview);
+
 	model = e_memo_table_get_model (e_memos_get_calendar_table (memos));
 	ecal = e_cal_model_get_default_client (model);
 	if (ecal)
@@ -141,13 +162,13 @@ memos_control_sensitize_commands (Bonobo
 				      n_selected != 1 ? "0" : "1",
 				      NULL);
 	bonobo_ui_component_set_prop (uic, "/commands/MemosCut", "sensitive",
-				      n_selected == 0 || read_only ? "0" : "1",
+				      n_selected == 0 || read_only || preview_active ? "0" : "1",
 				      NULL);
 	bonobo_ui_component_set_prop (uic, "/commands/MemosCopy", "sensitive",
 				      n_selected == 0 ? "0" : "1",
 				      NULL);
 	bonobo_ui_component_set_prop (uic, "/commands/MemosPaste", "sensitive",
-				      read_only ? "0" : "1",
+				      read_only || preview_active ? "0" : "1",
 				      NULL);
 	bonobo_ui_component_set_prop (uic, "/commands/MemosDelete", "sensitive",
 				      n_selected == 0 || read_only ? "0" : "1",
@@ -165,6 +186,16 @@ selection_changed_cb (EMemos *memos, int
 	memos_control_sensitize_commands (control, memos, n_selected);
 }
 
+static gboolean
+memos_control_focus_changed (GtkWidget *widget, GdkEventFocus *event, struct focus_changed_data *fc_data)
+{
+	g_return_val_if_fail (fc_data != NULL, FALSE);
+
+	memos_control_sensitize_commands (fc_data->control, fc_data->memos, e_table_selected_count (e_memo_table_get_table (e_memos_get_calendar_table (fc_data->memos))));
+
+	return FALSE;
+}
+
 static BonoboUIVerb verbs [] = {
 	BONOBO_UI_VERB ("MemosOpenMemo", memos_control_open_memo_cmd),
 	BONOBO_UI_VERB ("MemosNewMemo", memos_control_new_memo_cmd),
@@ -304,10 +335,18 @@ memos_control_copy_cmd                  
 {
 	EMemos *memos;
 	EMemoTable *cal_table;
+	GtkWidget *preview;
 
 	memos = E_MEMOS (data);
-	cal_table = e_memos_get_calendar_table (memos);
-	e_memo_table_copy_clipboard (cal_table);
+
+	preview = e_cal_component_memo_preview_get_html (E_CAL_COMPONENT_MEMO_PREVIEW (e_memos_get_preview (memos)));
+	if (preview && GTK_WIDGET_VISIBLE (preview) && GTK_WIDGET_HAS_FOCUS (preview)) {
+		/* copy selected text in a preview when that's shown and focused */
+		gtk_html_copy (GTK_HTML (preview));
+	} else {
+		cal_table = e_memos_get_calendar_table (memos);
+		e_memo_table_copy_clipboard (cal_table);
+	}
 }
 
 static void
Index: calendar/gui/e-cal-component-preview.c
===================================================================
--- calendar/gui/e-cal-component-preview.c	(revision 37274)
+++ calendar/gui/e-cal-component-preview.c	(working copy)
@@ -449,3 +449,11 @@ e_cal_component_preview_clear (ECalCompo
 	gtk_html_load_empty (GTK_HTML (priv->html));
 }
 
+GtkWidget *
+e_cal_component_preview_get_html (ECalComponentPreview *preview)
+{
+	g_return_val_if_fail (preview != NULL, NULL);
+	g_return_val_if_fail (E_IS_CAL_COMPONENT_PREVIEW (preview), NULL);
+
+	return preview->priv->html;
+}
Index: calendar/gui/e-cal-component-preview.h
===================================================================
--- calendar/gui/e-cal-component-preview.h	(revision 37274)
+++ calendar/gui/e-cal-component-preview.h	(working copy)
@@ -68,5 +68,6 @@ void e_cal_component_preview_clear      
 /* Callback used when GtkHTML widget requests URL */
 void e_cal_comp_preview_url_requested_cb (GtkHTML *html, const char *url, GtkHTMLStream *html_stream, gpointer data);
 
+GtkWidget *e_cal_component_preview_get_html (ECalComponentPreview *preview);
 
 #endif /* _E_CAL_COMPONENT_PREVIEW_H_ */
Index: calendar/gui/e-cal-component-memo-preview.c
===================================================================
--- calendar/gui/e-cal-component-memo-preview.c	(revision 37274)
+++ calendar/gui/e-cal-component-memo-preview.c	(working copy)
@@ -358,3 +358,11 @@ e_cal_component_memo_preview_clear (ECal
 	gtk_html_load_empty (GTK_HTML (priv->html));
 }
 
+GtkWidget *
+e_cal_component_memo_preview_get_html (ECalComponentMemoPreview *preview)
+{
+	g_return_val_if_fail (preview != NULL, NULL);
+	g_return_val_if_fail (E_IS_CAL_COMPONENT_MEMO_PREVIEW (preview), NULL);
+
+	return preview->priv->html;
+}
Index: calendar/gui/e-cal-component-memo-preview.h
===================================================================
--- calendar/gui/e-cal-component-memo-preview.h	(revision 37274)
+++ calendar/gui/e-cal-component-memo-preview.h	(working copy)
@@ -62,5 +62,6 @@ void e_cal_component_memo_preview_set_de
 
 void e_cal_component_memo_preview_display             (ECalComponentMemoPreview *preview, ECal *ecal, ECalComponent *comp);
 void e_cal_component_memo_preview_clear             (ECalComponentMemoPreview *preview);
+GtkWidget *e_cal_component_memo_preview_get_html (ECalComponentMemoPreview *preview);
 
 #endif /* _E_CAL_COMPONENT_MEMO_PREVIEW_H_ */
Index: calendar/ChangeLog
===================================================================
--- calendar/ChangeLog	(revision 37274)
+++ calendar/ChangeLog	(working copy)
@@ -1,3 +1,24 @@
+2009-02-16  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #523802
+
+	* gui/e-tasks.h: (e_tasks_get_preview):
+	* gui/e-tasks.c: (e_tasks_get_preview):
+	* gui/e-cal-component-preview.h: (e_cal_component_preview_get_html):
+	* gui/e-cal-component-preview.c: (e_cal_component_preview_get_html):
+	* gui/tasks-control.c: (tasks_control_new), (tasks_sensitize_table[]),
+	(tasks_control_sensitize_commands), (tasks_control_focus_changed),
+	(tasks_control_copy_cmd):
+	* gui/e-memos.h: (e_memos_get_preview):
+	* gui/e-memos.c: (e_memos_get_preview):
+	* gui/e-cal-component-memo-preview.h:
+	* gui/e-cal-component-memo-preview.c:
+	(e_cal_component_memo_preview_get_html):
+	* gui/memos-control.c: (memos_control_new),
+	(memos_control_sensitize_commands), (memos_control_focus_changed),
+	(memos_control_copy_cmd):
+	Use copy of the preview panel, when focused, and events' copy otherwise.
+
 2009-02-13  Chow Loong Jin <hyperair@gmail.com>
 
 	** Fixes bug #571625
