implemented element swapping in one place only
authormishas <mikhail.sobolev@gmail.com>
Fri, 22 Dec 2006 06:58:11 +0000 (06:58 +0000)
committermishas <mikhail.sobolev@gmail.com>
Fri, 22 Dec 2006 06:58:11 +0000 (06:58 +0000)
git-svn-id: file:///svnroot/simple-launcher/trunk@59 3ba93dab-e023-0410-b42a-de7732cf370a

sla-list.cc
sla-list.h

index 70dea06..f8da1ac 100644 (file)
@@ -166,17 +166,7 @@ void SLAList::moveUp(GtkButton *) {
       GtkTreeIter next;
 
       if (gtk_tree_model_get_iter(GTK_TREE_MODEL(myStore), &next, path)) {
-        int i1, i2;
-
-        gtk_tree_model_get(GTK_TREE_MODEL(myStore), &current, 1, &i1, -1);
-        gtk_tree_model_get(GTK_TREE_MODEL(myStore), &next, 1, &i2, -1);
-
-        std::swap(myItems[i1], myItems[i2]);
-
-        gtk_list_store_set(myStore, &current, 1, i2, -1);
-        gtk_list_store_set(myStore, &next, 1, i1, -1);
-
-        gtk_list_store_swap(myStore, &current, &next);
+        swap(current, next);
       }
     }
 
@@ -196,21 +186,25 @@ void SLAList::moveDown(GtkButton *) {
     gtk_tree_path_next(path);
 
     if (gtk_tree_model_get_iter(GTK_TREE_MODEL(myStore), &next, path)) {
-      int i1, i2;
+      swap(current, next);
+    }
+
+    gtk_tree_path_free(path);
+  }
+}
 
-      gtk_tree_model_get(GTK_TREE_MODEL(myStore), &current, 1, &i1, -1);
-      gtk_tree_model_get(GTK_TREE_MODEL(myStore), &next, 1, &i2, -1);
+void SLAList::swap(GtkTreeIter *a, GtkTreeIter *b) {
+  int i1, i2;
 
-      std::swap(myItems[i1], myItems[i2]);
+  gtk_tree_model_get(GTK_TREE_MODEL(myStore), &a, 1, &i1, -1);
+  gtk_tree_model_get(GTK_TREE_MODEL(myStore), &b, 1, &i2, -1);
 
-      gtk_list_store_set(myStore, &current, 1, i2, -1);
-      gtk_list_store_set(myStore, &next, 1, i1, -1);
+  std::swap(myItems[i1], myItems[i2]);
 
-      gtk_list_store_swap(myStore, &current, &next);
-    }
+  gtk_list_store_set(myStore, &a, 1, i2, -1);
+  gtk_list_store_set(myStore, &b, 1, i1, -1);
 
-    gtk_tree_path_free(path);
-  }
+  gtk_list_store_swap(myStore, &a, &b);
 }
 
 // vim:ts=2:sw=2:et
index 5ca852d..a323c70 100644 (file)
@@ -45,6 +45,8 @@ private:
   void moveDown(GtkButton *);
   void toggleBool(GtkCellRendererToggle *, const gchar *);
 
+  void swap(GtkTreeIter *a, GtkTreeIter *b);
+
 private:
   GtkWidget *myWidget;
   GtkListStore *myStore;