This commit is contained in:
niksedk 2023-03-11 04:35:27 +01:00
parent 546674c5df
commit 66e3903536
6 changed files with 426 additions and 29 deletions

View File

@ -59,6 +59,7 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripMenuItemStorageMoveDown = new System.Windows.Forms.ToolStripMenuItem();
this.toggleForcedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toggleDefaultToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.setLanguageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonOpenVideoFile = new System.Windows.Forms.Button();
this.textBoxInputFileName = new System.Windows.Forms.TextBox();
this.textBoxLog = new System.Windows.Forms.TextBox();
@ -79,7 +80,8 @@ namespace Nikse.SubtitleEdit.Forms
this.x272ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStripForm = new System.Windows.Forms.ContextMenuStrip(this.components);
this.closeWindowAfterGenerateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.setLanguageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.defaultSaveInMatroskamkvToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.defaultSaveInMp4ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBoxSettings.SuspendLayout();
this.contextMenuSubtitles.SuspendLayout();
this.contextMenuStripRes.SuspendLayout();
@ -262,6 +264,7 @@ namespace Nikse.SubtitleEdit.Forms
this.listViewSubtitles.TabIndex = 25;
this.listViewSubtitles.UseCompatibleStateImageBehavior = false;
this.listViewSubtitles.View = System.Windows.Forms.View.Details;
this.listViewSubtitles.SelectedIndexChanged += new System.EventHandler(this.listViewSubtitles_SelectedIndexChanged);
this.listViewSubtitles.DragDrop += new System.Windows.Forms.DragEventHandler(this.listViewSubtitles_DragDrop);
this.listViewSubtitles.DragEnter += new System.Windows.Forms.DragEventHandler(this.listViewSubtitles_DragEnter);
//
@ -366,6 +369,13 @@ namespace Nikse.SubtitleEdit.Forms
this.toggleDefaultToolStripMenuItem.DropDownOpening += new System.EventHandler(this.toggleDefaultToolStripMenuItem_DropDownOpening);
this.toggleDefaultToolStripMenuItem.Click += new System.EventHandler(this.buttonSetDefault_Click);
//
// setLanguageToolStripMenuItem
//
this.setLanguageToolStripMenuItem.Name = "setLanguageToolStripMenuItem";
this.setLanguageToolStripMenuItem.Size = new System.Drawing.Size(202, 22);
this.setLanguageToolStripMenuItem.Text = "Set language...";
this.setLanguageToolStripMenuItem.Click += new System.EventHandler(this.buttonSetLanguage_Click);
//
// buttonOpenVideoFile
//
this.buttonOpenVideoFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
@ -503,9 +513,11 @@ namespace Nikse.SubtitleEdit.Forms
// contextMenuStripForm
//
this.contextMenuStripForm.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.closeWindowAfterGenerateToolStripMenuItem});
this.closeWindowAfterGenerateToolStripMenuItem,
this.defaultSaveInMatroskamkvToolStripMenuItem,
this.defaultSaveInMp4ToolStripMenuItem});
this.contextMenuStripForm.Name = "contextMenuStripForm";
this.contextMenuStripForm.Size = new System.Drawing.Size(225, 26);
this.contextMenuStripForm.Size = new System.Drawing.Size(238, 92);
//
// closeWindowAfterGenerateToolStripMenuItem
//
@ -513,15 +525,24 @@ namespace Nikse.SubtitleEdit.Forms
this.closeWindowAfterGenerateToolStripMenuItem.CheckOnClick = true;
this.closeWindowAfterGenerateToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.closeWindowAfterGenerateToolStripMenuItem.Name = "closeWindowAfterGenerateToolStripMenuItem";
this.closeWindowAfterGenerateToolStripMenuItem.Size = new System.Drawing.Size(224, 22);
this.closeWindowAfterGenerateToolStripMenuItem.Size = new System.Drawing.Size(237, 22);
this.closeWindowAfterGenerateToolStripMenuItem.Text = "Close window after generate";
//
// setLanguageToolStripMenuItem
// defaultSaveInMatroskamkvToolStripMenuItem
//
this.setLanguageToolStripMenuItem.Name = "setLanguageToolStripMenuItem";
this.setLanguageToolStripMenuItem.Size = new System.Drawing.Size(202, 22);
this.setLanguageToolStripMenuItem.Text = "Set language...";
this.setLanguageToolStripMenuItem.Click += new System.EventHandler(this.buttonSetLanguage_Click);
this.defaultSaveInMatroskamkvToolStripMenuItem.Checked = true;
this.defaultSaveInMatroskamkvToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.defaultSaveInMatroskamkvToolStripMenuItem.Name = "defaultSaveInMatroskamkvToolStripMenuItem";
this.defaultSaveInMatroskamkvToolStripMenuItem.Size = new System.Drawing.Size(237, 22);
this.defaultSaveInMatroskamkvToolStripMenuItem.Text = "Default save in Matroska (mkv)";
this.defaultSaveInMatroskamkvToolStripMenuItem.Click += new System.EventHandler(this.defaultSaveInMatroskamkvToolStripMenuItem_Click);
//
// defaultSaveInMp4ToolStripMenuItem
//
this.defaultSaveInMp4ToolStripMenuItem.Name = "defaultSaveInMp4ToolStripMenuItem";
this.defaultSaveInMp4ToolStripMenuItem.Size = new System.Drawing.Size(237, 22);
this.defaultSaveInMp4ToolStripMenuItem.Text = "Default save in mp4";
this.defaultSaveInMp4ToolStripMenuItem.Click += new System.EventHandler(this.defaultSaveInMp4ToolStripMenuItem_Click);
//
// GenerateVideoWithSoftSubs
//
@ -605,5 +626,7 @@ namespace Nikse.SubtitleEdit.Forms
private System.Windows.Forms.ToolStripMenuItem closeWindowAfterGenerateToolStripMenuItem;
private System.Windows.Forms.Button buttonSetLanguage;
private System.Windows.Forms.ToolStripMenuItem setLanguageToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem defaultSaveInMatroskamkvToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem defaultSaveInMp4ToolStripMenuItem;
}
}

