Skip to content

Commit 3d16d56

Browse files
Fix dragging songs around and scratch pad header
1 parent e1ec7f8 commit 3d16d56

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

MSUScripter/Services/ControlServices/MsuProjectWindowService.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -840,21 +840,18 @@ private void HandleDragged(MsuProjectWindowViewModelTreeData from, MsuProjectWin
840840

841841
if (currentParent == destinationParent)
842842
{
843-
var currentSongIndex = destinationParent.ChildTreeData.IndexOf(from);
844-
var destinationTreeIndex = _viewModel.TreeItems.IndexOf(to) + 1;
845-
if (currentSongIndex < destinationIndex)
846-
{
847-
destinationTreeIndex--;
848-
destinationIndex--;
849-
}
843+
var dictionary = destinationParent.ChildTreeData.ToDictionary(x => x.SongInfo!, x => x);
844+
destinationParent.ChildTreeData.Clear();
845+
var destinationParentIndex = _viewModel.TreeItems.IndexOf(destinationParent);
850846

851-
destinationParent.ChildTreeData.Remove(from);
852-
destinationParent.ChildTreeData.Insert(destinationIndex, from);
853-
_viewModel.TreeItems.Remove(from);
854-
_viewModel.TreeItems.Insert(destinationTreeIndex, from);
855-
for (var i = 0; i < destinationParent.ChildTreeData.Count; i++)
847+
for (var i = 0; i < destinationTrack.Songs.Count; i++)
856848
{
857-
destinationParent.ChildTreeData[i].SortIndex = destinationParent.SortIndex + i + 1;
849+
var song = destinationTrack.Songs[i];
850+
var songTreeData = dictionary[song];
851+
destinationParent.ChildTreeData.Add(songTreeData);
852+
_viewModel.TreeItems.Remove(songTreeData);
853+
_viewModel.TreeItems.Insert(destinationParentIndex + i + 1, songTreeData);
854+
songTreeData.SortIndex = destinationParent.SortIndex + i + 1;
858855
}
859856

860857
_viewModel.MsuSongViewModel.UpdateViewModel(_project, destinationTrack, from.SongInfo, from);
@@ -863,6 +860,7 @@ private void HandleDragged(MsuProjectWindowViewModelTreeData from, MsuProjectWin
863860
else
864861
{
865862
var newTreeData = from;
863+
var fromSongInfo = from.SongInfo;
866864

867865
foreach (var previousTree in currentParent.ChildTreeData.Concat(destinationParent.ChildTreeData))
868866
{
@@ -940,7 +938,7 @@ private void HandleDragged(MsuProjectWindowViewModelTreeData from, MsuProjectWin
940938
SongInfo = song,
941939
};
942940

943-
if (song == from.SongInfo)
941+
if (song == fromSongInfo)
944942
{
945943
newTreeData = songTreeData;
946944
}
@@ -960,7 +958,7 @@ private void HandleDragged(MsuProjectWindowViewModelTreeData from, MsuProjectWin
960958
destinationParent.ToggleAsParent(true, false);
961959
}
962960

963-
_viewModel.MsuSongViewModel.UpdateViewModel(_project, destinationTrack, from.SongInfo, newTreeData);
961+
_viewModel.MsuSongViewModel.UpdateViewModel(_project, destinationTrack, fromSongInfo, newTreeData);
964962
_viewModel.SelectedTreeItem = newTreeData;
965963
}
966964

MSUScripter/ViewModels/MsuSongOuterPanelViewModel.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ void OnPropertyChanged(object? sender, PropertyChangedEventArgs e)
6060

6161
public void UpdateViewModel(MsuProject project, MsuTrackInfo trackInfo, MsuSongInfo? songInfo, MsuProjectWindowViewModelTreeData treeData)
6262
{
63-
var altText = trackInfo.Songs.Count <= 1 || songInfo == null
63+
var altText = trackInfo.TrackNumber == 9999
6464
? ""
65-
: songInfo.IsAlt
66-
? " - Alt Song #" + trackInfo.Songs.IndexOf(songInfo)
67-
: " - Primary Song";
65+
: trackInfo.Songs.Count <= 1 || songInfo == null
66+
? ""
67+
: songInfo.IsAlt
68+
? " - Alt Song #" + trackInfo.Songs.IndexOf(songInfo)
69+
: " - Primary Song";
6870
var trackInfoNumber = trackInfo.TrackNumber != 9999 ? $"#{trackInfo.TrackNumber} " : string.Empty;
6971
Project = project;
7072
TrackInfo = trackInfo;

0 commit comments

Comments
 (0)