From 738e8404e7e32a34bfba0fbba71db6ef832ae55b Mon Sep 17 00:00:00 2001 From: niksedk Date: Fri, 23 Jun 2023 21:18:32 +0200 Subject: [PATCH] Work on WebVTT --- src/ui/Forms/Main.Designer.cs | 12 +- src/ui/Forms/Main.cs | 9 + src/ui/Forms/Main.resx | 2 +- .../Forms/VTT/WebVttStylePicker.Designer.cs | 169 ++++++++++++++++++ src/ui/Forms/VTT/WebVttStylePicker.cs | 63 +++++++ src/ui/Forms/VTT/WebVttStylePicker.resx | 126 +++++++++++++ src/ui/SubtitleEdit.csproj | 9 + 7 files changed, 388 insertions(+), 2 deletions(-) create mode 100644 src/ui/Forms/VTT/WebVttStylePicker.Designer.cs create mode 100644 src/ui/Forms/VTT/WebVttStylePicker.cs create mode 100644 src/ui/Forms/VTT/WebVttStylePicker.resx diff --git a/src/ui/Forms/Main.Designer.cs b/src/ui/Forms/Main.Designer.cs index 668b56fb3..e3565586e 100644 --- a/src/ui/Forms/Main.Designer.cs +++ b/src/ui/Forms/Main.Designer.cs @@ -575,6 +575,7 @@ namespace Nikse.SubtitleEdit.Forms this.timerOriginalTextUndo = new System.Windows.Forms.Timer(this.components); this.contextMenuStripShowVideoControls = new System.Windows.Forms.ContextMenuStrip(this.components); this.toolStripMenuItemShowVideoControls = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItemWebVttStyle = new System.Windows.Forms.ToolStripMenuItem(); this.statusStrip1.SuspendLayout(); this.toolStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout(); @@ -2641,6 +2642,7 @@ namespace Nikse.SubtitleEdit.Forms this.toolStripSeparatorAssa, this.toolStripMenuItemSetRegion, this.toolStripMenuItemSetLanguage, + this.toolStripMenuItemWebVttStyle, this.toolStripMenuItemWebVTT, this.toolStripMenuItemPreview, this.toolStripMenuItemDelete, @@ -2674,7 +2676,7 @@ namespace Nikse.SubtitleEdit.Forms this.toolStripMenuItemSelectedLines, this.toolStripMenuItemGoogleMicrosoftTranslateSelLine}); this.contextMenuStripListView.Name = "contextMenuStripListView"; - this.contextMenuStripListView.Size = new System.Drawing.Size(285, 804); + this.contextMenuStripListView.Size = new System.Drawing.Size(285, 848); this.contextMenuStripListView.Closed += new System.Windows.Forms.ToolStripDropDownClosedEventHandler(this.MenuClosed); this.contextMenuStripListView.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuStripListViewOpening); this.contextMenuStripListView.Opened += new System.EventHandler(this.MenuOpened); @@ -5621,6 +5623,13 @@ namespace Nikse.SubtitleEdit.Forms this.toolStripMenuItemShowVideoControls.Text = "Show video controls"; this.toolStripMenuItemShowVideoControls.Click += new System.EventHandler(this.toolStripMenuItemShowVideoControls_Click); // + // toolStripMenuItemWebVttStyle + // + this.toolStripMenuItemWebVttStyle.Name = "toolStripMenuItemWebVttStyle"; + this.toolStripMenuItemWebVttStyle.Size = new System.Drawing.Size(284, 22); + this.toolStripMenuItemWebVttStyle.Text = "WebVTT style..."; + this.toolStripMenuItemWebVttStyle.Click += new System.EventHandler(this.toolStripMenuItemWebVttStyle_Click); + // // Main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -6242,5 +6251,6 @@ namespace Nikse.SubtitleEdit.Forms private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemSetLayer; private System.Windows.Forms.NumericUpDown numericUpDownLayer; private System.Windows.Forms.Label labelLayer; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemWebVttStyle; } } \ No newline at end of file diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index db6e152ee..9af9e33aa 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -35209,5 +35209,14 @@ namespace Nikse.SubtitleEdit.Forms exportBdnXmlPng.ShowDialog(this); } } + + private void toolStripMenuItemWebVttStyle_Click(object sender, EventArgs e) + { + var styles = WebVttHelper.GetStyles(_subtitle.Header); + using (var form = new WebVttStylePicker(styles)) + { + form.ShowDialog(this); + } + } } } \ No newline at end of file diff --git a/src/ui/Forms/Main.resx b/src/ui/Forms/Main.resx index 0d28aceb5..f57ca859c 100644 --- a/src/ui/Forms/Main.resx +++ b/src/ui/Forms/Main.resx @@ -857,7 +857,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD2 - CAAAAk1TRnQBSQFMAgEBAgEAAcwBLgHMAS4BEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + CAAAAk1TRnQBSQFMAgEBAgEAAdQBLgHUAS4BEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA diff --git a/src/ui/Forms/VTT/WebVttStylePicker.Designer.cs b/src/ui/Forms/VTT/WebVttStylePicker.Designer.cs new file mode 100644 index 000000000..64a770090 --- /dev/null +++ b/src/ui/Forms/VTT/WebVttStylePicker.Designer.cs @@ -0,0 +1,169 @@ +namespace Nikse.SubtitleEdit.Forms.VTT +{ + sealed partial class WebVttStylePicker + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.listViewExportStyles = new System.Windows.Forms.ListView(); + this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.toolStripMenuItemSelectAll = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItemInverseSelection = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonOK = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.saveFileDialogStyle = new System.Windows.Forms.SaveFileDialog(); + this.labelStyles = new System.Windows.Forms.Label(); + this.groupBoxStyle = new System.Windows.Forms.GroupBox(); + this.contextMenuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // listViewExportStyles + // + this.listViewExportStyles.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); + this.listViewExportStyles.CheckBoxes = true; + this.listViewExportStyles.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.columnHeader1}); + this.listViewExportStyles.ContextMenuStrip = this.contextMenuStrip1; + this.listViewExportStyles.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; + this.listViewExportStyles.HideSelection = false; + this.listViewExportStyles.Location = new System.Drawing.Point(15, 36); + this.listViewExportStyles.Name = "listViewExportStyles"; + this.listViewExportStyles.Size = new System.Drawing.Size(180, 187); + this.listViewExportStyles.TabIndex = 0; + this.listViewExportStyles.UseCompatibleStateImageBehavior = false; + this.listViewExportStyles.View = System.Windows.Forms.View.Details; + // + // contextMenuStrip1 + // + this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItemSelectAll, + this.toolStripMenuItemInverseSelection}); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(162, 48); + // + // toolStripMenuItemSelectAll + // + this.toolStripMenuItemSelectAll.Name = "toolStripMenuItemSelectAll"; + this.toolStripMenuItemSelectAll.Size = new System.Drawing.Size(161, 22); + this.toolStripMenuItemSelectAll.Text = "Select all"; + this.toolStripMenuItemSelectAll.Click += new System.EventHandler(this.toolStripMenuItemSelectAll_Click); + // + // toolStripMenuItemInverseSelection + // + this.toolStripMenuItemInverseSelection.Name = "toolStripMenuItemInverseSelection"; + this.toolStripMenuItemInverseSelection.Size = new System.Drawing.Size(161, 22); + this.toolStripMenuItemInverseSelection.Text = "Inverse selection"; + this.toolStripMenuItemInverseSelection.Click += new System.EventHandler(this.toolStripMenuItemInverseSelection_Click); + // + // buttonOK + // + this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonOK.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.buttonOK.Location = new System.Drawing.Point(361, 231); + this.buttonOK.Name = "buttonOK"; + this.buttonOK.Size = new System.Drawing.Size(75, 23); + this.buttonOK.TabIndex = 4; + this.buttonOK.Text = "&OK"; + this.buttonOK.UseVisualStyleBackColor = true; + this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.buttonCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.buttonCancel.Location = new System.Drawing.Point(445, 231); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "C&ancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // saveFileDialogStyle + // + this.saveFileDialogStyle.OverwritePrompt = false; + // + // labelStyles + // + this.labelStyles.AutoSize = true; + this.labelStyles.Location = new System.Drawing.Point(12, 20); + this.labelStyles.Name = "labelStyles"; + this.labelStyles.Size = new System.Drawing.Size(35, 13); + this.labelStyles.TabIndex = 6; + this.labelStyles.Text = "Styles"; + // + // groupBoxStyle + // + this.groupBoxStyle.Location = new System.Drawing.Point(201, 38); + this.groupBoxStyle.Name = "groupBoxStyle"; + this.groupBoxStyle.Size = new System.Drawing.Size(319, 187); + this.groupBoxStyle.TabIndex = 7; + this.groupBoxStyle.TabStop = false; + this.groupBoxStyle.Text = "Style"; + // + // WebVttIStylePicker + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(532, 264); + this.Controls.Add(this.groupBoxStyle); + this.Controls.Add(this.labelStyles); + this.Controls.Add(this.buttonOK); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.listViewExportStyles); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.KeyPreview = true; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "WebVttStylePicker"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "SubStationAlphaStylesExport"; + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.WebVttImportExport_KeyDown); + this.contextMenuStrip1.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ListView listViewExportStyles; + private System.Windows.Forms.Button buttonOK; + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.SaveFileDialog saveFileDialogStyle; + private System.Windows.Forms.ColumnHeader columnHeader1; + private System.Windows.Forms.Label labelStyles; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemSelectAll; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemInverseSelection; + private System.Windows.Forms.GroupBox groupBoxStyle; + } +} \ No newline at end of file diff --git a/src/ui/Forms/VTT/WebVttStylePicker.cs b/src/ui/Forms/VTT/WebVttStylePicker.cs new file mode 100644 index 000000000..17787ab32 --- /dev/null +++ b/src/ui/Forms/VTT/WebVttStylePicker.cs @@ -0,0 +1,63 @@ +using Nikse.SubtitleEdit.Core.Common; +using Nikse.SubtitleEdit.Logic; +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace Nikse.SubtitleEdit.Forms.VTT +{ + public sealed partial class WebVttStylePicker : Form + { + private readonly List _styles; + public List ImportExportStyles { get; set; } + + public WebVttStylePicker(List styles) + { + InitializeComponent(); + UiUtil.FixFonts(this); + + _styles = styles; + listViewExportStyles.Columns[0].Width = listViewExportStyles.Width - 20; + foreach (var style in _styles) + { + listViewExportStyles.Items.Add(new ListViewItem(style.Name) { Checked = true, Tag = style }); + } + + Text = LanguageSettings.Current.SubStationAlphaStyles.Export; + labelStyles.Text = LanguageSettings.Current.SubStationAlphaStyles.Styles; + toolStripMenuItemInverseSelection.Text = LanguageSettings.Current.Main.Menu.Edit.InverseSelection; + toolStripMenuItemSelectAll.Text = LanguageSettings.Current.Main.Menu.ContextMenu.SelectAll; + buttonOK.Text = LanguageSettings.Current.General.Ok; + buttonCancel.Text = LanguageSettings.Current.General.Cancel; + } + + private void buttonOK_Click(object sender, EventArgs e) + { + + } + + private void WebVttImportExport_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + { + DialogResult = DialogResult.Cancel; + } + } + + private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e) + { + foreach (ListViewItem item in listViewExportStyles.Items) + { + item.Checked = true; + } + } + + private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e) + { + foreach (ListViewItem item in listViewExportStyles.Items) + { + item.Checked = !item.Checked; + } + } + } +} diff --git a/src/ui/Forms/VTT/WebVttStylePicker.resx b/src/ui/Forms/VTT/WebVttStylePicker.resx new file mode 100644 index 000000000..0a39974e8 --- /dev/null +++ b/src/ui/Forms/VTT/WebVttStylePicker.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 172, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/src/ui/SubtitleEdit.csproj b/src/ui/SubtitleEdit.csproj index 021289a0b..374d8a888 100644 --- a/src/ui/SubtitleEdit.csproj +++ b/src/ui/SubtitleEdit.csproj @@ -1366,6 +1366,12 @@ VobSubOcrSetItalicFactor.cs + + Form + + + WebVttStylePicker.cs + Form @@ -2139,6 +2145,9 @@ VobSubOcrSetItalicFactor.cs + + WebVttStylePicker.cs + WebVttImportExport.cs