[evolution/webkit-composer: 16/111] Port Find dialog and search functionality



commit 6d865edb9b500f96923b89c3500331aac50c205e
Author: Dan VrÃtil <dvratil redhat com>
Date:   Mon Jul 30 22:05:47 2012 +0200

    Port Find dialog and search functionality
    
    Create EEditorFindDialog class and move all the search 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 the match until the dialog is closed
     - WebKit seems to eat all the shortcuts, therefor Ctrl+F or Ctrl+G don't
       work atm.

 e-util/Makefile.am            |    2 +
 e-util/e-editor-actions.c     |   81 ++++--------
 e-util/e-editor-actions.h     |    2 +
 e-util/e-editor-builder.ui    |  150 ----------------------
 e-util/e-editor-find-dialog.c |  282 +++++++++++++++++++++++++++++++++++++++++
 e-util/e-editor-find-dialog.h |   73 +++++++++++
 e-util/e-editor-private.h     |    3 +
 e-util/e-editor-widgets.h     |   18 ---
 e-util/e-util.h               |    1 +
 9 files changed, 389 insertions(+), 223 deletions(-)
---
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index c5452ff..a60d925 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -172,6 +172,7 @@ eutilinclude_HEADERS =  \
 	e-dialog-utils.h \
 	e-dialog-widgets.h \
 	e-editor-actions.h \
+	e-editor-find-dialog.h \
 	e-editor-selection.h \
 	e-editor-widget.h \
 	e-editor-widgets.h \
@@ -430,6 +431,7 @@ libeutil_la_SOURCES = \
 	e-dialog-utils.c \
 	e-dialog-widgets.c \
 	e-editor-actions.c \
+	e-editor-find-dialog.c \
 	e-editor-private.h \
 	e-editor-selection.c \
 	e-editor-widget.c \
diff --git a/e-util/e-editor-actions.c b/e-util/e-editor-actions.c
index a492953..552f967 100644
--- a/e-util/e-editor-actions.c
+++ b/e-util/e-editor-actions.c
@@ -612,44 +612,6 @@ action_cut_cb (GtkAction *action,
 }
 
 static void
