Skip to content

Commit eecc25d

Browse files
committed
feat(key): add ToggleSidebarShowSecondary, ToggleSidebarShowOriginalText keys for sidebar
1 parent 244b255 commit eecc25d

File tree

5 files changed

+55
-28
lines changed

5 files changed

+55
-28
lines changed

LLPlayer/Services/AppActions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ private Dictionary<CustomKeyBindingAction, Action> GetCustomActions()
7171
[CustomKeyBindingAction.SubsPrimaryTextCopy] = () => CmdSubsPrimaryTextCopy.Execute(false),
7272
[CustomKeyBindingAction.SubsSecondaryTextCopy] = () => CmdSubsSecondaryTextCopy.Execute(false),
7373
[CustomKeyBindingAction.ToggleSubsAutoTextCopy] = CmdToggleSubsAutoTextCopy.Execute,
74+
[CustomKeyBindingAction.ToggleSidebarShowSecondary] = CmdToggleSidebarShowSecondary.Execute,
75+
[CustomKeyBindingAction.ToggleSidebarShowOriginalText] = CmdToggleSidebarShowOriginalText.Execute,
7476

7577
[CustomKeyBindingAction.ToggleSidebar] = CmdToggleSidebar.Execute,
7678
[CustomKeyBindingAction.ToggleDebugOverlay] = CmdToggleDebugOverlay.Execute,
@@ -346,6 +348,16 @@ private void SubsTextCopyInternal(int subIndex, bool? suppressOsd)
346348
_config.Subs.SubsAutoTextCopy = !_config.Subs.SubsAutoTextCopy;
347349
});
348350

