Skip to content

Commit

Permalink
WinGui: When the Add subtitle buttons do nothing, display a message b…
Browse files Browse the repository at this point in the history
…ox explaining why to the user. Fixes HandBrake#4303
  • Loading branch information
sr55 committed Apr 21, 2022
1 parent 8ce948f commit 1e2404d
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 36 deletions.
20 changes: 20 additions & 0 deletions win/CS/HandBrakeWPF/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions win/CS/HandBrakeWPF/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2655,4 +2655,12 @@ Hardware encoding support can be re-enabled in preferences. </value>
<data name="OptionsView_FileCollisionNotice" xml:space="preserve">
<value>Only when file already exists on disk.</value>
</data>
<data name="Info" xml:space="preserve">
<value>Info</value>
</data>
<data name="SubtitleView_NoSubtitlesAdded" xml:space="preserve">
<value>There were no subtitle tracks added.

This may be due to limitations of the file container you have selected. Please see our subtitle help documentation for more information.</value>
</data>
</root>
76 changes: 48 additions & 28 deletions win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace HandBrakeWPF.ViewModels
using HandBrakeWPF.Services.Scan.Model;
using HandBrakeWPF.ViewModels.Interfaces;

using MahApps.Metro.Controls;

using Microsoft.Win32;

using EncodeTask = Services.Encode.Model.EncodeTask;
Expand All @@ -42,15 +44,9 @@ public class SubtitlesViewModel : ViewModelBase, ISubtitlesViewModel
{
private readonly IErrorService errorService;

#region Constants and Fields

private readonly Subtitle foreignAudioSearchTrack;
private IList<Subtitle> sourceTracks;

#endregion

#region Constructors and Destructors


/// <summary>
/// Initializes a new instance of the <see cref="HandBrakeWPF.ViewModels.SubtitlesViewModel"/> class.
/// </summary>
Expand All @@ -74,12 +70,8 @@ public SubtitlesViewModel(IErrorService errorService, IWindowManager windowManag
this.SourceTracks = new List<Subtitle> { this.foreignAudioSearchTrack };
}

#endregion

public event EventHandler<TabStatusEventArgs> TabStatusChanged;

#region Properties

/// <summary>
/// Gets or sets the audio defaults view model.
/// </summary>
Expand Down Expand Up @@ -123,18 +115,44 @@ public IList<Subtitle> SourceTracks
/// Gets the default audio behaviours.
/// </summary>
public SubtitleBehaviours SubtitleBehaviours { get; private set; }

public bool IsBurnableOnly => this.Task.OutputFormat == OutputFormat.WebM;

public bool IsBurnableOnly
public void AddUser()
{
get
{
return this.Task.OutputFormat == OutputFormat.WebM;
}
int count = this.Task.SubtitleTracks.Count;
this.Add();
this.CheckAddState(count);
}

public void AddAllRemainingUser()
{
int count = this.Task.SubtitleTracks.Count;
this.AddAllRemaining();
this.CheckAddState(count);
}

public void AddAllClosedCaptionsUser()
{
int count = this.Task.SubtitleTracks.Count;
this.AddAllClosedCaptions();
this.CheckAddState(count);
}

public void AddAllRemainingForSelectedLanguagesUser()
{
int count = this.Task.SubtitleTracks.Count;
this.AddAllRemainingForSelectedLanguages();
this.CheckAddState(count);
}

#endregion
public void AddFirstForSelectedLanguagesUser()
{
int count = this.Task.SubtitleTracks.Count;
this.AddFirstForSelectedLanguages();
this.CheckAddState(count);
}

#region Public Methods

/// <summary>
/// Add a new Track
Expand Down Expand Up @@ -461,11 +479,7 @@ public void RefreshTask()
}
}
}

#endregion

#region Implemented Interfaces


/// <summary>
/// Setup this tab for the specified preset.
/// </summary>
Expand Down Expand Up @@ -601,10 +615,6 @@ public bool ValidateSubtitles()
return true;
}

#endregion

#region Methods

protected virtual void OnTabStatusChanged(TabStatusEventArgs e)
{
this.TabStatusChanged?.Invoke(this, e);
Expand Down Expand Up @@ -769,6 +779,16 @@ private void AddInputSubtitles(string[] filenames)
}
}

