Merge pull request #6156 from OmrSi/add-shortcut-loop-selected-line

Add `Loop selected line` shortcut
This commit is contained in:
Nikolaj Olsson 2022-08-18 07:02:24 +02:00 committed by GitHub
commit 74d706d5b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 67 additions and 16 deletions

View File

@ -2453,6 +2453,7 @@ can edit in same subtitle file (collaboration)</Information>
<GoToStartCurrent>Set video pos to start of current subtitle</GoToStartCurrent>
<ToggleStartEndCurrent>Toggle video pos between start/end of current subtitle</ToggleStartEndCurrent>
<PlaySelectedLines>Play selected lines</PlaySelectedLines>
<LoopSelectedLines>Loop selected line</LoopSelectedLines>
<WaveformGoToPrevSubtitle>Go to previous subtitle (from video position)</WaveformGoToPrevSubtitle>
<WaveformGoToNextSubtitle>Go to next subtitle (from video position)</WaveformGoToNextSubtitle>
<WaveformGoToPrevChapter>Go to previous chapter</WaveformGoToPrevChapter>

View File

@ -2282,6 +2282,7 @@ $HorzAlign = Center
public string MainVideoGoToStartCurrent { get; set; }
public string MainVideoToggleStartEndCurrent { get; set; }
public string MainVideoPlaySelectedLines { get; set; }
public string MainVideoLoopSelectedLines { get; set; }
public string MainVideoGoToPrevSubtitle { get; set; }
public string MainVideoGoToNextSubtitle { get; set; }
public string MainVideoGoToPrevChapter { get; set; }
@ -8403,6 +8404,12 @@ $HorzAlign = Center
shortcuts.MainVideoPlaySelectedLines = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainVideoLoopSelectedLines");
if (subNode != null)
{
shortcuts.MainVideoLoopSelectedLines = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainVideoGoToPrevSubtitle");
if (subNode != null)
{
@ -10713,6 +10720,7 @@ $HorzAlign = Center
textWriter.WriteElementString("MainVideoGoToStartCurrent", shortcuts.MainVideoGoToStartCurrent);
textWriter.WriteElementString("MainVideoToggleStartEndCurrent", shortcuts.MainVideoToggleStartEndCurrent);
textWriter.WriteElementString("MainVideoPlaySelectedLines", shortcuts.MainVideoPlaySelectedLines);
textWriter.WriteElementString("MainVideoLoopSelectedLines", shortcuts.MainVideoLoopSelectedLines);
textWriter.WriteElementString("MainVideoGoToPrevSubtitle", shortcuts.MainVideoGoToPrevSubtitle);
textWriter.WriteElementString("MainVideoGoToNextSubtitle", shortcuts.MainVideoGoToNextSubtitle);
textWriter.WriteElementString("MainVideoGoToPrevChapter", shortcuts.MainVideoGoToPrevChapter);

View File

@ -46,6 +46,7 @@ namespace Nikse.SubtitleEdit.Controls
public event EventHandler OnButtonClicked;
public event EventHandler OnEmptyPlayerClicked;
public event EventHandler OnPlayerClicked;
public Panel PanelPlayer { get; private set; }
private Panel _panelSubtitle;
@ -366,6 +367,7 @@ namespace Nikse.SubtitleEdit.Controls
private void SubtitleTextBoxMouseClick(object sender, MouseEventArgs e)
{
TogglePlayPause();
OnPlayerClicked?.Invoke(sender, e);
}
public Paragraph LastParagraph { get; set; }
@ -581,6 +583,7 @@ namespace Nikse.SubtitleEdit.Controls
}
TogglePlayPause();
OnPlayerClicked?.Invoke(sender, e);
}
public void InitializeVolume(double defaultVolume)

View File

