diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2006-01-25 06:20:54 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2006-01-25 06:20:54 +0800 |
commit | 3ca9a4923aa2aad1c33faa3033f0d8748cd2c69b (patch) | |
tree | 07f246e1451013fb1647bd5f76683eae74e1409f | |
parent | 6ba78f4bcb58c02bd4b6b41757eeeab3af2fbf6e (diff) | |
download | gsoc2013-epiphany-3ca9a4923aa2aad1c33faa3033f0d8748cd2c69b.tar gsoc2013-epiphany-3ca9a4923aa2aad1c33faa3033f0d8748cd2c69b.tar.gz gsoc2013-epiphany-3ca9a4923aa2aad1c33faa3033f0d8748cd2c69b.tar.bz2 gsoc2013-epiphany-3ca9a4923aa2aad1c33faa3033f0d8748cd2c69b.tar.lz gsoc2013-epiphany-3ca9a4923aa2aad1c33faa3033f0d8748cd2c69b.tar.xz gsoc2013-epiphany-3ca9a4923aa2aad1c33faa3033f0d8748cd2c69b.tar.zst gsoc2013-epiphany-3ca9a4923aa2aad1c33faa3033f0d8748cd2c69b.zip |
Refactored, code cleanups. Don't make the bookmark properties window
2006-01-24 Christian Persch <chpe@cvs.gnome.org>
* src/bookmarks/ephy-bookmark-properties.c:
(ephy_bookmark_properties_set_bookmark),
(bookmark_properties_close_cb), (bookmark_properties_response_cb),
(update_entry), (update_window_title), (combo_changed_cb),
(title_entry_changed_cb), (location_entry_changed_cb),
(set_window_icon), (ephy_bookmark_properties_init),
(ephy_bookmark_properties_constructor),
(ephy_bookmark_properties_set_property),
(ephy_bookmark_properties_get_property),
(ephy_bookmark_properties_class_init),
(ephy_bookmark_properties_get_type),
(ephy_bookmark_properties_new):
* src/bookmarks/ephy-bookmark-properties.h:
Refactored, code cleanups. Don't make the bookmark properties
window transient.
* src/bookmarks/ephy-bookmarks-editor.c: (cmd_bookmark_properties):
* src/bookmarks/ephy-bookmarks-ui.c:
(activate_bookmark_properties), (activate_bookmark_open_tab),
(activate_bookmark_open_window), (selected_bookmark_action),
(erase_bookmarks_menu), (tree_changed_cb), (node_added_cb),
(node_changed_cb), (node_removed_cb),
(ephy_bookmarks_ui_attach_window), (properties_dialog_destroy_cb),
(add_bookmark), (duplicate_bookmark_response_cb),
(ephy_bookmarks_ui_add_bookmark), (add_topic_changed_cb),
(add_topic_response_cb), (ephy_bookmarks_ui_add_topic),
(ephy_bookmarks_ui_show_bookmark):
* src/bookmarks/ephy-bookmarks-ui.h:
Cleanups. Make the New Topic dialogue modal to the bookmark properties
window. Change some strings, don't unnecessarily use markup when
constructing a message dialog.
2006-01-24 Christian Persch <chpe@cvs.gnome.org>
-rw-r--r-- | ChangeLog | 36 | ||||
-rw-r--r-- | src/bookmarks/.cvsignore | 1 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmark-properties.c | 405 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmark-properties.h | 40 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-editor.c | 10 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-ui.c | 471 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-ui.h | 3 |
7 files changed, 531 insertions, 435 deletions
@@ -1,5 +1,41 @@ 2006-01-24 Christian Persch <chpe@cvs.gnome.org> + * src/bookmarks/ephy-bookmark-properties.c: + (ephy_bookmark_properties_set_bookmark), + (bookmark_properties_close_cb), (bookmark_properties_response_cb), + (update_entry), (update_window_title), (combo_changed_cb), + (title_entry_changed_cb), (location_entry_changed_cb), + (set_window_icon), (ephy_bookmark_properties_init), + (ephy_bookmark_properties_constructor), + (ephy_bookmark_properties_set_property), + (ephy_bookmark_properties_get_property), + (ephy_bookmark_properties_class_init), + (ephy_bookmark_properties_get_type), + (ephy_bookmark_properties_new): + * src/bookmarks/ephy-bookmark-properties.h: + + Refactored, code cleanups. Don't make the bookmark properties + window transient. + + * src/bookmarks/ephy-bookmarks-editor.c: (cmd_bookmark_properties): + * src/bookmarks/ephy-bookmarks-ui.c: + (activate_bookmark_properties), (activate_bookmark_open_tab), + (activate_bookmark_open_window), (selected_bookmark_action), + (erase_bookmarks_menu), (tree_changed_cb), (node_added_cb), + (node_changed_cb), (node_removed_cb), + (ephy_bookmarks_ui_attach_window), (properties_dialog_destroy_cb), + (add_bookmark), (duplicate_bookmark_response_cb), + (ephy_bookmarks_ui_add_bookmark), (add_topic_changed_cb), + (add_topic_response_cb), (ephy_bookmarks_ui_add_topic), + (ephy_bookmarks_ui_show_bookmark): + * src/bookmarks/ephy-bookmarks-ui.h: + + Cleanups. Make the New Topic dialogue modal to the bookmark properties + window. Change some strings, don't unnecessarily use markup when + constructing a message dialog. + +2006-01-24 Christian Persch <chpe@cvs.gnome.org> + * src/bookmarks/ephy-bookmarks-editor.c: (import_dialog_response_cb), (export_format_combo_changed_cb), (export_dialog_response_cb), (cmd_bookmarks_export): diff --git a/src/bookmarks/.cvsignore b/src/bookmarks/.cvsignore index 9d2901549..390c5c8ba 100644 --- a/src/bookmarks/.cvsignore +++ b/src/bookmarks/.cvsignore @@ -2,6 +2,7 @@ Makefile Makefile.in .deps .libs +*.o *.lo *.la *-type-builtins.? diff --git a/src/bookmarks/ephy-bookmark-properties.c b/src/bookmarks/ephy-bookmark-properties.c index 7c64339cd..803380f3c 100644 --- a/src/bookmarks/ephy-bookmark-properties.c +++ b/src/bookmarks/ephy-bookmark-properties.c @@ -1,5 +1,7 @@ /* * Copyright (C) 2002 Marco Pesenti Gritti <mpeseng@tin.it> + * Copyright (C) 2005, 2006 Peter A. Harvey + * Copyright (C) 2006 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 @@ -46,17 +48,6 @@ static const GtkTargetEntry dest_drag_types[] = { {EPHY_DND_URL_TYPE, 0, 0}, }; -static void ephy_bookmark_properties_class_init (EphyBookmarkPropertiesClass *klass); -static void ephy_bookmark_properties_init (EphyBookmarkProperties *properties); -static void ephy_bookmark_properties_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void ephy_bookmark_properties_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - #define EPHY_BOOKMARK_PROPERTIES_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_BOOKMARK_PROPERTIES, EphyBookmarkPropertiesPrivate)) struct _EphyBookmarkPropertiesPrivate @@ -77,74 +68,10 @@ enum enum { - RESPONSE_NEW_TOPIC + RESPONSE_NEW_TOPIC = 1 }; -static GObjectClass *parent_class = NULL; - -GType -ephy_bookmark_properties_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) - { - static const GTypeInfo our_info = - { - sizeof (EphyBookmarkPropertiesClass), - NULL, - NULL, - (GClassInitFunc) ephy_bookmark_properties_class_init, - NULL, - NULL, - sizeof (EphyBookmarkProperties), - 0, - (GInstanceInitFunc) ephy_bookmark_properties_init - }; - - type = g_type_register_static (GTK_TYPE_DIALOG, - "EphyBookmarkProperties", - &our_info, 0); - } - - return type; -} - -static void -ephy_bookmark_properties_class_init (EphyBookmarkPropertiesClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - object_class->set_property = ephy_bookmark_properties_set_property; - object_class->get_property = ephy_bookmark_properties_get_property; - - g_object_class_install_property (object_class, - PROP_BOOKMARKS, - g_param_spec_object ("bookmarks", - "Bookmarks set", - "Bookmarks set", - EPHY_TYPE_BOOKMARKS, - G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, - PROP_BOOKMARK, - g_param_spec_pointer ("bookmark", - "Bookmark", - "Bookmark", - G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, - PROP_CREATING, - g_param_spec_boolean ("creating", - "New bookmark", - "New bookmark", - FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_type_class_add_private (object_class, sizeof(EphyBookmarkPropertiesPrivate)); -} +static GObjectClass *parent_class; static void node_destroy_cb (EphyNode *bookmark, @@ -157,69 +84,24 @@ static void ephy_bookmark_properties_set_bookmark (EphyBookmarkProperties *properties, EphyNode *bookmark) { + EphyBookmarkPropertiesPrivate *priv = properties->priv; + LOG ("Set bookmark"); - if (properties->priv->bookmark) + if (priv->bookmark) { - ephy_node_signal_disconnect_object (properties->priv->bookmark, + ephy_node_signal_disconnect_object (priv->bookmark, EPHY_NODE_DESTROY, (EphyNodeCallback) node_destroy_cb, G_OBJECT (properties)); } - properties->priv->bookmark = bookmark; + priv->bookmark = bookmark; - ephy_node_signal_connect_object (properties->priv->bookmark, + ephy_node_signal_connect_object (priv->bookmark, EPHY_NODE_DESTROY, (EphyNodeCallback) node_destroy_cb, G_OBJECT (properties)); - - g_object_notify (G_OBJECT (properties), "bookmark"); -} - -static void -ephy_bookmark_properties_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - EphyBookmarkProperties *properties = EPHY_BOOKMARK_PROPERTIES (object); - - switch (prop_id) - { - case PROP_BOOKMARKS: - properties->priv->bookmarks = g_value_get_object (value); - break; - case PROP_BOOKMARK: - ephy_bookmark_properties_set_bookmark - (properties, g_value_get_pointer (value)); - break; - case PROP_CREATING: - properties->priv->creating = g_value_get_boolean (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -ephy_bookmark_properties_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - EphyBookmarkProperties *properties = EPHY_BOOKMARK_PROPERTIES (object); - - switch (prop_id) - { - case PROP_BOOKMARK: - g_value_set_object (value, properties); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } } static void @@ -227,9 +109,12 @@ bookmark_properties_close_cb (GtkDialog *dialog, gpointer data) { EphyBookmarkProperties *properties = EPHY_BOOKMARK_PROPERTIES (dialog); - if (properties->priv->creating) + EphyBookmarkPropertiesPrivate *priv = properties->priv; + + if (priv->creating) { - ephy_node_unref (properties->priv->bookmark); + ephy_node_unref (priv->bookmark); + priv->bookmark = NULL; } } @@ -239,6 +124,8 @@ bookmark_properties_response_cb (GtkDialog *dialog, gpointer data) { EphyBookmarkProperties *properties = EPHY_BOOKMARK_PROPERTIES (dialog); + EphyBookmarkPropertiesPrivate *priv = properties->priv; + switch (response_id) { case GTK_RESPONSE_HELP: @@ -248,79 +135,92 @@ bookmark_properties_response_cb (GtkDialog *dialog, return; case RESPONSE_NEW_TOPIC: ephy_bookmarks_ui_add_topic (GTK_WIDGET (dialog), - properties->priv->bookmark); + priv->bookmark); return; case GTK_RESPONSE_CANCEL: - ephy_node_unref (properties->priv->bookmark); + ephy_node_unref (priv->bookmark); + priv->bookmark = NULL; break; default: break; } + gtk_widget_destroy (GTK_WIDGET (dialog)); } static void -update_entry (EphyBookmarkProperties *props, GtkWidget *entry, guint prop) +update_entry (EphyBookmarkProperties *props, + GtkWidget *entry, + guint prop) { GValue value = { 0, }; char *text; text = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1); g_value_init (&value, G_TYPE_STRING); - g_value_set_string (&value, text); + g_value_take_string (&value, text); ephy_node_set_property (props->priv->bookmark, prop, &value); g_value_unset (&value); - g_free (text); } static void update_window_title (EphyBookmarkProperties *properties) { + EphyBookmarkPropertiesPrivate *priv = properties->priv; char *title; const char *tmp; - tmp = ephy_node_get_property_string (properties->priv->bookmark, + tmp = ephy_node_get_property_string (priv->bookmark, EPHY_NODE_BMK_PROP_TITLE); + title = g_strdup_printf (_("“%s” Properties"), tmp); gtk_window_set_title (GTK_WINDOW (properties), title); g_free (title); } static void -combo_changed_cb (GtkComboBox *combobox, GtkWidget *palette) +combo_changed_cb (GtkComboBox *combobox, + GtkWidget *palette) { - int active = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox)); + int active; + + active = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox)); g_object_set (palette, "mode", active, NULL); } static void -title_entry_changed_cb (GtkWidget *entry, EphyBookmarkProperties *props) +title_entry_changed_cb (GtkWidget *entry, + EphyBookmarkProperties *props) { update_entry (props, entry, EPHY_NODE_BMK_PROP_TITLE); update_window_title(props); } static void -location_entry_changed_cb (GtkWidget *entry, EphyBookmarkProperties *props) +location_entry_changed_cb (GtkWidget *entry, + EphyBookmarkProperties *properties) { - ephy_bookmarks_set_address (props->priv->bookmarks, - props->priv->bookmark, + EphyBookmarkPropertiesPrivate *priv = properties->priv; + + ephy_bookmarks_set_address (priv->bookmarks, + priv->bookmark, gtk_entry_get_text (GTK_ENTRY (entry))); } static void set_window_icon (EphyBookmarkProperties *properties) { + EphyBookmarkPropertiesPrivate *priv = properties->priv; EphyFaviconCache *cache; const char *icon_location; GdkPixbuf *icon = NULL; cache = EPHY_FAVICON_CACHE - (ephy_embed_shell_get_favicon_cache (embed_shell)); + (ephy_embed_shell_get_favicon_cache (ephy_embed_shell_get_default ())); icon_location = ephy_node_get_property_string - (properties->priv->bookmark, EPHY_NODE_BMK_PROP_ICON); + (priv->bookmark, EPHY_NODE_BMK_PROP_ICON); LOG ("Get favicon for %s", icon_location ? icon_location : "None"); @@ -342,24 +242,45 @@ set_window_icon (EphyBookmarkProperties *properties) } static void -build_ui (EphyBookmarkProperties *properties) +ephy_bookmark_properties_init (EphyBookmarkProperties *properties) { - GtkWidget *table, *label, *entry, *palette; + properties->priv = EPHY_BOOKMARK_PROPERTIES_GET_PRIVATE (properties); +} + +static GObject * +ephy_bookmark_properties_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_params) +{ + GObject *object; + EphyBookmarkProperties *properties; + EphyBookmarkPropertiesPrivate *priv; + GtkWidget *widget, *table, *label, *entry, *palette; GtkWidget *scrolled_window; + GtkWindow *window; + GtkDialog *dialog; GtkComboBox *cbox; const char *tmp; - g_signal_connect (G_OBJECT (properties), - "response", - G_CALLBACK (bookmark_properties_response_cb), - properties); + object = parent_class->constructor (type, n_construct_properties, + construct_params); + + widget = GTK_WIDGET (object); + window = GTK_WINDOW (object); + dialog = GTK_DIALOG (object); + properties = EPHY_BOOKMARK_PROPERTIES (object); + priv = properties->priv; + + gtk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_NORMAL); + ephy_gui_ensure_window_group (window); - g_signal_connect (G_OBJECT (properties), - "close", - G_CALLBACK (bookmark_properties_close_cb), - properties); + g_signal_connect (properties, "response", + G_CALLBACK (bookmark_properties_response_cb), properties); - ephy_state_add_window (GTK_WIDGET(properties), + g_signal_connect (properties, "close", + G_CALLBACK (bookmark_properties_close_cb), properties); + + ephy_state_add_window (widget, "bookmark_properties", 290, 280, FALSE, EPHY_STATE_WINDOW_SAVE_SIZE); @@ -367,14 +288,14 @@ build_ui (EphyBookmarkProperties *properties) update_window_title (properties); set_window_icon (properties); - gtk_dialog_set_has_separator (GTK_DIALOG (properties), FALSE); + gtk_dialog_set_has_separator (dialog, FALSE); gtk_container_set_border_width (GTK_CONTAINER (properties), 5); - gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (properties)->vbox), 2); + gtk_box_set_spacing (GTK_BOX (dialog->vbox), 2); table = gtk_table_new (5, 2, FALSE); gtk_table_set_row_spacings (GTK_TABLE (table), 6); gtk_table_set_col_spacings (GTK_TABLE (table), 12); - gtk_container_set_border_width (GTK_CONTAINER (GTK_TABLE (table)), 5); + gtk_container_set_border_width (GTK_CONTAINER (table), 5); gtk_widget_show (table); entry = gtk_entry_new (); @@ -419,10 +340,9 @@ build_ui (EphyBookmarkProperties *properties) gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3, GTK_FILL, 0, 0, 0); gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (cbox), 1, 2, 2, 3, GTK_FILL, 0, 0, 0); - palette = ephy_topics_palette_new (properties->priv->bookmarks, - properties->priv->bookmark); - properties->priv->palette = EPHY_TOPICS_PALETTE (palette); - gtk_widget_show (palette); + palette = ephy_topics_palette_new (priv->bookmarks, priv->bookmark); + priv->palette = EPHY_TOPICS_PALETTE (palette); + scrolled_window = g_object_new (GTK_TYPE_SCROLLED_WINDOW, "hadjustment", NULL, "vadjustment", NULL, @@ -430,51 +350,161 @@ build_ui (EphyBookmarkProperties *properties) "vscrollbar_policy", GTK_POLICY_AUTOMATIC, "shadow_type", GTK_SHADOW_IN, NULL); - gtk_widget_show (scrolled_window); gtk_container_add (GTK_CONTAINER (scrolled_window), palette); - - g_signal_connect_object (G_OBJECT (cbox), "changed", G_CALLBACK (combo_changed_cb), - palette, G_CONNECT_AFTER); + gtk_widget_show (palette); + + g_signal_connect_object (cbox, "changed", + G_CALLBACK (combo_changed_cb), palette, + G_CONNECT_AFTER); gtk_table_attach (GTK_TABLE (table), scrolled_window, 1, 2, 3, 4, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0); gtk_table_set_row_spacing (GTK_TABLE (table), 3, 3); + gtk_widget_show (scrolled_window); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (properties)->vbox), - table, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (dialog->vbox), table, TRUE, TRUE, 0); - gtk_dialog_add_button (GTK_DIALOG (properties), + gtk_dialog_add_button (dialog, GTK_STOCK_HELP, GTK_RESPONSE_HELP); - gtk_dialog_add_button (GTK_DIALOG (properties), + gtk_dialog_add_button (dialog, _("_New Topic"), RESPONSE_NEW_TOPIC); - if (properties->priv->creating) + if (priv->creating) { - gtk_dialog_add_button (GTK_DIALOG (properties), + gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - gtk_dialog_add_button (GTK_DIALOG (properties), + gtk_dialog_add_button (dialog, GTK_STOCK_OK, GTK_RESPONSE_OK); - gtk_dialog_set_default_response (GTK_DIALOG (properties), GTK_RESPONSE_OK); + gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK); } else { - gtk_dialog_add_button (GTK_DIALOG (properties), + gtk_dialog_add_button (dialog, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); - gtk_dialog_set_default_response (GTK_DIALOG (properties), GTK_RESPONSE_CLOSE); + gtk_dialog_set_default_response (dialog, GTK_RESPONSE_CLOSE); } gtk_combo_box_set_active (cbox, 1); + + return object; } static void -ephy_bookmark_properties_init (EphyBookmarkProperties *properties) +ephy_bookmark_properties_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - properties->priv = EPHY_BOOKMARK_PROPERTIES_GET_PRIVATE (properties); + EphyBookmarkProperties *properties = EPHY_BOOKMARK_PROPERTIES (object); + EphyBookmarkPropertiesPrivate *priv = properties->priv; + + switch (prop_id) + { + case PROP_BOOKMARKS: + priv->bookmarks = g_value_get_object (value); + break; + case PROP_BOOKMARK: + ephy_bookmark_properties_set_bookmark + (properties, g_value_get_pointer (value)); + break; + case PROP_CREATING: + priv->creating = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +ephy_bookmark_properties_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EphyBookmarkProperties *properties = EPHY_BOOKMARK_PROPERTIES (object); + + switch (prop_id) + { + case PROP_BOOKMARK: + g_value_set_object (value, properties); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +ephy_bookmark_properties_class_init (EphyBookmarkPropertiesClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + object_class->constructor = ephy_bookmark_properties_constructor; + object_class->set_property = ephy_bookmark_properties_set_property; + object_class->get_property = ephy_bookmark_properties_get_property; + + g_object_class_install_property (object_class, + PROP_BOOKMARKS, + g_param_spec_object ("bookmarks", + "bookmarks", + "bookmarks", + EPHY_TYPE_BOOKMARKS, + G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, + PROP_BOOKMARK, + g_param_spec_pointer ("bookmark", + "bookmark", + "bookmark", + G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT)); + + g_object_class_install_property (object_class, + PROP_CREATING, + g_param_spec_boolean ("creating", + "creating", + "creating", + FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_type_class_add_private (object_class, sizeof (EphyBookmarkPropertiesPrivate)); +} + +/* public API */ + +GType +ephy_bookmark_properties_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) + { + static const GTypeInfo our_info = + { + sizeof (EphyBookmarkPropertiesClass), + NULL, + NULL, + (GClassInitFunc) ephy_bookmark_properties_class_init, + NULL, + NULL, + sizeof (EphyBookmarkProperties), + 0, + (GInstanceInitFunc) ephy_bookmark_properties_init + }; + + type = g_type_register_static (GTK_TYPE_DIALOG, + "EphyBookmarkProperties", + &our_info, 0); + } + + return type; } GtkWidget * @@ -482,22 +512,13 @@ ephy_bookmark_properties_new (EphyBookmarks *bookmarks, EphyNode *bookmark, gboolean creating) { - EphyBookmarkProperties *properties; - g_assert (bookmarks != NULL); - properties = EPHY_BOOKMARK_PROPERTIES (g_object_new - (EPHY_TYPE_BOOKMARK_PROPERTIES, - "bookmarks", bookmarks, - "bookmark", bookmark, - "creating", creating, - NULL)); - - build_ui (properties); - - gtk_window_set_destroy_with_parent (GTK_WINDOW (properties), TRUE); - - return GTK_WIDGET (properties); + return GTK_WIDGET (g_object_new (EPHY_TYPE_BOOKMARK_PROPERTIES, + "bookmarks", bookmarks, + "bookmark", bookmark, + "creating", creating, + NULL)); } EphyNode * diff --git a/src/bookmarks/ephy-bookmark-properties.h b/src/bookmarks/ephy-bookmark-properties.h index 887323049..afc3db7cf 100644 --- a/src/bookmarks/ephy-bookmark-properties.h +++ b/src/bookmarks/ephy-bookmark-properties.h @@ -1,5 +1,7 @@ /* * Copyright (C) 2002 Marco Pesenti Gritti <mpeseng@tin.it> + * Copyright (C) 2005, 2006 Peter A. Harvey + * Copyright (C) 2006 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 @@ -27,35 +29,37 @@ G_BEGIN_DECLS -#define EPHY_TYPE_BOOKMARK_PROPERTIES (ephy_bookmark_properties_get_type ()) -#define EPHY_BOOKMARK_PROPERTIES(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_BOOKMARK_PROPERTIES, EphyBookmarkProperties)) -#define EPHY_BOOKMARK_PROPERTIES_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_BOOKMARK_PROPERTIES, EphyBookmarkPropertiesClass)) -#define EPHY_IS_BOOKMARK_PROPERTIES(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_BOOKMARK_PROPERTIES)) -#define EPHY_IS_BOOKMARK_PROPERTIES_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_BOOKMARK_PROPERTIES)) -#define EPHY_BOOKMARK_PROPERTIES_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_BOOKMARK_PROPERTIES, EphyBookmarkPropertiesClass)) +#define EPHY_TYPE_BOOKMARK_PROPERTIES (ephy_bookmark_properties_get_type ()) +#define EPHY_BOOKMARK_PROPERTIES(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_BOOKMARK_PROPERTIES, EphyBookmarkProperties)) +#define EPHY_BOOKMARK_PROPERTIES_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_BOOKMARK_PROPERTIES, EphyBookmarkPropertiesClass)) +#define EPHY_IS_BOOKMARK_PROPERTIES(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_BOOKMARK_PROPERTIES)) +#define EPHY_IS_BOOKMARK_PROPERTIES_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_BOOKMARK_PROPERTIES)) +#define EPHY_BOOKMARK_PROPERTIES_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_BOOKMARK_PROPERTIES, EphyBookmarkPropertiesClass)) -typedef struct _EphyBookmarkPropertiesPrivate EphyBookmarkPropertiesPrivate; +typedef struct _EphyBookmarkProperties EphyBookmarkProperties; +typedef struct _EphyBookmarkPropertiesPrivate EphyBookmarkPropertiesPrivate; +typedef struct _EphyBookmarkPropertiesClass EphyBookmarkPropertiesClass; -typedef struct +struct _EphyBookmarkProperties { - GtkDialog parent; + GtkDialog parent_instance; /*< private >*/ EphyBookmarkPropertiesPrivate *priv; -} EphyBookmarkProperties; +}; -typedef struct +struct _EphyBookmarkPropertiesClass { - GtkDialogClass parent; -} EphyBookmarkPropertiesClass; + GtkDialogClass parent_class; +}; -GType ephy_bookmark_properties_get_type (void); +GType ephy_bookmark_properties_get_type (void); -GtkWidget *ephy_bookmark_properties_new (EphyBookmarks *bookmarks, - EphyNode *bookmark, - gboolean creating); +GtkWidget *ephy_bookmark_properties_new (EphyBookmarks *bookmarks, + EphyNode *bookmark, + gboolean creating); -EphyNode *ephy_bookmark_properties_get_node (EphyBookmarkProperties *properties); +EphyNode *ephy_bookmark_properties_get_node (EphyBookmarkProperties *properties); G_END_DECLS diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c index 655d8ae2b..e3cb8fa1c 100644 --- a/src/bookmarks/ephy-bookmarks-editor.c +++ b/src/bookmarks/ephy-bookmarks-editor.c @@ -469,13 +469,6 @@ cmd_delete (GtkAction *action, } } -static void -show_properties_dialog (EphyBookmarksEditor *editor, - EphyNode *bookmark) -{ - ephy_bookmarks_ui_show_bookmark (GTK_WIDGET (editor), bookmark); -} - static GSList * add_bookmarks_files (const char *dir, const char *filename, @@ -909,7 +902,8 @@ cmd_bookmark_properties (GtkAction *action, for (l = selection; l; l = l->next) { EphyNode *node = l->data; - show_properties_dialog (editor, node); + + ephy_bookmarks_ui_show_bookmark (node); } g_list_free (selection); diff --git a/src/bookmarks/ephy-bookmarks-ui.c b/src/bookmarks/ephy-bookmarks-ui.c index ae801ff36..e60761913 100644 --- a/src/bookmarks/ephy-bookmarks-ui.c +++ b/src/bookmarks/ephy-bookmarks-ui.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2005 Peter Harvey + * Copyright (C) 2006 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 @@ -39,10 +40,12 @@ #include "ephy-debug.h" #include "ephy-file-helpers.h" #include "ephy-gui.h" +#include "ephy-stock-icons.h" #include "egg-editable-toolbar.h" #include <string.h> #include <glib/gi18n.h> +#include <gtk/gtkmain.h> #define BM_WINDOW_DATA_KEY "bookmarks-window-data" @@ -52,12 +55,15 @@ typedef struct guint toolbar_menu; } BookmarksWindowData; - +enum +{ + RESPONSE_SHOW_PROPERTIES = 1, + RESPONSE_NEW_BOOKMARK = 2 +}; static GString * bookmarks_menu_string = 0; static GHashTable *properties_dialogs = 0; - static GtkAction * find_action (GtkUIManager *manager, const char *name) { @@ -99,35 +105,51 @@ activate_bookmarks_menu (GtkAction *action, EphyWindow *window) } static void -activate_bookmark_properties (GtkAction *action, EggEditableToolbar *etoolbar) +activate_bookmark_properties (GtkAction *action, + EggEditableToolbar *etoolbar) { - GtkWidget *widget = gtk_widget_get_ancestor - (egg_editable_toolbar_get_selected (etoolbar), GTK_TYPE_TOOL_ITEM); - GtkAction *baction = widget ? g_object_get_data (G_OBJECT (widget), "gtk-action") : NULL; + GtkAction *baction; + GtkWidget *widget; + + widget = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), + GTK_TYPE_TOOL_ITEM); + baction = widget ? g_object_get_data (G_OBJECT (widget), "gtk-action") : NULL; g_return_if_fail (EPHY_IS_BOOKMARK_ACTION (baction)); - ephy_bookmarks_ui_show_bookmark (GTK_WIDGET (etoolbar), - ephy_bookmark_action_get_bookmark - (EPHY_BOOKMARK_ACTION (baction))); + + ephy_bookmarks_ui_show_bookmark (ephy_bookmark_action_get_bookmark + (EPHY_BOOKMARK_ACTION (baction))); } static void -activate_bookmark_open_tab (GtkAction *action, EggEditableToolbar *etoolbar) +activate_bookmark_open_tab (GtkAction *action, + EggEditableToolbar *etoolbar) { - GtkWidget *widget = gtk_widget_get_ancestor - (egg_editable_toolbar_get_selected (etoolbar), GTK_TYPE_TOOL_ITEM); - GtkAction *baction = widget ? g_object_get_data (G_OBJECT (widget), "gtk-action") : NULL; + GtkAction *baction; + GtkWidget *widget; + + widget = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), + GTK_TYPE_TOOL_ITEM); + baction = widget ? g_object_get_data (G_OBJECT (widget), "gtk-action") : NULL; g_return_if_fail (EPHY_IS_BOOKMARK_ACTION (baction)); - ephy_bookmark_action_activate (EPHY_BOOKMARK_ACTION (baction), widget, EPHY_LINK_NEW_TAB); + + ephy_bookmark_action_activate (EPHY_BOOKMARK_ACTION (baction), widget, + EPHY_LINK_NEW_TAB); } static void -activate_bookmark_open_window (GtkAction *action, EggEditableToolbar *etoolbar) +activate_bookmark_open_window (GtkAction *action, + EggEditableToolbar *etoolbar) { - GtkWidget *widget = gtk_widget_get_ancestor - (egg_editable_toolbar_get_selected (etoolbar), GTK_TYPE_TOOL_ITEM); - GtkAction *baction = widget ? g_object_get_data (G_OBJECT (widget), "gtk-action") : NULL; + GtkAction *baction; + GtkWidget *widget; + + widget = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), + GTK_TYPE_TOOL_ITEM); + baction = widget ? g_object_get_data (G_OBJECT (widget), "gtk-action") : NULL; g_return_if_fail (EPHY_IS_BOOKMARK_ACTION (baction)); - ephy_bookmark_action_activate (EPHY_BOOKMARK_ACTION (baction), widget, EPHY_LINK_NEW_WINDOW); + + ephy_bookmark_action_activate (EPHY_BOOKMARK_ACTION (baction), widget, + EPHY_LINK_NEW_WINDOW); } static void @@ -135,49 +157,67 @@ selected_bookmark_action (EggEditableToolbar *etoolbar, GParamSpec *pspec, GtkAction *action) { - GtkWidget *widget = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), - GTK_TYPE_TOOL_ITEM); - GtkAction *baction = widget ? g_object_get_data (G_OBJECT (widget), "gtk-action") : NULL; + GtkAction *baction; + GtkWidget *widget; + + widget = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), + GTK_TYPE_TOOL_ITEM); + baction = widget ? g_object_get_data (G_OBJECT (widget), "gtk-action") : NULL; + gtk_action_set_visible (action, EPHY_IS_BOOKMARK_ACTION (baction)); } static void erase_bookmarks_menu (EphyWindow *window) { - BookmarksWindowData *data = g_object_get_data (G_OBJECT (window), BM_WINDOW_DATA_KEY); - GtkUIManager *manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (window)); - + BookmarksWindowData *data; + GtkUIManager *manager; + + manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (window)); + data = g_object_get_data (G_OBJECT (window), BM_WINDOW_DATA_KEY); + if (data != NULL && data->bookmarks_menu != 0) { gtk_ui_manager_remove_ui (manager, data->bookmarks_menu); data->bookmarks_menu = 0; } + g_string_truncate (bookmarks_menu_string, 0); } static void -tree_changed_cb (EphyBookmarks *bookmarks, EphyWindow *window) +tree_changed_cb (EphyBookmarks *bookmarks, + EphyWindow *window) { erase_bookmarks_menu (window); } static void -node_added_cb (EphyNode *parent, EphyNode *child, EphyWindow *window) +node_added_cb (EphyNode *parent, + EphyNode *child, + EphyWindow *window) { erase_bookmarks_menu (window); } static void -node_changed_cb (EphyNode *parent, EphyNode *child, guint property_id, EphyWindow *window) +node_changed_cb (EphyNode *parent, + EphyNode *child, + guint property_id, + EphyWindow *window) { - if (property_id == EPHY_NODE_KEYWORD_PROP_NAME || property_id == EPHY_NODE_BMK_PROP_TITLE) + if (property_id == EPHY_NODE_KEYWORD_PROP_NAME || + property_id == EPHY_NODE_BMK_PROP_TITLE) { erase_bookmarks_menu (window); } } static void -node_removed_cb (EphyNode *parent, EphyNode *child, guint index, EphyWindow *window) +node_removed_cb (EphyNode *parent, + EphyNode *child, + guint index, + EphyWindow *window) { erase_bookmarks_menu (window); } @@ -185,47 +225,51 @@ node_removed_cb (EphyNode *parent, EphyNode *child, guint index, EphyWindow *win void ephy_bookmarks_ui_attach_window (EphyWindow *window) { - EphyBookmarks *eb = ephy_shell_get_bookmarks (ephy_shell); - EphyNode *bookmarks = ephy_bookmarks_get_bookmarks (eb); - EphyNode *topics = ephy_bookmarks_get_keywords (eb); - - BookmarksWindowData *data = g_object_get_data (G_OBJECT (window), BM_WINDOW_DATA_KEY); - GtkUIManager *manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (window)); - EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (ephy_window_get_toolbar (window)); + EphyBookmarks *eb; + EphyNode *bookmarks; + EphyNode *topics; + BookmarksWindowData *data; + GtkUIManager *manager; + EggEditableToolbar *etoolbar; GtkActionGroup *actions; GtkAction *action; - g_return_if_fail (data == 0); + eb = ephy_shell_get_bookmarks (ephy_shell); + bookmarks = ephy_bookmarks_get_bookmarks (eb); + topics = ephy_bookmarks_get_keywords (eb); + data = g_object_get_data (G_OBJECT (window), BM_WINDOW_DATA_KEY); + g_return_if_fail (data == NULL); + + manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (window)); + etoolbar = EGG_EDITABLE_TOOLBAR (ephy_window_get_toolbar (window)); + data = g_new0 (BookmarksWindowData, 1); g_object_set_data_full (G_OBJECT (window), BM_WINDOW_DATA_KEY, data, g_free); - /* Create the self-maintaining action groups for bookmarks and topics */ actions = ephy_bookmark_group_new (bookmarks); - gtk_ui_manager_insert_action_group (manager, actions, 0); + gtk_ui_manager_insert_action_group (manager, actions, -1); g_signal_connect_object (G_OBJECT (actions), "open-link", G_CALLBACK (ephy_link_open), G_OBJECT (window), G_CONNECT_SWAPPED | G_CONNECT_AFTER); g_object_unref (G_OBJECT (actions)); actions = ephy_topic_group_new (topics, manager); - gtk_ui_manager_insert_action_group (manager, actions, 0); + gtk_ui_manager_insert_action_group (manager, actions, -1); g_object_unref (G_OBJECT (actions)); actions = ephy_open_tabs_group_new (topics); - gtk_ui_manager_insert_action_group (manager, actions, 0); - g_signal_connect_object (G_OBJECT (actions), "open-link", + gtk_ui_manager_insert_action_group (manager, actions, -1); + g_signal_connect_object (actions, "open-link", G_CALLBACK (ephy_link_open), G_OBJECT (window), G_CONNECT_SWAPPED | G_CONNECT_AFTER); - g_object_unref (G_OBJECT (actions)); - + g_object_unref (actions); /* Create and add an action group specifically foor bookmarks on the toolbar */ actions = gtk_action_group_new ("BookmarkToolbarActions"); gtk_ui_manager_insert_action_group (manager, actions, 0); - g_object_unref (G_OBJECT (actions)); + g_object_unref (actions); - /* Add factory actions */ action = ephy_topic_factory_action_new ("AddTopicToToolbar"); gtk_action_group_add_action (actions, action); @@ -234,48 +278,48 @@ ephy_bookmarks_ui_attach_window (EphyWindow *window) action = ephy_bookmark_factory_action_new ("AddBookmarkToToolbar"); gtk_action_group_add_action (actions, action); g_object_unref (action); - - + /* Add the dynamic 'related topic' action */ action = ephy_related_action_new (EPHY_LINK (window), manager, "RelatedTopic"); gtk_action_group_add_action (actions, action); g_object_unref (action); - - + /* Add popup menu actions that are specific to the bookmark widgets */ action = gtk_action_new ("ToolbarBookmarkProperties", _("Properties"), _("Show properties for this bookmark"), GTK_STOCK_PROPERTIES); - g_signal_connect_object (G_OBJECT (action), "activate", + g_signal_connect_object (action, "activate", G_CALLBACK (activate_bookmark_properties), G_OBJECT (etoolbar), 0); - g_signal_connect_object (G_OBJECT (etoolbar), "notify::selected", + g_signal_connect_object (etoolbar, "notify::selected", G_CALLBACK (selected_bookmark_action), G_OBJECT (action), 0); gtk_action_group_add_action (actions, action); g_object_unref (action); - + + /* FIXME ngettext */ action = gtk_action_new ("ToolbarBookmarkOpenInTab", _("Open in New _Tab"), _("Open this bookmark in a new tab"), NULL); - g_signal_connect_object (G_OBJECT (action), "activate", + g_signal_connect_object (action, "activate", G_CALLBACK (activate_bookmark_open_tab), G_OBJECT (etoolbar), 0); - g_signal_connect_object (G_OBJECT (etoolbar), "notify::selected", + g_signal_connect_object (etoolbar, "notify::selected", G_CALLBACK (selected_bookmark_action), G_OBJECT (action), 0); gtk_action_group_add_action (actions, action); g_object_unref (action); - + + /* FIXME ngettext */ action = gtk_action_new ("ToolbarBookmarkOpenInWindow", _("Open in New _Window"), _("Open this bookmark in a new window"), NULL); - g_signal_connect_object (G_OBJECT (action), "activate", + g_signal_connect_object (action, "activate", G_CALLBACK (activate_bookmark_open_window), G_OBJECT (etoolbar), 0); - g_signal_connect_object (G_OBJECT (etoolbar), "notify::selected", + g_signal_connect_object (etoolbar, "notify::selected", G_CALLBACK (selected_bookmark_action), G_OBJECT (action), 0); gtk_action_group_add_action (actions, action); g_object_unref (action); - + data->toolbar_menu = gtk_ui_manager_add_ui_from_string (manager, "<popup name=\"ToolbarPopup\">" "<separator/>" @@ -285,7 +329,6 @@ ephy_bookmarks_ui_attach_window (EphyWindow *window) "<menuitem action=\"ToolbarBookmarkProperties\"/>" "</popup>", -1, NULL); - /* Add signal handlers for the bookmark database */ ephy_node_signal_connect_object (bookmarks, EPHY_NODE_CHILD_ADDED, (EphyNodeCallback)node_added_cb, @@ -293,14 +336,14 @@ ephy_bookmarks_ui_attach_window (EphyWindow *window) ephy_node_signal_connect_object (topics, EPHY_NODE_CHILD_ADDED, (EphyNodeCallback)node_added_cb, G_OBJECT (window)); - + ephy_node_signal_connect_object (bookmarks, EPHY_NODE_CHILD_REMOVED, (EphyNodeCallback)node_removed_cb, G_OBJECT (window)); ephy_node_signal_connect_object (topics, EPHY_NODE_CHILD_REMOVED, (EphyNodeCallback)node_removed_cb, G_OBJECT (window)); - + ephy_node_signal_connect_object (bookmarks, EPHY_NODE_CHILD_CHANGED, (EphyNodeCallback)node_changed_cb, G_OBJECT (window)); @@ -308,15 +351,14 @@ ephy_bookmarks_ui_attach_window (EphyWindow *window) (EphyNodeCallback)node_changed_cb, G_OBJECT (window)); - g_signal_connect_object (G_OBJECT (eb), "tree_changed", + g_signal_connect_object (eb, "tree_changed", G_CALLBACK (tree_changed_cb), G_OBJECT (window), 0); - - + /* Setup empty menu strings and add signal handlers to build the menus on demand */ if (!bookmarks_menu_string) bookmarks_menu_string = g_string_new (""); action = find_action (manager, "Bookmarks"); - g_signal_connect_object (G_OBJECT (action), "activate", + g_signal_connect_object (action, "activate", G_CALLBACK (activate_bookmarks_menu), G_OBJECT (window), 0); } @@ -370,35 +412,26 @@ static void properties_dialog_destroy_cb (EphyBookmarkProperties *dialog, gpointer user_data) { - g_hash_table_remove (properties_dialogs, ephy_bookmark_properties_get_node (dialog)); + g_hash_table_remove (properties_dialogs, + ephy_bookmark_properties_get_node (dialog)); } static void -add_bookmark (GtkWidget *parent, - const char *location, +add_bookmark (const char *location, const char *title) { - GtkWidget *dialog; EphyBookmarks *bookmarks; EphyNode *bookmark; - bookmarks = ephy_shell_get_bookmarks (ephy_shell); + bookmarks = ephy_shell_get_bookmarks (ephy_shell_get_default ()); bookmark = ephy_bookmarks_add (bookmarks, title, location); if (properties_dialogs == 0) { properties_dialogs = g_hash_table_new (g_direct_hash, g_direct_equal); } - - dialog = ephy_bookmark_properties_new (bookmarks, bookmark, TRUE); - if (parent != NULL) gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent)); - - g_signal_connect (dialog, "destroy", - G_CALLBACK (properties_dialog_destroy_cb), bookmarks); - g_hash_table_insert (properties_dialogs, - bookmark, dialog); - - gtk_window_present (GTK_WINDOW (dialog)); + + ephy_bookmarks_ui_show_bookmark (bookmark); } static void @@ -406,18 +439,19 @@ duplicate_bookmark_response_cb (GtkWidget *dialog, int response, EphyNode *node) { - GtkWidget *parent; - parent = GTK_WIDGET (gtk_window_get_transient_for (GTK_WINDOW (dialog))); - - if (response == GTK_RESPONSE_ACCEPT) + if (response == RESPONSE_SHOW_PROPERTIES) { - ephy_bookmarks_ui_show_bookmark (parent, node); + ephy_bookmarks_ui_show_bookmark (node); } - else if (response == GTK_RESPONSE_REJECT) + else if (response == RESPONSE_NEW_BOOKMARK) { - const char *location = g_object_get_data (G_OBJECT (dialog), "location"); - const char *title = g_object_get_data (G_OBJECT (dialog), "title"); - add_bookmark (parent, location, title); + const char *location; + const char *title; + + location = g_object_get_data (G_OBJECT (dialog), "location"); + title = g_object_get_data (G_OBJECT (dialog), "title"); + + add_bookmark (location, title); } gtk_widget_destroy (dialog); @@ -444,60 +478,64 @@ ephy_bookmarks_ui_add_bookmark (GtkWidget *parent, if (bookmark != NULL) { GtkWidget *button, *dialog; - char *str; - - dialog = gtk_message_dialog_new_with_markup - (GTK_WINDOW (parent), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, GTK_BUTTONS_NONE, - "<span weight=\"bold\" size=\"larger\">%s</span>", - _("Bookmark exists")); - - str = g_strdup_printf - (_("You already have a bookmark titled “%s” for this page."), - "<span weight=\"bold\">%s</span>"); - - gtk_message_dialog_format_secondary_markup - (GTK_MESSAGE_DIALOG (dialog), str, - ephy_node_get_property_string (bookmark, EPHY_NODE_BMK_PROP_TITLE)); - - g_free (str); + + dialog = gtk_message_dialog_new + (GTK_WINDOW (parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, GTK_BUTTONS_NONE, + _("Bookmark exists")); + + gtk_message_dialog_format_secondary_text + (GTK_MESSAGE_DIALOG (dialog), + _("You already have a bookmark titled “%s” for this page."), + ephy_node_get_property_string (bookmark, EPHY_NODE_BMK_PROP_TITLE)); + + if (parent != NULL) + { + gtk_window_group_add_window (ephy_gui_ensure_window_group (GTK_WINDOW (parent)), + GTK_WINDOW (dialog)); + } button = gtk_dialog_add_button (GTK_DIALOG (dialog), - _("_Create New"), GTK_RESPONSE_REJECT); + _("_Create New"), + RESPONSE_NEW_BOOKMARK); gtk_button_set_image (GTK_BUTTON (button), gtk_image_new_from_stock - (GTK_STOCK_NEW, GTK_ICON_SIZE_BUTTON)); + (STOCK_BOOKMARK, GTK_ICON_SIZE_BUTTON)); button = gtk_dialog_add_button (GTK_DIALOG (dialog), - _("_View Properties"), GTK_RESPONSE_ACCEPT); + _("_View Properties"), + RESPONSE_SHOW_PROPERTIES); gtk_button_set_image (GTK_BUTTON (button), gtk_image_new_from_stock (GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_BUTTON)); gtk_dialog_add_button (GTK_DIALOG (dialog), - GTK_STOCK_OK, GTK_RESPONSE_OK); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); + GTK_STOCK_OK, + GTK_RESPONSE_OK); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT); gtk_window_set_title (GTK_WINDOW (dialog), _("Bookmark Exists")); gtk_window_set_icon_name (GTK_WINDOW (dialog), "web-browser"); - g_object_set_data_full (G_OBJECT (dialog), "location", g_strdup (location), g_free); - g_object_set_data_full (G_OBJECT (dialog), "title", g_strdup (title), g_free); + g_object_set_data_full (G_OBJECT (dialog), "location", + g_strdup (location), g_free); + g_object_set_data_full (G_OBJECT (dialog), "title", + g_strdup (title), g_free); - g_signal_connect (G_OBJECT (dialog), - "response", - G_CALLBACK (duplicate_bookmark_response_cb), - bookmark); + g_signal_connect (dialog, "response", + G_CALLBACK (duplicate_bookmark_response_cb), bookmark); ephy_node_signal_connect_object (bookmark, EPHY_NODE_DESTROY, (EphyNodeCallback) dialog_node_destroy_cb, G_OBJECT (dialog)); - - gtk_window_present (GTK_WINDOW (dialog)); + + gtk_window_present_with_time (GTK_WINDOW (dialog), + gtk_get_current_event_time ()); } else { - add_bookmark (parent, location, title); + add_bookmark (location, title); } } @@ -530,19 +568,15 @@ ephy_bookmarks_ui_find_topic (const char *name) } static void -add_topic_changed_cb (GtkEditable *editable, +add_topic_changed_cb (GtkEntry *entry, GtkDialog *dialog) { - const char *title = gtk_entry_get_text (GTK_ENTRY (editable)); - gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_OK, *title != 0); -} + const char *title; -static void -duplicate_topic_response_cb (GtkWidget *dialog, - int response, - EphyNode *node) -{ - gtk_widget_destroy (dialog); + title = gtk_entry_get_text (entry); + + gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_ACCEPT, + title[0] != '\0'); } static void @@ -550,48 +584,53 @@ add_topic_response_cb (GtkWidget *dialog, int response, EphyNode *bookmark) { - if (response == GTK_RESPONSE_OK) - { - EphyBookmarks *bookmarks; - GtkEntry *entry; - EphyNode *topic; - const char *name; - - entry = g_object_get_data (G_OBJECT (dialog), "name"); - name = gtk_entry_get_text (entry); - g_return_if_fail (name && *name); - - topic = ephy_bookmarks_ui_find_topic (name); - if (topic != NULL) - { - GtkWidget *message; - char *str = g_strdup_printf - (_("You already have a topic named “%s”.\nPlease use a new topic name."), - "<span weight=\"bold\">%s</span>"); - - message = gtk_message_dialog_new_with_markup - (GTK_WINDOW (dialog), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, str, - ephy_node_get_property_string (topic, EPHY_NODE_KEYWORD_PROP_NAME)); - - g_free (str); - - g_signal_connect (message, "response", - G_CALLBACK (duplicate_topic_response_cb), - bookmark); + EphyBookmarks *bookmarks; + GtkEntry *entry; + EphyNode *topic; + const char *name; + + if (response != GTK_RESPONSE_ACCEPT) + { + gtk_widget_destroy (dialog); + return; + } + + entry = g_object_get_data (G_OBJECT (dialog), "name"); + name = gtk_entry_get_text (entry); + g_return_if_fail (name != NULL && name[0] != '\0'); - gtk_window_group_add_window - (ephy_gui_ensure_window_group (GTK_WINDOW (dialog)), GTK_WINDOW (message)); - gtk_window_present (GTK_WINDOW (message)); - - return; - } - + topic = ephy_bookmarks_ui_find_topic (name); + if (topic != NULL) + { + GtkWidget *message; + + message = gtk_message_dialog_new + (GTK_WINDOW (dialog), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, + _("You already have a topic named “%s”"), + ephy_node_get_property_string (topic, EPHY_NODE_KEYWORD_PROP_NAME)); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message), + "%s", + _("Please use a different topic name.")); + + g_signal_connect (message, "response", + G_CALLBACK (gtk_widget_destroy), NULL); + + gtk_window_group_add_window + (ephy_gui_ensure_window_group (GTK_WINDOW (dialog)), + GTK_WINDOW (message)); + + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + gtk_window_present_with_time (GTK_WINDOW (message), + gtk_get_current_event_time ()); - bookmarks = ephy_shell_get_bookmarks (ephy_shell); - topic = ephy_bookmarks_add_keyword (bookmarks, name); - ephy_bookmarks_set_keyword (bookmarks, topic, bookmark); + return; } + + bookmarks = ephy_shell_get_bookmarks (ephy_shell); + topic = ephy_bookmarks_add_keyword (bookmarks, name); + ephy_bookmarks_set_keyword (bookmarks, topic, bookmark); gtk_widget_destroy (dialog); } @@ -604,28 +643,31 @@ ephy_bookmarks_ui_add_topic (GtkWidget *parent, GtkContainer *container; GList *children; + g_assert (parent != NULL); + if (bookmark != NULL) { - char *str = g_strdup_printf - ("<span weight=\"bold\" size=\"larger\">%s</span>", _("New topic for “%s”")); - - dialog = gtk_message_dialog_new_with_markup - (GTK_WINDOW (parent), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, - str, ephy_node_get_property_string (bookmark, EPHY_NODE_BMK_PROP_TITLE)); - - g_free (str); + dialog = gtk_message_dialog_new + (GTK_WINDOW (parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + _("New topic for “%s”"), + ephy_node_get_property_string (bookmark, EPHY_NODE_BMK_PROP_TITLE)); } else { - dialog = gtk_message_dialog_new_with_markup - (GTK_WINDOW (parent), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, - "<span weight=\"bold\" size=\"larger\">%s</span>", _("New topic")); + dialog = gtk_message_dialog_new + (GTK_WINDOW (parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + _("New topic")); } gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), - _("Enter a unique name for the topic.")); + "%s", + _("Enter a unique name for the topic.")); hbox = gtk_hbox_new (FALSE, 12); gtk_widget_show (hbox); @@ -639,58 +681,58 @@ ephy_bookmarks_ui_add_topic (GtkWidget *parent, gtk_widget_show (label); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); /* Get the hbox which is the first child of the main vbox */ children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox)); container = GTK_CONTAINER (children->data); g_list_free (children); - + /* Get the vbox which is the second child of the hbox */ children = gtk_container_get_children (container); container = GTK_CONTAINER (children->next->data); g_list_free (children); - - gtk_container_add (container, hbox); + gtk_box_pack_start (GTK_BOX (container), hbox, FALSE, FALSE, 0); + g_object_set_data (G_OBJECT (dialog), "name", entry); - + gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); gtk_dialog_add_button (GTK_DIALOG (dialog), - _("Create"), GTK_RESPONSE_OK); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); - + _("Create"), GTK_RESPONSE_ACCEPT); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT); + gtk_window_set_title (GTK_WINDOW (dialog), _("New Topic")); gtk_window_set_icon_name (GTK_WINDOW (dialog), "web-browser"); - - g_signal_connect (G_OBJECT (dialog), - "response", - G_CALLBACK (add_topic_response_cb), - bookmark); - - g_signal_connect (G_OBJECT (entry), - "changed", - G_CALLBACK (add_topic_changed_cb), - dialog); - - add_topic_changed_cb (GTK_EDITABLE (entry), GTK_DIALOG (dialog)); - + + g_signal_connect (dialog, "response", + G_CALLBACK (add_topic_response_cb), bookmark); + + add_topic_changed_cb (GTK_ENTRY (entry), GTK_DIALOG (dialog)); + g_signal_connect (entry, "changed", + G_CALLBACK (add_topic_changed_cb), dialog); + ephy_node_signal_connect_object (bookmark, EPHY_NODE_DESTROY, (EphyNodeCallback) dialog_node_destroy_cb, G_OBJECT (dialog)); - + gtk_window_group_add_window - (ephy_gui_ensure_window_group (GTK_WINDOW (parent)), GTK_WINDOW (dialog)); - gtk_window_present (GTK_WINDOW (dialog)); + (ephy_gui_ensure_window_group (GTK_WINDOW (parent)), + GTK_WINDOW (dialog)); + + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + gtk_window_present_with_time (GTK_WINDOW (dialog), + gtk_get_current_event_time ()); } void -ephy_bookmarks_ui_show_bookmark (GtkWidget *parent, - EphyNode *bookmark) +ephy_bookmarks_ui_show_bookmark (EphyNode *bookmark) { - EphyBookmarks *bookmarks = ephy_shell_get_bookmarks (ephy_shell); + EphyBookmarks *bookmarks; GtkWidget *dialog; + bookmarks = ephy_shell_get_bookmarks (ephy_shell_get_default ()); + g_return_if_fail (EPHY_IS_BOOKMARKS (bookmarks)); g_return_if_fail (EPHY_IS_NODE (bookmark)); @@ -711,9 +753,8 @@ ephy_bookmarks_ui_show_bookmark (GtkWidget *parent, bookmark, dialog); } - parent = gtk_widget_get_ancestor (parent, GTK_TYPE_WINDOW); - if (parent != NULL) gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent)); - gtk_window_present (GTK_WINDOW (dialog)); + gtk_window_present_with_time (GTK_WINDOW (dialog), + gtk_get_current_event_time ()); } /* Below this line we have functions relating to toolbar code */ diff --git a/src/bookmarks/ephy-bookmarks-ui.h b/src/bookmarks/ephy-bookmarks-ui.h index e4e1d854d..065356712 100644 --- a/src/bookmarks/ephy-bookmarks-ui.h +++ b/src/bookmarks/ephy-bookmarks-ui.h @@ -37,7 +37,6 @@ void ephy_bookmarks_ui_add_bookmark (GtkWidget *parent, void ephy_bookmarks_ui_add_topic (GtkWidget *parent, EphyNode *bookmark); -void ephy_bookmarks_ui_show_bookmark (GtkWidget *parent, - EphyNode *bookmark); +void ephy_bookmarks_ui_show_bookmark (EphyNode *bookmark); #endif |