[evolution/449-support-markdown-in-composer] EHTMLEditor: Update content editor in find/replace dialogs on show/hide



commit 047cdaee2340282da7676b0b88a9399296228e81
Author: Milan Crha <mcrha redhat com>
Date:   Fri Feb 11 08:32:20 2022 +0100

    EHTMLEditor: Update content editor in find/replace dialogs on show/hide

 src/e-util/e-html-editor-find-dialog.c    | 77 ++++++++++++++++---------------
 src/e-util/e-html-editor-replace-dialog.c | 60 +++++++++++++-----------
 2 files changed, 73 insertions(+), 64 deletions(-)
---
diff --git a/src/e-util/e-html-editor-find-dialog.c b/src/e-util/e-html-editor-find-dialog.c
index fe063ccc70..f38e3883c4 100644
--- a/src/e-util/e-html-editor-find-dialog.c
+++ b/src/e-util/e-html-editor-find-dialog.c
@@ -56,13 +56,39 @@ reset_dialog (EHTMLEditorFindDialog *dialog)
        gtk_widget_hide (dialog->priv->result_label);
 }
 
+static void
+content_editor_find_done_cb (EContentEditor *cnt_editor,
+                            guint match_count,
+                            EHTMLEditorFindDialog *dialog)
+{
+       if (match_count) {
+               gtk_widget_hide (dialog->priv->result_label);
+       } else {
+               gtk_label_set_label (GTK_LABEL (dialog->priv->result_label), _("No match found"));
+               gtk_widget_show (dialog->priv->result_label);
+       }
+
+       gtk_widget_set_sensitive (dialog->priv->find_button, match_count > 0);
+}
+
 static void
 html_editor_find_dialog_hide (GtkWidget *widget)
 {
        EHTMLEditorFindDialog *dialog = E_HTML_EDITOR_FIND_DIALOG (widget);
 
+       g_warn_if_fail (dialog->priv->cnt_editor != NULL);
+
        e_content_editor_on_dialog_close (dialog->priv->cnt_editor, E_CONTENT_EDITOR_DIALOG_FIND);
 
+       if (dialog->priv->find_done_handler_id > 0) {
+               g_signal_handler_disconnect (
+                       dialog->priv->cnt_editor,
+                       dialog->priv->find_done_handler_id);
+               dialog->priv->find_done_handler_id = 0;
+       }
+
+       dialog->priv->cnt_editor = NULL;
+
        /* Chain up to parent's implementation */
        GTK_WIDGET_CLASS (e_html_editor_find_dialog_parent_class)->hide (widget);
 }
@@ -71,6 +97,19 @@ static void
 html_editor_find_dialog_show (GtkWidget *widget)
 {
        EHTMLEditorFindDialog *dialog = E_HTML_EDITOR_FIND_DIALOG (widget);
+       EHTMLEditor *editor;
+       EContentEditor *cnt_editor;
+
+       g_warn_if_fail (dialog->priv->cnt_editor == NULL);
+
+       editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
+       cnt_editor = e_html_editor_get_content_editor (editor);
+
+       dialog->priv->find_done_handler_id = g_signal_connect (
+               cnt_editor, "find-done",
+               G_CALLBACK (content_editor_find_done_cb), dialog);
+
+       dialog->priv->cnt_editor = cnt_editor;
 
        reset_dialog (dialog);
        gtk_widget_grab_focus (dialog->priv->entry);
@@ -81,21 +120,6 @@ html_editor_find_dialog_show (GtkWidget *widget)
        GTK_WIDGET_CLASS (e_html_editor_find_dialog_parent_class)->show (widget);
 }
 
-static void
-content_editor_find_done_cb (EContentEditor *cnt_editor,
-                            guint match_count,
-                            EHTMLEditorFindDialog *dialog)
-{
-       if (match_count) {
-               gtk_widget_hide (dialog->priv->result_label);
-       } else {
-               gtk_label_set_label (GTK_LABEL (dialog->priv->result_label), _("No match found"));
-               gtk_widget_show (dialog->priv->result_label);
-       }
-
-       gtk_widget_set_sensitive (dialog->priv->find_button, match_count > 0);
-}
-
 static void
 html_editor_find_dialog_find_cb (EHTMLEditorFindDialog *dialog)
 {
@@ -151,28 +175,6 @@ html_editor_find_dialog_dispose (GObject *object)
        G_OBJECT_CLASS (e_html_editor_find_dialog_parent_class)->dispose (object);
 }
 