@ -8748,7 +8748,7 @@ namespace Nikse.SubtitleEdit.Forms
var audioToText = new ToolStripMenuItem(LanguageSettings.Current.Main.Menu.Video.VideoAudioToText);
UiUtil.FixFonts(audioToText);
audio.DropDownItems.Insert(0, audioClip);
if (Configuration.IsRunningOnWindows)
{
audio.DropDownItems.Insert(0, audioToText);
@ -10178,6 +10178,13 @@ namespace Nikse.SubtitleEdit.Forms
private void SubtitleListview1_SelectedIndexChanged(object sender, EventArgs e)
{
if (_playSelectionIndexLoopStart >= 0)
{
_endSeconds = -1;
_playSelectionIndex = -1;
_playSelectionIndexLoopStart = -1;
}
if (SubtitleListview1.SelectedIndices.Count == 0)
{
_listViewTextUndoIndex = -1;
@ -16760,7 +16767,7 @@ namespace Nikse.SubtitleEdit.Forms
mediaPlayer.Pause();
}
e.SuppressKeyPress = true;
e.SuppressKeyPress = true;
}
}
else if (e.KeyData == _shortcuts.VideoPlay200Speed)
@ -16904,16 +16911,16 @@ namespace Nikse.SubtitleEdit.Forms
{
if (SubtitleListview1.SelectedItems.Count > 0 && _subtitle != null && mediaPlayer.VideoPlayer != null)
{
var p = _subtitle.GetParagraphOrDefault(SubtitleListview1.SelectedItems[0].Index);
if (p != null)
{
mediaPlayer.CurrentPosition = p.StartTime.TotalSeconds;
ShowSubtitle();
mediaPlayer.Play();
_endSeconds = p.EndTime.TotalSeconds;
_playSelectionIndex = _subtitle.GetIndex(p);
_playSelectionIndexLoopStart = -1;
}
PlaySelectedLines(false);
}
e.SuppressKeyPress = true;
}
else if (_shortcuts.MainVideoLoopSelectedLines == e.KeyData)
{
if (SubtitleListview1.SelectedItems.Count > 0 && _subtitle != null && mediaPlayer.VideoPlayer != null)
{
PlaySelectedLines(true);
}
e.SuppressKeyPress = true;
@ -22198,7 +22205,7 @@ namespace Nikse.SubtitleEdit.Forms
{
var first = _subtitle.GetParagraphOrDefault(_playSelectionIndexLoopStart);
if (first != null)
{ // nixe harboe debug
{
_endSeconds = first.EndTime.TotalSeconds;
mediaPlayer.CurrentPosition = first.StartTime.TotalSeconds;
System.Threading.SynchronizationContext.Current.Post(TimeSpan.FromMilliseconds(151), () =>
@ -22324,8 +22331,6 @@ namespace Nikse.SubtitleEdit.Forms
}
ShowSubtitleTimer.Start();
Text = "EndSeconds=" + _endSeconds + " startIdx=" + _playSelectionIndexLoopStart + " Idx=" + _playSelectionIndex;
}
private void AddTitleBarChangeAsterisk(bool currentChanged, bool originalChanged, bool originalActive)
@ -22953,6 +22958,24 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private void PlaySelectedLines(bool loop)
{
var p = _subtitle.GetParagraphOrDefault(SubtitleListview1.SelectedItems[0].Index);
if (p != null)
{
mediaPlayer.CurrentPosition = p.StartTime.TotalSeconds;
ShowSubtitle();
mediaPlayer.Play();
_endSeconds = p.EndTime.TotalSeconds;
_playSelectionIndex = _subtitle.GetIndex(p);
if (loop)
{
_playSelectionIndexLoopStart = SubtitleListview1.SelectedItems[0].Index;
}
}
}
private void buttonSetStartTime_Click(object sender, EventArgs e)
{
SetStartTime(false, mediaPlayer.CurrentPosition);
@ -23802,7 +23825,7 @@ namespace Nikse.SubtitleEdit.Forms
{
if (!string.IsNullOrEmpty(_fileName) && File.Exists(_fileName))
{
UiUtil.OpenFolderFromFileName(_fileName);
UiUtil.OpenFolderFromFileName(_fileName);
}
}
@ -24262,6 +24285,7 @@ namespace Nikse.SubtitleEdit.Forms
LoadPlugins();
mediaPlayer.OnEmptyPlayerClicked += MediaPlayer_OnEmptyPlayerClicked;
mediaPlayer.OnPlayerClicked += MediaPlayer_OnPlayerClicked;
SubtitleListview1.SelectIndexAndEnsureVisible(_subtitleListViewIndex, true);
if (Configuration.Settings.General.StartInSourceView)
{
@ -24525,6 +24549,13 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private void MediaPlayer_OnPlayerClicked(object sender, EventArgs e)
{
_endSeconds = -1;
_playSelectionIndex = -1;
_playSelectionIndexLoopStart = -1;
}
private void SetPlayRateAndPlay(int playRate)
{
SetPlayRate(toolStripSplitButtonPlayRate.DropDownItems[playRate.ToString()], null, false, true);

View File

@ -1371,6 +1371,7 @@ namespace Nikse.SubtitleEdit.Forms.Options
AddNode(videoNode, language.GoToStartCurrent, nameof(Configuration.Settings.Shortcuts.MainVideoGoToStartCurrent));
AddNode(videoNode, language.ToggleStartEndCurrent, nameof(Configuration.Settings.Shortcuts.MainVideoToggleStartEndCurrent));
AddNode(videoNode, language.PlaySelectedLines, nameof(Configuration.Settings.Shortcuts.MainVideoPlaySelectedLines));
AddNode(videoNode, language.LoopSelectedLines, nameof(Configuration.Settings.Shortcuts.MainVideoLoopSelectedLines));
AddNode(videoNode, language.WaveformGoToPrevSubtitle, nameof(Configuration.Settings.Shortcuts.MainVideoGoToPrevSubtitle));
AddNode(videoNode, language.WaveformGoToNextSubtitle, nameof(Configuration.Settings.Shortcuts.MainVideoGoToNextSubtitle));
AddNode(videoNode, language.WaveformGoToPrevChapter, nameof(Configuration.Settings.Shortcuts.MainVideoGoToPrevChapter));

View File

@ -2786,6 +2786,7 @@ can edit in same subtitle file (collaboration)",
GoToStartCurrent = "Set video pos to start of current subtitle",
ToggleStartEndCurrent = "Toggle video pos between start/end of current subtitle",
PlaySelectedLines = "Play selected lines",
LoopSelectedLines = "Loop selected line",
Pause = "Pause",
TogglePlayPause = "Toggle play/pause",
Play150Speed = "Play video with 1.5x speed",

View File

@ -6724,6 +6724,9 @@ namespace Nikse.SubtitleEdit.Logic
case "Settings/PlaySelectedLines":
language.Settings.PlaySelectedLines = reader.Value;
break;
case "Settings/LoopSelectedLines":
language.Settings.LoopSelectedLines = reader.Value;
break;
case "Settings/WaveformGoToPrevSubtitle":
language.Settings.WaveformGoToPrevSubtitle = reader.Value;
break;

View File

@ -2634,6 +2634,7 @@
public string GoToStartCurrent { get; set; }
public string ToggleStartEndCurrent { get; set; }
public string PlaySelectedLines { get; set; }
public string LoopSelectedLines { get; set; }
public string WaveformGoToPrevSubtitle { get; set; }
public string WaveformGoToNextSubtitle { get; set; }

View File

@ -63,6 +63,7 @@ namespace Nikse.SubtitleEdit.Logic
public Keys MainVideoGoToStartCurrent { get; set; }
public Keys MainVideoToggleStartEndCurrent { get; set; }
public Keys MainVideoPlaySelectedLines { get; set; }
public Keys MainVideoLoopSelectedLines { get; set; }
public Keys VideoGoToPrevSubtitle { get; set; }
public Keys VideoGoToNextSubtitle { get; set; }
public Keys VideoGoToPrevChapter { get; set; }
@ -294,6 +295,7 @@ namespace Nikse.SubtitleEdit.Logic
MainVideoGoToStartCurrent = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoGoToStartCurrent);
MainVideoToggleStartEndCurrent = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoToggleStartEndCurrent);
MainVideoPlaySelectedLines = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoPlaySelectedLines);
MainVideoLoopSelectedLines = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoLoopSelectedLines);
VideoGoToPrevSubtitle = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoGoToPrevSubtitle);
VideoGoToNextSubtitle = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoGoToNextSubtitle);
VideoGoToPrevChapter = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoGoToPrevChapter);