]> 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)
committerJames Turner <zakalawe@mac.com>
Sun, 23 Jan 2011 10:45:31 +0000 (10:45 +0000)
Drag&drop, insert and remove now update the current waypoint as expected.

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

index 127e2c39792c7fbae347536850608eb8c3f9c7f7..8f2cacf590ef60367e8e2c20c00d65cfcbdbd302 100644 (file)
@@ -352,11 +352,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;
   
@@ -364,6 +359,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();
   
@@ -680,7 +684,7 @@ void FGRouteMgr::insertWayptAtIndex(Waypt* aWpt, int aIndex)
   WayptVec::iterator it = _route.begin();
   it += index;
       
-  if (_currentIndex > index) {
+  if (_currentIndex >= index) {
     ++_currentIndex;
   }
   
index 31c5e480c57ad46ddbd909fb3c10109b0188849f..f525f213b200b23d48f41ca1b428d9a497a01b65 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)