Skip to content

Commit

Permalink
Add keyboard shortcuts for Download Manager
Browse files Browse the repository at this point in the history
Almost all of them are same in JDownloader 2.
For now no shortcut keys for Resume, Pause, Cancel and Filters, cuz I'm not sure what key shortcuts will be best for those.
  • Loading branch information
hawkeye116477 committed Feb 25, 2024
1 parent 6b66e45 commit 9ee0e72
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/LegendaryDownloadManager.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:pcmd="clr-namespace:Playnite.Commands"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="800" DataContext="{Binding RelativeSource={RelativeSource Self}}" Name="LegendaryDownloadManagerUC">
d:DesignHeight="300" d:DesignWidth="800" DataContext="{Binding RelativeSource={RelativeSource Self}}" Name="LegendaryDownloadManagerUC" PreviewKeyDown="LegendaryDownloadManagerUC_PreviewKeyDown">

<UserControl.Resources>
<sys:Boolean x:Key="True">True</sys:Boolean>
Expand Down Expand Up @@ -78,34 +78,34 @@
Margin="5,0,0,0" IsCancel="True" Click="CancelDownloadBtn_Click" IsEnabled="False" />
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Background="{DynamicResource PanelSeparatorBrush}" Margin="10,0,5,0" />
<Button Name="MoveTopBtn" Content="&#xea95;" FontFamily="{DynamicResource FontIcoFont}"
Margin="5,0,0,0" Click="MoveTopBtn_Click" ToolTip="{DynamicResource LOCLegendaryMoveEntryTop}"
Margin="5,0,0,0" Click="MoveTopBtn_Click"
IsEnabled="False" />
<Button Name="MoveUpBtn" Content="&#xea5e;" FontFamily="{DynamicResource FontIcoFont}"
Margin="5,0,0,0" Click="MoveUpBtn_Click" ToolTip="{DynamicResource LOCLegendaryMoveEntryUp}"
Margin="5,0,0,0" Click="MoveUpBtn_Click"
IsEnabled="False" />
<Button Name="MoveDownBtn" Content="&#xea5b;" FontFamily="{DynamicResource FontIcoFont}"
Margin="5,0,0,0" Click="MoveDownBtn_Click" ToolTip="{DynamicResource LOCLegendaryMoveEntryDown}"
Margin="5,0,0,0" Click="MoveDownBtn_Click"
IsEnabled="False" />
<Button Name="MoveBottomBtn" Content="&#xea92;" FontFamily="{DynamicResource FontIcoFont}"
Margin="5,0,0,0" Click="MoveBottomBtn_Click" ToolTip="{DynamicResource LOCLegendaryMoveEntryBottom}"
Margin="5,0,0,0" Click="MoveBottomBtn_Click"
IsEnabled="False" />
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Background="{DynamicResource PanelSeparatorBrush}" Margin="10,0,5,0" />
<Button x:Name="SelectAllBtn" Content="&#xeed9;" FontFamily="{DynamicResource FontIcoFont}"
Margin="5,0,0,0" Click="SelectAllBtn_Click" />
<Button x:Name="RemoveDownloadBtn" Content="&#xec53;" FontFamily="{DynamicResource FontIcoFont}" ToolTip="{DynamicResource LOCLegendaryRemoveEntry}"
<Button x:Name="RemoveDownloadBtn" Content="&#xec53;" FontFamily="{DynamicResource FontIcoFont}"
Margin="5,0,0,0" Click="RemoveDownloadBtn_Click" IsEnabled="False" />
<Button x:Name="RemoveCompletedDownloadsBtn" Content="&#xef9f;" FontFamily="{DynamicResource FontIcoFont}" ToolTip="{DynamicResource LOCLegendaryRemoveCompletedDownloads}"
Margin="5,0,0,0" Click="RemoveCompletedDownloadsBtn_Click" />
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Background="{DynamicResource PanelSeparatorBrush}" Margin="10,0,5,0" />
<Button x:Name="DownloadPropertiesBtn" Content="&#xefe2;" FontFamily="{DynamicResource FontIcoFont}" ToolTip="{DynamicResource LOCLegendaryEditSelectedDownloadProperties}"
<Button x:Name="DownloadPropertiesBtn" Content="&#xefe2;" FontFamily="{DynamicResource FontIcoFont}"
Margin="5,0,0,0" Click="DownloadPropertiesBtn_Click" IsEnabled="False" />
<Button x:Name="OpenDownloadDirectoryBtn" Content="&#xef35;" FontFamily="{DynamicResource FontIcoFont}" ToolTip="{DynamicResource LOCLegendaryOpenDownloadDirectory}"
<Button x:Name="OpenDownloadDirectoryBtn" Content="&#xef35;" FontFamily="{DynamicResource FontIcoFont}"
Margin="5,0,0,0" Click="OpenDownloadDirectoryBtn_Click" IsEnabled="False" />
<ToggleButton x:Name="FilterDownloadBtn" Content="&#xef29;" FontFamily="{DynamicResource FontIcoFont}" ToolTip="{DynamicResource LOCLegendary3P_PlayniteFilters}"
Margin="5,0,0,0" Checked="FilterDownloadBtn_Checked" Unchecked="FilterDownloadBtn_Unchecked" />
</StackPanel>
<Separator Margin="0,5,0,5"></Separator>
<DataGrid x:Name="DownloadsDG" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,10" AutoGenerateColumns="False" IsReadOnly="True" HeadersVisibility="Column" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" ColumnWidth="*" CanUserSortColumns="True" CanUserResizeColumns="True" SelectionChanged="DownloadsDG_SelectionChanged" >
<DataGrid x:Name="DownloadsDG" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,10" AutoGenerateColumns="False" IsReadOnly="True" HeadersVisibility="Column" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" ColumnWidth="*" CanUserSortColumns="True" CanUserResizeColumns="True" SelectionChanged="DownloadsDG_SelectionChanged">
<DataGrid.Columns>
<DataGridTextColumn Header="{DynamicResource LOCLegendary3P_PlayniteGameNameTitle}" Binding="{Binding name}"></DataGridTextColumn>
<DataGridTextColumn Header="{DynamicResource LOCLegendaryDownloadStatus}" Binding="{Binding status, Converter={StaticResource DownloadStatusEnumToStringConverter}}"/>
Expand Down
54 changes: 52 additions & 2 deletions src/LegendaryDownloadManager.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using LegendaryLibraryNS.Services;
using System.Windows.Input;