View File

@ -304,27 +304,12 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private static string GetAssaFileName(string inputVideoFileName)
{
var path = Path.GetDirectoryName(inputVideoFileName);
for (var i = 0; i < int.MaxValue; i++)
{
var guidLetters = Guid.NewGuid().ToString().RemoveChar('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-');
var fileName = Path.Combine(path, $"{guidLetters}.ass");
if (!File.Exists(fileName))
{
return fileName;
}
}
return Path.Combine(path, "qwerty12.ass");
}
private string SuggestNewVideoFileName()
{
var fileName = Path.GetFileNameWithoutExtension(_inputVideoFileName);
fileName += ".embed";
return fileName.Replace(".", "_") + ".mkv";
fileName += defaultSaveInMatroskamkvToolStripMenuItem.Checked ? ".mkv" : ".mp4";
return fileName.Replace(".", "_");
}
private void RunEmbedding()
@ -413,6 +398,7 @@ namespace Nikse.SubtitleEdit.Forms
private void GenerateVideoWithHardSubs_Shown(object sender, EventArgs e)
{
listViewSubtitles.AutoSizeLastColumn();
listViewSubtitles_SelectedIndexChanged(null, null);
if (!File.Exists(_inputVideoFileName))
{
@ -421,9 +407,7 @@ namespace Nikse.SubtitleEdit.Forms
return;
}
var targetFileSizeMb = (int)Math.Round(new FileInfo(_inputVideoFileName).Length / 1024.0 / 1024);
UiUtil.FixFonts(groupBoxSettings, 2000);
buttonGenerate.Focus();
}
@ -663,7 +647,47 @@ namespace Nikse.SubtitleEdit.Forms
private void buttonSetLanguage_Click(object sender, EventArgs e)
{
if (listViewSubtitles.SelectedIndices.Count < 1)
{
return;
}
using (var cl = new Options.ChooseIsoLanguage())
{
if (cl.ShowDialog(this) == DialogResult.OK)
{
foreach (int index in listViewSubtitles.SelectedIndices)
{
_softSubs[index].Language = cl.CultureName;
listViewSubtitles.Items[index].SubItems[1].Text = GetDisplayLanguage(cl.CultureName);
}
}
}
}
private void listViewSubtitles_SelectedIndexChanged(object sender, EventArgs e)
{
var count = listViewSubtitles.SelectedItems.Count;
ButtonRemoveSubtitles.Enabled = count > 0;
buttonClear.Enabled = count > 0;
ButtonMoveSubUp.Enabled = count == 1;
ButtonMoveSubDown.Enabled = count == 1;
buttonToggleForced.Enabled = count > 0;
buttonSetDefault.Enabled = count == 1;
buttonSetLanguage.Enabled = count > 0;
}
private void defaultSaveInMatroskamkvToolStripMenuItem_Click(object sender, EventArgs e)
{
defaultSaveInMatroskamkvToolStripMenuItem.Checked = true;
defaultSaveInMp4ToolStripMenuItem.Checked = false;
}
private void defaultSaveInMp4ToolStripMenuItem_Click(object sender, EventArgs e)
{
defaultSaveInMatroskamkvToolStripMenuItem.Checked = false;
defaultSaveInMp4ToolStripMenuItem.Checked = true;
}
}
}

