Example #1
0
 /// <summary>
 /// Move the model systems inside of a project.
 /// </summary>
 /// <param name="currentIndex">The index to move</param>
 /// <param name="newIndex">The new index for the model system</param>
 /// <param name="error">If there is a failure this will contain a message</param>
 /// <returns>True if successful, false otherwise</returns>
 public bool MoveModelSystem(int currentIndex, int newIndex, ref string error)
 {
     lock (_EditingSessionsLock)
     {
         if (currentIndex < 0 | currentIndex >= _EditingSessions.Length)
         {
             error = "The model system to move is out of range!";
             return(false);
         }
         if (newIndex < 0 | newIndex >= _EditingSessions.Length)
         {
             error = "The new position is out of range!";
             return(false);
         }
         // if they are the same then success (we don't want to shortcut though if invalid data is given though)
         if (currentIndex == newIndex)
         {
             return(true);
         }
         if (!Project.MoveModelSystems(currentIndex, newIndex, ref error))
         {
             return(false);
         }
         // move the indexes around
         var temp = _EditingSessions[currentIndex];
         if (currentIndex < newIndex)
         {
             // move everything up
             Array.Copy(_EditingSessions, currentIndex + 1, _EditingSessions, currentIndex, newIndex - currentIndex);
             _EditingSessions[newIndex] = temp;
         }
         else
         {
             // move everything down
             Array.Copy(_EditingSessions, newIndex, _EditingSessions, newIndex + 1, currentIndex - newIndex);
             _EditingSessions[newIndex] = temp;
         }
         return(true);
     }
 }