namespace LegendaryLibraryNS
{
Expand All @@ -38,7 +39,15 @@ public LegendaryDownloadManager()
{
InitializeComponent();
SetControlTextBlockStyle();
SelectAllBtn.ToolTip = $"{ResourceProvider.GetResource(LOC.LegendarySelectAllEntries)} (Ctrl+A)";

SelectAllBtn.ToolTip = GetToolTipWithKey(LOC.LegendarySelectAllEntries, "Ctrl+A");
RemoveDownloadBtn.ToolTip = GetToolTipWithKey(LOC.LegendaryRemoveEntry, "Delete");
MoveTopBtn.ToolTip = GetToolTipWithKey(LOC.LegendaryMoveEntryTop, "Alt+Home");
MoveUpBtn.ToolTip = GetToolTipWithKey(LOC.LegendaryMoveEntryUp, "Alt+Up");
MoveDownBtn.ToolTip = GetToolTipWithKey(LOC.LegendaryMoveEntryDown, "Alt+Down");
MoveBottomBtn.ToolTip = GetToolTipWithKey(LOC.LegendaryMoveEntryBottom, "Alt+End");
DownloadPropertiesBtn.ToolTip = GetToolTipWithKey(LOC.LegendaryEditSelectedDownloadProperties, "Ctrl+P");
OpenDownloadDirectoryBtn.ToolTip = GetToolTipWithKey(LOC.LegendaryOpenDownloadDirectory, "Ctrl+O");
LoadSavedData();
var runningAndQueuedDownloads = downloadManagerData.downloads.Where(i => i.status == DownloadStatus.Running
|| i.status == DownloadStatus.Queued).ToList();
Expand All @@ -60,6 +69,11 @@ public RelayCommand<object> NavigateBackCommand
});
}

public string GetToolTipWithKey(string description, string shortcut)
{
return $"{ResourceProvider.GetString(description)} [{shortcut}]";
}

public DownloadManagerData.Rootobject LoadSavedData()
{
var dataDir = LegendaryLibrary.Instance.GetPluginUserDataPath();
Expand Down Expand Up @@ -872,7 +886,7 @@ private enum EntryPosition
Bottom
}

private void MoveEntries(EntryPosition entryPosition)
private void MoveEntries(EntryPosition entryPosition, bool moveFocus = false)
{
if (DownloadsDG.SelectedIndex != -1)
{
Expand Down Expand Up @@ -928,6 +942,10 @@ private void MoveEntries(EntryPosition entryPosition)
downloadManagerData.downloads.Move(newSelectedIndex, newIndex);
loopIndex++;
}
if (moveFocus)
{
DownloadsDG.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
SaveData();
}
}
Expand All @@ -950,5 +968,37 @@ private void MoveBottomBtn_Click(object sender, RoutedEventArgs e)
{
MoveEntries(EntryPosition.Bottom);
}

private void LegendaryDownloadManagerUC_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Delete)
{
RemoveDownloadBtn_Click(sender, e);
}
else if (Keyboard.IsKeyDown(Key.LeftAlt) && Keyboard.IsKeyDown(Key.Home))
{
MoveEntries(EntryPosition.Top, true);
}
else if (Keyboard.IsKeyDown(Key.LeftAlt) && Keyboard.IsKeyDown(Key.Up))
{
MoveEntries(EntryPosition.Up, true);
}
else if (Keyboard.IsKeyDown(Key.LeftAlt) && Keyboard.IsKeyDown(Key.Down))
{
MoveEntries(EntryPosition.Down, true);
}
else if (Keyboard.IsKeyDown(Key.LeftAlt) && Keyboard.IsKeyDown(Key.End))
{
MoveEntries(EntryPosition.Bottom, true);
}
else if ((Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) && e.Key == Key.P)
{
DownloadPropertiesBtn_Click(sender, e);
}
else if ((Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) && e.Key == Key.O)
{
OpenDownloadDirectoryBtn_Click(sender, e);
}
}
}
}

0 comments on commit 9ee0e72

Please sign in to comment.