diff options
author | Peter Harvey <peter.a.harvey@gmail.com> | 2006-02-04 17:26:09 +0800 |
---|---|---|
committer | Peter Anthony Harvey <paharvey@src.gnome.org> | 2006-02-04 17:26:09 +0800 |
commit | be7c992ff6b3a05d6facf24e42826fe14a94ad89 (patch) | |
tree | 04d249c803c08eb13a25e67493d04782a262eb25 /src | |
parent | f0a9cca06cffa42a88ef20f80004ed99609efee1 (diff) | |
download | gsoc2013-epiphany-be7c992ff6b3a05d6facf24e42826fe14a94ad89.tar gsoc2013-epiphany-be7c992ff6b3a05d6facf24e42826fe14a94ad89.tar.gz gsoc2013-epiphany-be7c992ff6b3a05d6facf24e42826fe14a94ad89.tar.bz2 gsoc2013-epiphany-be7c992ff6b3a05d6facf24e42826fe14a94ad89.tar.lz gsoc2013-epiphany-be7c992ff6b3a05d6facf24e42826fe14a94ad89.tar.xz gsoc2013-epiphany-be7c992ff6b3a05d6facf24e42826fe14a94ad89.tar.zst gsoc2013-epiphany-be7c992ff6b3a05d6facf24e42826fe14a94ad89.zip |
src/bookmarks/ephy-bookmark-properties.c src/bookmarks/ephy-bookmarks-ui.c
2006-02-04 Peter Harvey <peter.a.harvey@gmail.com>
* src/bookmarks/ephy-bookmark-properties.c
* src/bookmarks/ephy-bookmarks-ui.c
* src/bookmarks/ephy-bookmarks-ui.h
* src/ephy-history-window.c
* src/popup-commands.c
* src/window-commands.c
Restore transient status to the properties dialog when
creating a new bookmark. Leave the topics entry sensitive,
and store the expanded state of the list. Make the similar
button a toggle button. Removed unused function to add topic.
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks/ephy-bookmark-properties.c | 122 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-ui.c | 217 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-ui.h | 6 | ||||
-rw-r--r-- | src/ephy-history-window.c | 2 | ||||
-rw-r--r-- | src/popup-commands.c | 2 | ||||
-rw-r--r-- | src/window-commands.c | 3 |
6 files changed, 115 insertions, 237 deletions
diff --git a/src/bookmarks/ephy-bookmark-properties.c b/src/bookmarks/ephy-bookmark-properties.c index c4a46a9cd..9182462ab 100644 --- a/src/bookmarks/ephy-bookmark-properties.c +++ b/src/bookmarks/ephy-bookmark-properties.c @@ -27,6 +27,7 @@ #include "ephy-bookmarks-ui.h" #include "ephy-topics-entry.h" #include "ephy-topics-palette.h" +#include "ephy-node-common.h" #include "ephy-stock-icons.h" #include "ephy-debug.h" #include "ephy-shell.h" @@ -174,13 +175,13 @@ ephy_bookmark_properties_set_bookmark (EphyBookmarkProperties *properties, } static void -activate_merge_cb (GtkMenuItem *item, - EphyBookmarkProperties *properties) +similar_merge_cb (GtkMenuItem *item, + EphyBookmarkProperties *properties) { EphyBookmarkPropertiesPrivate *priv = properties->priv; GPtrArray *topics; EphyNode *node, *topic; - gint i, j; + gint i, j, priority; GPtrArray *identical = g_ptr_array_new (); @@ -196,6 +197,11 @@ activate_merge_cb (GtkMenuItem *item, for (j = 0; j < topics->len; j++) { topic = g_ptr_array_index (topics, j); + + priority = ephy_node_get_property_int + (topic, EPHY_NODE_KEYWORD_PROP_PRIORITY); + if (priority != EPHY_NODE_NORMAL_PRIORITY) + continue; if (ephy_node_has_child (topic, node)) { @@ -212,25 +218,39 @@ activate_merge_cb (GtkMenuItem *item, } static void -activate_show_cb (GtkMenuItem *item, - EphyNode *node) +similar_show_cb (GtkMenuItem *item, + EphyNode *node) { ephy_bookmarks_ui_show_bookmark (node); } static void -show_duplicate_cb (GtkButton *button, - EphyBookmarkProperties *properties) +similar_deactivate_cb (GtkMenuShell *ms, + GtkWidget *button) +{ + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE); + gtk_button_released (GTK_BUTTON (button)); +} + +static void +similar_toggled_cb (GtkWidget *button, + EphyBookmarkProperties *properties) { EphyBookmarkPropertiesPrivate *priv = properties->priv; EphyNode *node; GtkMenuShell *menu; GtkWidget *item, *image; + GPtrArray *identical, *similar; char *label; gint i; - GPtrArray *identical = g_ptr_array_new (); - GPtrArray *similar = g_ptr_array_new (); + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) + { + return; + } + + identical = g_ptr_array_new (); + similar = g_ptr_array_new (); ephy_bookmarks_get_similar (priv->bookmarks, priv->bookmark, @@ -251,7 +271,7 @@ show_duplicate_cb (GtkButton *button, g_free (label); image = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); - g_signal_connect (item, "activate", G_CALLBACK (activate_merge_cb), properties); + g_signal_connect (item, "activate", G_CALLBACK (similar_merge_cb), properties); gtk_widget_show (image); gtk_widget_show (item); gtk_menu_shell_append (menu, item); @@ -267,7 +287,7 @@ show_duplicate_cb (GtkButton *button, ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_TITLE)); item = gtk_image_menu_item_new_with_label (label); g_free (label); - g_signal_connect (item, "activate", G_CALLBACK (activate_show_cb), node); + g_signal_connect (item, "activate", G_CALLBACK (similar_show_cb), node); gtk_widget_show (item); gtk_menu_shell_append (menu, item); } @@ -289,21 +309,56 @@ show_duplicate_cb (GtkButton *button, ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_TITLE)); item = gtk_image_menu_item_new_with_label (label); g_free (label); - g_signal_connect (item, "activate", G_CALLBACK (activate_show_cb), node); + g_signal_connect (item, "activate", G_CALLBACK (similar_show_cb), node); gtk_widget_show (item); gtk_menu_shell_append (menu, item); } } + g_signal_connect_object (menu, "deactivate", + G_CALLBACK (similar_deactivate_cb), button, 0); + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, ephy_gui_menu_position_under_widget, button, - 0, gtk_get_current_event_time ()); + 1, gtk_get_current_event_time ()); } g_ptr_array_free (similar, TRUE); g_ptr_array_free (identical, TRUE); } +static gboolean +similar_release_cb (GtkWidget *button, + GdkEventButton *event, + EphyBookmarkProperties *properties) +{ + if (event->button == 1) + { + gtk_toggle_button_set_active + (GTK_TOGGLE_BUTTON (button), FALSE); + } + + return FALSE; +} + +static gboolean +similar_press_cb (GtkWidget *button, + GdkEventButton *event, + EphyBookmarkProperties *properties) +{ + if (event->button == 1) + { + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); + + return TRUE; + } + } + + return FALSE; +} + static void bookmark_properties_destroy_cb (GtkDialog *dialog, gpointer data) @@ -401,15 +456,14 @@ location_entry_changed_cb (GtkWidget *entry, } static void -toggled_cb (GtkToggleButton *button, - EphyBookmarkProperties *properties) +list_toggled_cb (GtkToggleButton *button, + EphyBookmarkProperties *properties) { EphyBookmarkPropertiesPrivate *priv = properties->priv; GdkGeometry geometry; if(gtk_toggle_button_get_active (button)) { - g_object_set (priv->entry, "sensitive", FALSE, NULL); gtk_widget_show (priv->palette); geometry.min_width = -1; @@ -420,7 +474,6 @@ toggled_cb (GtkToggleButton *button, } else { - g_object_set (priv->entry, "sensitive", TRUE, NULL); gtk_widget_hide (priv->palette); geometry.max_height = -1; @@ -431,7 +484,6 @@ toggled_cb (GtkToggleButton *button, } } - static void ephy_bookmark_properties_init (EphyBookmarkProperties *properties) { @@ -464,7 +516,6 @@ ephy_bookmark_properties_constructor (GType type, gtk_window_set_icon_name (window, STOCK_BOOKMARK); gtk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_NORMAL); - ephy_gui_ensure_window_group (window); g_signal_connect (properties, "response", G_CALLBACK (bookmark_properties_response_cb), properties); @@ -472,11 +523,14 @@ ephy_bookmark_properties_constructor (GType type, g_signal_connect (properties, "destroy", G_CALLBACK (bookmark_properties_destroy_cb), properties); - ephy_state_add_window (widget, - "bookmark_properties", - 290, 280, FALSE, - EPHY_STATE_WINDOW_SAVE_SIZE | - EPHY_STATE_WINDOW_SAVE_POSITION); + if (!priv->creating) + { + ephy_state_add_window (widget, + "bookmark_properties", + 290, 280, FALSE, + EPHY_STATE_WINDOW_SAVE_POSITION | + EPHY_STATE_WINDOW_SAVE_SIZE); + } update_window_title (properties); @@ -551,14 +605,16 @@ ephy_bookmark_properties_constructor (GType type, gtk_widget_show (widget); button = gtk_toggle_button_new_with_label (""); gtk_button_set_image (GTK_BUTTON (button), widget); - g_signal_connect (button, "toggled", G_CALLBACK (toggled_cb), properties); - toggled_cb (GTK_TOGGLE_BUTTON (button), properties); + ephy_state_add_toggle (button, "bookmark_properties_list", FALSE); + g_signal_connect (button, "toggled", G_CALLBACK (list_toggled_cb), properties); + list_toggled_cb (GTK_TOGGLE_BUTTON (button), properties); gtk_widget_show (button); gtk_table_attach (GTK_TABLE (table), button, 2, 3, 2, 3, GTK_FILL, GTK_FILL, 0, 0); - gtk_box_pack_start (GTK_BOX (dialog->vbox), table, TRUE, TRUE, 0); - - priv->warning = gtk_button_new (); + gtk_box_pack_start (GTK_BOX (dialog->vbox), table, TRUE, TRUE, 0); + + priv->warning = gtk_toggle_button_new (); + gtk_button_set_focus_on_click (GTK_BUTTON (priv->warning), FALSE); gtk_button_set_use_underline (GTK_BUTTON (priv->warning), TRUE); text = g_strdup_printf (ngettext("%d _Similar", "%d _Similar", 0), 0); gtk_button_set_label (GTK_BUTTON (priv->warning), text); @@ -568,8 +624,12 @@ ephy_bookmark_properties_constructor (GType type, gtk_button_set_image (GTK_BUTTON (priv->warning), widget); g_object_set (priv->warning, "sensitive", FALSE, NULL); gtk_widget_show (priv->warning); - g_signal_connect (priv->warning, "clicked", - G_CALLBACK(show_duplicate_cb), properties); + g_signal_connect (priv->warning, "toggled", + G_CALLBACK (similar_toggled_cb), properties); + g_signal_connect (priv->warning, "button-press-event", + G_CALLBACK (similar_press_cb), properties); + g_signal_connect (priv->warning, "button-release-event", + G_CALLBACK (similar_release_cb), properties); gtk_dialog_add_button (dialog, GTK_STOCK_HELP, diff --git a/src/bookmarks/ephy-bookmarks-ui.c b/src/bookmarks/ephy-bookmarks-ui.c index f560e1f56..199e8d5bc 100644 --- a/src/bookmarks/ephy-bookmarks-ui.c +++ b/src/bookmarks/ephy-bookmarks-ui.c @@ -418,7 +418,8 @@ properties_dialog_destroy_cb (EphyBookmarkProperties *dialog, } void -ephy_bookmarks_ui_add_bookmark (const char *location, +ephy_bookmarks_ui_add_bookmark (GtkWindow *parent, + const char *location, const char *title) { EphyBookmarks *bookmarks; @@ -434,7 +435,13 @@ ephy_bookmarks_ui_add_bookmark (const char *location, } dialog = ephy_bookmark_properties_new (bookmarks, bookmark, TRUE); - + + g_assert (parent != NULL); + + gtk_window_group_add_window (ephy_gui_ensure_window_group (parent), + GTK_WINDOW (dialog)); + gtk_window_set_transient_for (GTK_WINDOW (dialog), parent); + g_signal_connect (dialog, "destroy", G_CALLBACK (properties_dialog_destroy_cb), bookmark); g_hash_table_insert (properties_dialogs, @@ -444,199 +451,6 @@ ephy_bookmarks_ui_add_bookmark (const char *location, gtk_get_current_event_time ()); } -static EphyNode * -find_topic (const char *name) -{ - EphyBookmarks *bookmarks; - GPtrArray *children; - EphyNode *node; - int i; - - bookmarks = ephy_shell_get_bookmarks (ephy_shell); - node = ephy_bookmarks_get_keywords (bookmarks); - children = ephy_node_get_children (node); - node = NULL; - for (i = 0; i < children->len; i++) - { - const char *title; - - node = g_ptr_array_index (children, i); - title = ephy_node_get_property_string (node, EPHY_NODE_KEYWORD_PROP_NAME); - - if (g_utf8_collate (title, name) == 0) - { - return node; - } - } - - return NULL; -} - -static void -dialog_node_destroy_cb (EphyNode *node, - GtkWidget *dialog) -{ - gtk_widget_destroy (dialog); -} - -static void -add_topic_changed_cb (GtkEntry *entry, - GtkDialog *dialog) -{ - const char *title; - - title = gtk_entry_get_text (entry); - - gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_ACCEPT, - title[0] != '\0'); -} - -static void -add_topic_response_cb (GtkWidget *dialog, - int response, - EphyNode *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'); - - topic = 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 ()); - - 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); -} - -void -ephy_bookmarks_ui_add_topic (GtkWidget *parent, - EphyNode *bookmark) -{ - GtkWidget *dialog, *hbox, *entry, *label; - GtkContainer *container; - GList *children; - - g_assert (parent != NULL); - - if (bookmark != NULL) - { - 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 - (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), - "%s", - _("Enter a unique name for the topic.")); - - hbox = gtk_hbox_new (FALSE, 12); - gtk_widget_show (hbox); - - entry = gtk_entry_new (); - gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE); - gtk_widget_show (entry); - - label = gtk_label_new_with_mnemonic ("_Name:"); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry); - gtk_widget_show (label); - - gtk_box_pack_start (GTK_BOX (hbox), label, 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_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_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 (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_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 (EphyNode *bookmark) { @@ -658,7 +472,7 @@ ephy_bookmarks_ui_show_bookmark (EphyNode *bookmark) if (dialog == NULL) { dialog = ephy_bookmark_properties_new (bookmarks, bookmark, FALSE); - + g_signal_connect (dialog, "destroy", G_CALLBACK (properties_dialog_destroy_cb), bookmark); g_hash_table_insert (properties_dialogs, @@ -853,9 +667,14 @@ ephy_bookmarks_ui_attach_toolbar_model (EggToolbarsModel *model) (EphyNodeCallback)toolbar_node_removed_cb, G_OBJECT (model)); - egg_toolbars_model_set_n_avail (model, "AddTopicToToolbar", G_MAXINT); - egg_toolbars_model_set_n_avail (model, "AddBookmarkToToolbar", G_MAXINT); - egg_toolbars_model_set_n_avail (model, "RelatedTopic", 1); + egg_toolbars_model_set_name_flags (model, "AddTopicToToolbar", + EGG_TB_MODEL_NAME_KNOWN | + EGG_TB_MODEL_NAME_INFINITE); + egg_toolbars_model_set_name_flags (model, "AddBookmarkToToolbar", + EGG_TB_MODEL_NAME_KNOWN | + EGG_TB_MODEL_NAME_INFINITE); + egg_toolbars_model_set_name_flags (model, "RelatedTopic", + EGG_TB_MODEL_NAME_KNOWN); } diff --git a/src/bookmarks/ephy-bookmarks-ui.h b/src/bookmarks/ephy-bookmarks-ui.h index 71361eae8..5a2e33ee6 100644 --- a/src/bookmarks/ephy-bookmarks-ui.h +++ b/src/bookmarks/ephy-bookmarks-ui.h @@ -32,12 +32,10 @@ void ephy_bookmarks_ui_detach_window (EphyWindow *window); void ephy_bookmarks_ui_attach_toolbar_model (EggToolbarsModel *model); void ephy_bookmarks_ui_detach_toolbar_model (EggToolbarsModel *model); -void ephy_bookmarks_ui_add_bookmark (const char *location, +void ephy_bookmarks_ui_add_bookmark (GtkWindow *parent, + const char *location, const char *title); -void ephy_bookmarks_ui_add_topic (GtkWidget *parent, - EphyNode *bookmark); - void ephy_bookmarks_ui_show_bookmark (EphyNode *bookmark); #endif diff --git a/src/ephy-history-window.c b/src/ephy-history-window.c index 1dea398c6..7b36b261f 100644 --- a/src/ephy-history-window.c +++ b/src/ephy-history-window.c @@ -489,7 +489,7 @@ cmd_bookmark_link (GtkAction *action, location = ephy_node_get_property_string (node, EPHY_NODE_PAGE_PROP_LOCATION); title = ephy_node_get_property_string (node, EPHY_NODE_PAGE_PROP_TITLE); - ephy_bookmarks_ui_add_bookmark (location, title); + ephy_bookmarks_ui_add_bookmark (GTK_WINDOW (editor), location, title); } g_list_free (selection); diff --git a/src/popup-commands.c b/src/popup-commands.c index 03494ac2b..3b5f66d29 100644 --- a/src/popup-commands.c +++ b/src/popup-commands.c @@ -127,7 +127,7 @@ popup_cmd_bookmark_link (GtkAction *action, location = rel; } - ephy_bookmarks_ui_add_bookmark (location, title); + ephy_bookmarks_ui_add_bookmark (GTK_WINDOW (window), location, title); } static void diff --git a/src/window-commands.c b/src/window-commands.c index 96321d08b..453afbc50 100644 --- a/src/window-commands.c +++ b/src/window-commands.c @@ -241,7 +241,8 @@ window_cmd_file_bookmark_page (GtkAction *action, embed = ephy_window_get_active_embed (window); g_return_if_fail (embed != NULL); - ephy_bookmarks_ui_add_bookmark (ephy_tab_get_address (tab), + ephy_bookmarks_ui_add_bookmark (GTK_WINDOW (window), + ephy_tab_get_address (tab), ephy_tab_get_title (tab)); } |