Add "Renumber" to "Import plain text" - thx Leon :)

This commit is contained in:
Nikolaj Olsson 2018-01-31 09:55:45 +01:00
parent 1db874eed3
commit f7bf3e9c3e
3 changed files with 65 additions and 20 deletions

View File

@ -31,12 +31,12 @@
this.components = new System.ComponentModel.Container();
this.buttonOpenText = new System.Windows.Forms.Button();
this.groupBoxImportText = new System.Windows.Forms.GroupBox();
this.checkBoxMultipleFiles = new System.Windows.Forms.CheckBox();
this.listViewInputFiles = new System.Windows.Forms.ListView();
this.columnHeaderFName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeaderSize = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.contextMenuStripListView = new System.Windows.Forms.ContextMenuStrip(this.components);
this.clearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.checkBoxMultipleFiles = new System.Windows.Forms.CheckBox();
this.textBoxText = new System.Windows.Forms.TextBox();
this.groupBoxImportOptions = new System.Windows.Forms.GroupBox();
this.checkBoxAutoBreak = new System.Windows.Forms.CheckBox();
@ -63,6 +63,8 @@
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonOK = new System.Windows.Forms.Button();
this.contextMenuStripPreview = new System.Windows.Forms.ContextMenuStrip(this.components);
this.startNumberingFromToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBoxImportText.SuspendLayout();
this.contextMenuStripListView.SuspendLayout();
this.groupBoxImportOptions.SuspendLayout();
@ -72,6 +74,7 @@
((System.ComponentModel.ISupportInitialize)(this.numericUpDownDurationFixed)).BeginInit();
this.groupBoxSplitting.SuspendLayout();
this.groupBoxImportResult.SuspendLayout();
this.contextMenuStripPreview.SuspendLayout();
this.SuspendLayout();
//
// buttonOpenText
@ -100,6 +103,18 @@
this.groupBoxImportText.TabStop = false;
this.groupBoxImportText.Text = "Import text";
//
// checkBoxMultipleFiles
//
this.checkBoxMultipleFiles.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.checkBoxMultipleFiles.AutoSize = true;
this.checkBoxMultipleFiles.Location = new System.Drawing.Point(178, 22);
this.checkBoxMultipleFiles.Name = "checkBoxMultipleFiles";
this.checkBoxMultipleFiles.Size = new System.Drawing.Size(198, 17);
this.checkBoxMultipleFiles.TabIndex = 5;
this.checkBoxMultipleFiles.Text = "Multiple files - one file is one subtitle";
this.checkBoxMultipleFiles.UseVisualStyleBackColor = true;
this.checkBoxMultipleFiles.CheckedChanged += new System.EventHandler(this.checkBoxMultipleFiles_CheckedChanged);
//
// listViewInputFiles
//
this.listViewInputFiles.AllowDrop = true;
@ -145,18 +160,6 @@
this.clearToolStripMenuItem.Text = "Clear";
this.clearToolStripMenuItem.Click += new System.EventHandler(this.clearToolStripMenuItem_Click);
//
// checkBoxMultipleFiles
//
this.checkBoxMultipleFiles.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.checkBoxMultipleFiles.AutoSize = true;
this.checkBoxMultipleFiles.Location = new System.Drawing.Point(178, 22);
this.checkBoxMultipleFiles.Name = "checkBoxMultipleFiles";
this.checkBoxMultipleFiles.Size = new System.Drawing.Size(198, 17);
this.checkBoxMultipleFiles.TabIndex = 5;
this.checkBoxMultipleFiles.Text = "Multiple files - one file is one subtitle";
this.checkBoxMultipleFiles.UseVisualStyleBackColor = true;
this.checkBoxMultipleFiles.CheckedChanged += new System.EventHandler(this.checkBoxMultipleFiles_CheckedChanged);
//
// textBoxText
//
this.textBoxText.AllowDrop = true;
@ -458,6 +461,7 @@
this.SubtitleListview1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.SubtitleListview1.ContextMenuStrip = this.contextMenuStripPreview;
this.SubtitleListview1.FirstVisibleIndex = -1;
this.SubtitleListview1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.SubtitleListview1.FullRowSelect = true;
@ -505,6 +509,20 @@
this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Click += new System.EventHandler(this.ButtonOkClick);
//
// contextMenuStripPreview
//
this.contextMenuStripPreview.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.startNumberingFromToolStripMenuItem});
this.contextMenuStripPreview.Name = "contextMenuStripPreview";
this.contextMenuStripPreview.Size = new System.Drawing.Size(199, 26);
//
// startNumberingFromToolStripMenuItem
//
this.startNumberingFromToolStripMenuItem.Name = "startNumberingFromToolStripMenuItem";
this.startNumberingFromToolStripMenuItem.Size = new System.Drawing.Size(198, 22);
this.startNumberingFromToolStripMenuItem.Text = "Start numbering from...";
this.startNumberingFromToolStripMenuItem.Click += new System.EventHandler(this.startNumberingFromToolStripMenuItem_Click);
//
// ImportText
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -540,6 +558,7 @@
this.groupBoxSplitting.ResumeLayout(false);
this.groupBoxSplitting.PerformLayout();
this.groupBoxImportResult.ResumeLayout(false);
this.contextMenuStripPreview.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -580,5 +599,7 @@
private System.Windows.Forms.ComboBox comboBoxLineBreak;
private System.Windows.Forms.ContextMenuStrip contextMenuStripListView;
private System.Windows.Forms.ToolStripMenuItem clearToolStripMenuItem;
private System.Windows.Forms.ContextMenuStrip contextMenuStripPreview;
private System.Windows.Forms.ToolStripMenuItem startNumberingFromToolStripMenuItem;
}
}