View File

@ -0,0 +1,109 @@
namespace Nikse.SubtitleEdit.Forms.Options
{
sealed partial class ChooseIsoLanguage
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonOK = new System.Windows.Forms.Button();
this.labelLanguage = new System.Windows.Forms.Label();
this.comboBoxLanguages = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// buttonCancel
//
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonCancel.Location = new System.Drawing.Point(203, 72);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 2;
this.buttonCancel.Text = "C&ancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// buttonOK
//
this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOK.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonOK.Location = new System.Drawing.Point(122, 72);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 23);
this.buttonOK.TabIndex = 1;
this.buttonOK.Text = "&OK";
this.buttonOK.UseVisualStyleBackColor = true;
//
// labelLanguage
//
this.labelLanguage.AutoSize = true;
this.labelLanguage.Location = new System.Drawing.Point(12, 14);
this.labelLanguage.Name = "labelLanguage";
this.labelLanguage.Size = new System.Drawing.Size(54, 13);
this.labelLanguage.TabIndex = 15;
this.labelLanguage.Text = "Language";
//
// comboBoxLanguages
//
this.comboBoxLanguages.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxLanguages.FormattingEnabled = true;
this.comboBoxLanguages.Location = new System.Drawing.Point(12, 31);
this.comboBoxLanguages.Name = "comboBoxLanguages";
this.comboBoxLanguages.Size = new System.Drawing.Size(266, 21);
this.comboBoxLanguages.TabIndex = 0;
//
// ChooseLanguage
//
this.AcceptButton = this.buttonOK;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(290, 105);
this.Controls.Add(this.labelLanguage);
this.Controls.Add(this.comboBoxLanguages);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.KeyPreview = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ChooseLanguage";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Choose language";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ChangeLanguage_KeyDown);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.Label labelLanguage;
private System.Windows.Forms.ComboBox comboBoxLanguages;
}
}

View File

