From: Christian Dywan Date: Sun, 13 Mar 2011 16:36:28 +0000 (+0100) Subject: Allow re-ordering of search engines X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2b5e82ce473fd6c4f5e418bdaed8975732a8350;p=midori Allow re-ordering of search engines --- diff --git a/midori/main.c b/midori/main.c index e4ca3984..5ce2c2bd 100644 --- a/midori/main.c +++ b/midori/main.c @@ -649,6 +649,15 @@ midori_search_engines_modify_cb (KatzeArray* array, g_free (config_file); } +static void +midori_search_engines_move_item_cb (KatzeArray* array, + gpointer item, + gint position, + KatzeArray* search_engines) +{ + midori_search_engines_modify_cb (array, item, search_engines); +} + static void midori_trash_add_item_cb (KatzeArray* trash, GObject* item) @@ -2282,6 +2291,8 @@ main (int argc, KATZE_ARRAY_FOREACH_ITEM (item, search_engines) g_signal_connect_after (item, "notify", G_CALLBACK (midori_search_engines_modify_cb), search_engines); + g_signal_connect_after (search_engines, "move-item", + G_CALLBACK (midori_search_engines_move_item_cb), search_engines); } } g_signal_connect_after (trash, "add-item", diff --git a/midori/midori-searchaction.c b/midori/midori-searchaction.c index 84872346..4a94bb61 100644 --- a/midori/midori-searchaction.c +++ b/midori/midori-searchaction.c @@ -1095,6 +1095,68 @@ midori_search_action_dialog_remove_cb (GtkWidget* widget, } } +static void +midori_search_action_dialog_move_up_cb (GtkWidget* widget, + MidoriSearchAction* search_action) +{ + KatzeArray* search_engines; + GtkWidget* treeview; + GtkTreeSelection* selection; + GtkTreeModel* liststore; + GtkTreeIter iter, prev; + GtkTreePath* path; + KatzeItem* item; + gint i; + + search_engines = search_action->search_engines; + treeview = search_action->treeview; + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); + + if (gtk_tree_selection_get_selected (selection, &liststore, &iter)) + { + path = gtk_tree_model_get_path (liststore, &iter); + if(gtk_tree_path_prev(path)) + { + gtk_tree_model_get (liststore, &iter, 0, &item, -1); + gtk_tree_model_get_iter (liststore, &prev, path); + gtk_list_store_swap (GTK_LIST_STORE(liststore), &iter, &prev); + + i = katze_array_get_item_index (search_engines, item); + katze_array_move_item (search_engines, item, i - 1); + } + gtk_tree_path_free (path); + } +} + +static void +midori_search_action_dialog_move_down_cb (GtkWidget* widget, + MidoriSearchAction* search_action) +{ + KatzeArray* search_engines; + GtkWidget* treeview; + GtkTreeSelection* selection; + GtkTreeModel* liststore; + GtkTreeIter iter, next; + KatzeItem* item; + gint i; + + search_engines = search_action->search_engines; + treeview = search_action->treeview; + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); + if (gtk_tree_selection_get_selected (selection, &liststore, &iter)) + { + next = iter; + if (gtk_tree_model_iter_next (liststore, &next)) + { + gtk_tree_model_get (liststore, &iter, 0, &item, -1); + gtk_list_store_swap (GTK_LIST_STORE(liststore), &iter, &next); + + i = katze_array_get_item_index (search_engines, item); + katze_array_move_item (search_engines, item, i + 1); + } + } +} + static void midori_search_action_dialog_default_cb (GtkWidget* widget, MidoriSearchAction* search_action) @@ -1349,10 +1411,12 @@ midori_search_action_get_dialog (MidoriSearchAction* search_action) button = gtk_label_new (""); /* This is an invisible separator */ gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 12); button = gtk_button_new_from_stock (GTK_STOCK_GO_DOWN); - gtk_widget_set_sensitive (button, FALSE); + g_signal_connect (button, "clicked", + G_CALLBACK (midori_search_action_dialog_move_down_cb), search_action); gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0); button = gtk_button_new_from_stock (GTK_STOCK_GO_UP); - gtk_widget_set_sensitive (button, FALSE); + g_signal_connect (button, "clicked", + G_CALLBACK (midori_search_action_dialog_move_up_cb), search_action); gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0); #if HAVE_OSX