Skip to content

Commit

Permalink
Added the possibility to move down a Block (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Aug 7, 2022
1 parent dbd56e5 commit 8271e48
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
27 changes: 27 additions & 0 deletions Datalya/Classes/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,31 @@ public static void MoveBlockUp(Block block)
}
}

public static void MoveBlockDown(Block block)
{
int currentIndex = CurrentDataBase.Blocks.IndexOf(block); // Get current index
if (currentIndex != CurrentDataBase.Blocks.Count - 1) // If the block isn't the last one
{
// Part 1: Swap the Block
Block tempBlock = CurrentDataBase.Blocks[currentIndex + 1]; // Get next block

// Swap tempBlock and the current block
CurrentDataBase.Blocks[currentIndex + 1] = block;
CurrentDataBase.Blocks[currentIndex] = tempBlock;

// Part 2: Swap the ItemsContent
if (CurrentDataBase.ItemsContent.Count > 0)
{
for (int i = 0; i < CurrentDataBase.ItemsContent.Count; i++) // For each item
{
string tempObject = CurrentDataBase.ItemsContent[i][currentIndex + 1]; // Get next object
CurrentDataBase.ItemsContent[i][currentIndex + 1] = CurrentDataBase.ItemsContent[i][currentIndex]; // Swap
CurrentDataBase.ItemsContent[i][currentIndex] = tempObject; // Swap
}
}

// Part 3: Update the UI
CreatorPage.InitUI(); // Update UI
}
}
}
2 changes: 1 addition & 1 deletion Datalya/UserControls/DateBlockCreatorUI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ private void MoveUpBtn_Click(object sender, RoutedEventArgs e)

private void MoveDownBtn_Click(object sender, RoutedEventArgs e)
{

Global.MoveBlockDown(DateBlock); // Move down
}
}
2 changes: 1 addition & 1 deletion Datalya/UserControls/InputBlockCreatorUI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ private void MoveUpBtn_Click(object sender, RoutedEventArgs e)

private void MoveDownBtn_Click(object sender, RoutedEventArgs e)
{

Global.MoveBlockDown(InputBlock); // Move down
}
}
2 changes: 1 addition & 1 deletion Datalya/UserControls/MultichoicesBlockCreatorUI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ private void MoveUpBtn_Click(object sender, RoutedEventArgs e)

private void MoveDownBtn_Click(object sender, RoutedEventArgs e)
{

Global.MoveBlockDown(MultichoicesBlock); // Move down
}
}
2 changes: 1 addition & 1 deletion Datalya/UserControls/SelectorBlockCreatorUI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ private void MoveUpBtn_Click(object sender, RoutedEventArgs e)

private void MoveDownBtn_Click(object sender, RoutedEventArgs e)
{

Global.MoveBlockDown(SelectorBlock); // Move down
}
}
2 changes: 1 addition & 1 deletion Datalya/UserControls/SingleChoiceBlockCreatorUI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ private void MoveUpBtn_Click(object sender, RoutedEventArgs e)

private void MoveDownBtn_Click(object sender, RoutedEventArgs e)
{

Global.MoveBlockDown(SingleChoiceBlock); // Move down
}
}

0 comments on commit 8271e48

Please sign in to comment.