From: Alexander Butenko Date: Fri, 25 Jun 2010 04:11:36 +0000 (-0400) Subject: Refactoring of bookmarks add functions X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08dab16bc22b755ea56d81fd06d2122398c3052b;p=midori Refactoring of bookmarks add functions --- diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 3becd48b..5b3fd372 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -956,20 +956,6 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser, gtk_widget_destroy (dialog); } -static void -midori_view_add_bookmark_cb (GtkWidget* menuitem, - const gchar* uri, - GtkWidget* view) -{ - KatzeItem* item; - MidoriBrowser* browser; - - item = katze_item_new (); - katze_item_set_uri (item, uri); - browser = midori_browser_get_for_widget (menuitem); - midori_browser_edit_bookmark_dialog_new (browser, item, TRUE, FALSE); -} - #if WEBKIT_CHECK_VERSION (1, 1, 3) static gboolean midori_browser_prepare_download (MidoriBrowser* browser, @@ -1601,8 +1587,6 @@ _midori_browser_add_tab (MidoriBrowser* browser, #endif "signal::search-text", midori_view_search_text_cb, browser, - "signal::add-bookmark", - midori_view_add_bookmark_cb, browser, "signal::save-as", midori_view_save_as_cb, browser, "signal::add-speed-dial", @@ -4269,14 +4253,10 @@ static void _action_bookmark_add_activate (GtkAction* action, MidoriBrowser* browser) { - midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, FALSE); -} - -static void -_action_bookmark_folder_add_activate (GtkAction* action, - MidoriBrowser* browser) -{ - midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, TRUE); + if (g_str_equal (gtk_action_get_name (action), "BookmarkFolderAdd")) + midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, TRUE); + else + midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, FALSE); } static void @@ -5276,7 +5256,7 @@ static const GtkActionEntry entries[] = N_("Add a new bookmark"), G_CALLBACK (_action_bookmark_add_activate) }, { "BookmarkFolderAdd", NULL, N_("Add a new _folder"), "", - N_("Add a new bookmark folder"), G_CALLBACK (_action_bookmark_folder_add_activate) }, + N_("Add a new bookmark folder"), G_CALLBACK (_action_bookmark_add_activate) }, { "BookmarksImport", NULL, N_("_Import bookmarks"), "", NULL, G_CALLBACK (_action_bookmarks_import_activate) }, diff --git a/midori/midori-view.c b/midori/midori-view.c index a889492f..a22daf14 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -397,6 +397,15 @@ midori_view_class_init (MidoriViewClass* class) G_TYPE_BOOLEAN, G_TYPE_STRING); + /** + * MidoriView::add-bookmark: + * @view: the object on which the signal is emitted + * @uri: the bookmark URI + * + * Emitted when a bookmark is added. + * + * Deprecated: 0.2.7 + */ signals[ADD_BOOKMARK] = g_signal_new ( "add-bookmark", G_TYPE_FROM_CLASS (class), diff --git a/panels/midori-bookmarks.c b/panels/midori-bookmarks.c index 225a73d1..b98724f4 100644 --- a/panels/midori-bookmarks.c +++ b/panels/midori-bookmarks.c @@ -309,7 +309,10 @@ midori_bookmarks_add_clicked_cb (GtkWidget* toolitem) { MidoriBrowser* browser = midori_browser_get_for_widget (toolitem); /* FIXME: Take selected folder into account */ - midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, FALSE); + if (g_str_equal (gtk_widget_get_name (toolitem), "BookmarkFolderAdd")) + midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, TRUE); + else + midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, FALSE); } static void @@ -365,15 +368,6 @@ midori_bookmarks_delete_clicked_cb (GtkWidget* toolitem, } } -static void -midori_bookmarks_folder_clicked_cb (GtkWidget* toolitem) -{ - MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (toolitem)); - /* FIXME: Take selected folder into account */ - midori_browser_edit_bookmark_dialog_new (browser, - NULL, TRUE, TRUE); -} - static void midori_bookmarks_cursor_or_row_changed_cb (GtkTreeView* treeview, MidoriBookmarks* bookmarks) @@ -419,6 +413,7 @@ midori_bookmarks_get_toolbar (MidoriViewable* viewable) gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_BUTTON); bookmarks->toolbar = toolbar; toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_ADD); + gtk_widget_set_name (GTK_WIDGET (toolitem), "BookmarkAdd"); gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem), _("Add a new bookmark")); gtk_tool_item_set_is_important (toolitem, TRUE); @@ -448,10 +443,11 @@ midori_bookmarks_get_toolbar (MidoriViewable* viewable) gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); gtk_widget_show (GTK_WIDGET (toolitem)); toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_DIRECTORY); + gtk_widget_set_name (GTK_WIDGET (toolitem), "BookmarkFolderAdd"); gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem), _("Add a new folder")); g_signal_connect (toolitem, "clicked", - G_CALLBACK (midori_bookmarks_folder_clicked_cb), bookmarks); + G_CALLBACK (midori_bookmarks_add_clicked_cb), bookmarks); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); gtk_widget_show (GTK_WIDGET (toolitem)); diff --git a/panels/midori-history.c b/panels/midori-history.c index 2eed597d..ba3fe3f7 100644 --- a/panels/midori-history.c +++ b/panels/midori-history.c @@ -336,14 +336,6 @@ midori_history_read_from_db (MidoriHistory* history, return FALSE; } -static void -midori_history_add_clicked_cb (GtkWidget* toolitem) -{ - MidoriBrowser* browser = midori_browser_get_for_widget (toolitem); - /* FIXME: Take selected folder into account */ - midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, FALSE); -} - static void midori_history_delete_clicked_cb (GtkWidget* toolitem, MidoriHistory* history) @@ -416,6 +408,21 @@ midori_history_cursor_or_row_changed_cb (GtkTreeView* treeview, } #endif +static void +midori_history_bookmark_add_cb (GtkWidget* menuitem, + MidoriHistory* history) +{ + KatzeItem* item; + + MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (history)); + item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem"); + + if (KATZE_IS_ITEM (item) && katze_item_get_uri (item)) + midori_browser_edit_bookmark_dialog_new (browser, item, TRUE, FALSE); + else + midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, FALSE); +} + static GtkWidget* midori_history_get_toolbar (MidoriViewable* viewable) { @@ -437,7 +444,7 @@ midori_history_get_toolbar (MidoriViewable* viewable) _("Bookmark the selected history item")); gtk_tool_item_set_is_important (toolitem, TRUE); g_signal_connect (toolitem, "clicked", - G_CALLBACK (midori_history_add_clicked_cb), history); + G_CALLBACK (midori_history_bookmark_add_cb), history); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); gtk_widget_show (GTK_WIDGET (toolitem)); history->bookmark = GTK_WIDGET (toolitem); @@ -718,22 +725,6 @@ midori_history_open_in_window_activate_cb (GtkWidget* menuitem, } } -static void -midori_history_bookmark_activate_cb (GtkWidget* menuitem, - MidoriHistory* history) -{ - KatzeItem* item; - const gchar* uri; - - item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem"); - uri = katze_item_get_uri (item); - - if (uri && *uri) - { - MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (history)); - midori_browser_edit_bookmark_dialog_new (browser, item, TRUE, FALSE); - } -} static void midori_history_popup (GtkWidget* widget, @@ -758,7 +749,7 @@ midori_history_popup (GtkWidget* widget, midori_history_popup_item (menu, STOCK_WINDOW_NEW, _("Open in New _Window"), item, midori_history_open_in_window_activate_cb, history); midori_history_popup_item (menu, STOCK_BOOKMARK_ADD, NULL, - item, midori_history_bookmark_activate_cb, history); + item, midori_history_bookmark_add_cb, history); } menuitem = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);