#endregion
private void CheckAddState(int before)
{
if (this.Task.SubtitleTracks.Count == before)
{
this.errorService.ShowMessageBox(
Resources.SubtitleView_NoSubtitlesAdded,
Resources.Info,
MessageBoxButton.OK,
MessageBoxImage.Information);
}
}
}
}
16 changes: 8 additions & 8 deletions win/CS/HandBrakeWPF/Views/SubtitlesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@

<Button.ContextMenu>
<ContextMenu x:Name="MainContextMenu" PlacementRectangle="{Binding RelativeSource={RelativeSource Self}}">
<MenuItem Header="{x:Static Properties:Resources.Shared_AddNewTrack}" cal:Message.Attach="[Event Click] = [Action Add]" />
<MenuItem Header="{x:Static Properties:Resources.Shared_AddAllRemaining}" cal:Message.Attach="[Event Click] = [Action AddAllRemaining]" />
<MenuItem Header="{x:Static Properties:Resources.SubtitleView_AddRemainingCC}" cal:Message.Attach="[Event Click] = [Action AddAllClosedCaptions]" />
<MenuItem Header="{x:Static Properties:Resources.Shared_AddAllForSelected}" cal:Message.Attach="[Event Click] = [Action AddAllRemainingForSelectedLanguages]" />
<MenuItem Header="{x:Static Properties:Resources.Shared_AddNewTrack}" cal:Message.Attach="[Event Click] = [Action AddUser]" />
<MenuItem Header="{x:Static Properties:Resources.Shared_AddAllRemaining}" cal:Message.Attach="[Event Click] = [Action AddAllRemainingUser]" />
<MenuItem Header="{x:Static Properties:Resources.SubtitleView_AddRemainingCC}" cal:Message.Attach="[Event Click] = [Action AddAllClosedCaptionsUser]" />
<MenuItem Header="{x:Static Properties:Resources.Shared_AddAllForSelected}" cal:Message.Attach="[Event Click] = [Action AddAllRemainingForSelectedLanguagesUser]" />
<Separator/>
<MenuItem Header="{x:Static Properties:Resources.SubtitlesView_ImportSubtitle}" cal:Message.Attach="[Event Click] = [Action Import]" />
</ContextMenu>
Expand Down Expand Up @@ -110,10 +110,10 @@

<ListBox.ContextMenu>
<ContextMenu>
<MenuItem Header="{x:Static Properties:Resources.Shared_AddNewTrack}" cal:Message.Attach="[Event Click] = [Action Add]" />
<MenuItem Header="{x:Static Properties:Resources.Shared_AddAllRemaining}" cal:Message.Attach="[Event Click] = [Action AddAllRemaining]" />
<MenuItem Header="{x:Static Properties:Resources.SubtitleView_AddAllCC}" cal:Message.Attach="[Event Click] = [Action AddAllClosedCaptions]" />
<MenuItem Header="{x:Static Properties:Resources.Shared_AddAllForSelected}" cal:Message.Attach="[Event Click] = [Action AddAllRemainingForSelectedLanguages]" />
<MenuItem Header="{x:Static Properties:Resources.Shared_AddNewTrack}" cal:Message.Attach="[Event Click] = [Action AddUser]" />
<MenuItem Header="{x:Static Properties:Resources.Shared_AddAllRemaining}" cal:Message.Attach="[Event Click] = [Action AddAllRemainingUser]" />
<MenuItem Header="{x:Static Properties:Resources.SubtitleView_AddAllCC}" cal:Message.Attach="[Event Click] = [Action AddAllClosedCaptionsUser]" />
<MenuItem Header="{x:Static Properties:Resources.Shared_AddAllForSelected}" cal:Message.Attach="[Event Click] = [Action AddAllRemainingForSelectedLanguagesUser]" />
<Separator />
<MenuItem Header="{x:Static Properties:Resources.Generic_Clear}" cal:Message.Attach="[Event Click] = [Action Clear]" />
<Separator />
Expand Down

0 comments on commit 1e2404d

Please sign in to comment.