]> git.mxchange.org Git - flightgear.git/commitdiff
Make route editing sane.
authorThorstenB <brehmt@gmail.com>
Sat, 22 Jan 2011 23:45:06 +0000 (00:45 +0100)
committerThorstenB <brehmt@gmail.com>
Sat, 22 Jan 2011 23:45:06 +0000 (00:45 +0100)
Drag&drop, insert and remove now update the current waypoint as expected.

src/Autopilot/route_mgr.cxx
src/GUI/WaypointList.cxx

index 57f7d5d5c7c3175ab1c10e5fc5cf7809c6d063d6..562c0ec68cd6f3c0ac6a187cd7d9c67c944119c0 100644 (file)
@@ -354,11 +354,6 @@ flightgear::WayptRef FGRouteMgr::removeWayptAtIndex(int aIndex)
     SG_LOG(SG_AUTOPILOT, SG_WARN, "removeWayptAtIndex with invalid index:" << aIndex);
     return NULL;
   }
-  
-  if (_currentIndex > index) {
-    --_currentIndex; // shift current index down if necessary
-  }
-
   WayptVec::iterator it = _route.begin();
   it += index;
   
@@ -366,6 +361,15 @@ flightgear::WayptRef FGRouteMgr::removeWayptAtIndex(int aIndex)
   _route.erase(it);
   
   update_mirror();
+  
+  if (_currentIndex == index) {
+    currentWaypointChanged(); // current waypoint was removed
+  }
+  else
+  if (_currentIndex > index) {
+    --_currentIndex; // shift current index down if necessary
+  }
+
   _edited->fireValueChanged();
   checkFinished();
   
@@ -682,7 +686,7 @@ void FGRouteMgr::insertWayptAtIndex(Waypt* aWpt, int aIndex)
   WayptVec::iterator it = _route.begin();
   it += index;
       
-  if (_currentIndex > index) {
+  if (_currentIndex >= index) {
     ++_currentIndex;
   }
   
index b014d1cd3bc417c9a6ca4f1639c67fa8b12a02f0..ded3d46ecfc1c3c2db2e193587222f8b02c907d9 100644 (file)
@@ -83,9 +83,15 @@ public:
       --destIndex;
     }
     
+    int currentWpIndex = currentWaypoint();
     WayptRef w(_rm->removeWayptAtIndex(srcIndex));
     SG_LOG(SG_GENERAL, SG_INFO, "wpt:" << w->ident());
     _rm->insertWayptAtIndex(w, destIndex);
+
+    if (srcIndex == currentWpIndex) {
+        // current waypoint was moved
+        _rm->jumpToIndex(destIndex);
+    }
   }
   
   virtual void setUpdateCallback(SGCallback* cb)