Allow re-ordering of search engines

This commit is contained in:
Christian Dywan 2011-03-13 17:36:28 +01:00
parent fb681fac09
commit f2b5e82ce4
2 changed files with 77 additions and 2 deletions

View file

@ -649,6 +649,15 @@ midori_search_engines_modify_cb (KatzeArray* array,
g_free (config_file); 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 static void
midori_trash_add_item_cb (KatzeArray* trash, midori_trash_add_item_cb (KatzeArray* trash,
GObject* item) GObject* item)
@ -2282,6 +2291,8 @@ main (int argc,
KATZE_ARRAY_FOREACH_ITEM (item, search_engines) KATZE_ARRAY_FOREACH_ITEM (item, search_engines)
g_signal_connect_after (item, "notify", g_signal_connect_after (item, "notify",
G_CALLBACK (midori_search_engines_modify_cb), search_engines); 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", g_signal_connect_after (trash, "add-item",

View file

@ -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 static void
midori_search_action_dialog_default_cb (GtkWidget* widget, midori_search_action_dialog_default_cb (GtkWidget* widget,
MidoriSearchAction* search_action) MidoriSearchAction* search_action)
@ -1349,10 +1411,12 @@ midori_search_action_get_dialog (MidoriSearchAction* search_action)
button = gtk_label_new (""); /* This is an invisible separator */ button = gtk_label_new (""); /* This is an invisible separator */
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 12); gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 12);
button = gtk_button_new_from_stock (GTK_STOCK_GO_DOWN); 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); gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
button = gtk_button_new_from_stock (GTK_STOCK_GO_UP); 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); gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
#if HAVE_OSX #if HAVE_OSX