diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2003-06-15 17:35:48 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2003-06-15 17:35:48 +0800 |
commit | 94a825c3865eacb771b64dd93ea7b0dff3c9db49 (patch) | |
tree | 87b012c17af788ad3aac39769ecc95f665e74095 /embed/find-dialog.c | |
parent | 53471bc2f89c2844c7bb81b41575ee253c1f6516 (diff) | |
download | gsoc2013-epiphany-94a825c3865eacb771b64dd93ea7b0dff3c9db49.tar gsoc2013-epiphany-94a825c3865eacb771b64dd93ea7b0dff3c9db49.tar.gz gsoc2013-epiphany-94a825c3865eacb771b64dd93ea7b0dff3c9db49.tar.bz2 gsoc2013-epiphany-94a825c3865eacb771b64dd93ea7b0dff3c9db49.tar.lz gsoc2013-epiphany-94a825c3865eacb771b64dd93ea7b0dff3c9db49.tar.xz gsoc2013-epiphany-94a825c3865eacb771b64dd93ea7b0dff3c9db49.tar.zst gsoc2013-epiphany-94a825c3865eacb771b64dd93ea7b0dff3c9db49.zip |
Make prev/next navigation capability an object property, and sync on embed
2003-06-15 Christian Persch <chpe@cvs.gnome.org>
* embed/find-dialog.h:
* embed/find-dialog.c: (set_navigation_flags),
(ephy_find_dialog_get_property), (find_dialog_class_init),
(sync_embed), (find_get_info), (impl_show), (find_dialog_finalize),
(find_dialog_go_next), (find_dialog_go_prev), (find_entry_changed_cb),
(find_check_toggled_cb), (find_dialog_get_navigation_flags):
Make prev/next navigation capability an object property, and sync
on embed changes.
* embed/find-dialog.c: (find_dialog_new_with_parent):
* embed/ephy-embed-dialog.c: (ephy_embed_dialog_class_init),
(ephy_embed_dialog_new), (ephy_embed_dialog_new_with_parent),
(ephy_embed_dialog_set_embed):
* embed/print-dialog.c: (print_dialog_new),
(print_dialog_new_with_parent):
s/EphyEmbed/embed/ for the object property name.
* src/ephy-window.h:
* src/ephy-window.c: (sync_find_dialog), (update_find_control),
(ephy_window_switch_page_cb), (find_dialog_search_cb),
(ephy_window_get_find_dialog):
* src/window-commands.c: (window_cmd_edit_find_next),
(window_cmd_edit_find_prev):
Sync on the find dialog on nav capability and embed changes instead of
explicit updating.
Diffstat (limited to 'embed/find-dialog.c')
-rwxr-xr-x | embed/find-dialog.c | 195 |
1 files changed, 111 insertions, 84 deletions
diff --git a/embed/find-dialog.c b/embed/find-dialog.c index 9cb2f8138..18ef22fcc 100755 --- a/embed/find-dialog.c +++ b/embed/find-dialog.c @@ -21,6 +21,8 @@ #include "find-dialog.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" @@ -55,15 +57,8 @@ struct FindDialogPrivate { EmbedFindInfo *properties; GtkWidget *window; - gboolean can_go_prev; - gboolean can_go_next; gboolean constructed; -}; - -enum -{ - SEARCH, - LAST_SIGNAL + FindNavigationFlags nav_flags; }; enum @@ -88,7 +83,11 @@ EphyDialogProperty properties [] = { -1, NULL, NULL } }; -static guint find_dialog_signals[LAST_SIGNAL] = { 0 }; +enum +{ + PROP_0, + PROP_NAVIGATION +}; GType find_dialog_get_type (void) @@ -120,6 +119,51 @@ find_dialog_get_type (void) } static void +set_navigation_flags (FindDialog *dialog, FindNavigationFlags flags) +{ + GtkWidget *forward_button; + GtkWidget *back_button; + gboolean can_go_prev = FALSE, can_go_next = FALSE; + + if (!dialog->priv->constructed) return; + + dialog->priv->nav_flags = flags; + + if (flags & FIND_CAN_GO_PREV) + { + can_go_prev = TRUE; + } + if (flags & FIND_CAN_GO_NEXT) + { + can_go_next = TRUE; + } + + back_button = ephy_dialog_get_control (EPHY_DIALOG (dialog), BACK_BUTTON); + gtk_widget_set_sensitive (back_button, can_go_prev); + + forward_button = ephy_dialog_get_control (EPHY_DIALOG (dialog), FORWARD_BUTTON); + gtk_widget_set_sensitive (forward_button, can_go_next); + + g_object_notify (G_OBJECT (dialog), "navigation"); +} + +static void +ephy_find_dialog_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + FindDialog *dialog = FIND_DIALOG (object); + + switch (prop_id) + { + case PROP_NAVIGATION: + g_value_set_int (value, dialog->priv->nav_flags); + break; + } +} + +static void find_dialog_class_init (FindDialogClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -129,39 +173,22 @@ find_dialog_class_init (FindDialogClass *klass) ephy_dialog_class = EPHY_DIALOG_CLASS (klass); object_class->finalize = find_dialog_finalize; + object_class->get_property = ephy_find_dialog_get_property; ephy_dialog_class->construct = impl_construct; ephy_dialog_class->destruct = impl_destruct; ephy_dialog_class->show = impl_show; - find_dialog_signals[SEARCH] = - g_signal_new ("search", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (FindDialogClass, search), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); -} - -static void -find_update_nav (EphyDialog *dialog) -{ - GtkWidget *forward_button; - GtkWidget *back_button; - - g_signal_emit (G_OBJECT (dialog), find_dialog_signals[SEARCH], 0); - - if (!FIND_DIALOG(dialog)->priv->constructed) return; - - forward_button = ephy_dialog_get_control (dialog, FORWARD_BUTTON); - gtk_widget_set_sensitive (forward_button, - FIND_DIALOG(dialog)->priv->can_go_next); - - back_button = ephy_dialog_get_control (dialog, BACK_BUTTON); - gtk_widget_set_sensitive (back_button, - FIND_DIALOG(dialog)->priv->can_go_prev); + g_object_class_install_property (object_class, + PROP_NAVIGATION, + g_param_spec_int ("navigation", + "Navigation flags", + "The find dialog's navigation flags", + 0, + FIND_CAN_GO_PREV | + FIND_CAN_GO_NEXT, + 0, + G_PARAM_READABLE)); } static void @@ -177,15 +204,25 @@ ensure_constructed (FindDialog *dialog) } static void +sync_embed (FindDialog *dialog, GParamSpec *pspec, gpointer data) +{ + LOG ("EphyEmbed changed") + + set_navigation_flags (dialog, FIND_CAN_GO_PREV | FIND_CAN_GO_NEXT); +} + +static void find_dialog_init (FindDialog *dialog) { dialog->priv = g_new0 (FindDialogPrivate, 1); dialog->priv->properties = NULL; - dialog->priv->can_go_prev = TRUE; - dialog->priv->can_go_next = TRUE; + dialog->priv->nav_flags = FIND_CAN_GO_PREV | FIND_CAN_GO_NEXT; dialog->priv->constructed = FALSE; + g_signal_connect_object (dialog, "notify::embed", + G_CALLBACK (sync_embed), NULL, 0); + ensure_constructed (dialog); } @@ -224,10 +261,9 @@ find_get_info (EphyDialog *dialog) g_value_unset (&word); /* don't do null searches */ - if (search_string[0] == '\0') + if (search_string && search_string[0] == '\0') { - find_dialog->priv->can_go_prev = FALSE; - find_dialog->priv->can_go_next = FALSE; + set_navigation_flags (find_dialog, 0); return; } @@ -260,11 +296,9 @@ impl_show (EphyDialog *dialog) FindDialog *find_dialog = FIND_DIALOG(dialog); ensure_constructed (find_dialog); - find_dialog->priv->can_go_prev = TRUE; - find_dialog->priv->can_go_next = TRUE; + set_navigation_flags (find_dialog, FIND_CAN_GO_PREV | FIND_CAN_GO_NEXT); find_dialog->priv->window = ephy_dialog_get_control (dialog, WINDOW_PROP); find_get_info (dialog); - find_update_nav (dialog); /* Focus the text entry. This will correctly select or leave * unselected the existing text in the entry depending on the @@ -272,14 +306,13 @@ impl_show (EphyDialog *dialog) */ gtk_widget_grab_focus (ephy_dialog_get_control (dialog, WORD_PROP)); - icon = gtk_widget_render_icon (find_dialog->priv->window, GTK_STOCK_FIND, GTK_ICON_SIZE_MENU, "find_dialog"); gtk_window_set_icon (GTK_WINDOW(find_dialog->priv->window), icon); g_object_unref (icon); - + EPHY_DIALOG_CLASS (parent_class)->show (dialog); } @@ -293,6 +326,8 @@ find_dialog_finalize (GObject *object) dialog = FIND_DIALOG (object); + g_signal_handlers_disconnect_by_func (dialog, G_CALLBACK (sync_embed), NULL); + g_return_if_fail (dialog->priv != NULL); g_free (dialog->priv); @@ -306,7 +341,7 @@ find_dialog_new (EphyEmbed *embed) FindDialog *dialog; dialog = FIND_DIALOG (g_object_new (FIND_DIALOG_TYPE, - "EphyEmbed", embed, + "embed", embed, NULL)); return EPHY_DIALOG(dialog); @@ -319,25 +354,13 @@ find_dialog_new_with_parent (GtkWidget *window, FindDialog *dialog; dialog = FIND_DIALOG (g_object_new (FIND_DIALOG_TYPE, - "EphyEmbed", embed, + "embed", embed, "ParentWindow", window, NULL)); return EPHY_DIALOG(dialog); } -gboolean -find_dialog_can_go_next (FindDialog *dialog) -{ - return dialog->priv->can_go_next; -} - -gboolean -find_dialog_can_go_prev (FindDialog *dialog) -{ - return dialog->priv->can_go_prev; -} - void find_dialog_go_next (FindDialog *dialog, gboolean interactive) @@ -345,7 +368,8 @@ find_dialog_go_next (FindDialog *dialog, gresult result; EphyEmbed *embed; - if (!find_dialog_can_go_next (dialog)) return; + g_return_if_fail (IS_FIND_DIALOG (dialog)); + if ((dialog->priv->nav_flags & FIND_CAN_GO_NEXT) == 0) return; dialog->priv->properties->backwards = FALSE; dialog->priv->properties->interactive = interactive; @@ -353,16 +377,16 @@ find_dialog_go_next (FindDialog *dialog, embed = ephy_embed_dialog_get_embed (EPHY_EMBED_DIALOG(dialog)); g_return_if_fail (embed != NULL); - result = ephy_embed_find (embed, - dialog->priv->properties); + result = ephy_embed_find (embed, dialog->priv->properties); - dialog->priv->can_go_prev = TRUE; - if (result != G_OK) + if (result == G_OK) { - dialog->priv->can_go_next = FALSE; + set_navigation_flags (dialog, FIND_CAN_GO_PREV | FIND_CAN_GO_NEXT); + } + else + { + set_navigation_flags (dialog, FIND_CAN_GO_PREV); } - - find_update_nav (EPHY_DIALOG(dialog)); } void @@ -372,7 +396,8 @@ find_dialog_go_prev (FindDialog *dialog, gresult result; EphyEmbed *embed; - if (!find_dialog_can_go_prev (dialog)) return; + g_return_if_fail (IS_FIND_DIALOG (dialog)); + if ((dialog->priv->nav_flags & FIND_CAN_GO_PREV) == 0) return; dialog->priv->properties->backwards = TRUE; dialog->priv->properties->interactive = interactive; @@ -380,16 +405,16 @@ find_dialog_go_prev (FindDialog *dialog, embed = ephy_embed_dialog_get_embed (EPHY_EMBED_DIALOG(dialog)); g_return_if_fail (embed != NULL); - result = ephy_embed_find (embed, - dialog->priv->properties); + result = ephy_embed_find (embed, dialog->priv->properties); - dialog->priv->can_go_next = TRUE; - if (result != G_OK) + if (result == G_OK) { - dialog->priv->can_go_prev = FALSE; + set_navigation_flags (dialog, FIND_CAN_GO_PREV | FIND_CAN_GO_NEXT); + } + else + { + set_navigation_flags (dialog, FIND_CAN_GO_NEXT); } - - find_update_nav (EPHY_DIALOG(dialog)); } void @@ -419,12 +444,9 @@ find_entry_changed_cb (GtkWidget *editable, { FindDialog *find_dialog = FIND_DIALOG(dialog); - find_dialog->priv->can_go_prev = TRUE; - find_dialog->priv->can_go_next = TRUE; + set_navigation_flags (find_dialog, FIND_CAN_GO_PREV | FIND_CAN_GO_NEXT); find_get_info (dialog); - - find_update_nav (dialog); } void @@ -433,10 +455,15 @@ find_check_toggled_cb (GtkWidget *toggle, { FindDialog *find_dialog = FIND_DIALOG(dialog); - find_dialog->priv->can_go_prev = TRUE; - find_dialog->priv->can_go_next = TRUE; + set_navigation_flags (find_dialog, FIND_CAN_GO_PREV | FIND_CAN_GO_NEXT); find_get_info (dialog); +} + +FindNavigationFlags +find_dialog_get_navigation_flags (FindDialog *dialog) +{ + g_return_val_if_fail (IS_FIND_DIALOG (dialog), 0); - find_update_nav (dialog); + return dialog->priv->nav_flags; } |