@ -0,0 +1,111 @@
using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Logic;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Forms.Options
{
public sealed partial class ChooseIsoLanguage : PositionAndSizeForm
{
private class TranslationInfo : IEquatable<TranslationInfo>
{
public string CultureName { get; }
public string DisplayName { get; }
public TranslationInfo(string cultureName, string displayName)
{
CultureName = cultureName;
try
{
DisplayName = displayName.CapitalizeFirstLetter(CultureInfo.GetCultureInfo(cultureName));
}
catch
{
DisplayName = displayName.CapitalizeFirstLetter(CultureInfo.InvariantCulture);
}
}
public bool Equals(TranslationInfo ti)
{
return !ReferenceEquals(ti, null) && CultureName.Equals(ti.CultureName, StringComparison.OrdinalIgnoreCase);
}
public override bool Equals(object obj)
{
return Equals(obj as TranslationInfo);
}
public override int GetHashCode()
{
return CultureName.ToUpperInvariant().GetHashCode();
}
public override string ToString()
{
return DisplayName;
}
}
private readonly TranslationInfo _defaultTranslation;
public string CultureName => !(comboBoxLanguages.SelectedItem is TranslationInfo translation) ? _defaultTranslation.CultureName : translation.CultureName;
public ChooseIsoLanguage()
{
TranslationInfo currentTranslation;
UiUtil.PreInitialize(this);
InitializeComponent();
UiUtil.FixFonts(this);
var defaultLanguage = new Language();
_defaultTranslation = new TranslationInfo(defaultLanguage.General.CultureName, defaultLanguage.Name);
var currentLanguage = LanguageSettings.Current;
if (currentLanguage == null)
{
currentTranslation = new TranslationInfo(CultureInfo.CurrentUICulture.Name, CultureInfo.CurrentUICulture.NativeName);
LanguageSettings.Current = defaultLanguage;
}
else
{
currentTranslation = new TranslationInfo(currentLanguage.General.CultureName, currentLanguage.Name);
}
var translations = new HashSet<TranslationInfo> { _defaultTranslation };
foreach (var iso in Iso639Dash2LanguageCode.List)
{
translations.Add(new TranslationInfo(iso.TwoLetterCode, iso.EnglishName));
}
int index = -1;
foreach (var translation in translations.OrderBy(ti => ti.DisplayName, StringComparer.CurrentCultureIgnoreCase).ThenBy(ti => ti.CultureName, StringComparer.Ordinal))
{
int i = comboBoxLanguages.Items.Add(translation);
if (translation.Equals(currentTranslation) || (index < 0 && translation.Equals(_defaultTranslation)))
{
index = i;
}
}
comboBoxLanguages.SelectedIndex = index;
comboBoxLanguages.AutoCompleteSource = AutoCompleteSource.ListItems;
comboBoxLanguages.AutoCompleteMode = AutoCompleteMode.Append;
Text = LanguageSettings.Current.ChooseLanguage.Title;
labelLanguage.Text = LanguageSettings.Current.ChooseLanguage.Language;
buttonOK.Text = LanguageSettings.Current.General.Ok;
buttonCancel.Text = LanguageSettings.Current.General.Cancel;
UiUtil.FixLargeFonts(this, buttonOK);
}
private void ChangeLanguage_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -345,6 +345,12 @@
<Compile Include="Forms\Ocr\WordSplitDictionaryGenerator.Designer.cs">
<DependentUpon>WordSplitDictionaryGenerator.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Options\ChooseIsoLanguage.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\Options\ChooseIsoLanguage.Designer.cs">
<DependentUpon>ChooseIsoLanguage.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Options\SettingsCustomContinuationStyle.cs">
<SubType>Form</SubType>
</Compile>
@ -1605,6 +1611,10 @@
<EmbeddedResource Include="Forms\Ocr\WordSplitDictionaryGenerator.resx">
<DependentUpon>WordSplitDictionaryGenerator.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Options\ChooseIsoLanguage.resx">
<DependentUpon>ChooseIsoLanguage.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Options\SettingsCustomContinuationStyle.resx">
<DependentUpon>SettingsCustomContinuationStyle.cs</DependentUpon>
</EmbeddedResource>