-static void
-html_editor_find_dialog_constructed (GObject *object)
-{
-       EHTMLEditor *editor;
-       EHTMLEditorFindDialog *dialog;
-       EContentEditor *cnt_editor;
-
-       dialog = E_HTML_EDITOR_FIND_DIALOG (object);
-       dialog->priv = E_HTML_EDITOR_FIND_DIALOG_GET_PRIVATE (dialog);
-
-       editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
-       cnt_editor = e_html_editor_get_content_editor (editor);
-
-       dialog->priv->find_done_handler_id = g_signal_connect (
-               cnt_editor, "find-done",
-               G_CALLBACK (content_editor_find_done_cb), dialog);
-
-       dialog->priv->cnt_editor = cnt_editor;
-
-       G_OBJECT_CLASS (e_html_editor_find_dialog_parent_class)->constructed (object);
-}
-
 static void
 e_html_editor_find_dialog_class_init (EHTMLEditorFindDialogClass *class)
 {
@@ -182,7 +184,6 @@ e_html_editor_find_dialog_class_init (EHTMLEditorFindDialogClass *class)
        g_type_class_add_private (class, sizeof (EHTMLEditorFindDialogPrivate));
 
        object_class = G_OBJECT_CLASS (class);
-       object_class->constructed = html_editor_find_dialog_constructed;
        object_class->dispose = html_editor_find_dialog_dispose;
 
        widget_class = GTK_WIDGET_CLASS (class);
diff --git a/src/e-util/e-html-editor-replace-dialog.c b/src/e-util/e-html-editor-replace-dialog.c
index e33e7dfcbc..55f1af62ac 100644
--- a/src/e-util/e-html-editor-replace-dialog.c
+++ b/src/e-util/e-html-editor-replace-dialog.c
@@ -168,6 +168,23 @@ static void
 html_editor_replace_dialog_show (GtkWidget *widget)
 {
        EHTMLEditorReplaceDialog *dialog = E_HTML_EDITOR_REPLACE_DIALOG (widget);
+       EHTMLEditor *editor;
+       EContentEditor *cnt_editor;
+
+       g_warn_if_fail (dialog->priv->cnt_editor == NULL);
+
+       editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
+       cnt_editor = e_html_editor_get_content_editor (editor);
+
+       dialog->priv->find_done_handler_id = g_signal_connect (
+               cnt_editor, "find-done",
+               G_CALLBACK (content_editor_find_done_cb), dialog);
+
+       dialog->priv->replace_all_done_handler_id = g_signal_connect (
+               cnt_editor, "replace-all-done",
+               G_CALLBACK (content_editor_replace_all_done_cb), dialog);
+
+       dialog->priv->cnt_editor = cnt_editor;
 
        e_content_editor_on_dialog_open (dialog->priv->cnt_editor, E_CONTENT_EDITOR_DIALOG_REPLACE);
 
@@ -183,36 +200,28 @@ html_editor_replace_dialog_hide (GtkWidget *widget)
 {
        EHTMLEditorReplaceDialog *dialog = E_HTML_EDITOR_REPLACE_DIALOG (widget);
 
-       e_content_editor_on_dialog_close (dialog->priv->cnt_editor, E_CONTENT_EDITOR_DIALOG_REPLACE);
-
-       /* Chain up to parent implementation */
-       GTK_WIDGET_CLASS (e_html_editor_replace_dialog_parent_class)->hide (widget);
-}
-
-static void
-html_editor_replace_dialog_constructed (GObject *object)
-{
-       EContentEditor *cnt_editor;
-       EHTMLEditor *editor;
-       EHTMLEditorReplaceDialog *dialog;
-
-       dialog = E_HTML_EDITOR_REPLACE_DIALOG (object);
-       dialog->priv = E_HTML_EDITOR_REPLACE_DIALOG_GET_PRIVATE (dialog);
+       g_warn_if_fail (dialog->priv->cnt_editor != NULL);
 
-       editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
-       cnt_editor = e_html_editor_get_content_editor (editor);
+       e_content_editor_on_dialog_close (dialog->priv->cnt_editor, E_CONTENT_EDITOR_DIALOG_REPLACE);
 
-       dialog->priv->find_done_handler_id = g_signal_connect (
-               cnt_editor, "find-done",
-               G_CALLBACK (content_editor_find_done_cb), dialog);
+       if (dialog->priv->find_done_handler_id > 0) {
+               g_signal_handler_disconnect (
+                       dialog->priv->cnt_editor,
+                       dialog->priv->find_done_handler_id);
+               dialog->priv->find_done_handler_id = 0;
+       }
 
-       dialog->priv->replace_all_done_handler_id = g_signal_connect (
-               cnt_editor, "replace-all-done",
-               G_CALLBACK (content_editor_replace_all_done_cb), dialog);
+       if (dialog->priv->replace_all_done_handler_id > 0) {
+               g_signal_handler_disconnect (
+                       dialog->priv->cnt_editor,
+                       dialog->priv->replace_all_done_handler_id);
+               dialog->priv->replace_all_done_handler_id = 0;
+       }
 
-       dialog->priv->cnt_editor = cnt_editor;
+       dialog->priv->cnt_editor = NULL;
 
-       G_OBJECT_CLASS (e_html_editor_replace_dialog_parent_class)->constructed (object);
+       /* Chain up to parent implementation */
+       GTK_WIDGET_CLASS (e_html_editor_replace_dialog_parent_class)->hide (widget);
 }
 
 static void
@@ -249,7 +258,6 @@ e_html_editor_replace_dialog_class_init (EHTMLEditorReplaceDialogClass *class)
        g_type_class_add_private (class, sizeof (EHTMLEditorReplaceDialogPrivate));
 
        object_class = G_OBJECT_CLASS (class);
-       object_class->constructed = html_editor_replace_dialog_constructed;
        object_class->dispose = html_editor_replace_dialog_dispose;
 
        widget_class = GTK_WIDGET_CLASS (class);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]