Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buttons for reordering tasks #1200

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
}
Loading