View File

@ -18,7 +18,8 @@ namespace Nikse.SubtitleEdit.Forms
private Subtitle _subtitleInput;
private string _videoFileName;
private readonly Timer _refreshTimer = new Timer();
private bool _exit;
private readonly bool _exit;
private int _startFromNumber = 1;
public Subtitle FixedSubtitle => _subtitle;
public SubtitleFormat Format { get; set; }
@ -63,6 +64,7 @@ namespace Nikse.SubtitleEdit.Forms
groupBoxTimeCodes.Text = Configuration.Settings.Language.ImportText.TimeCodes;
groupBoxImportResult.Text = Configuration.Settings.Language.General.Preview;
clearToolStripMenuItem.Text = Configuration.Settings.Language.DvdSubRip.Clear;
startNumberingFromToolStripMenuItem.Text = Configuration.Settings.Language.Main.Menu.Tools.StartNumberingFrom;
buttonOK.Text = Configuration.Settings.Language.General.Ok;
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;
SubtitleListview1.InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings);
@ -128,6 +130,7 @@ namespace Nikse.SubtitleEdit.Forms
openFileDialog1.Multiselect = checkBoxMultipleFiles.Visible && checkBoxMultipleFiles.Checked;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
_startFromNumber = 1;
if (checkBoxMultipleFiles.Visible && checkBoxMultipleFiles.Checked)
{
foreach (string fileName in openFileDialog1.FileNames)
@ -219,7 +222,7 @@ namespace Nikse.SubtitleEdit.Forms
if (checkBoxMergeShortLines.Checked)
MergeLinesWithContinuation();
_subtitle.Renumber();
_subtitle.Renumber(_startFromNumber);
if (checkBoxGenerateTimeCodes.Checked)
{
FixDurations();
@ -706,7 +709,7 @@ namespace Nikse.SubtitleEdit.Forms
{
Encoding encoding = LanguageAutoDetect.GetEncodingFromFile(fileName);
var text = FileUtil.ReadAllTextShared(fileName, encoding);
if (fileName.EndsWith(".htm", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".htm", StringComparison.OrdinalIgnoreCase))
if (fileName.EndsWith(".html", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".htm", StringComparison.OrdinalIgnoreCase))
text = HtmlToPlainText(text);
return text;
}
@ -755,12 +758,17 @@ namespace Nikse.SubtitleEdit.Forms
var sb = new StringBuilder();
var doc = new XmlDocument();
doc.Load(fileName);
foreach (XmlNode node in doc.DocumentElement.SelectNodes("//paragraph[@element='Dialog']")) // <paragraph objID="1:28" element="Dialog">
var nodes = doc.DocumentElement?.SelectNodes("//paragraph[@element='Dialog']");
if (nodes != null)
{
XmlNode textRun = node.SelectSingleNode("textRun"); // <textRun objID="1:259">Yeah...I suppose</textRun>
if (textRun != null)
sb.AppendLine(textRun.InnerText);
foreach (XmlNode node in nodes) // <paragraph objID="1:28" element="Dialog">
{
XmlNode textRun = node.SelectSingleNode("textRun"); // <textRun objID="1:259">Yeah...I suppose</textRun>
if (textRun != null)
sb.AppendLine(textRun.InnerText);
}
}
textBoxText.Text = sb.ToString();
_videoFileName = null;
Text = Configuration.Settings.Language.ImportText.Title + " - " + fileName;
@ -996,5 +1004,18 @@ namespace Nikse.SubtitleEdit.Forms
if (_exit)
DialogResult = DialogResult.Cancel;
}
private void startNumberingFromToolStripMenuItem_Click(object sender, EventArgs e)
{
using (var startNumberingFrom = new StartNumberingFrom())
{
if (startNumberingFrom.ShowDialog(this) == DialogResult.OK)
{
_startFromNumber = startNumberingFrom.StartFromNumber;
_subtitle.Renumber(startNumberingFrom.StartFromNumber);
SubtitleListview1.Fill(_subtitle);
}
}
}
}
}

View File

@ -120,6 +120,9 @@
<metadata name="contextMenuStripListView.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>157, 17</value>
</metadata>
<metadata name="contextMenuStripPreview.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>350, 17</value>
</metadata>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>