+static void prefs_template_top_cb(void)
+{
+ gint row;
+ GtkTreeIter top, sel;
+ GtkTreeModel *model;
+
+ row = gtkut_list_view_get_selected_row(templates.list_view);
+ if (row <= 1)
+ return;
+
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(templates.list_view));
+
+ if (!gtk_tree_model_iter_nth_child(model, &top, NULL, 0)
+ || !gtk_tree_model_iter_nth_child(model, &sel, NULL, row))
+ return;
+
+ gtk_list_store_move_after(GTK_LIST_STORE(model), &sel, &top);
+ gtkut_list_view_select_row(templates.list_view, 1);
+}
+
+static void prefs_template_up_cb(void)
+{
+ gint row;
+ GtkTreeIter top, sel;
+ GtkTreeModel *model;
+
+ row = gtkut_list_view_get_selected_row(templates.list_view);
+ if (row <= 1)
+ return;
+
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(templates.list_view));
+
+ if (!gtk_tree_model_iter_nth_child(model, &top, NULL, row - 1)
+ || !gtk_tree_model_iter_nth_child(model, &sel, NULL, row))
+ return;
+
+ gtk_list_store_swap(GTK_LIST_STORE(model), &top, &sel);
+ gtkut_list_view_select_row(templates.list_view, row - 1);
+}
+
+static void prefs_template_down_cb(void)
+{
+ gint row, n_rows;
+ GtkTreeIter top, sel;
+ GtkTreeModel *model;
+
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(templates.list_view));
+ n_rows = gtk_tree_model_iter_n_children(model, NULL);
+ row = gtkut_list_view_get_selected_row(templates.list_view);
+ if (row < 1 || row >= n_rows - 1)
+ return;
+
+ if (!gtk_tree_model_iter_nth_child(model, &top, NULL, row)
+ || !gtk_tree_model_iter_nth_child(model, &sel, NULL, row + 1))
+ return;
+
+ gtk_list_store_swap(GTK_LIST_STORE(model), &top, &sel);
+ gtkut_list_view_select_row(templates.list_view, row + 1);
+}
+
+static void prefs_template_bottom_cb(void)
+{
+ gint row, n_rows;
+ GtkTreeIter top, sel;
+ GtkTreeModel *model;
+
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(templates.list_view));
+ n_rows = gtk_tree_model_iter_n_children(model, NULL);
+ row = gtkut_list_view_get_selected_row(templates.list_view);
+ if (row < 1 || row >= n_rows - 1)
+ return;
+
+ if (!gtk_tree_model_iter_nth_child(model, &top, NULL, row)
+ || !gtk_tree_model_iter_nth_child(model, &sel, NULL, n_rows - 1))
+ return;
+
+ gtk_list_store_move_after(GTK_LIST_STORE(model), &top, &sel);
+ gtkut_list_view_select_row(templates.list_view, n_rows - 1);
+}
+