351+
public DelegateCommand CmdToggleSidebarShowSecondary => field ?? new(() =>
352+
{
353+
_config.SidebarShowSecondary = !_config.SidebarShowSecondary;
354+
});
355+
356+
public DelegateCommand CmdToggleSidebarShowOriginalText => field ?? new(() =>
357+
{
358+
_config.SidebarShowOriginalText = !_config.SidebarShowOriginalText;
359+
});
360+
349361
public DelegateCommand CmdToggleSidebar => field ?? new(() =>
350362
{
351363
_config.ShowSidebar = !_config.ShowSidebar;
@@ -664,6 +676,11 @@ public enum CustomKeyBindingAction
664676
[Description("Toggle Auto Subtitles Text Copy")]
665677
ToggleSubsAutoTextCopy,
666678

679+
[Description("Toggle Primary / Secondary in Subtitles Sidebar")]
680+
ToggleSidebarShowSecondary,
681+
[Description("Toggle to show original text in Subtitles Sidebar")]
682+
ToggleSidebarShowOriginalText,
683+
667684
[Description("Toggle Subitltes Sidebar")]
668685
ToggleSidebar,
669686
[Description("Toggle Debug Overlay")]
@@ -736,6 +753,8 @@ public static KeyBindingActionGroup ToGroup(this CustomKeyBindingAction action)
736753
case CustomKeyBindingAction.SubsPrimaryTextCopy:
737754
case CustomKeyBindingAction.SubsSecondaryTextCopy:
738755
case CustomKeyBindingAction.ToggleSubsAutoTextCopy:
756+
case CustomKeyBindingAction.ToggleSidebarShowSecondary:
757+
case CustomKeyBindingAction.ToggleSidebarShowOriginalText:
739758
return KeyBindingActionGroup.Subtitles;
740759

741760
case CustomKeyBindingAction.ToggleSidebar:

LLPlayer/Services/AppConfig.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ public bool ShowDebug
121121

122122
public int SidebarSubPadding { get; set => Set(ref field, value); } = 5;
123123

124+
[JsonIgnore]
125+
public bool SidebarShowSecondary { get; set => Set(ref field, value); }
126+
124127
public bool SidebarShowOriginalText { get; set => Set(ref field, value); }
125128

126129
public bool SidebarTextMask { get; set => Set(ref field, value); }

LLPlayer/ViewModels/SubtitlesSidebarVM.cs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,48 @@
1-
using FlyleafLib;
1+
using System.ComponentModel;
2+
using FlyleafLib;
23
using FlyleafLib.MediaPlayer;
34
using LLPlayer.Extensions;
45
using LLPlayer.Services;
56

67
namespace LLPlayer.ViewModels;
78

8-
public class SubtitlesSidebarVM : Bindable
9+
public class SubtitlesSidebarVM : Bindable, IDisposable
910
{
1011
public FlyleafManager FL { get; }
1112

1213
public SubtitlesSidebarVM(FlyleafManager fl)
1314
{
1415
FL = fl;
16+
17+
FL.Config.PropertyChanged += OnConfigOnPropertyChanged;
1518
}
1619

17-
public bool IsPrimary
20+
private void OnConfigOnPropertyChanged(object? sender, PropertyChangedEventArgs args)
1821
{
19-
get;
20-
set
22+
switch (args.PropertyName)
2123
{
22-
if (Set(ref field, value))
23-
{
24+
case nameof(FL.Config.SidebarShowSecondary):
2425
OnPropertyChanged(nameof(SubIndex));
2526
OnPropertyChanged(nameof(SubManager));
26-
}
27+
break;
28+
case nameof(FL.Config.SidebarShowOriginalText):
29+
// Update ListBox
30+
OnPropertyChanged(nameof(SubManager));
31+
break;
2732
}
28-
} = true;
33+
}
2934

30-
public int SubIndex => IsPrimary ? 0 : 1;
35+
public void Dispose()
36+
{
37+
FL.Config.PropertyChanged -= OnConfigOnPropertyChanged;
38+
}
39+
40+
public int SubIndex => !FL.Config.SidebarShowSecondary ? 0 : 1;
3141

3242
public SubManager SubManager => FL.Player.SubtitlesManager[SubIndex];
3343

3444
// ReSharper disable NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract
3545

36-
public DelegateCommand CmdSubIndexToggle => field ??= new(() =>
37-
{
38-
IsPrimary = !IsPrimary;
39-
});
40-
4146
// TODO: L: Fix implicit changes to reflect
4247
public DelegateCommand<string> CmdSubFontSizeChange => field ??= new(increase =>
4348
{
@@ -55,14 +60,6 @@ public bool IsPrimary
5560
OnPropertyChanged(nameof(SubManager));
5661
});
5762

58-
public DelegateCommand CmdShowOriginalTextToggle => field ??= new(() =>
59-
{
60-
FL.Config.SidebarShowOriginalText = !FL.Config.SidebarShowOriginalText;
61-
62-
// Update ListBox
63-
OnPropertyChanged(nameof(SubManager));
64-
});
65-
6663
public DelegateCommand CmdShowDownloadSubsDialog => field ??= new(() =>
6764
{
6865
FL.Action.CmdOpenWindowSubsDownloader.Execute();

LLPlayer/Views/SubtitlesSidebar.xaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@
8181
<!-- Primary Secondary Toggle -->
8282
<ToggleButton
8383
Style="{StaticResource ToggleButton}"
84-
materialDesign:ToggleButtonAssist.OnContent="{materialDesign:PackIcon Kind=Numeric1BoxMultipleOutline}"
85-
Content="{materialDesign:PackIcon Kind=Numeric2BoxMultipleOutline}"
84+
materialDesign:ToggleButtonAssist.OnContent="{materialDesign:PackIcon Kind=Numeric2BoxMultipleOutline}"
85+
Content="{materialDesign:PackIcon Kind=Numeric1BoxMultipleOutline}"
8686
ToolTip="Toggle Primary / Secondary"
87-
Command="{Binding CmdSubIndexToggle}"
88-
IsChecked="{Binding IsPrimary, Mode=OneWay}" />
87+
Command="{Binding FL.Action.CmdToggleSidebarShowSecondary}"
88+
IsChecked="{Binding FL.Config.SidebarShowSecondary, Mode=OneWay}" />
8989

9090
<!-- Font Size -->
9191
<materialDesign:PopupBox
@@ -141,7 +141,7 @@
141141
materialDesign:ToggleButtonAssist.OnContent="{materialDesign:PackIcon Kind=TranslateOff}"
142142
Content="{materialDesign:PackIcon Kind=Translate}"
143143
ToolTip="Toggle to show original text when translating enabled"
144-
Command="{Binding CmdShowOriginalTextToggle}"
144+
Command="{Binding FL.Action.CmdToggleSidebarShowOriginalText}"
145145
IsChecked="{Binding FL.Config.SidebarShowOriginalText, Mode=OneWay}" />
146146

147147
<!-- Subtitles Downloader -->

LLPlayer/Views/SubtitlesSidebar.xaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ public SubtitlesSidebar()
1212
InitializeComponent();
1313

1414
DataContext = ((App)Application.Current).Container.Resolve<SubtitlesSidebarVM>();
15+
16+
Unloaded += (sender, args) =>
17+
{
18+
if (DataContext is SubtitlesSidebarVM vm)
19+
{
20+
vm.Dispose();
21+
}
22+
};
1523
}
1624

1725
/// <summary>

0 commit comments

Comments
 (0)