[evolution/webkit-composer: 16/147] Port Replace dialog and it's functionality



commit 531897561199876b637c2eaac42b1a9b4dd92e63
Author: Dan VrÃtil <dvratil redhat com>
Date:   Tue Jul 31 10:48:04 2012 +0200

    Port Replace dialog and it's functionality
    
    Create EEditorReplaceDialog class and move all the find&replace functionality
    in there. The dialog is constructed manually, instead of using Glade UI.
    
    Known issues:
     - WebKit does not draw text selection when it does not have focus,
       which means that we can't see which string we are replacing atm.
     - WebKit seems to eat all the shortcuts, therefore Ctl+F and Ctrl+G don't
       work.

 e-util/Makefile.am               |    2 +
 e-util/e-editor-actions.c        |  182 +--------------------
 e-util/e-editor-actions.h        |    4 -
 e-util/e-editor-builder.ui       |  234 --------------------------
 e-util/e-editor-private.h        |    2 +
 e-util/e-editor-replace-dialog.c |  339 ++++++++++++++++++++++++++++++++++++++
 e-util/e-editor-replace-dialog.h |   71 ++++++++
 e-util/e-editor-widgets.h        |   30 ----
 e-util/e-util.h                  |    1 +
 9 files changed, 422 insertions(+), 443 deletions(-)
---
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index a60d925..1df402a 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -173,6 +173,7 @@ eutilinclude_HEADERS =  \
 	e-dialog-widgets.h \
 	e-editor-actions.h \
 	e-editor-find-dialog.h \
+	e-editor-replace-dialog.h \
 	e-editor-selection.h \
 	e-editor-widget.h \
 	e-editor-widgets.h \
@@ -433,6 +434,7 @@ libeutil_la_SOURCES = \
 	e-editor-actions.c \
 	e-editor-find-dialog.c \
 	e-editor-private.h \
+	e-editor-replace-dialog.c \
 	e-editor-selection.c \
 	e-editor-widget.c \
 	e-editor.c \
diff --git a/e-util/e-editor-actions.c b/e-util/e-editor-actions.c
index 552f967..94e5702 100644
--- a/e-util/e-editor-actions.c
+++ b/e-util/e-editor-actions.c
@@ -106,16 +106,6 @@ insert_text_file_ready_cb (GFile *file,
 	g_object_unref (editor);
 }
 
-static void
-replace_answer (EEditor *editor,
-                EEditorWidgetReplaceAnswer answer)
-{
-	/* FIXME WEBKIT
-	if (e_editor_widget_replace (e_editor_get_editor_widget (editor), answer))
-		gtk_widget_hide (WIDGET (REPLACE_CONFIRMATION_WINDOW));
-	*/
-}
-
 /*****************************************************************************
  * Action Callbacks
  *****************************************************************************/
@@ -132,35 +122,6 @@ action_bold_cb (GtkToggleAction *action,
 		selection, gtk_toggle_action_get_active (action));
 }
 
