]> spindle.queued.net Git - midori/commitdiff
Allow re-ordering of search engines
authorChristian Dywan <christian@twotoasts.de>
Sun, 13 Mar 2011 16:36:28 +0000 (17:36 +0100)
committerChristian Dywan <christian@twotoasts.de>
Sun, 13 Mar 2011 16:36:28 +0000 (17:36 +0100)
midori/main.c
midori/midori-searchaction.c

index e4ca3984cb7be6437d94a76a777f558c4fae37ae..5ce2c2bdeafb59afe6d924903f9717f62664eedd 100644 (file)
@@ -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",
index 84872346993af8c0120e6fd841ec74440b10aff2..4a94bb61bf4f00826965b88b46c9e2c0bb37f065 100644 (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
 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