Skip to content

Commit

Permalink
Add buttons for reordering tasks (#1200)
Browse files Browse the repository at this point in the history
* Add buttons and logic for rearranging tasks

* Use FontAwesome for close button

* Fix potential race condition
  • Loading branch information
ScrubN authored Aug 29, 2024
1 parent 4bcb917 commit c878915
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
12 changes: 11 additions & 1 deletion TwitchDownloaderWPF/PageQueue.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,17 @@
<Image MaxHeight="20" Margin="5,0" gif:ImageBehavior.AnimatedSource="{Binding StatusImage, Mode=OneWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
</StackPanel>
<Button Grid.Column="2" Padding="7, 0" VerticalAlignment="Top" Height="24" FontSize="12" Content="X" Click="BtnRemoveTask_Click" Background="{DynamicResource AppElementBackground}" Foreground="{DynamicResource AppTextDisabled}" BorderBrush="{DynamicResource AppElementBorder}" />
<StackPanel Grid.Column="2" Orientation="Horizontal">
<Button Padding="0" VerticalAlignment="Top" Width="22" Height="22" Margin="0, 0, 2, 0" Click="BtnMoveTaskUp_Click" Background="{DynamicResource AppElementBackground}" BorderBrush="{DynamicResource AppElementBorder}">
<fa:SvgAwesome Icon="Solid_CaretUp" Foreground="{DynamicResource AppTextDisabled}" />
</Button>
<Button Padding="0" VerticalAlignment="Top" Width="22" Height="22" Margin="0, 0, 2, 0" Click="BtnMoveTaskDown_Click" Background="{DynamicResource AppElementBackground}" BorderBrush="{DynamicResource AppElementBorder}">
<fa:SvgAwesome Icon="Solid_CaretDown" Foreground="{DynamicResource AppTextDisabled}" />
</Button>
<Button Padding="3" VerticalAlignment="Top" Width="22" Height="22" FontSize="12" Click="BtnRemoveTask_Click" Background="{DynamicResource AppElementBackground}" Foreground="{DynamicResource AppTextDisabled}" BorderBrush="{DynamicResource AppElementBorder}">
<fa:SvgAwesome Icon="Solid_Times" Foreground="{DynamicResource AppTextDisabled}" />
</Button>
</StackPanel>
</Grid>
</Border>
</DataTemplate>
Expand Down
41 changes: 39 additions & 2 deletions TwitchDownloaderWPF/PageQueue.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,12 @@ private static void RemoveTask(TwitchTask task)
return;
}

if (!taskList.Remove(task))
lock (taskLock)
{
MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.TaskCouldNotBeRemoved, Translations.Strings.UnknownErrorOccurred, MessageBoxButton.OK, MessageBoxImage.Error);
if (!taskList.Remove(task))
{
MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.TaskCouldNotBeRemoved, Translations.Strings.UnknownErrorOccurred, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}

Expand Down Expand Up @@ -333,5 +336,39 @@ private static void RetryTask(TwitchTask task)
task.Reinitialize();
}
}

private void BtnMoveTaskUp_Click(object sender, RoutedEventArgs e)
{
if (sender is not Button { DataContext: TwitchTask task })
{
return;
}

lock (taskLock)
{
var index = taskList.IndexOf(task);
if (index < 1)
return;

taskList.Move(index, index - 1);
}
}

private void BtnMoveTaskDown_Click(object sender, RoutedEventArgs e)
{
if (sender is not Button { DataContext: TwitchTask task })
{
return;
}

lock (taskLock)
{
var index = taskList.IndexOf(task);
if (index == -1 || index == taskList.Count - 1)
return;

taskList.Move(index, index + 1);
}
}
}
}

0 comments on commit c878915

Please sign in to comment.