-action_find_cb (GtkAction *action,
-                EEditor *editor)
-{
-	gboolean found;
-
-
-	found = webkit_web_view_search_text (
-		WEBKIT_WEB_VIEW (e_editor_get_editor_widget (editor)),
-		gtk_entry_get_text (GTK_ENTRY (WIDGET (FIND_ENTRY))),
-		gtk_toggle_button_get_active (
-			GTK_TOGGLE_BUTTON (WIDGET (FIND_CASE_SENSITIVE))),
-		!gtk_toggle_button_get_active (
-			GTK_TOGGLE_BUTTON (WIDGET (FIND_BACKWARDS))),
-		gtk_toggle_button_get_active (
-			GTK_TOGGLE_BUTTON (WIDGET (FIND_WRAP))));
-
-	gtk_action_set_sensitive (ACTION (FIND), found);
-
-	if (!found)
-		gtk_label_set_label (
-			GTK_LABEL (WIDGET (FIND_RESULT_LABEL)),
-			N_("No match found"));
-}
-
-static void
-action_find_again_cb (GtkAction *action,
-                      EEditor *editor)
-{
-	/* FIXME WEBKIT
-	 * Verify that this actually works and if so, then just change the
-	 * callback and remove this function. If not, then we are in trouble...
-	 */
-
-	action_find_cb (action, editor);
-}
-
-
-static void
 action_find_and_replace_cb (GtkAction *action,
                             EEditor *editor)
 {
@@ -1277,9 +1239,24 @@ static void
 action_show_find_cb (GtkAction *action,
                      EEditor *editor)
 {
-	gtk_widget_set_sensitive (WIDGET (FIND_BUTTON), TRUE);
+	if (editor->priv->find_dialog == NULL) {
+		editor->priv->find_dialog = e_editor_find_dialog_new (editor);
+		gtk_action_set_sensitive (ACTION (FIND_AGAIN), TRUE);
+	}
+
+	gtk_window_present (GTK_WINDOW (editor->priv->find_dialog));
+}
+
+static void
+action_find_again_cb (GtkAction *action,
+                      EEditor *editor)
+{
+	if (editor->priv->find_dialog == NULL) {
+		return;
+	}
 
-	gtk_window_present (GTK_WINDOW (WIDGET (FIND_WINDOW)));
+	e_editor_find_dialog_find_next (
+		E_EDITOR_FIND_DIALOG (editor->priv->find_dialog));
 }
 
 static void
@@ -1444,20 +1421,6 @@ static GtkActionEntry core_entries[] = {
 	  NULL,
 	  G_CALLBACK (action_cut_cb) },
 
-	{ "find",
-	  GTK_STOCK_FIND,
-	  NULL,
-	  NULL,
-	  NULL,
-	  G_CALLBACK (action_find_cb) },
-
-	{ "find-again",
-	  NULL,
-	  N_("Find A_gain"),
-	  "<Control>g",
-	  NULL,
-	  G_CALLBACK (action_find_again_cb) },
-
 	{ "find-and-replace",
 	  GTK_STOCK_FIND_AND_REPLACE,
 	  NULL,
@@ -1521,6 +1484,13 @@ static GtkActionEntry core_entries[] = {
 	  NULL,
 	  G_CALLBACK (action_show_find_cb) },
 
+	{ "find-again",
+	  NULL,
+	  N_("Find A_gain"),
+	  "<Control>g",
+	  NULL,
+	  G_CALLBACK (action_find_again_cb) },
+
 	{ "show-replace",
 	  GTK_STOCK_FIND_AND_REPLACE,
 	  N_("Re_place..."),
@@ -2415,7 +2385,7 @@ editor_actions_init (EEditor *editor)
 	/* Fine Tuning */
 
 	g_object_set (
-		G_OBJECT (ACTION (FIND)),
+		G_OBJECT (ACTION (SHOW_FIND)),
 		"short-label", _("_Find"), NULL);
 	g_object_set (
 		G_OBJECT (ACTION (FIND_AND_REPLACE)),
@@ -2435,6 +2405,7 @@ editor_actions_init (EEditor *editor)
 		"short-label", _("_Table"), NULL);
 
 	gtk_action_set_sensitive (ACTION (UNINDENT), FALSE);
+	gtk_action_set_sensitive (ACTION (FIND_AGAIN), FALSE);
 
 	editor_widget = e_editor_get_editor_widget (editor);
 	g_object_bind_property (
diff --git a/e-util/e-editor-actions.h b/e-util/e-editor-actions.h
index 488451b..9f0616a 100644
--- a/e-util/e-editor-actions.h
+++ b/e-util/e-editor-actions.h
@@ -82,6 +82,8 @@
 	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) \
diff --git a/e-util/e-editor-builder.ui b/e-util/e-editor-builder.ui
index f4c6ae2..6552439 100644
--- a/e-util/e-editor-builder.ui
+++ b/e-util/e-editor-builder.ui
@@ -760,156 +760,6 @@
       </object>
     </child>
   </object>
-  <object class="GtkWindow" id="find-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">Find</property>
-    <property name="resizable">False</property>
-    <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
-    <property name="destroy_with_parent">True</property>
-    <property name="icon_name">gtk-find</property>
-    <signal handler="gtk_widget_hide_on_delete" name="delete_event"/>
-    <signal handler="gtk_widget_grab_focus" name="show" object="find-entry"/>
-    <child>
-      <object class="GtkVBox" id="find-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="GtkVBox" id="find-inner-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="spacing">6</property>
-            <child>
-              <object class="GtkEntry" id="find-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>
-                <property name="activates_default">True</property>
-                <signal handler="gtkhtml_editor_find_entry_changed_cb" name="changed" object="find-window"/>
-                <signal handler="gtkhtml_editor_find_entry_activate_cb" name="activate" object="find-window"/>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkHBox" id="find-hbox">
-                <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">6</property>
-                <child>
-                  <object class="GtkCheckButton" id="find-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>
-                    <signal handler="gtkhtml_editor_find_backwards_toggled_cb" name="toggled" object="find-window"/>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkCheckButton" id="find-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>
-                    <signal handler="gtkhtml_editor_find_case_sensitive_toggled_cb" name="toggled" object="find-window"/>
-                  </object>
-                  <packing>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkCheckButton" id="find-regular-expression">
-                    <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">_Regular expression</property>
-                    <property name="use_underline">True</property>
-                    <property name="draw_indicator">True</property>
-                    <signal handler="gtkhtml_editor_find_regular_expression_toggled_cb" name="toggled" object="find-window"/>
-                  </object>
-                  <packing>
-                    <property name="position">2</property>
-                  </packing>
-                </child>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkHBox" id="find-inner-hbox">
-            <property name="visible">True</property>
-            <child>
-              <object class="GtkLabel" id="find-result-label">
-                <property name="visible">True</property>
-                <property name="label"></property>
-                <property name="xalign">0</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkHButtonBox" id="find-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="find-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="find-window"/>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkButton" id="find-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</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>
-          <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
-          </packing>
-        </child>
-      </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>
diff --git a/e-util/e-editor-find-dialog.c b/e-util/e-editor-find-dialog.c
new file mode 100644
index 0000000..f3ef249
--- /dev/null
+++ b/e-util/e-editor-find-dialog.c
@@ -0,0 +1,282 @@
+/*
+ * e-editor-find-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-find-dialog.h"
+
+#include <glib/gi18n-lib.h>
+#include <gdk/gdkkeysyms.h>
+
+G_DEFINE_TYPE (
+	EEditorFindDialog,
+	e_editor_find_dialog,
+	GTK_TYPE_WINDOW);
+
+struct _EEditorFindDialogPrivate {
+	GtkWidget *entry;
+	GtkWidget *backwards;
+	GtkWidget *case_sensitive;
+	GtkWidget *wrap_search;
+
+	GtkWidget *find_button;
+	GtkWidget *cancel_button;
+
+	GtkWidget *result_label;
+
+	EEditor *editor;
+};
+
+enum {
+	PROP_0,
+	PROP_EDITOR
+};
+
+static void
+reset_dialog (EEditorFindDialog *dialog)
+{
+	gtk_widget_set_sensitive (dialog->priv->find_button, TRUE);
+	gtk_widget_hide (dialog->priv->result_label);
+}
+
+static void
+editor_find_dialog_show (GtkWidget *widget)
+{
+	EEditorFindDialog *dialog = E_EDITOR_FIND_DIALOG (widget);
+
+	reset_dialog (dialog);
+	gtk_widget_grab_focus (dialog->priv->entry);
+
+	/* Chain up to parent's implementation */
+	GTK_WIDGET_CLASS (e_editor_find_dialog_parent_class)->show (widget);
+}
+
+static void
+editor_find_dialog_close_cb (EEditorFindDialog *dialog)
+{
+	gtk_widget_hide (GTK_WIDGET (dialog));
+}
+
+static void
+editor_find_dialog_find_cb (EEditorFindDialog *dialog)
+{
+	gboolean found;
+	EEditorWidget *editor_widget;
+
+	editor_widget = e_editor_get_editor_widget (dialog->priv->editor);
+	found = webkit_web_view_search_text (
+			WEBKIT_WEB_VIEW (editor_widget),
+			gtk_entry_get_text (
+				GTK_ENTRY (dialog->priv->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_search)));
+
+	gtk_widget_set_sensitive (dialog->priv->find_button, found);
+
+	if (!found) {
+		gtk_label_set_label (
+			GTK_LABEL (dialog->priv->result_label),
+			N_("No match found"));
+		gtk_widget_show (dialog->priv->result_label);
+	}
+}
+
+static gboolean
+entry_key_release_event (GtkWidget *widget,
+			 GdkEvent *event,
+			 gpointer user_data)
+{
+	GdkEventKey *key = &event->key;
+	EEditorFindDialog *dialog = user_data;
+
+	if (key->keyval == GDK_KEY_Return) {
+		editor_find_dialog_find_cb (dialog);
+		return TRUE;
+	}
+
+	reset_dialog (dialog);
+	return FALSE;
+}
+
+static void
+editor_find_dialog_set_property (GObject *object,
+				 guint property_id,
+				 const GValue *value,
+				 GParamSpec *pspec)
+{
+	EEditorFindDialog *dialog = E_EDITOR_FIND_DIALOG (object);
+
+	switch (property_id) {
+		case PROP_EDITOR:
+			dialog->priv->editor =
+				g_object_ref (g_value_get_object (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+editor_find_dialog_finalize (GObject *object)
+{
+	EEditorFindDialogPrivate *priv = E_EDITOR_FIND_DIALOG (object)->priv;
+
+	g_clear_object (&priv->editor);
+
+	/* Chain up to parent's finalize */
+	G_OBJECT_CLASS (e_editor_find_dialog_parent_class)->finalize (object);
+}
+
+static void
+e_editor_find_dialog_class_init (EEditorFindDialogClass *klass)
+{
+	GObjectClass *object_class;
+	GtkWidgetClass *widget_class;
+
+	e_editor_find_dialog_parent_class = g_type_class_peek_parent (klass);
+	g_type_class_add_private (klass, sizeof (EEditorFindDialogPrivate));
+
+	widget_class = GTK_WIDGET_CLASS (klass);
+	widget_class->show = editor_find_dialog_show;
+
+	object_class = G_OBJECT_CLASS (klass);
+	object_class->set_property = editor_find_dialog_set_property;
+	object_class->finalize = editor_find_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_find_dialog_init (EEditorFindDialog *dialog)
+{
+	GtkBox *main_layout, *box;
+	GtkWidget *widget;
+
+	dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (
+		dialog, E_TYPE_EDITOR_FIND_DIALOG, EEditorFindDialogPrivate);
+
+	main_layout = GTK_BOX (gtk_vbox_new (FALSE, 5));
+	gtk_container_add (GTK_CONTAINER (dialog), GTK_WIDGET (main_layout));
+	gtk_container_set_border_width (GTK_CONTAINER (dialog), 10);
+
+	widget = gtk_entry_new ();
+	gtk_box_pack_start (main_layout, widget, TRUE, TRUE, 5);
+	dialog->priv->entry = widget;
+	g_signal_connect (
+		widget, "key-release-event",
+		G_CALLBACK (entry_key_release_event), dialog);
+
+	box = GTK_BOX (gtk_hbox_new (FALSE, 5));
+	gtk_box_pack_start (main_layout, GTK_WIDGET (box), TRUE, TRUE, 0);
+
+	widget = gtk_check_button_new_with_mnemonic (N_("Search _backwards"));
+	gtk_box_pack_start (box, widget, FALSE, FALSE, 0);
+	dialog->priv->backwards = widget;
+	g_signal_connect_swapped (
+		widget, "toggled",
+		G_CALLBACK (reset_dialog), dialog);
+
+	widget = gtk_check_button_new_with_mnemonic (N_("Case _Sensitive"));
+	gtk_box_pack_start (box, widget, FALSE, FALSE, 0);
+	dialog->priv->case_sensitive = widget;
+	g_signal_connect_swapped (
+		widget, "toggled",
+		G_CALLBACK (reset_dialog), dialog);
+
+	widget = gtk_check_button_new_with_mnemonic (N_("_Wrap Search"));
+	gtk_box_pack_start (box, widget, FALSE, FALSE, 0);
+	dialog->priv->wrap_search = widget;
+	g_signal_connect_swapped (
+		widget, "toggled",
+		G_CALLBACK (reset_dialog), dialog);
+
+	box = GTK_BOX (gtk_hbox_new (FALSE, 5));
+	gtk_box_pack_start (main_layout, GTK_WIDGET (box), TRUE, TRUE, 0);
+
+	widget = gtk_label_new ("");
+	gtk_box_pack_start (box, widget, FALSE, FALSE, 0);
+	dialog->priv->result_label = widget;
+
+	widget = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
+	gtk_box_set_spacing (GTK_BOX (widget), 5);
+	gtk_button_box_set_layout (GTK_BUTTON_BOX (widget), GTK_BUTTONBOX_END);
+	gtk_box_pack_end (box, widget, TRUE, TRUE, 0);
+	box = GTK_BOX (widget);
+
+	widget = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
+	gtk_box_pack_start (box, widget, FALSE, FALSE, 5);
+	g_signal_connect_swapped (
+		widget, "clicked",
+		G_CALLBACK (editor_find_dialog_close_cb), dialog);
+	dialog->priv->cancel_button = widget;
+
+	widget = gtk_button_new_from_stock (GTK_STOCK_FIND);
+	gtk_box_pack_start (box, widget, FALSE, FALSE, 5);
+	g_signal_connect_swapped (
+		widget, "clicked",
+		G_CALLBACK (editor_find_dialog_find_cb), dialog);
+	dialog->priv->find_button = widget;
+
+	gtk_widget_show_all (GTK_WIDGET (main_layout));
+}
+
+GtkWidget *
+e_editor_find_dialog_new(EEditor *editor)
+{
+	return GTK_WIDGET (
+		g_object_new (
+			E_TYPE_EDITOR_FIND_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,
+			"resizable", FALSE,
+			"title", N_("Find"),
+			"transient-for", gtk_widget_get_toplevel (GTK_WIDGET (editor)),
+			"type", GTK_WINDOW_TOPLEVEL,
+			"type-hint", GDK_WINDOW_TYPE_HINT_POPUP_MENU,
+			"window-position", GTK_WIN_POS_CENTER_ON_PARENT,
+			NULL));
+}
+
+void
+e_editor_find_dialog_find_next (EEditorFindDialog *dialog)
+{
+	if (gtk_entry_get_text_length (GTK_ENTRY (dialog->priv->entry)) == 0) {
+		return;
+	}
+
+	editor_find_dialog_find_cb (dialog);
+}
diff --git a/e-util/e-editor-find-dialog.h b/e-util/e-editor-find-dialog.h
new file mode 100644
index 0000000..43e2d9e
--- /dev/null
+++ b/e-util/e-editor-find-dialog.h
@@ -0,0 +1,73 @@
+/*
+ * e-editor-find-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_FIND_DIALOG_H
+#define E_EDITOR_FIND_DIALOG_H
+
+#include <gtk/gtk.h>
+#include <e-util/e-editor.h>
+
+/* Standard GObject macros */
+#define E_TYPE_EDITOR_FIND_DIALOG \
+	(e_editor_find_dialog_get_type ())
+#define E_EDITOR_FIND_DIALOG(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), E_TYPE_EDITOR_FIND_DIALOG, EEditorFindDialog))
+#define E_EDITOR_FIND_DIALOG_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), E_TYPE_EDITOR_FIND_DIALOG, EEditorFindDialogClass))
+#define E_IS_EDITOR_FIND_DIALOG(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), E_TYPE_EDITOR_FIND_DIALOG))
+#define E_IS_EDITOR_FIND_DIALOG_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), E_TYPE_EDITOR_FIND_DIALOG))
+#define E_EDITOR_FIND_DIALOG_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), E_TYPE_EDITOR_FIND_DIALOG, EEditorFindDialogClass))
+
+G_BEGIN_DECLS
+
+typedef struct _EEditorFindDialog EEditorFindDialog;
+typedef struct _EEditorFindDialogClass EEditorFindDialogClass;
+typedef struct _EEditorFindDialogPrivate EEditorFindDialogPrivate;
+
+struct _EEditorFindDialog {
+	GtkWindow parent;
+
+	EEditorFindDialogPrivate *priv;
+};
+
+struct _EEditorFindDialogClass {
+	GtkWindowClass parent_class;
+};
+
+GType		e_editor_find_dialog_get_type	(void);
+
+GtkWidget*	e_editor_find_dialog_new	(EEditor *editor);
+
+void		e_editor_find_dialog_find_next	(EEditorFindDialog *dialog);
+
+G_END_DECLS
+
+#endif /* E_EDITOR_FIND_DIALOG_H */
+
diff --git a/e-util/e-editor-private.h b/e-util/e-editor-private.h
index 31451f0..1688dd3 100644
--- a/e-util/e-editor-private.h
+++ b/e-util/e-editor-private.h
@@ -24,6 +24,7 @@
 #include <e-editor-actions.h>
 #include <e-editor-widgets.h>
 #include <e-editor-widget.h>
+#include <e-editor-find-dialog.h>
 
 #ifdef HAVE_XFREE
 #include <X11/XF86keysym.h>
@@ -52,6 +53,8 @@ struct _EEditorPrivate {
 	GtkWidget *html_toolbar;
 	GtkWidget *edit_area;
 
+	GtkWidget *find_dialog;
+
 	GtkWidget *color_combo_box;
 	GtkWidget *mode_combo_box;
 	GtkWidget *size_combo_box;
diff --git a/e-util/e-editor-widgets.h b/e-util/e-editor-widgets.h
index 5b28a7e..fb8bb45 100644
--- a/e-util/e-editor-widgets.h
+++ b/e-util/e-editor-widgets.h
@@ -59,24 +59,6 @@
 #define E_EDITOR_WIDGETS_CELL_PROPERTIES_WRAP_TEXT_CHECK_BUTTON(editor) \
 	E_EDITOR_WIDGETS ((editor), "cell-properties-wrap-text-check-button")
 
-/* Find Window */
-#define E_EDITOR_WIDGETS_FIND_BACKWARDS(editor) \
-	E_EDITOR_WIDGETS ((editor), "find-backwards")
-#define E_EDITOR_WIDGETS_FIND_BUTTON(editor) \
-	E_EDITOR_WIDGETS ((editor), "find-button")
-#define E_EDITOR_WIDGETS_FIND_CASE_SENSITIVE(editor) \
-	E_EDITOR_WIDGETS ((editor), "find-case-sensitive")
-#define E_EDITOR_WIDGETS_FIND_WINDOW(editor) \
-	E_EDITOR_WIDGETS ((editor), "find-window")
-#define E_EDITOR_WIDGETS_FIND_ENTRY(editor) \
-	E_EDITOR_WIDGETS ((editor), "find-entry")
-#define E_EDITOR_WIDGETS_FIND_REGULAR_EXPRESSION(editor) \
-	E_EDITOR_WIDGETS ((editor), "find-regular-expression")
-#define E_EDITOR_WIDGETS_FIND_RESULT_LABEL(editor) \
-	E_EDITOR_WIDGETS ((editor), "find-result-label")
-#define E_EDITOR_WIDGETS_FIND_WRAP(editor) \
-	E_EDITOR_WIDGETS ((editor), "find-wrap")
-
 /* Image Properties Window */
 #define E_EDITOR_WIDGETS_IMAGE_PROPERTIES_ALIGNMENT_COMBO_BOX(editor) \
 	E_EDITOR_WIDGETS ((editor), "image-properties-alignment-combo-box")
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 25cee07..ecdd9bf 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -91,6 +91,7 @@
 #include <e-util/e-dialog-utils.h>
 #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-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]