From 1ef81526cf916de661935e556130a67e47799088 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Wed, 6 May 2020 20:35:29 +0200 Subject: [PATCH] Add extra move shortcuts to waveform - thx Shaddy :) Arrow left = 1 sec left, arrow right = 1 sec right + 100ms shortcuts too --- libse/Settings.cs | 36 ++++++++++++++++++++++ src/Controls/AudioVisualizer.cs | 53 +++++++++++++++++++++++++++++++++ src/Forms/Main.cs | 4 +++ src/Forms/Settings.cs | 10 +++++-- 4 files changed, 101 insertions(+), 2 deletions(-) diff --git a/libse/Settings.cs b/libse/Settings.cs index 1ed37d704..7321f3192 100644 --- a/libse/Settings.cs +++ b/libse/Settings.cs @@ -1660,6 +1660,10 @@ $HorzAlign = Center public string WaveformGoToNextSceneChange { get; set; } public string WaveformToggleSceneChange { get; set; } public string WaveformGuessStart { get; set; } + public string Waveform100MsLeft { get; set; } + public string Waveform100MsRight { get; set; } + public string Waveform1000MsLeft { get; set; } + public string Waveform1000MsRight { get; set; } public string MainTranslateGoogleIt { get; set; } public string MainTranslateGoogleTranslate { get; set; } public string MainTranslateCustomSearch1 { get; set; } @@ -1777,6 +1781,10 @@ $HorzAlign = Center WaveformSearchSilenceForward = string.Empty; WaveformSearchSilenceBack = string.Empty; WaveformAddTextHere = "Return"; + Waveform100MsLeft = "Shift+Left"; + Waveform100MsRight = "Shift+Right"; + Waveform1000MsLeft = "Left"; + Waveform1000MsRight = "Right"; MainAdjustExtendToNextSceneChange = string.Empty; MainAdjustExtendToPreviousSceneChange = string.Empty; MainAdjustExtendToNextSubtitle = "Control+Shift+E"; @@ -6568,6 +6576,30 @@ $HorzAlign = Center settings.Shortcuts.WaveformGuessStart = subNode.InnerText; } + subNode = node.SelectSingleNode("Waveform100MsLeft"); + if (subNode != null) + { + settings.Shortcuts.Waveform100MsLeft = subNode.InnerText; + } + + subNode = node.SelectSingleNode("Waveform100MsRight"); + if (subNode != null) + { + settings.Shortcuts.Waveform100MsRight = subNode.InnerText; + } + + subNode = node.SelectSingleNode("Waveform1000MsLeft"); + if (subNode != null) + { + settings.Shortcuts.Waveform1000MsLeft = subNode.InnerText; + } + + subNode = node.SelectSingleNode("Waveform1000MsRight"); + if (subNode != null) + { + settings.Shortcuts.Waveform1000MsRight = subNode.InnerText; + } + subNode = node.SelectSingleNode("MainTranslateGoogleIt"); if (subNode != null) { @@ -7621,6 +7653,10 @@ $HorzAlign = Center textWriter.WriteElementString("WaveformGoToNextSceneChange", settings.Shortcuts.WaveformGoToNextSceneChange); textWriter.WriteElementString("WaveformToggleSceneChange", settings.Shortcuts.WaveformToggleSceneChange); textWriter.WriteElementString("WaveformGuessStart", settings.Shortcuts.WaveformGuessStart); + textWriter.WriteElementString("Waveform100MsLeft", settings.Shortcuts.Waveform100MsLeft); + textWriter.WriteElementString("Waveform100MsRight", settings.Shortcuts.Waveform100MsRight); + textWriter.WriteElementString("Waveform1000MsLeft", settings.Shortcuts.Waveform1000MsLeft); + textWriter.WriteElementString("Waveform1000MsRight", settings.Shortcuts.Waveform1000MsRight); textWriter.WriteElementString("MainTranslateGoogleIt", settings.Shortcuts.MainTranslateGoogleIt); textWriter.WriteElementString("MainTranslateGoogleTranslate", settings.Shortcuts.MainTranslateGoogleTranslate); textWriter.WriteElementString("MainTranslateCustomSearch1", settings.Shortcuts.MainTranslateCustomSearch1); diff --git a/src/Controls/AudioVisualizer.cs b/src/Controls/AudioVisualizer.cs index 32881cd28..90fa23ab4 100644 --- a/src/Controls/AudioVisualizer.cs +++ b/src/Controls/AudioVisualizer.cs @@ -115,6 +115,10 @@ namespace Nikse.SubtitleEdit.Controls private double _wholeParagraphMinMilliseconds; private double _wholeParagraphMaxMilliseconds = double.MaxValue; public Keys InsertAtVideoPositionShortcut { get; set; } + public Keys Move100MsLeft { get; set; } + public Keys Move100MsRight { get; set; } + public Keys MoveOneSecondLeft { get; set; } + public Keys MoveOneSecondRight { get; set; } public bool MouseWheelScrollUpIsForward { get; set; } = true; public const double ZoomMinimum = 0.1; @@ -350,6 +354,23 @@ namespace Nikse.SubtitleEdit.Controls InsertAtVideoPositionShortcut = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainWaveformInsertAtCurrentPosition); } + protected override bool IsInputKey(Keys keyData) + { + Keys key = keyData & Keys.KeyCode; + + switch (key) + { + case Keys.Up: + case Keys.Down: + case Keys.Right: + case Keys.Left: + return true; + + default: + return base.IsInputKey(keyData); + } + } + private void LoadParagraphs(Subtitle subtitle, int primarySelectedIndex, ListView.SelectedIndexCollection selectedIndexes) { _subtitle.Paragraphs.Clear(); @@ -1958,6 +1979,38 @@ namespace Nikse.SubtitleEdit.Controls e.Handled = true; } } + else if (e.KeyData == Move100MsLeft) + { + var pos = Math.Max(0, _currentVideoPositionSeconds - 0.1); + OnPositionSelected?.Invoke(this, new ParagraphEventArgs(pos, null)); + Invalidate(); + e.SuppressKeyPress = true; + e.Handled = true; + } + else if (e.KeyData == Move100MsRight) + { + var pos = _currentVideoPositionSeconds + 0.1; + OnPositionSelected?.Invoke(this, new ParagraphEventArgs(pos, null)); + Invalidate(); + e.SuppressKeyPress = true; + e.Handled = true; + } + else if (e.KeyData == MoveOneSecondLeft) + { + var pos = Math.Max(0, _currentVideoPositionSeconds - 1); + OnPositionSelected?.Invoke(this, new ParagraphEventArgs(pos, null)); + Invalidate(); + e.SuppressKeyPress = true; + e.Handled = true; + } + else if (e.KeyData == MoveOneSecondRight) + { + var pos = _currentVideoPositionSeconds + 1; + OnPositionSelected?.Invoke(this, new ParagraphEventArgs(pos, null)); + Invalidate(); + e.SuppressKeyPress = true; + e.Handled = true; + } } public void ZoomIn() diff --git a/src/Forms/Main.cs b/src/Forms/Main.cs index 8b2f9b946..e99aa2ca4 100644 --- a/src/Forms/Main.cs +++ b/src/Forms/Main.cs @@ -20085,6 +20085,10 @@ namespace Nikse.SubtitleEdit.Forms italicToolStripMenuItem1.ShortcutKeys = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxItalic); audioVisualizer.InsertAtVideoPositionShortcut = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainWaveformInsertAtCurrentPosition); + audioVisualizer.Move100MsLeft = UiUtil.GetKeys(Configuration.Settings.Shortcuts.Waveform100MsLeft); + audioVisualizer.Move100MsRight = UiUtil.GetKeys(Configuration.Settings.Shortcuts.Waveform100MsRight); + audioVisualizer.MoveOneSecondLeft = UiUtil.GetKeys(Configuration.Settings.Shortcuts.Waveform1000MsLeft); + audioVisualizer.MoveOneSecondRight = UiUtil.GetKeys(Configuration.Settings.Shortcuts.Waveform1000MsRight); UiUtil.HelpKeys = UiUtil.GetKeys(Configuration.Settings.Shortcuts.GeneralHelp); helpToolStripMenuItem1.ShortcutKeys = UiUtil.HelpKeys; diff --git a/src/Forms/Settings.cs b/src/Forms/Settings.cs index bece644e3..24383236c 100644 --- a/src/Forms/Settings.cs +++ b/src/Forms/Settings.cs @@ -1372,6 +1372,10 @@ namespace Nikse.SubtitleEdit.Forms AddNode(audioVisualizerNode, language.WaveformGoToNextSceneChange, nameof(Configuration.Settings.Shortcuts.WaveformGoToNextSceneChange)); AddNode(audioVisualizerNode, language.WaveformToggleSceneChange, nameof(Configuration.Settings.Shortcuts.WaveformToggleSceneChange)); AddNode(audioVisualizerNode, language.WaveformGuessStart, nameof(Configuration.Settings.Shortcuts.WaveformGuessStart)); + AddNode(audioVisualizerNode, language.GoBack100Milliseconds, nameof(Configuration.Settings.Shortcuts.Waveform100MsLeft)); + AddNode(audioVisualizerNode, language.GoForward100Milliseconds, nameof(Configuration.Settings.Shortcuts.Waveform100MsRight)); + AddNode(audioVisualizerNode, language.GoBack1Second, nameof(Configuration.Settings.Shortcuts.Waveform1000MsLeft)); + AddNode(audioVisualizerNode, language.GoForward1Second, nameof(Configuration.Settings.Shortcuts.Waveform1000MsRight)); if (audioVisualizerNode.Nodes.Count > 0) { _shortcuts.Nodes.Add(audioVisualizerNode); @@ -2851,8 +2855,10 @@ namespace Nikse.SubtitleEdit.Forms } if (existsIn.Length > 0 && comboBoxShortcutKey.SelectedIndex > 0) { - MessageBox.Show(existsIn.ToString(), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Warning); - return; + if (MessageBox.Show(existsIn.ToString(), string.Empty, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) + { + return; + } } treeViewShortcuts.SelectedNode.Text = text + " " + shortcutText; AddToSaveList((ShortcutHelper)treeViewShortcuts.SelectedNode.Tag, shortcutText);