+
+void
+modest_msg_edit_window_toggle_find_toolbar (ModestMsgEditWindow *window,
+ gboolean show)
+{
+ ModestMsgEditWindowPrivate *priv = NULL;
+
+ g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+ gtk_widget_set_no_show_all (priv->find_toolbar, FALSE);
+ if (show) {
+ gtk_widget_show_all (priv->find_toolbar);
+ hildon_find_toolbar_highlight_entry (HILDON_FIND_TOOLBAR (priv->find_toolbar), TRUE);
+ } else {
+ gtk_widget_hide_all (priv->find_toolbar);
+ gtk_widget_grab_focus (priv->msg_body);
+ }
+
+}
+
+static void
+modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
+ ModestMsgEditWindow *window)
+{
+ gchar *current_search = NULL;
+ ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+ gboolean result;
+ GtkTextIter selection_start, selection_end;
+ GtkTextIter match_start, match_end;
+
+ g_object_get (G_OBJECT (widget), "prefix", ¤t_search, NULL);
+ if ((current_search == NULL) && (strcmp (current_search, "") == 0)) {
+ g_free (current_search);
+ return;
+ }
+
+ gtk_text_buffer_get_selection_bounds (priv->text_buffer, &selection_start, &selection_end);
+ result = gtk_text_iter_forward_search (&selection_end, current_search, GTK_TEXT_SEARCH_VISIBLE_ONLY, &match_start, &match_end, NULL);
+ if (!result) {
+ GtkTextIter buffer_start;
+ gtk_text_buffer_get_start_iter (priv->text_buffer, &buffer_start);
+ result = gtk_text_iter_forward_search (&buffer_start, current_search, GTK_TEXT_SEARCH_VISIBLE_ONLY, &match_start, &match_end, &selection_start);
+ }
+ if (result) {
+ gtk_text_buffer_select_range (priv->text_buffer, &match_start, &match_end);
+ gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (priv->msg_body), &match_start, 0.0, TRUE, 0.0, 0.0);
+ } else {
+ /* TODO: warning about non succesful search */
+ }
+ g_free (current_search);
+}
+
+static void
+modest_msg_edit_window_find_toolbar_close (GtkWidget *widget,
+ ModestMsgEditWindow *window)
+{
+ GtkToggleAction *toggle;
+ ModestWindowPrivate *parent_priv;
+ parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+
+ toggle = GTK_TOGGLE_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ToolsMenu/FindInMessageMenu"));
+ gtk_toggle_action_set_active (toggle, FALSE);
+}
+
+
+static void
+update_paste_dimming (ModestMsgEditWindow *window)
+{
+ ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+ GtkAction *action = NULL;
+ GtkClipboard *clipboard = NULL;
+ GtkWidget *focused;
+ gboolean active;
+
+ focused = gtk_window_get_focus (GTK_WINDOW (window));
+
+ clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+ active = gtk_clipboard_wait_is_text_available (clipboard);
+
+ if (active) {
+ if (MODEST_IS_ATTACHMENTS_VIEW (focused))
+ active = FALSE;
+ }
+
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/PasteMenu");
+ gtk_action_set_sensitive (action, active);
+
+}
+
+static void
+paste_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor)
+{
+ GtkWidget *focused = gtk_window_get_focus (GTK_WINDOW (editor));
+
+ if (MODEST_IS_ATTACHMENTS_VIEW (focused))
+ hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_unable_to_paste_here"));
+ else
+ hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ecoc_ib_edwin_nothing_to_paste"));
+
+}
+
+
+static void
+modest_msg_edit_window_system_clipboard_owner_change (GtkClipboard *clipboard,
+ GdkEvent *event,
+ ModestMsgEditWindow *window)
+{
+ update_paste_dimming (window);
+}
+
+static void
+update_select_all_dimming (ModestMsgEditWindow *window)
+{
+ GtkWidget *focused;
+ gboolean dimmed = FALSE;
+ GtkAction *action;
+ ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+
+ focused = gtk_window_get_focus (GTK_WINDOW (window));
+ if (GTK_IS_ENTRY (focused)) {
+ const gchar *current_text;
+ current_text = gtk_entry_get_text (GTK_ENTRY (focused));
+ dimmed = ((current_text == NULL) || (current_text[0] == '\0'));
+ } else if (GTK_IS_TEXT_VIEW (focused)) {
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused));
+ dimmed = (gtk_text_buffer_get_char_count (buffer) < 1);
+ } else if (MODEST_IS_ATTACHMENTS_VIEW (focused)) {
+ dimmed = FALSE;
+ }
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/SelectAllMenu");
+ gtk_action_set_sensitive (action, !dimmed);
+}
+
+static void
+update_zoom_dimming (ModestMsgEditWindow *window)
+{
+ GtkWidget *focused;
+ gboolean dimmed = FALSE;
+ GtkAction *action;
+ ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+
+ focused = gtk_window_get_focus (GTK_WINDOW (window));
+ dimmed = ! WP_IS_TEXT_VIEW (focused);
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ZoomMenu");
+ gtk_action_set_sensitive (action, !dimmed);
+}
+
+static void
+edit_menu_activated (GtkAction *action,
+ gpointer userdata)
+{
+ ModestMsgEditWindow *window = MODEST_MSG_EDIT_WINDOW (userdata);
+
+ update_select_all_dimming (window);
+}
+static void
+view_menu_activated (GtkAction *action,
+ gpointer userdata)
+{
+ ModestMsgEditWindow *window = MODEST_MSG_EDIT_WINDOW (userdata);
+
+ update_zoom_dimming (window);
+}
+
+gboolean
+modest_msg_edit_window_get_sent (ModestMsgEditWindow *window)
+{
+ ModestMsgEditWindowPrivate *priv;
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(window);
+ return priv->sent;
+}
+
+void
+modest_msg_edit_window_set_sent (ModestMsgEditWindow *window,
+ gboolean sent)
+{
+ ModestMsgEditWindowPrivate *priv;
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(window);
+ priv->sent = sent;
+}