diff options
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | embed/Makefile.am | 2 | ||||
-rwxr-xr-x | embed/find-dialog.c | 390 | ||||
-rw-r--r-- | embed/find-dialog.h | 62 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/ephy-find-toolbar.c | 386 | ||||
-rw-r--r-- | src/ephy-find-toolbar.h | 72 | ||||
-rw-r--r-- | src/ephy-window.c | 155 |
8 files changed, 584 insertions, 502 deletions
@@ -1,3 +1,20 @@ +2005-05-25 Christian Persch <chpe@cvs.gnome.org> + + * embed/Makefile.am: + * embed/find-dialog.c: + * embed/find-dialog.h: + A src/ephy-find-toolbar.c: + A src/ephy-find-toolbar.h: + * src/ephy-window.c: (sync_tab_document_type), + (tab_content_changed_cb), (ephy_window_set_active_tab), + (ephy_window_dispose), (sync_find_toolbar_text_cb), + (find_toolbar_find_next_cb), (find_toolbar_find_previous_cb), + (find_toolbar_close_cb), (ephy_window_init), + (ephy_window_notebook_switch_page_cb), (ephy_window_find): + + Replace the find dialogue with a find toolbar. Work in progress; + no typeaheadfind yet. + 2005-05-24 Christian Persch <chpe@cvs.gnome.org> * data/Makefile.am: diff --git a/embed/Makefile.am b/embed/Makefile.am index 75314e7e9..ba50008f5 100644 --- a/embed/Makefile.am +++ b/embed/Makefile.am @@ -13,7 +13,6 @@ NOINST_H_FILES = \ ephy-embed-dialog.h \ ephy-encodings.h \ ephy-favicon-cache.h \ - find-dialog.h \ print-dialog.h INST_H_FILES = \ @@ -46,7 +45,6 @@ libephyembed_la_SOURCES = \ ephy-history.c \ ephy-password-manager.c \ ephy-permission-manager.c \ - find-dialog.c \ print-dialog.c \ $(INST_H_FILES) \ $(NOINST_H_FILES) \ diff --git a/embed/find-dialog.c b/embed/find-dialog.c deleted file mode 100755 index 752d05012..000000000 --- a/embed/find-dialog.c +++ /dev/null @@ -1,390 +0,0 @@ -/* - * Copyright (C) 2002 Jorn Baayen - * Copyright (C) 2003 Marco Pesenti Gritti - * Copyright (C) 2003, 2004 Christian Persch - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - */ - -#include "config.h" - -#include "find-dialog.h" -#include "ephy-file-helpers.h" -#include "ephy-prefs.h" -#include "ephy-embed.h" -#include "ephy-debug.h" - -#include <gtk/gtk.h> - -#define CONF_FIND_MATCH_CASE "/apps/epiphany/dialogs/find_match_case" -#define CONF_FIND_AUTOWRAP "/apps/epiphany/dialogs/find_autowrap" -#define CONF_FIND_WORD "/apps/epiphany/dialogs/find_word" - -static void find_dialog_class_init (FindDialogClass *klass); -static void find_dialog_init (FindDialog *dialog); -static void find_dialog_finalize (GObject *object); - -/* Glade callbacks */ -void find_close_button_clicked_cb (GtkWidget *button, EphyDialog *dialog); -void find_next_button_clicked_cb (GtkWidget *button, EphyDialog *dialog); -void find_prev_button_clicked_cb (GtkWidget *button, EphyDialog *dialog); -void find_entry_changed_cb (GtkWidget *editable, EphyDialog *dialog); -void find_check_toggled_cb (GtkWidget *toggle, EphyDialog *dialog); - -static GObjectClass *parent_class = NULL; - -#define EPHY_FIND_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_FIND_DIALOG, FindDialogPrivate)) - -struct FindDialogPrivate -{ - EphyEmbed *old_embed; - gboolean initialised; -}; - -enum -{ - WINDOW_PROP, - MATCH_CASE_PROP, - AUTOWRAP_PROP, - WORD_PROP, - BACK_BUTTON, - FORWARD_BUTTON -}; - -static const -EphyDialogProperty properties [] = -{ - { "find_dialog", NULL, PT_NORMAL, 0 }, - { "case_check", CONF_FIND_MATCH_CASE, PT_NORMAL, 0 }, - { "wrap_check", CONF_FIND_AUTOWRAP, PT_NORMAL, 0 }, - { "find_entry", CONF_FIND_WORD, PT_NORMAL, 0 }, - { "back_button", NULL, PT_NORMAL, 0 }, - { "forward_button", NULL, PT_NORMAL, 0 }, - { NULL } -}; - -GType -find_dialog_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) - { - static const GTypeInfo our_info = - { - sizeof (FindDialogClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) find_dialog_class_init, - NULL, - NULL, /* class_data */ - sizeof (FindDialog), - 0, /* n_preallocs */ - (GInstanceInitFunc) find_dialog_init - }; - - type = g_type_register_static (EPHY_TYPE_EMBED_DIALOG, - "FindDialog", - &our_info, 0); - } - - return type; - -} - -static void -update_navigation_controls (FindDialog *dialog, gboolean prev, gboolean next) -{ - GtkWidget *button; - - button = ephy_dialog_get_control (EPHY_DIALOG (dialog), - properties[BACK_BUTTON].id); - gtk_widget_set_sensitive (button, prev); - - button = ephy_dialog_get_control (EPHY_DIALOG (dialog), - properties[FORWARD_BUTTON].id); - gtk_widget_set_sensitive (button, next); -} - - -static void -set_properties (FindDialog *find_dialog) -{ - char *search_string; - GValue match_case = {0, }; - GValue wrap = {0, }; - GValue word = {0, }; - gboolean b_match_case; - gboolean b_wrap; - EphyDialog *dialog = EPHY_DIALOG (find_dialog); - EphyEmbed *embed; - - if (!find_dialog->priv->initialised) return; - - /* get the search string from the entry field */ - ephy_dialog_get_value (dialog, properties[WORD_PROP].id, &word); - search_string = g_strdup (g_value_get_string (&word)); - g_value_unset (&word); - - /* don't do null searches */ - if (search_string == NULL || search_string[0] == '\0') - { - update_navigation_controls (find_dialog, FALSE, FALSE); - g_free (search_string); - - return; - } - - ephy_dialog_get_value (dialog, properties[MATCH_CASE_PROP].id, &match_case); - b_match_case = g_value_get_boolean (&match_case); - g_value_unset (&match_case); - - ephy_dialog_get_value (dialog, properties[AUTOWRAP_PROP].id, &wrap); - b_wrap = g_value_get_boolean (&wrap); - g_value_unset (&wrap); - - embed = ephy_embed_dialog_get_embed (EPHY_EMBED_DIALOG(dialog)); - g_return_if_fail (embed != NULL); - - ephy_embed_find_set_properties (embed, search_string, - b_match_case, b_wrap); - - g_free (search_string); -} - -static void -impl_show (EphyDialog *dialog) -{ - EPHY_DIALOG_CLASS (parent_class)->show (dialog); - - EPHY_FIND_DIALOG (dialog)->priv->initialised = TRUE; - - set_properties (EPHY_FIND_DIALOG (dialog)); - - /* Focus the text entry. This will correctly select or leave - * unselected the existing text in the entry depending on the - * 'gtk-entry-select-on-focus = 0 / 1' setting in user's gtkrc. - */ - gtk_widget_grab_focus (ephy_dialog_get_control - (dialog, properties[WORD_PROP].id)); -} - -static void -find_dialog_class_init (FindDialogClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - EphyDialogClass *ephy_dialog_class; - - parent_class = g_type_class_peek_parent (klass); - ephy_dialog_class = EPHY_DIALOG_CLASS (klass); - - object_class->finalize = find_dialog_finalize; - - ephy_dialog_class->show = impl_show; - - g_type_class_add_private (object_class, sizeof (FindDialogPrivate)); -} - -static void -sync_page_change (EphyEmbed *embed, const char *address, FindDialog *dialog) -{ - g_return_if_fail (EPHY_IS_EMBED (embed)); - - update_navigation_controls (dialog, TRUE, TRUE); - set_properties (dialog); -} - -static void -unset_old_embed (FindDialog *dialog) -{ - if (dialog->priv->old_embed != NULL) - { - g_signal_handlers_disconnect_by_func (dialog->priv->old_embed, - G_CALLBACK (sync_page_change), - dialog); - g_object_remove_weak_pointer (G_OBJECT (dialog->priv->old_embed), - (gpointer *)&dialog->priv->old_embed); - - dialog->priv->old_embed = NULL; - } -} - -static void -sync_embed (FindDialog *dialog, GParamSpec *pspec, gpointer data) -{ - EphyEmbed *embed; - - unset_old_embed (dialog); - - embed = ephy_embed_dialog_get_embed (EPHY_EMBED_DIALOG (dialog)); - g_return_if_fail (EPHY_IS_EMBED (embed)); - dialog->priv->old_embed = embed; - - g_signal_connect (G_OBJECT (embed), "ge_location", - G_CALLBACK (sync_page_change), dialog); - - g_object_add_weak_pointer (G_OBJECT (embed), - (gpointer *)&dialog->priv->old_embed); - - update_navigation_controls (dialog, TRUE, TRUE); - set_properties (dialog); -} - -static void -find_dialog_init (FindDialog *dialog) -{ - GtkWidget *window; - - dialog->priv = EPHY_FIND_DIALOG_GET_PRIVATE (dialog); - - ephy_dialog_construct (EPHY_DIALOG(dialog), - properties, - ephy_file ("epiphany.glade"), - "find_dialog", - NULL); - - update_navigation_controls (dialog, TRUE, TRUE); - - window = ephy_dialog_get_control (EPHY_DIALOG (dialog), - properties[WINDOW_PROP].id); - gtk_window_set_icon_name (GTK_WINDOW (window), GTK_STOCK_FIND); - - g_signal_connect_object (dialog, "notify::embed", - G_CALLBACK (sync_embed), NULL, 0); -} - -static void -find_dialog_finalize (GObject *object) -{ - FindDialog *dialog; - - g_return_if_fail (EPHY_IS_FIND_DIALOG (object)); - - dialog = EPHY_FIND_DIALOG (object); - - g_signal_handlers_disconnect_by_func (dialog, G_CALLBACK (sync_embed), NULL); - - unset_old_embed (dialog); - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -EphyDialog * -find_dialog_new (EphyEmbed *embed) -{ - FindDialog *dialog; - - dialog = EPHY_FIND_DIALOG (g_object_new (EPHY_TYPE_FIND_DIALOG, - "embed", embed, - NULL)); - - return EPHY_DIALOG(dialog); -} - -EphyDialog * -find_dialog_new_with_parent (GtkWidget *window, - EphyEmbed *embed) -{ - FindDialog *dialog; - - dialog = EPHY_FIND_DIALOG (g_object_new (EPHY_TYPE_FIND_DIALOG, - "embed", embed, - "parent-window", window, - NULL)); - - return EPHY_DIALOG(dialog); -} - -static void -find_dialog_go_next (FindDialog *dialog) -{ - EphyEmbed *embed; - - g_return_if_fail (EPHY_IS_FIND_DIALOG (dialog)); - - embed = ephy_embed_dialog_get_embed (EPHY_EMBED_DIALOG(dialog)); - g_return_if_fail (embed != NULL); - - if (ephy_embed_find_next (embed, FALSE)) - { - update_navigation_controls (dialog, TRUE, TRUE); - } - else - { - update_navigation_controls (dialog, TRUE, FALSE); - } -} - -static void -find_dialog_go_prev (FindDialog *dialog) -{ - EphyEmbed *embed; - - g_return_if_fail (EPHY_IS_FIND_DIALOG (dialog)); - - embed = ephy_embed_dialog_get_embed (EPHY_EMBED_DIALOG(dialog)); - g_return_if_fail (embed != NULL); - - if (ephy_embed_find_next (embed, TRUE)) - { - update_navigation_controls (dialog, TRUE, TRUE); - } - else - { - update_navigation_controls (dialog, FALSE, TRUE); - } -} - -void -find_close_button_clicked_cb (GtkWidget *button, - EphyDialog *dialog) -{ - g_object_unref (dialog); -} - -void find_next_button_clicked_cb (GtkWidget *button, - EphyDialog *dialog) -{ - find_dialog_go_next (EPHY_FIND_DIALOG(dialog)); -} - -void -find_prev_button_clicked_cb (GtkWidget *button, - EphyDialog *dialog) -{ - find_dialog_go_prev (EPHY_FIND_DIALOG(dialog)); -} - -void -find_entry_changed_cb (GtkWidget *editable, - EphyDialog *dialog) -{ - FindDialog *find_dialog = EPHY_FIND_DIALOG(dialog); - - update_navigation_controls (find_dialog, TRUE, TRUE); - set_properties (find_dialog); -} - -void -find_check_toggled_cb (GtkWidget *toggle, - EphyDialog *dialog) -{ - FindDialog *find_dialog = EPHY_FIND_DIALOG(dialog); - - update_navigation_controls (find_dialog, TRUE, TRUE); - set_properties (find_dialog); -} diff --git a/embed/find-dialog.h b/embed/find-dialog.h deleted file mode 100644 index a2a952d1d..000000000 --- a/embed/find-dialog.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2002 Jorn Baayen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - */ - -#ifndef FIND_DIALOG_H -#define FIND_DIALOG_H - -#include "ephy-embed-dialog.h" - -G_BEGIN_DECLS - -#define EPHY_TYPE_FIND_DIALOG (find_dialog_get_type ()) -#define EPHY_FIND_DIALOG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_FIND_DIALOG, FindDialog)) -#define EPHY_FIND_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_FIND_DIALOG, FindDialogClass)) -#define EPHY_IS_FIND_DIALOG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_FIND_DIALOG)) -#define EPHY_IS_FIND_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_FIND_DIALOG)) -#define EPHY_FIND_DIALOG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_FIND_DIALOG, FindDialogClass)) - -typedef struct FindDialogClass FindDialogClass; -typedef struct FindDialog FindDialog; -typedef struct FindDialogPrivate FindDialogPrivate; - -struct FindDialog -{ - EphyEmbedDialog parent; - - /*< private >*/ - FindDialogPrivate *priv; -}; - -struct FindDialogClass -{ - EphyEmbedDialogClass parent_class; -}; - -GType find_dialog_get_type (void); - -EphyDialog* find_dialog_new (EphyEmbed *embed); - -EphyDialog * find_dialog_new_with_parent (GtkWidget *window, - EphyEmbed *embed); - -G_END_DECLS - -#endif - diff --git a/src/Makefile.am b/src/Makefile.am index 71f511843..ecad19dbf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,6 +34,7 @@ NOINST_H_FILES = \ ephy-automation.h \ ephy-encoding-dialog.h \ ephy-encoding-menu.h \ + ephy-find-toolbar.h \ ephy-fullscreen-popup.h \ ephy-go-action.h \ ephy-history-window.h \ @@ -75,6 +76,7 @@ libephymain_la_SOURCES = \ ephy-encoding-menu.c \ ephy-extension.c \ ephy-extensions-manager.c \ + ephy-find-toolbar.c \ ephy-fullscreen-popup.c \ ephy-go-action.c \ ephy-home-action.c \ diff --git a/src/ephy-find-toolbar.c b/src/ephy-find-toolbar.c new file mode 100644 index 000000000..93ce237fe --- /dev/null +++ b/src/ephy-find-toolbar.c @@ -0,0 +1,386 @@ +/* + * Copyright (C) 2004 Tommi Komulainen + * Copyright (C) 2004, 2005 Christian Persch + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "config.h" + +#include "ephy-find-toolbar.h" +#include "ephy-debug.h" + +#include <gdk/gdkkeysyms.h> +#include <glib/gi18n.h> +#include <gtk/gtkarrow.h> +#include <gtk/gtkhbox.h> +#include <gtk/gtkimage.h> +#include <gtk/gtkentry.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkseparatortoolitem.h> +#include <gtk/gtkstock.h> +#include <gtk/gtktoolbutton.h> +#include <gtk/gtkmain.h> +#include <string.h> + +#define EPHY_FIND_TOOLBAR_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object),EPHY_TYPE_FIND_TOOLBAR, EphyFindToolbarPrivate)) + +struct _EphyFindToolbarPrivate +{ + EphyWindow *window; + GtkWidget *entry; + GtkToolItem *next; + GtkToolItem *prev; + gulong set_focus_handler; +}; + +enum +{ + PROP_0, + PROP_TEXT +}; + +enum +{ + NEXT, + PREVIOUS, + CLOSE, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +static GObjectClass *parent_class = NULL; + +/* public functions */ + +const char * +ephy_find_toolbar_get_text (EphyFindToolbar *toolbar) +{ + EphyFindToolbarPrivate *priv = toolbar->priv; + + return gtk_entry_get_text (GTK_ENTRY (priv->entry)); +} + +void +ephy_find_toolbar_set_controls (EphyFindToolbar *toolbar, + gboolean can_find_next, + gboolean can_find_prev) +{ + EphyFindToolbarPrivate *priv = toolbar->priv; + + gtk_widget_set_sensitive (GTK_WIDGET (priv->next), can_find_next); + gtk_widget_set_sensitive (GTK_WIDGET (priv->prev), can_find_prev); +} + +/* private functions */ + +static void +find_next_cb (EphyFindToolbar *toolbar) +{ + g_signal_emit (toolbar, signals[NEXT], 0); +} + +static void +find_prev_cb (EphyFindToolbar *toolbar) +{ + g_signal_emit (toolbar, signals[PREVIOUS], 0); +} + +static void +entry_changed_cb (GtkEntry *entry, + GObject *toolbar) +{ + g_object_notify (toolbar, "text"); +} + +static gboolean +entry_key_press_event_cb (GtkEntry *entry, + GdkEventKey *event, + EphyFindToolbar *toolbar) +{ + //EphyFindToolbarPrivate *priv = toolbar->priv; + guint mask = gtk_accelerator_get_default_mod_mask (); + gboolean handled = FALSE; + + /* Hide the toolbar when ESC is pressed */ + if ((event->state & mask) == 0) + { + if (event->keyval == GDK_Escape) + { + g_signal_emit (toolbar, signals[CLOSE], 0); + + handled = TRUE; + } +#if 0 + else if (event->keyval == GDK_Page_Up) + { + ephy_command_manager_do_command + (EPHY_COMMAND_MANAGER (priv->embed), + "cmd_movePageUp"); + handled = TRUE; + } + else if (event->keyval == GDK_Page_Down) + { + ephy_command_manager_do_command + (EPHY_COMMAND_MANAGER (priv->embed), + "cmd_movePageDown"); + handled = TRUE; + } +#endif + } + + return handled; +} + +static void +set_focus_cb (EphyWindow *window, + GtkWidget *widget, + EphyFindToolbar *toolbar) +{ + GtkWidget *wtoolbar = GTK_WIDGET (toolbar); + + while (widget != NULL && widget != wtoolbar) + { + widget = widget->parent; + } + + /* if widget == toolbar, the new focus widget is in the toolbar, so we + * don't deactivate. + */ + if (widget != wtoolbar) + { + gtk_widget_hide (wtoolbar); + } +} + +static void +ephy_find_toolbar_parent_set (GtkWidget *widget, + GtkWidget *previous_parent) +{ + EphyFindToolbar *toolbar = EPHY_FIND_TOOLBAR (widget); + EphyFindToolbarPrivate *priv = toolbar->priv; + GtkWidget *toplevel; + + if (widget->parent != NULL && priv->set_focus_handler == 0) + { + toplevel = gtk_widget_get_toplevel (widget); + priv->set_focus_handler = + g_signal_connect (toplevel, "set-focus", + G_CALLBACK (set_focus_cb), toolbar); + } +} + +static void +ephy_find_toolbar_grab_focus (GtkWidget *widget) +{ + EphyFindToolbar *toolbar = EPHY_FIND_TOOLBAR (widget); + EphyFindToolbarPrivate *priv = toolbar->priv; + + gtk_widget_grab_focus (priv->entry); +} + +static void +ephy_find_toolbar_init (EphyFindToolbar *toolbar) +{ + EphyFindToolbarPrivate *priv; + GtkToolbar *gtoolbar; + GtkToolItem *item; + GtkWidget *arrow, *box, *label; + + priv = toolbar->priv = EPHY_FIND_TOOLBAR_GET_PRIVATE (toolbar); + gtoolbar = GTK_TOOLBAR (toolbar); + + gtk_toolbar_set_style (gtoolbar, GTK_TOOLBAR_BOTH_HORIZ); + + /* Find: |_____| */ + box = gtk_hbox_new (FALSE, 12); + + label = gtk_label_new (NULL); + gtk_label_set_markup (GTK_LABEL (label), _("Find:")); + gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); + + priv->entry = gtk_entry_new (); + gtk_entry_set_width_chars (GTK_ENTRY (priv->entry), 32); + gtk_entry_set_max_length (GTK_ENTRY (priv->entry), 512); + gtk_box_pack_start (GTK_BOX (box), priv->entry, TRUE, TRUE, 0); + + item = gtk_tool_item_new (); + gtk_container_add (GTK_CONTAINER (item), box); + //gtk_tool_item_set_expand (item, TRUE); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); + gtk_widget_show_all (GTK_WIDGET (item)); + + // FIXME padding + + /* Next */ + arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE); + label = gtk_label_new (_("Find Next")); + priv->next = gtk_tool_button_new (arrow, _("Find Next")); + gtk_tool_item_set_is_important (priv->next, TRUE); + gtk_tool_item_set_tooltip (priv->next, gtoolbar->tooltips, + _("Find next occurrence of the search string"), + NULL); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->next, -1); + gtk_widget_show_all (GTK_WIDGET (priv->next)); + + /* Prev */ + arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE); + label = gtk_label_new (_("Find Previous")); + priv->prev = gtk_tool_button_new (arrow, _("Find Previous")); + gtk_tool_item_set_is_important (priv->prev, TRUE); + gtk_tool_item_set_tooltip (priv->prev, gtoolbar->tooltips, + _("Find previous occurrence of the search string"), + NULL); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->prev, -1); + gtk_widget_show_all (GTK_WIDGET (priv->prev)); + + /* connect signals */ + g_signal_connect (priv->entry, "key-press-event", + G_CALLBACK (entry_key_press_event_cb), toolbar); + g_signal_connect_after (priv->entry, "changed", + G_CALLBACK (entry_changed_cb), toolbar); + //g_signal_connect (GTK_ENTRY (priv->entry)->im_context, "preedit-changed", + // G_CALLBACK (entry_preedit_changed_cb), toolbar); + g_signal_connect_swapped (priv->entry, "activate", + G_CALLBACK (find_next_cb), toolbar); + g_signal_connect_swapped (priv->next, "clicked", + G_CALLBACK (find_next_cb), toolbar); + g_signal_connect_swapped (priv->prev, "clicked", + G_CALLBACK (find_prev_cb), toolbar); +} + +static void +ephy_find_toolbar_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EphyFindToolbar *toolbar = EPHY_FIND_TOOLBAR (object); + EphyFindToolbarPrivate *priv = toolbar->priv; + + switch (prop_id) + { + case PROP_TEXT: + gtk_entry_set_text (GTK_ENTRY (priv->entry), + g_value_get_string (value)); + break; + } +} + +static void +ephy_find_toolbar_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EphyFindToolbar *toolbar = EPHY_FIND_TOOLBAR (object); + + switch (prop_id) + { + case PROP_TEXT: + g_value_set_string (value, ephy_find_toolbar_get_text (toolbar)); + break; + } +} + +static void +ephy_find_toolbar_class_init (EphyFindToolbarClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + object_class->set_property = ephy_find_toolbar_set_property; + object_class->get_property = ephy_find_toolbar_get_property; + + widget_class->parent_set = ephy_find_toolbar_parent_set; + widget_class->grab_focus = ephy_find_toolbar_grab_focus; + + signals[NEXT] = + g_signal_new ("next", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (EphyFindToolbarClass, next), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + signals[PREVIOUS] = + g_signal_new ("previous", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (EphyFindToolbarClass, previous), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + signals[CLOSE] = + g_signal_new ("close", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EphyFindToolbarClass, close), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + g_object_class_install_property + (object_class, + PROP_TEXT, + g_param_spec_string ("text", + "Search string", + "Search string", + "", + G_PARAM_READWRITE)); + + g_type_class_add_private (klass, sizeof (EphyFindToolbarPrivate)); +} + +GType +ephy_find_toolbar_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) + { + static const GTypeInfo our_info = + { + sizeof (EphyFindToolbarClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) ephy_find_toolbar_class_init, + NULL, + NULL, /* class_data */ + sizeof (EphyFindToolbar), + 0, /* n_preallocs */ + (GInstanceInitFunc) ephy_find_toolbar_init + }; + + type = g_type_register_static (GTK_TYPE_TOOLBAR, + "EphyFindToolbar", + &our_info, 0); + } + + return type; +} + +EphyFindToolbar * +ephy_find_toolbar_new (void) +{ + return EPHY_FIND_TOOLBAR (g_object_new (EPHY_TYPE_FIND_TOOLBAR, NULL)); +} diff --git a/src/ephy-find-toolbar.h b/src/ephy-find-toolbar.h new file mode 100644 index 000000000..8f3ef4567 --- /dev/null +++ b/src/ephy-find-toolbar.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2004 Tommi Komulainen + * Copyright (C) 2004, 2005 Christian Persch + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef EPHY_FIND_TOOLBAR_H +#define EPHY_FIND_TOOLBAR_H + +#include <gtk/gtktoolbar.h> + +#include "ephy-window.h" + +G_BEGIN_DECLS + +#define EPHY_TYPE_FIND_TOOLBAR (ephy_find_toolbar_get_type ()) +#define EPHY_FIND_TOOLBAR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_FIND_TOOLBAR, EphyFindToolbar)) +#define EPHY_FIND_TOOLBAR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_FIND_TOOLBAR, EphyFindToolbarClass)) +#define EPHY_IS_FIND_TOOLBAR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_FIND_TOOLBAR)) +#define EPHY_IS_FIND_TOOLBAR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_FIND_TOOLBAR)) +#define EPHY_FIND_TOOLBAR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_FIND_TOOLBAR, EphyFindToolbarClass)) + +typedef struct _EphyFindToolbar EphyFindToolbar; +typedef struct _EphyFindToolbarPrivate EphyFindToolbarPrivate; +typedef struct _EphyFindToolbarClass EphyFindToolbarClass; + +struct _EphyFindToolbar +{ + GtkToolbar parent; + + /*< private >*/ + EphyFindToolbarPrivate *priv; +}; + +struct _EphyFindToolbarClass +{ + GtkToolbarClass parent_class; + + /* Signals */ + void (* next) (EphyFindToolbar *toolbar); + void (* previous) (EphyFindToolbar *toolbar); + void (* close) (EphyFindToolbar *toolbar); +}; + +GType ephy_find_toolbar_get_type (void) G_GNUC_CONST; + +EphyFindToolbar *ephy_find_toolbar_new (void); + +const char *ephy_find_toolbar_get_text (EphyFindToolbar *toolbar); + +void ephy_find_toolbar_set_controls (EphyFindToolbar *toolbar, + gboolean next, + gboolean previous); + +G_END_DECLS + +#endif /* EPHY_FIND_TOOLBAR_H */ diff --git a/src/ephy-window.c b/src/ephy-window.c index 642e9a8eb..79c5efee4 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -31,8 +31,6 @@ #include "ephy-state.h" #include "ppview-toolbar.h" #include "window-commands.h" -#include "find-dialog.h" -#include "print-dialog.h" #include "ephy-embed-shell.h" #include "ephy-embed-single.h" #include "ephy-shell.h" @@ -57,6 +55,7 @@ #include "ephy-notebook.h" #include "ephy-fullscreen-popup.h" #include "ephy-action-helper.h" +#include "ephy-find-toolbar.h" #include <string.h> #include <glib/gi18n.h> @@ -411,7 +410,7 @@ struct _EphyWindowPrivate PPViewToolbar *ppview_toolbar; GtkNotebook *notebook; EphyTab *active_tab; - EphyDialog *find_dialog; + EphyFindToolbar *find_toolbar; guint num_tabs; guint tab_message_cid; guint help_message_cid; @@ -1129,11 +1128,14 @@ sync_tab_document_type (EphyTab *tab, GParamSpec *pspec, EphyWindow *window) { - GtkActionGroup *action_group; + EphyWindowPrivate *priv = window->priv; + GtkActionGroup *action_group = priv->action_group; GtkAction *action; EphyEmbedDocumentType type; gboolean can_find, disable; + if (priv->closing) return; + /* update zoom actions */ sync_tab_zoom (tab, NULL, window); @@ -1141,7 +1143,6 @@ sync_tab_document_type (EphyTab *tab, can_find = (type != EPHY_EMBED_DOCUMENT_IMAGE); disable = (type != EPHY_EMBED_DOCUMENT_HTML); - action_group = window->priv->action_group; action = gtk_action_group_get_action (action_group, "ViewEncoding"); ephy_action_change_sensitivity_flags (action, SENS_FLAG_DOCUMENT, disable); action = gtk_action_group_get_action (action_group, "ViewPageSource"); @@ -1152,6 +1153,11 @@ sync_tab_document_type (EphyTab *tab, ephy_action_change_sensitivity_flags (action, SENS_FLAG_DOCUMENT, !can_find); action = gtk_action_group_get_action (action_group, "EditFindPrev"); ephy_action_change_sensitivity_flags (action, SENS_FLAG_DOCUMENT, !can_find); + + if (!can_find) + { + gtk_widget_hide (GTK_WIDGET (priv->find_toolbar)); + } } static void @@ -1784,6 +1790,18 @@ tab_context_menu_cb (EphyEmbed *embed, return TRUE; } +static void +tab_content_changed_cb (EphyEmbed *embed, + const char *uri, + EphyWindow *window) +{ + EphyWindowPrivate *priv = window->priv; + + if (priv->closing) return; + + ephy_find_toolbar_set_controls (priv->find_toolbar, TRUE, TRUE); +} + static gboolean let_me_resize_hack (EphyWindow *window) { @@ -1904,6 +1922,8 @@ ephy_window_set_active_tab (EphyWindow *window, EphyTab *new_tab) g_signal_handlers_disconnect_by_func (embed, G_CALLBACK (tab_context_menu_cb), window); g_signal_handlers_disconnect_by_func + (embed, G_CALLBACK (tab_content_changed_cb), window); + g_signal_handlers_disconnect_by_func (embed, G_CALLBACK (tab_size_to_cb), window); } @@ -1965,6 +1985,9 @@ ephy_window_set_active_tab (EphyWindow *window, EphyTab *new_tab) g_signal_connect_object (embed, "ge-context-menu", G_CALLBACK (tab_context_menu_cb), window, G_CONNECT_AFTER); + g_signal_connect_object (embed, "ge-content-change", + G_CALLBACK (tab_content_changed_cb), + window, G_CONNECT_AFTER); g_signal_connect_object (embed, "size-to", G_CALLBACK (tab_size_to_cb), window, 0); @@ -2334,12 +2357,6 @@ ephy_window_dispose (GObject *object) priv->idle_resize_handler = 0; } - if (priv->find_dialog) - { - g_object_unref (G_OBJECT (priv->find_dialog)); - priv->find_dialog = NULL; - } - g_object_unref (priv->fav_menu); priv->fav_menu = NULL; @@ -2673,8 +2690,66 @@ ephy_window_open_link (EphyLink *link, } static void +sync_find_toolbar_text_cb (EphyFindToolbar *toolbar, + GParamSpec *pspec, + EphyWindow *window) +{ + EphyEmbed *embed; + const char *text; + + embed = ephy_window_get_active_embed (window); + g_return_if_fail (embed != NULL); + + text = ephy_find_toolbar_get_text (toolbar); + ephy_embed_find_set_properties (embed, text, FALSE, TRUE); + ephy_find_toolbar_set_controls (toolbar, TRUE, TRUE); +} + +static void +find_toolbar_find_next_cb (EphyFindToolbar *toolbar, + EphyWindow *window) +{ + EphyEmbed *embed; + const char *text; + gboolean found; + + embed = ephy_window_get_active_embed (window); + g_return_if_fail (embed != NULL); + + text = ephy_find_toolbar_get_text (toolbar); + ephy_embed_find_set_properties (embed, text, FALSE, TRUE); + found = ephy_embed_find_next (embed, FALSE); + ephy_find_toolbar_set_controls (toolbar, found, found); +} + +static void +find_toolbar_find_previous_cb (EphyFindToolbar *toolbar, + EphyWindow *window) +{ + EphyEmbed *embed; + const char *text; + gboolean found; + + embed = ephy_window_get_active_embed (window); + g_return_if_fail (embed != NULL); + + text = ephy_find_toolbar_get_text (toolbar); + ephy_embed_find_set_properties (embed, text, FALSE, TRUE); + found = ephy_embed_find_next (embed, TRUE); + ephy_find_toolbar_set_controls (toolbar, found, found); +} + +static void +find_toolbar_close_cb (EphyFindToolbar *toolbar, + EphyWindow *window) +{ + gtk_widget_hide (GTK_WIDGET (toolbar)); +} + +static void ephy_window_init (EphyWindow *window) { + EphyWindowPrivate *priv; EphyExtension *manager; EphyEmbedSingle *single; EggToolbarsModel *model; @@ -2684,7 +2759,7 @@ ephy_window_init (EphyWindow *window) g_object_ref (ephy_shell); - window->priv = EPHY_WINDOW_GET_PRIVATE (window); + priv = window->priv = EPHY_WINDOW_GET_PRIVATE (window); window->priv->chrome = EPHY_EMBED_CHROME_ALL; @@ -2701,6 +2776,19 @@ ephy_window_init (EphyWindow *window) TRUE, TRUE, 0); gtk_widget_show (GTK_WIDGET (window->priv->notebook)); + priv->find_toolbar = ephy_find_toolbar_new (); + g_signal_connect (priv->find_toolbar, "notify::text", + G_CALLBACK (sync_find_toolbar_text_cb), window); + g_signal_connect (priv->find_toolbar, "next", + G_CALLBACK (find_toolbar_find_next_cb), window); + g_signal_connect (priv->find_toolbar, "previous", + G_CALLBACK (find_toolbar_find_previous_cb), window); + g_signal_connect (priv->find_toolbar, "close", + G_CALLBACK (find_toolbar_close_cb), window); + gtk_box_pack_start (GTK_BOX (window->priv->main_vbox), + GTK_WIDGET (priv->find_toolbar), FALSE, FALSE, 0); + gtk_widget_show (GTK_WIDGET (priv->find_toolbar)); + window->priv->statusbar = ephy_statusbar_new (); gtk_box_pack_end (GTK_BOX (window->priv->main_vbox), GTK_WIDGET (window->priv->statusbar), @@ -3196,32 +3284,15 @@ ephy_window_get_tabs (EphyWindow *window) } static void -update_embed_dialogs (EphyWindow *window, - EphyTab *tab) -{ - EphyEmbed *embed; - EphyDialog *find_dialog = window->priv->find_dialog; - - embed = ephy_tab_get_embed (tab); - - if (find_dialog) - { - ephy_embed_dialog_set_embed - (EPHY_EMBED_DIALOG(find_dialog), - embed); - } -} - -static void ephy_window_notebook_switch_page_cb (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, EphyWindow *window) { + EphyWindowPrivate *priv = window->priv; EphyTab *tab; - g_return_if_fail (EPHY_IS_WINDOW (window)); - if (window->priv->closing) return; + if (priv->closing) return; /* get the new tab */ tab = real_get_active_tab (window, page_num); @@ -3229,7 +3300,7 @@ ephy_window_notebook_switch_page_cb (GtkNotebook *notebook, /* update new tab */ ephy_window_set_active_tab (window, tab); - update_embed_dialogs (window, tab); + ephy_find_toolbar_set_controls (priv->find_toolbar, TRUE, TRUE); /* update window controls */ update_tabs_menu_sensitivity (window); @@ -3244,23 +3315,11 @@ ephy_window_notebook_switch_page_cb (GtkNotebook *notebook, void ephy_window_find (EphyWindow *window) { - EphyDialog *dialog; - EphyEmbed *embed; - - if (window->priv->find_dialog == NULL) - { - embed = ephy_window_get_active_embed (window); - g_return_if_fail (GTK_IS_WINDOW(window)); - - dialog = find_dialog_new_with_parent (GTK_WIDGET(window), - embed); - window->priv->find_dialog = dialog; - - g_object_add_weak_pointer(G_OBJECT (dialog), - (gpointer *) &window->priv->find_dialog); - } + EphyWindowPrivate *priv = window->priv; + GtkWidget *toolbar = GTK_WIDGET (priv->find_toolbar); - ephy_dialog_show (window->priv->find_dialog); + gtk_widget_show (toolbar); + gtk_widget_grab_focus (toolbar); } /** |