gtk_text_buffer_end_user_action (buffer);
}
+static void
+cut_clipboard_check (GtkTextView *text_view,
+ gpointer userdata)
+{
+ GtkTextBuffer *buffer;
+
+ buffer = gtk_text_view_get_buffer (text_view);
+ if (!modest_text_utils_buffer_selection_is_valid (buffer)) {
+ g_signal_stop_emission_by_name ((gpointer )text_view, "cut-clipboard");
+ }
+}
+
+static void
+copy_clipboard_check (GtkTextView *text_view,
+ gpointer userdata)
+{
+ GtkTextBuffer *buffer;
+
+ buffer = gtk_text_view_get_buffer (text_view);
+ if (!modest_text_utils_buffer_selection_is_valid (buffer)) {
+ g_signal_stop_emission_by_name ((gpointer )text_view, "copy-clipboard");
+ }
+}
+
void vadj_changed (GtkAdjustment *adj,
ModestMsgEditWindow *window)
{
g_signal_connect (G_OBJECT (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD)), "owner-change",
G_CALLBACK (modest_msg_edit_window_clipboard_owner_change), obj);
+ g_signal_connect (G_OBJECT (priv->msg_body), "cut-clipboard", G_CALLBACK (cut_clipboard_check), NULL);
+ g_signal_connect (G_OBJECT (priv->msg_body), "copy-clipboard", G_CALLBACK (copy_clipboard_check), NULL);
+
}
static void
return g_strdup ("");
}
}
+
+static gboolean
+_forward_search_image_char (gunichar ch,
+ gpointer userdata)
+{
+ return (ch == 0xFFFC);
+}
+
+gboolean
+modest_text_utils_buffer_selection_is_valid (GtkTextBuffer *buffer)
+{
+ gboolean result;
+ GtkTextIter start, end;
+
+ g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
+
+ result = gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (buffer));
+
+ /* check there are no images in selection */
+ if (result) {
+ gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
+ if (gtk_text_iter_get_char (&start)== 0xFFFC)
+ result = FALSE;
+ else {
+ gtk_text_iter_backward_char (&end);
+ if (gtk_text_iter_forward_find_char (&start, _forward_search_image_char,
+ NULL, &end))
+ result = FALSE;
+ }
+
+ }
+
+ return result;
+}
gboolean modest_text_utils_is_forbidden_char (const gchar character,
ModestTextUtilsForbiddenCharType type);
+/**
+ * modest_text_utils_buffer_selection_is_valid:
+ * @buffer: a #GtkTextBuffer
+ *
+ * Checks if @buffer contains a valid selection for cut/copy. This means it's
+ * not empty, and no images are in the selection.
+ *
+ * Returns: %TRUE if there's a valid selection, false otherwise.
+ */
+gboolean modest_text_utils_buffer_selection_is_valid (GtkTextBuffer *buffer);
+
#endif /* __MODEST_TEXT_UTILS_H__ */
GtkTextBuffer *buffer;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
- gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
- gtk_clipboard_set_can_store (clipboard, NULL, 0);
- gtk_clipboard_store (clipboard);
+ if (modest_text_utils_buffer_selection_is_valid (buffer)) {
+ gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
+ gtk_clipboard_set_can_store (clipboard, NULL, 0);
+ gtk_clipboard_store (clipboard);
+ }
} else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
TnyList *header_list = modest_header_view_get_selected_headers (
MODEST_HEADER_VIEW (focused_widget));
} else if (GTK_IS_TEXT_VIEW (focused_widget)) {
GtkTextBuffer *buffer;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
- gtk_text_buffer_copy_clipboard (buffer, clipboard);
- gtk_clipboard_set_can_store (clipboard, NULL, 0);
- gtk_clipboard_store (clipboard);
+ if (modest_text_utils_buffer_selection_is_valid (buffer)) {
+ gtk_text_buffer_copy_clipboard (buffer, clipboard);
+ gtk_clipboard_set_can_store (clipboard, NULL, 0);
+ gtk_clipboard_store (clipboard);
+ }
} else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
TnyList *header_list = modest_header_view_get_selected_headers (
MODEST_HEADER_VIEW (focused_widget));
}
static gboolean
-_forward_search_image_char (gunichar ch,
- gpointer userdata)
-{
- return (ch == 0xFFFC);
-}
-
-static gboolean
_invalid_clipboard_selected (ModestWindow *win,
ModestDimmingRule *rule)
{
gboolean has_selection = FALSE;
if (GTK_IS_TEXT_VIEW (focused)) {
GtkTextBuffer *buffer = NULL;
- GtkTextIter start, end;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused));
- has_selection = gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (buffer));
-
- /* check there are no images in selection */
- if (has_selection) {
- gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer), &start, &end);
- if (gtk_text_iter_get_char (&start)== 0xFFFC)
- has_selection = FALSE;
- else {
- gtk_text_iter_backward_char (&end);
- if (gtk_text_iter_forward_find_char (&start, _forward_search_image_char,
- NULL, &end))
- has_selection = FALSE;
- }
-
- }
+ has_selection = modest_text_utils_buffer_selection_is_valid (buffer);
} else if (GTK_IS_EDITABLE (focused)) {
has_selection = gtk_editable_get_selection_bounds (GTK_EDITABLE (focused), NULL, NULL);
}