-
-static void
-action_confirm_replace_cb (GtkAction *action,
-                           EEditor *editor)
-{
-	replace_answer (editor, E_EDITOR_WIDGET_REPLACE_ANSWER_REPLACE);
-}
-
-static void
-action_confirm_replace_all_cb (GtkAction *action,
-                               EEditor *editor)
-{
-	replace_answer (editor, E_EDITOR_WIDGET_REPLACE_ANSWER_REPLACE_ALL);
-}
-
-static void
-action_confirm_replace_cancel_cb (GtkAction *action,
-                                  EEditor *editor)
-{
-	replace_answer (editor, E_EDITOR_WIDGET_REPLACE_ANSWER_CANCEL);
-}
-
-static void
-action_confirm_replace_next_cb (GtkAction *action,
-                                EEditor *editor)
-{
-	replace_answer (editor, E_EDITOR_WIDGET_REPLACE_ANSWER_NEXT);
-}
-
 static WebKitDOMNode *
 find_parent_element_by_type (WebKitDOMNode *node, GType type)
 {
@@ -612,105 +573,6 @@ action_cut_cb (GtkAction *action,
 }
 
 static void
-action_find_and_replace_cb (GtkAction *action,
-                            EEditor *editor)
-{
-	WebKitDOMDocument *document;
-	WebKitDOMNode *start, *end;
-	WebKitDOMNodeList *children;
-	WebKitDOMDOMWindow *window;
-	WebKitDOMDOMSelection *selection;
-	WebKitDOMRange *range;
-	WebKitDOMNode *node;
-
-	gulong length, i;
-	const gchar *needle, *replacement;
-	gboolean case_sensitive, backwards, wrap, only_selection;
-
-	needle = gtk_entry_get_text (GTK_ENTRY (WIDGET (REPLACE_ENTRY)));
-	replacement = gtk_entry_get_text (
-				GTK_ENTRY (WIDGET (REPLACE_WITH_ENTRY)));
-	case_sensitive = gtk_toggle_button_get_active (
-				GTK_TOGGLE_BUTTON (WIDGET (REPLACE_CASE_SENSITIVE)));
-	wrap = gtk_toggle_button_get_active (
-				GTK_TOGGLE_BUTTON (WIDGET (REPLACE_WRAP)));
-	backwards = gtk_toggle_button_get_active (
-				GTK_TOGGLE_BUTTON (WIDGET (REPLACE_BACKWARDS)));
-	only_selection = gtk_toggle_button_get_active (
-				GTK_TOGGLE_BUTTON (WIDGET (REPLACE_ONLY_SELECTION)));
-
-	/* XXX Port this if to native WebKit API if they ever implement
-	 * support for find&replace...unless this implementation
-	 * is better ;) */
-
-	/* FIXME WEBKIT This is not working at all */
-	document = webkit_web_view_get_dom_document (
-			WEBKIT_WEB_VIEW (e_editor_get_editor_widget (editor)));
-	window = webkit_dom_document_get_default_view (document);
-	selection = webkit_dom_dom_window_get_selection (window);
-	if (webkit_dom_dom_selection_get_range_count (selection) < 1)
-		return;
-
-	range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
-	start = webkit_dom_range_get_start_container (range, NULL);
-
-	if (only_selection) {
-		end = webkit_dom_range_get_end_container (range, NULL);
-	} else {
-		end = NULL;
-	}
-
-	/* WEBKIT FIXME Implement me! */
-	/*
-	node = start;
-	while (node && (node != end)) {
-
-
-
-	}
-	*/
-
-	/*
-	html = gtkhtml_editor_get_html (editor);
-
-	gtk_widget_hide (WIDGET (REPLACE_WINDOW));
-
-	html_engine_replace (
-		html->engine,
-		gtk_entry_get_text (GTK_ENTRY (WIDGET (REPLACE_ENTRY))),
-		gtk_entry_get_text (GTK_ENTRY (WIDGET (REPLACE_WITH_ENTRY))),
-		gtk_toggle_button_get_active (
-			GTK_TOGGLE_BUTTON (WIDGET (REPLACE_CASE_SENSITIVE))),
-		!gtk_toggle_button_get_active (
-			GTK_TOGGLE_BUTTON (WIDGET (REPLACE_BACKWARDS))),
-		FALSE, replace_ask_cb, editor);
-	*/
-}
-
-/* FIXME WEBKIT
-static void
-replace_ask_cb (HTMLEngine *engine,
-                gpointer data)
-{
-	GtkhtmlEditor *editor = data;
-
-	gtk_window_present (GTK_WINDOW (WIDGET (REPLACE_CONFIRMATION_WINDOW)));
-}
-
-static void
-replace_answer (GtkhtmlEditor *editor,
-                HTMLReplaceQueryAnswer answer)
-{
-	GtkHTML *html;
-
-	html = gtkhtml_editor_get_html (editor);
-
-	if (html_engine_replace_do (html->engine, answer))
-		gtk_widget_hide (WIDGET (REPLACE_CONFIRMATION_WINDOW));
-}
-*/
-
-static void
 action_indent_cb (GtkAction *action,
                   EEditor *editor)
 {
@@ -1263,7 +1125,12 @@ static void
 action_show_replace_cb (GtkAction *action,
                         EEditor *editor)
 {
-	gtk_window_present (GTK_WINDOW (WIDGET (REPLACE_WINDOW)));
+	if (editor->priv->replace_dialog == NULL) {
+		editor->priv->replace_dialog =
+			e_editor_replace_dialog_new (editor);
+	}
+
+	gtk_window_present (GTK_WINDOW (editor->priv->replace_dialog));
 }
 
 static void
@@ -1379,34 +1246,6 @@ action_wrap_lines_cb (GtkAction *action,
 
 static GtkActionEntry core_entries[] = {
 
-	{ "confirm-replace",
-	  NULL,
-	  N_("_Replace"),
-	  NULL,
-	  NULL,
-	  G_CALLBACK (action_confirm_replace_cb) },
-
-	{ "confirm-replace-all",
-	  NULL,
-	  N_("Replace _All"),
-	  NULL,
-	  NULL,
-	  G_CALLBACK (action_confirm_replace_all_cb) },
-
-	{ "confirm-replace-cancel",
-	  GTK_STOCK_CLOSE,
-	  NULL,
-	  NULL,
-	  NULL,
-	  G_CALLBACK (action_confirm_replace_cancel_cb) },
-
-	{ "confirm-replace-next",
-	  NULL,
-	  N_("_Next"),
-	  NULL,
-	  NULL,
-	  G_CALLBACK (action_confirm_replace_next_cb) },
-
 	{ "copy",
 	  GTK_STOCK_COPY,
 	  N_("_Copy"),
@@ -1421,13 +1260,6 @@ static GtkActionEntry core_entries[] = {
 	  NULL,
 	  G_CALLBACK (action_cut_cb) },
 
-	{ "find-and-replace",
-	  GTK_STOCK_FIND_AND_REPLACE,
-	  NULL,
-	  NULL,
-	  NULL,
-	  G_CALLBACK (action_find_and_replace_cb) },
-
 	{ "indent",
 	  GTK_STOCK_INDENT,
 	  N_("_Increase Indent"),
@@ -2388,7 +2220,7 @@ editor_actions_init (EEditor *editor)
 		G_OBJECT (ACTION (SHOW_FIND)),
 		"short-label", _("_Find"), NULL);
 	g_object_set (
-		G_OBJECT (ACTION (FIND_AND_REPLACE)),
+		G_OBJECT (ACTION (SHOW_REPLACE)),
 		"short-label", _("Re_place"), NULL);
 	g_object_set (
 		G_OBJECT (ACTION (INSERT_IMAGE)),
diff --git a/e-util/e-editor-actions.h b/e-util/e-editor-actions.h
index 9f0616a..1fdab3b 100644
--- a/e-util/e-editor-actions.h
+++ b/e-util/e-editor-actions.h
@@ -80,12 +80,8 @@
 	E_EDITOR_ACTION ((editor), "cut")
 #define E_EDITOR_ACTION_EDIT_MENU(editor) \
 	E_EDITOR_ACTION ((editor), "edit-menu")
-#define E_EDITOR_ACTION_FIND(editor) \
-	E_EDITOR_ACTION ((editor), "find")
 #define E_EDITOR_ACTION_FIND_AGAIN(editor) \
 	E_EDITOR_ACTION ((editor), "find-again")
-#define E_EDITOR_ACTION_FIND_AND_REPLACE(editor) \
-	E_EDITOR_ACTION ((editor), "find-and-replace")
 #define E_EDITOR_ACTION_FORMAT_MENU(editor) \
 	E_EDITOR_ACTION ((editor), "format-menu")
 #define E_EDITOR_ACTION_FORMAT_TEXT(editor) \
diff --git a/e-util/e-editor-builder.ui b/e-util/e-editor-builder.ui
index 6552439..5414238 100644
--- a/e-util/e-editor-builder.ui
+++ b/e-util/e-editor-builder.ui
@@ -760,240 +760,6 @@
       </object>
     </child>
   </object>
-  <object class="GtkWindow" id="replace-window">
-    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-    <property name="title" translatable="yes">Replace</property>
-    <property name="resizable">False</property>
-    <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
-    <property name="destroy_with_parent">True</property>
-    <signal handler="gtk_widget_hide_on_delete" name="delete_event"/>
-    <signal handler="gtk_widget_grab_focus" name="show" object="replace-entry"/>
-    <child>
-      <object class="GtkVBox" id="replace-vbox">
-        <property name="visible">True</property>
-        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-        <property name="border_width">12</property>
-        <property name="spacing">12</property>
-        <child>
-          <object class="GtkTable" id="replace-table">
-            <property name="visible">True</property>
-            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-            <property name="n_rows">3</property>
-            <property name="n_columns">3</property>
-            <property name="column_spacing">6</property>
-            <property name="row_spacing">6</property>
-            <child>
-              <object class="GtkEntry" id="replace-with-entry">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-              </object>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="right_attach">3</property>
-                <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkEntry" id="replace-entry">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-              </object>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="right_attach">3</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel" id="replace-with-label">
-                <property name="visible">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="xalign">1</property>
-                <property name="label" translatable="yes">_With:</property>
-                <property name="use_underline">True</property>
-                <property name="mnemonic_widget">replace-with-entry</property>
-              </object>
-              <packing>
-                <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
-                <property name="x_options">GTK_FILL</property>
-                <property name="y_options"/>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel" id="replace-label">
-                <property name="visible">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="xalign">1</property>
-                <property name="label" translatable="yes">R_eplace:</property>
-                <property name="use_underline">True</property>
-                <property name="mnemonic_widget">replace-entry</property>
-              </object>
-              <packing>
-                <property name="x_options">GTK_FILL</property>
-                <property name="y_options"/>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkCheckButton" id="replace-backwards">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label" translatable="yes">Search _backwards</property>
-                <property name="use_underline">True</property>
-                <property name="draw_indicator">True</property>
-              </object>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="right_attach">2</property>
-                <property name="top_attach">2</property>
-                <property name="bottom_attach">3</property>
-                <property name="x_options"/>
-                <property name="y_options"/>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkCheckButton" id="replace-case-sensitive">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label" translatable="yes">Case _sensitive</property>
-                <property name="use_underline">True</property>
-                <property name="draw_indicator">True</property>
-              </object>
-              <packing>
-                <property name="left_attach">2</property>
-                <property name="right_attach">3</property>
-                <property name="top_attach">2</property>
-                <property name="bottom_attach">3</property>
-                <property name="y_options"/>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkAlignment" id="replace-alignment">
-                <property name="visible">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <child>
-                  <placeholder/>
-                </child>
-              </object>
-              <packing>
-                <property name="top_attach">2</property>
-                <property name="bottom_attach">3</property>
-                <property name="x_options"/>
-                <property name="y_options"/>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkHButtonBox" id="replace-button-box">
-            <property name="visible">True</property>
-            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-            <property name="spacing">12</property>
-            <property name="layout_style">GTK_BUTTONBOX_END</property>
-            <child>
-              <object class="GtkButton" id="replace-close-button">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label">gtk-close</property>
-                <property name="use_stock">True</property>
-                <signal handler="gtk_widget_hide" name="clicked" object="replace-window"/>
-              </object>
-            </child>
-            <child>
-              <object class="GtkButton" id="replace-button">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="has_default">True</property>
-                <property name="receives_default">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label">gtk-find-and-replace</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="pack_type">GTK_PACK_END</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-      </object>
-    </child>
-  </object>
-  <object class="GtkWindow" id="replace-confirmation-window">
-    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-    <property name="title" translatable="yes">Replace Confirmation</property>
-    <property name="resizable">False</property>
-    <property name="destroy_with_parent">True</property>
-    <property name="icon_name">gtk-find-and-replace</property>
-    <signal handler="gtkhtml_editor_replace_confirmation_delete_event_cb" name="delete_event"/>
-    <child>
-      <object class="GtkHButtonBox" id="replace-confirmation-button-box">
-        <property name="visible">True</property>
-        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-        <property name="border_width">12</property>
-        <property name="spacing">12</property>
-        <property name="homogeneous">True</property>
-        <child>
-          <object class="GtkButton" id="replace-confirmation-replace-all-button">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">True</property>
-            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkButton" id="replace-confirmation-next-button">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">True</property>
-            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-          </object>
-          <packing>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkButton" id="replace-confirmation-close-button">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">True</property>
-            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-            <property name="use_stock">True</property>
-          </object>
-          <packing>
-            <property name="position">2</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkButton" id="replace-confirmation-replace-button">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">True</property>
-            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-          </object>
-          <packing>
-            <property name="position">3</property>
-          </packing>
-        </child>
-      </object>
-    </child>
-  </object>
   <object class="GtkWindow" id="link-properties-window">
     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
     <property name="title" translatable="yes">Link Properties</property>
diff --git a/e-util/e-editor-private.h b/e-util/e-editor-private.h
index 1688dd3..cdb2379 100644
--- a/e-util/e-editor-private.h
+++ b/e-util/e-editor-private.h
@@ -25,6 +25,7 @@
 #include <e-editor-widgets.h>
 #include <e-editor-widget.h>
 #include <e-editor-find-dialog.h>
+#include <e-editor-replace-dialog.h>
 
 #ifdef HAVE_XFREE
 #include <X11/XF86keysym.h>
@@ -54,6 +55,7 @@ struct _EEditorPrivate {
 	GtkWidget *edit_area;
 
 	GtkWidget *find_dialog;
+	GtkWidget *replace_dialog;
 
 	GtkWidget *color_combo_box;
 	GtkWidget *mode_combo_box;
diff --git a/e-util/e-editor-replace-dialog.c b/e-util/e-editor-replace-dialog.c
new file mode 100644
index 0000000..150af90
--- /dev/null
+++ b/e-util/e-editor-replace-dialog.c
@@ -0,0 +1,339 @@
+/*
+ * e-editor-replace-dialog.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "e-editor-replace-dialog.h"
+
+#include <glib/gi18n-lib.h>
+
+G_DEFINE_TYPE (
+	EEditorReplaceDialog,
+	e_editor_replace_dialog,
+	GTK_TYPE_WINDOW);
+
+struct _EEditorReplaceDialogPrivate {
+	GtkWidget *search_entry;
+	GtkWidget *replace_entry;
+
+	GtkWidget *case_sensitive;
+	GtkWidget *backwards;
+	GtkWidget *wrap;
+
+	GtkWidget *result_label;
+
+	GtkWidget *close_button;
+	GtkWidget *skip_button;
+	GtkWidget *replace_button;
+	GtkWidget *replace_all_button;
+
+	EEditor *editor;
+};
+
+enum {
+	PROP_0,
+	PROP_EDITOR
+};
+
+static gboolean
+jump (EEditorReplaceDialog *dialog)
+{
+	WebKitWebView *webview;
+	gboolean found;
+
+	webview = WEBKIT_WEB_VIEW (
+			e_editor_get_editor_widget (dialog->priv->editor));
+
+	found = webkit_web_view_search_text (
+		webview,
+		gtk_entry_get_text (GTK_ENTRY (dialog->priv->search_entry)),
+		gtk_toggle_button_get_active (
+			GTK_TOGGLE_BUTTON (dialog->priv->case_sensitive)),
+		!gtk_toggle_button_get_active (
+			GTK_TOGGLE_BUTTON (dialog->priv->backwards)),
+		gtk_toggle_button_get_active (
+			GTK_TOGGLE_BUTTON (dialog->priv->wrap)));
+
+	return found;
+}
+
+static void
+editor_replace_dialog_skip_cb (EEditorReplaceDialog *dialog)
+{
+	if (!jump (dialog)) {
+		gtk_label_set_label (
+			GTK_LABEL (dialog->priv->result_label),
+			N_("No match found"));
+		gtk_widget_show (dialog->priv->result_label);
+	} else {
+		gtk_widget_hide (dialog->priv->result_label);
+	}
+}
+
+static void
+editor_replace_dialog_replace_cb (EEditorReplaceDialog *dialog)
+{
+	EEditorWidget *editor_widget;
+	EEditorSelection *selection;
+
+	/* Jump to next matching word */
+	if (!jump (dialog)) {
+		gtk_label_set_label (
+			GTK_LABEL (dialog->priv->result_label),
+			N_("No match found"));
+		gtk_widget_show (dialog->priv->result_label);
+		return;
+	} else {
+		gtk_widget_hide (dialog->priv->result_label);
+	}
+
+	editor_widget = e_editor_get_editor_widget (dialog->priv->editor);
+	selection = e_editor_widget_get_selection (editor_widget);
+
+	e_editor_selection_replace (
+		selection,
+		gtk_entry_get_text (GTK_ENTRY (dialog->priv->replace_entry)));
+}
+
+static void
+editor_replace_dialog_replace_all_cb (EEditorReplaceDialog *dialog)
+{
+	gint i = 0;
+	gchar *result;
+	EEditorWidget *widget;
+	EEditorSelection *selection;
+	const gchar *replacement;
+
+	widget = e_editor_get_editor_widget (dialog->priv->editor);
+	selection = e_editor_widget_get_selection (widget);
+	replacement = gtk_entry_get_text (GTK_ENTRY (dialog->priv->replace_entry));
+
+	while (jump (dialog)) {
+		e_editor_selection_replace (selection, replacement);
+		i++;
+	}
+
+	result = g_strdup_printf (_("%d occurences replaced"), i);
+	gtk_label_set_label (GTK_LABEL (dialog->priv->result_label), result);
+	gtk_widget_show (dialog->priv->result_label);
+	g_free (result);
+}
+
+static void
+editor_replace_dialog_close_cb (EEditorReplaceDialog *dialog)
+{
+	gtk_widget_hide (GTK_WIDGET (dialog));
+}
+
+static void
+editor_replace_dialog_entry_changed (EEditorReplaceDialog *dialog)
+{
+	gboolean ready;
+	ready = ((gtk_entry_get_text_length (
+			GTK_ENTRY (dialog->priv->search_entry)) != 0) &&
+		 (gtk_entry_get_text_length (
+			 GTK_ENTRY (dialog->priv->replace_entry)) != 0));
+
+	gtk_widget_set_sensitive (dialog->priv->skip_button, ready);
+	gtk_widget_set_sensitive (dialog->priv->replace_button, ready);
+	gtk_widget_set_sensitive (dialog->priv->replace_all_button, ready);
+}
+
+static void
+editor_replace_dialog_show (GtkWidget *widget)
+{
+	EEditorReplaceDialog *dialog = E_EDITOR_REPLACE_DIALOG (widget);
+
+	gtk_widget_grab_focus (dialog->priv->search_entry);
+	gtk_widget_hide (dialog->priv->result_label);
+
+	/* Chain up to parent implementation */
+	GTK_WIDGET_CLASS (e_editor_replace_dialog_parent_class)->show (widget);
+}
+
+static void
+editor_replace_dialog_set_property (GObject *object,
+				    guint property_id,
+				    const GValue *value,
+				    GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_EDITOR:
+			E_EDITOR_REPLACE_DIALOG (object)->priv->editor =
+				g_object_ref (g_value_get_object (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+editor_replace_dialog_finalize (GObject *object)
+{
+	EEditorReplaceDialogPrivate *priv = E_EDITOR_REPLACE_DIALOG (object)->priv;
+
+	g_clear_object (&priv->editor);
+
+	/* Chain up to parent implementation */
+	G_OBJECT_CLASS (e_editor_replace_dialog_parent_class)->finalize (object);
+}
+
+static void
+e_editor_replace_dialog_class_init (EEditorReplaceDialogClass *klass)
+{
+	GObjectClass *object_class;
+	GtkWidgetClass *widget_class;
+
+	e_editor_replace_dialog_parent_class = g_type_class_peek_parent (klass);
+	g_type_class_add_private (klass, sizeof (EEditorReplaceDialogPrivate));
+
+	widget_class = GTK_WIDGET_CLASS (klass);
+	widget_class->show = editor_replace_dialog_show;
+
+	object_class = G_OBJECT_CLASS (klass);
+	object_class->set_property = editor_replace_dialog_set_property;
+	object_class->finalize = editor_replace_dialog_finalize;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_EDITOR,
+		g_param_spec_object (
+			"editor",
+		        NULL,
+		        NULL,
+		        E_TYPE_EDITOR,
+		        G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+}
+
+static void
+e_editor_replace_dialog_init (EEditorReplaceDialog *dialog)
+{
+	GtkGrid *main_layout;
+	GtkWidget *widget, *layout;
+
+	dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (
+				dialog, E_TYPE_EDITOR_REPLACE_DIALOG,
+				EEditorReplaceDialogPrivate);
+
+	main_layout = GTK_GRID (gtk_grid_new ());
+	gtk_grid_set_row_spacing (main_layout, 10);
+	gtk_grid_set_column_spacing (main_layout, 10);
+	gtk_container_add (GTK_CONTAINER (dialog), GTK_WIDGET (main_layout));
+	gtk_container_set_border_width (GTK_CONTAINER (dialog), 10);
+
+	widget = gtk_entry_new ();
+	gtk_grid_attach (main_layout, widget, 1, 0, 2, 1);
+	dialog->priv->search_entry = widget;
+	g_signal_connect_swapped (
+		widget, "notify::text-length",
+		G_CALLBACK (editor_replace_dialog_entry_changed), dialog);
+
+	widget = gtk_label_new_with_mnemonic (_("R_eplace:"));
+	gtk_label_set_mnemonic_widget (GTK_LABEL (widget), dialog->priv->search_entry);
+	gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_RIGHT);
+	gtk_grid_attach (main_layout, widget, 0, 0, 1, 1);
+
+	widget = gtk_entry_new ();
+	gtk_grid_attach (main_layout, widget, 1, 1, 2, 1);
+	dialog->priv->replace_entry = widget;
+	g_signal_connect_swapped (
+		widget, "notify::text-length",
+		G_CALLBACK (editor_replace_dialog_entry_changed), dialog);
+
+	widget = gtk_label_new_with_mnemonic (_("_With:"));
+	gtk_label_set_mnemonic_widget (GTK_LABEL (widget), dialog->priv->replace_entry);
+	gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_RIGHT);
+	gtk_grid_attach (main_layout, widget, 0, 1, 1, 1);
+
+	layout = gtk_hbox_new (FALSE, 5);
+	gtk_grid_attach (main_layout, layout, 1, 2, 2, 1);
+
+	widget = gtk_check_button_new_with_mnemonic (_("Search _backwards"));
+	gtk_box_pack_start (GTK_BOX (layout), widget, FALSE, FALSE, 0);
+	dialog->priv->backwards = widget;
+
+	widget = gtk_check_button_new_with_mnemonic (_("_Case sensitive"));
+	gtk_box_pack_start (GTK_BOX (layout), widget, FALSE, FALSE, 0);
+	dialog->priv->case_sensitive = widget;
+
+	widget = gtk_check_button_new_with_mnemonic (_("Wra_p search"));
+	gtk_box_pack_start (GTK_BOX (layout), widget, FALSE, FALSE, 0);
+	dialog->priv->wrap = widget;
+
+	widget = gtk_label_new ("");
+	gtk_grid_attach (main_layout, widget, 0, 3, 2, 1);
+	dialog->priv->result_label = widget;
+
+	layout = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
+	gtk_box_set_spacing (GTK_BOX (layout), 5);
+	gtk_button_box_set_layout (GTK_BUTTON_BOX (layout), GTK_BUTTONBOX_START);
+	gtk_grid_attach (main_layout, layout, 2, 3, 1, 1);
+
+	widget = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
+	gtk_box_pack_start (GTK_BOX (layout), widget, FALSE, FALSE, 5);
+	dialog->priv->close_button = widget;
+	g_signal_connect_swapped (
+		widget, "clicked",
+		G_CALLBACK (editor_replace_dialog_close_cb), dialog);
+
+	widget = gtk_button_new_with_mnemonic (_("_Skip"));
+	gtk_box_pack_start (GTK_BOX (layout), widget, FALSE, FALSE, 5);
+	gtk_widget_set_sensitive (widget, FALSE);
+	dialog->priv->skip_button = widget;
+	g_signal_connect_swapped (
+		widget, "clicked",
+		G_CALLBACK (editor_replace_dialog_skip_cb), dialog);
+
+	widget = gtk_button_new_with_mnemonic (_("_Replace"));
+	gtk_box_pack_start (GTK_BOX (layout), widget, FALSE, FALSE, 5);
+	gtk_widget_set_sensitive (widget, FALSE);
+	dialog->priv->replace_button = widget;
+	g_signal_connect_swapped (
+		widget, "clicked",
+		G_CALLBACK (editor_replace_dialog_replace_cb), dialog);
+
+	widget = gtk_button_new_with_mnemonic (_("Replace _All"));
+	gtk_box_pack_start (GTK_BOX (layout), widget, FALSE, FALSE, 5);
+	gtk_widget_set_sensitive (widget, FALSE);
+	dialog->priv->replace_all_button = widget;
+	g_signal_connect_swapped (
+		widget, "clicked",
+		G_CALLBACK (editor_replace_dialog_replace_all_cb), dialog);
+
+	gtk_widget_show_all (GTK_WIDGET (main_layout));
+}
+
+GtkWidget *
+e_editor_replace_dialog_new (EEditor *editor)
+{
+	return GTK_WIDGET (
+		g_object_new (
+			E_TYPE_EDITOR_REPLACE_DIALOG,
+			"destroy-with-parent", TRUE,
+			"events", GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK,
+			"editor", editor,
+			"icon-name", GTK_STOCK_FIND_AND_REPLACE,
+			"resizable", FALSE,
+			"title", N_("Replace"),
+			"transient-for", gtk_widget_get_toplevel (GTK_WIDGET (editor)),
+			"type", GTK_WINDOW_TOPLEVEL,
+			"window-position", GTK_WIN_POS_CENTER_ON_PARENT,
+			NULL));
+}
diff --git a/e-util/e-editor-replace-dialog.h b/e-util/e-editor-replace-dialog.h
new file mode 100644
index 0000000..99132f5
--- /dev/null
+++ b/e-util/e-editor-replace-dialog.h
@@ -0,0 +1,71 @@
+/*
+ * e-editor-replace-dialog.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#if !defined (__E_UTIL_H_INSIDE__) && !defined (LIBEUTIL_COMPILATION)
+#error "Only <e-util/e-util.h> should be included directly."
+#endif
+
+#ifndef E_EDITOR_REPLACE_DIALOG_H
+#define E_EDITOR_REPLACE_DIALOG_H
+
+#include <gtk/gtk.h>
+#include <e-util/e-editor.h>
+
+/* Standard GObject macros */
+#define E_TYPE_EDITOR_REPLACE_DIALOG \
+	(e_editor_replace_dialog_get_type ())
+#define E_EDITOR_REPLACE_DIALOG(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), E_TYPE_EDITOR_REPLACE_DIALOG, EEditorReplaceDialog))
+#define E_EDITOR_REPLACE_DIALOG_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), E_TYPE_EDITOR_REPLACE_DIALOG, EEditorReplaceDialogClass))
+#define E_IS_EDITOR_REPLACE_DIALOG(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), E_TYPE_EDITOR_REPLACE_DIALOG))
+#define E_IS_EDITOR_REPLACE_DIALOG_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), E_TYPE_EDITOR_REPLACE_DIALOG))
+#define E_EDITOR_REPLACE_DIALOG_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), E_TYPE_EDITOR_REPLACE_DIALOG, EEditorReplaceDialogClass))
+
+G_BEGIN_DECLS
+
+typedef struct _EEditorReplaceDialog EEditorReplaceDialog;
+typedef struct _EEditorReplaceDialogClass EEditorReplaceDialogClass;
+typedef struct _EEditorReplaceDialogPrivate EEditorReplaceDialogPrivate;
+
+struct _EEditorReplaceDialog {
+	GtkWindow parent;
+
+	EEditorReplaceDialogPrivate *priv;
+};
+
+struct _EEditorReplaceDialogClass {
+	GtkWindowClass parent_class;
+};
+
+GType		e_editor_replace_dialog_get_type	(void);
+
+GtkWidget*	e_editor_replace_dialog_new		(EEditor *editor);
+
+G_END_DECLS
+
+#endif /* E_EDITOR_REPLACE_DIALOG_H */
+
diff --git a/e-util/e-editor-widgets.h b/e-util/e-editor-widgets.h
index fb8bb45..6c697cf 100644
--- a/e-util/e-editor-widgets.h
+++ b/e-util/e-editor-widgets.h
@@ -123,36 +123,6 @@
 #define E_EDITOR_WIDGETS_PARAGRAPH_PROPERTIES_WINDOW(editor) \
 	E_EDITOR_WIDGETS ((editor), "paragraph-properties-window")
 
-/* Replace Confirmation Window */
-#define E_EDITOR_WIDGETS_REPLACE_CONFIRMATION_CLOSE_BUTTON(editor) \
-	E_EDITOR_WIDGETS ((editor), "replace-confirmation-close-button")
-#define E_EDITOR_WIDGETS_REPLACE_CONFIRMATION_NEXT_BUTTON(editor) \
-	E_EDITOR_WIDGETS ((editor), "replace-confirmation-next-button")
-#define E_EDITOR_WIDGETS_REPLACE_CONFIRMATION_REPLACE_BUTTON(editor) \
-	E_EDITOR_WIDGETS ((editor), "replace-confirmation-replace-button")
-#define E_EDITOR_WIDGETS_REPLACE_CONFIRMATION_REPLACE_ALL_BUTTON(editor) \
-	E_EDITOR_WIDGETS ((editor), "replace-confirmation-replace-all-button")
-#define E_EDITOR_WIDGETS_REPLACE_CONFIRMATION_WINDOW(editor) \
-	E_EDITOR_WIDGETS ((editor), "replace-confirmation-window")
-
-/* Replace Window */
-#define E_EDITOR_WIDGETS_REPLACE_BACKWARDS(editor) \
-	E_EDITOR_WIDGETS ((editor), "replace-backwards")
-#define E_EDITOR_WIDGETS_REPLACE_BUTTON(editor) \
-	E_EDITOR_WIDGETS ((editor), "replace-button")
-#define E_EDITOR_WIDGETS_REPLACE_CASE_SENSITIVE(editor) \
-	E_EDITOR_WIDGETS ((editor), "replace-case-sensitive")
-#define E_EDITOR_WIDGETS_REPLACE_ENTRY(editor) \
-	E_EDITOR_WIDGETS ((editor), "replace-entry")
-#define E_EDITOR_WIDGETS_REPLACE_WITH_ENTRY(editor) \
-	E_EDITOR_WIDGETS ((editor), "replace-with-entry")
-#define E_EDITOR_WIDGETS_REPLACE_WINDOW(editor) \
-	E_EDITOR_WIDGETS ((editor), "replace-window")
-#define E_EDITOR_WIDGETS_REPLACE_WRAP(editor) \
-	E_EDITOR_WIDGETS ((editor), "replace-wrap")
-#define E_EDITOR_WIDGETS_REPLACE_ONLY_SELECTION(editor) \
-	E_EDITOR_WIDGETS ((editor), "replace-only-selection")
-
 /* Rule Properties Window */
 #define E_EDITOR_WIDGETS_RULE_PROPERTIES_ALIGNMENT_COMBO_BOX(editor) \
 	E_EDITOR_WIDGETS ((editor), "rule-properties-alignment-combo-box")
diff --git a/e-util/e-util.h b/e-util/e-util.h
index ecdd9bf..cdb5c40 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -92,6 +92,7 @@
 #include <e-util/e-dialog-widgets.h>
 #include <e-util/e-editor-actions.h>
 #include <e-util/e-editor-find-dialog.h>
+#include <e-util/e-editor-replace-dialog.h>
 #include <e-util/e-editor-selection.h>
 #include <e-util/e-editor-widget.h>
 #include <e-util/e-editor-widgets.h>



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