From b25b2a0e2e29cc227ae93ed2a9e3120e58f6aba8 Mon Sep 17 00:00:00 2001 From: niksedk Date: Sat, 31 Dec 2022 18:41:01 +0100 Subject: [PATCH] Add ASSA style - add "Replace" - thxMishasama :) Work on #6509 --- src/libse/Common/Paragraph.cs | 3 + src/ui/Forms/Assa/AssaStyles.Designer.cs | 68 +++--- src/ui/Forms/Assa/AssaStyles.cs | 68 ++++-- src/ui/Forms/Assa/AssaStyles.resx | 3 + .../Forms/Assa/ReplaceStyleWith.Designer.cs | 161 +++++++++++++++ src/ui/Forms/Assa/ReplaceStyleWith.cs | 193 ++++++++++++++++++ src/ui/Forms/Assa/ReplaceStyleWith.resx | 120 +++++++++++ src/ui/Forms/Main.cs | 8 +- src/ui/Logic/Language.cs | 1 + src/ui/Logic/LanguageStructure.cs | 1 + src/ui/SubtitleEdit.csproj | 9 + 11 files changed, 587 insertions(+), 48 deletions(-) create mode 100644 src/ui/Forms/Assa/ReplaceStyleWith.Designer.cs create mode 100644 src/ui/Forms/Assa/ReplaceStyleWith.cs create mode 100644 src/ui/Forms/Assa/ReplaceStyleWith.resx diff --git a/src/libse/Common/Paragraph.cs b/src/libse/Common/Paragraph.cs index 594aba760..1abd9460b 100644 --- a/src/libse/Common/Paragraph.cs +++ b/src/libse/Common/Paragraph.cs @@ -17,6 +17,9 @@ namespace Nikse.SubtitleEdit.Core.Common public bool Forced { get; set; } + /// + /// Extra info (style name for ASSA). + /// public string Extra { get; set; } public bool IsComment { get; set; } diff --git a/src/ui/Forms/Assa/AssaStyles.Designer.cs b/src/ui/Forms/Assa/AssaStyles.Designer.cs index 6daf95517..493445558 100644 --- a/src/ui/Forms/Assa/AssaStyles.Designer.cs +++ b/src/ui/Forms/Assa/AssaStyles.Designer.cs @@ -38,6 +38,7 @@ this.columnHeaderOutline = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.contextMenuStripFile = new System.Windows.Forms.ContextMenuStrip(this.components); this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.removeAndReplaceWithToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemRemoveAll = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator(); this.addToStorageToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); @@ -213,7 +214,7 @@ this.listViewStyles.HideSelection = false; this.listViewStyles.Location = new System.Drawing.Point(6, 19); this.listViewStyles.Name = "listViewStyles"; - this.listViewStyles.Size = new System.Drawing.Size(545, 250); + this.listViewStyles.Size = new System.Drawing.Size(545, 230); this.listViewStyles.TabIndex = 0; this.listViewStyles.UseCompatibleStateImageBehavior = false; this.listViewStyles.View = System.Windows.Forms.View.Details; @@ -256,6 +257,7 @@ this.contextMenuStripFile.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.deleteToolStripMenuItem, this.toolStripMenuItemRemoveAll, + this.removeAndReplaceWithToolStripMenuItem, this.toolStripSeparator4, this.addToStorageToolStripMenuItem1, this.toolStripSeparator8, @@ -270,7 +272,7 @@ this.toolStripMenuItemImport, this.toolStripMenuItemExport}); this.contextMenuStripFile.Name = "contextMenuStrip1"; - this.contextMenuStripFile.Size = new System.Drawing.Size(216, 270); + this.contextMenuStripFile.Size = new System.Drawing.Size(216, 314); this.contextMenuStripFile.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStripFile_Opening); // // deleteToolStripMenuItem @@ -281,6 +283,13 @@ this.deleteToolStripMenuItem.Text = "Remove"; this.deleteToolStripMenuItem.Click += new System.EventHandler(this.buttonRemove_Click); // + // removeAndReplaceWithToolStripMenuItem + // + this.removeAndReplaceWithToolStripMenuItem.Name = "removeAndReplaceWithToolStripMenuItem"; + this.removeAndReplaceWithToolStripMenuItem.Size = new System.Drawing.Size(215, 22); + this.removeAndReplaceWithToolStripMenuItem.Text = "Replace with..."; + this.removeAndReplaceWithToolStripMenuItem.Click += new System.EventHandler(this.buttonRemoveAndReplaceWith_Click); + // // toolStripMenuItemRemoveAll // this.toolStripMenuItemRemoveAll.Name = "toolStripMenuItemRemoveAll"; @@ -385,7 +394,7 @@ 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(977, 676); + this.buttonCancel.Location = new System.Drawing.Point(977, 637); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(75, 23); this.buttonCancel.TabIndex = 3; @@ -397,7 +406,7 @@ // 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(896, 676); + this.buttonOK.Location = new System.Drawing.Point(896, 637); this.buttonOK.Name = "buttonOK"; this.buttonOK.Size = new System.Drawing.Size(75, 23); this.buttonOK.TabIndex = 2; @@ -418,7 +427,7 @@ this.groupBoxStyles.Dock = System.Windows.Forms.DockStyle.Fill; this.groupBoxStyles.Location = new System.Drawing.Point(0, 0); this.groupBoxStyles.Name = "groupBoxStyles"; - this.groupBoxStyles.Size = new System.Drawing.Size(557, 333); + this.groupBoxStyles.Size = new System.Drawing.Size(557, 313); this.groupBoxStyles.TabIndex = 0; this.groupBoxStyles.TabStop = false; this.groupBoxStyles.Text = "File styles"; @@ -427,7 +436,7 @@ // this.buttonAddStyleToStorage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonAddStyleToStorage.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonAddStyleToStorage.Location = new System.Drawing.Point(290, 275); + this.buttonAddStyleToStorage.Location = new System.Drawing.Point(290, 255); this.buttonAddStyleToStorage.Name = "buttonAddStyleToStorage"; this.buttonAddStyleToStorage.Size = new System.Drawing.Size(163, 52); this.buttonAddStyleToStorage.TabIndex = 4; @@ -439,7 +448,7 @@ // this.buttonExport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonExport.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonExport.Location = new System.Drawing.Point(6, 304); + this.buttonExport.Location = new System.Drawing.Point(6, 284); this.buttonExport.Name = "buttonExport"; this.buttonExport.Size = new System.Drawing.Size(82, 23); this.buttonExport.TabIndex = 5; @@ -451,7 +460,7 @@ // this.buttonImport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonImport.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonImport.Location = new System.Drawing.Point(6, 275); + this.buttonImport.Location = new System.Drawing.Point(6, 255); this.buttonImport.Name = "buttonImport"; this.buttonImport.Size = new System.Drawing.Size(82, 23); this.buttonImport.TabIndex = 1; @@ -463,7 +472,7 @@ // this.buttonCopy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonCopy.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonCopy.Location = new System.Drawing.Point(94, 304); + this.buttonCopy.Location = new System.Drawing.Point(94, 284); this.buttonCopy.Name = "buttonCopy"; this.buttonCopy.Size = new System.Drawing.Size(82, 23); this.buttonCopy.TabIndex = 6; @@ -475,7 +484,7 @@ // this.buttonRemoveAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonRemoveAll.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonRemoveAll.Location = new System.Drawing.Point(182, 304); + this.buttonRemoveAll.Location = new System.Drawing.Point(182, 284); this.buttonRemoveAll.Name = "buttonRemoveAll"; this.buttonRemoveAll.Size = new System.Drawing.Size(102, 23); this.buttonRemoveAll.TabIndex = 7; @@ -487,7 +496,7 @@ // this.buttonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonAdd.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonAdd.Location = new System.Drawing.Point(94, 275); + this.buttonAdd.Location = new System.Drawing.Point(94, 255); this.buttonAdd.Name = "buttonAdd"; this.buttonAdd.Size = new System.Drawing.Size(82, 23); this.buttonAdd.TabIndex = 2; @@ -499,7 +508,7 @@ // this.buttonRemove.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonRemove.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonRemove.Location = new System.Drawing.Point(182, 275); + this.buttonRemove.Location = new System.Drawing.Point(182, 255); this.buttonRemove.Name = "buttonRemove"; this.buttonRemove.Size = new System.Drawing.Size(102, 23); this.buttonRemove.TabIndex = 3; @@ -522,7 +531,7 @@ this.groupBoxProperties.Controls.Add(this.groupBoxFont); this.groupBoxProperties.Location = new System.Drawing.Point(575, 4); this.groupBoxProperties.Name = "groupBoxProperties"; - this.groupBoxProperties.Size = new System.Drawing.Size(477, 666); + this.groupBoxProperties.Size = new System.Drawing.Size(477, 627); this.groupBoxProperties.TabIndex = 0; this.groupBoxProperties.TabStop = false; this.groupBoxProperties.Text = "Properties"; @@ -925,7 +934,7 @@ this.groupBoxPreview.Controls.Add(this.pictureBoxPreview); this.groupBoxPreview.Location = new System.Drawing.Point(7, 335); this.groupBoxPreview.Name = "groupBoxPreview"; - this.groupBoxPreview.Size = new System.Drawing.Size(465, 325); + this.groupBoxPreview.Size = new System.Drawing.Size(465, 286); this.groupBoxPreview.TabIndex = 7; this.groupBoxPreview.TabStop = false; this.groupBoxPreview.Text = "Preview"; @@ -936,7 +945,7 @@ this.pictureBoxPreview.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxPreview.Location = new System.Drawing.Point(3, 16); this.pictureBoxPreview.Name = "pictureBoxPreview"; - this.pictureBoxPreview.Size = new System.Drawing.Size(459, 306); + this.pictureBoxPreview.Size = new System.Drawing.Size(459, 267); this.pictureBoxPreview.TabIndex = 0; this.pictureBoxPreview.TabStop = false; this.pictureBoxPreview.Click += new System.EventHandler(this.pictureBoxPreview_Click); @@ -1222,7 +1231,7 @@ this.groupBoxStorage.Dock = System.Windows.Forms.DockStyle.Fill; this.groupBoxStorage.Location = new System.Drawing.Point(0, 0); this.groupBoxStorage.Name = "groupBoxStorage"; - this.groupBoxStorage.Size = new System.Drawing.Size(557, 329); + this.groupBoxStorage.Size = new System.Drawing.Size(557, 310); this.groupBoxStorage.TabIndex = 0; this.groupBoxStorage.TabStop = false; this.groupBoxStorage.Text = "Style storage"; @@ -1231,7 +1240,7 @@ // this.buttonAddToFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonAddToFile.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonAddToFile.Location = new System.Drawing.Point(290, 271); + this.buttonAddToFile.Location = new System.Drawing.Point(290, 252); this.buttonAddToFile.Name = "buttonAddToFile"; this.buttonAddToFile.Size = new System.Drawing.Size(163, 52); this.buttonAddToFile.TabIndex = 10; @@ -1243,7 +1252,7 @@ // this.buttonStorageExport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonStorageExport.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonStorageExport.Location = new System.Drawing.Point(6, 300); + this.buttonStorageExport.Location = new System.Drawing.Point(6, 281); this.buttonStorageExport.Name = "buttonStorageExport"; this.buttonStorageExport.Size = new System.Drawing.Size(82, 23); this.buttonStorageExport.TabIndex = 11; @@ -1255,7 +1264,7 @@ // this.buttonStorageImport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonStorageImport.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonStorageImport.Location = new System.Drawing.Point(6, 271); + this.buttonStorageImport.Location = new System.Drawing.Point(6, 252); this.buttonStorageImport.Name = "buttonStorageImport"; this.buttonStorageImport.Size = new System.Drawing.Size(82, 23); this.buttonStorageImport.TabIndex = 7; @@ -1267,7 +1276,7 @@ // this.buttonStorageCopy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonStorageCopy.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonStorageCopy.Location = new System.Drawing.Point(94, 300); + this.buttonStorageCopy.Location = new System.Drawing.Point(94, 281); this.buttonStorageCopy.Name = "buttonStorageCopy"; this.buttonStorageCopy.Size = new System.Drawing.Size(82, 23); this.buttonStorageCopy.TabIndex = 12; @@ -1279,7 +1288,7 @@ // this.buttonStorageRemoveAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonStorageRemoveAll.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonStorageRemoveAll.Location = new System.Drawing.Point(182, 300); + this.buttonStorageRemoveAll.Location = new System.Drawing.Point(182, 281); this.buttonStorageRemoveAll.Name = "buttonStorageRemoveAll"; this.buttonStorageRemoveAll.Size = new System.Drawing.Size(102, 23); this.buttonStorageRemoveAll.TabIndex = 13; @@ -1291,7 +1300,7 @@ // this.buttonStorageAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonStorageAdd.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonStorageAdd.Location = new System.Drawing.Point(94, 271); + this.buttonStorageAdd.Location = new System.Drawing.Point(94, 252); this.buttonStorageAdd.Name = "buttonStorageAdd"; this.buttonStorageAdd.Size = new System.Drawing.Size(82, 23); this.buttonStorageAdd.TabIndex = 8; @@ -1303,7 +1312,7 @@ // this.buttonStorageRemove.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonStorageRemove.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonStorageRemove.Location = new System.Drawing.Point(182, 271); + this.buttonStorageRemove.Location = new System.Drawing.Point(182, 252); this.buttonStorageRemove.Name = "buttonStorageRemove"; this.buttonStorageRemove.Size = new System.Drawing.Size(102, 23); this.buttonStorageRemove.TabIndex = 9; @@ -1328,7 +1337,7 @@ this.listViewStorage.HideSelection = false; this.listViewStorage.Location = new System.Drawing.Point(6, 68); this.listViewStorage.Name = "listViewStorage"; - this.listViewStorage.Size = new System.Drawing.Size(545, 197); + this.listViewStorage.Size = new System.Drawing.Size(545, 178); this.listViewStorage.TabIndex = 6; this.listViewStorage.UseCompatibleStateImageBehavior = false; this.listViewStorage.View = System.Windows.Forms.View.Details; @@ -1588,15 +1597,15 @@ // this.splitContainer1.Panel2.Controls.Add(this.groupBoxStorage); this.splitContainer1.Panel2MinSize = 150; - this.splitContainer1.Size = new System.Drawing.Size(557, 666); - this.splitContainer1.SplitterDistance = 333; + this.splitContainer1.Size = new System.Drawing.Size(557, 627); + this.splitContainer1.SplitterDistance = 313; this.splitContainer1.TabIndex = 8; // // buttonApply // this.buttonApply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonApply.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonApply.Location = new System.Drawing.Point(785, 676); + this.buttonApply.Location = new System.Drawing.Point(785, 637); this.buttonApply.Name = "buttonApply"; this.buttonApply.Size = new System.Drawing.Size(105, 23); this.buttonApply.TabIndex = 1; @@ -1610,7 +1619,7 @@ this.labelDuplicateStyleNames.AutoSize = true; this.labelDuplicateStyleNames.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.labelDuplicateStyleNames.ForeColor = System.Drawing.Color.Firebrick; - this.labelDuplicateStyleNames.Location = new System.Drawing.Point(12, 687); + this.labelDuplicateStyleNames.Location = new System.Drawing.Point(12, 648); this.labelDuplicateStyleNames.Name = "labelDuplicateStyleNames"; this.labelDuplicateStyleNames.Size = new System.Drawing.Size(154, 13); this.labelDuplicateStyleNames.TabIndex = 10; @@ -1620,7 +1629,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1064, 709); + this.ClientSize = new System.Drawing.Size(1064, 670); this.Controls.Add(this.labelDuplicateStyleNames); this.Controls.Add(this.buttonApply); this.Controls.Add(this.splitContainer1); @@ -1819,5 +1828,6 @@ private System.Windows.Forms.Label labelScaleX; private System.Windows.Forms.ComboBox comboBoxOpaqueBoxStyle; private System.Windows.Forms.Label labelDuplicateStyleNames; + private System.Windows.Forms.ToolStripMenuItem removeAndReplaceWithToolStripMenuItem; } } \ No newline at end of file diff --git a/src/ui/Forms/Assa/AssaStyles.cs b/src/ui/Forms/Assa/AssaStyles.cs index 5eac15414..6e28e994c 100644 --- a/src/ui/Forms/Assa/AssaStyles.cs +++ b/src/ui/Forms/Assa/AssaStyles.cs @@ -60,7 +60,7 @@ namespace Nikse.SubtitleEdit.Forms.Assa InitializeComponent(); UiUtil.FixFonts(this); - _subtitle = subtitle; + _subtitle = new Subtitle(subtitle); RenameActions = new List(); labelStatus.Text = string.Empty; _header = subtitle.Header; @@ -181,6 +181,7 @@ namespace Nikse.SubtitleEdit.Forms.Assa buttonAddStyleToStorage.Text = l.AddToStorage; deleteToolStripMenuItem.Text = l.Remove; + removeAndReplaceWithToolStripMenuItem.Text = l.ReplaceWith; toolStripMenuItemRemoveAll.Text = l.RemoveAll; addToStorageToolStripMenuItem1.Text = l.AddToStorage; moveUpToolStripMenuItem.Text = LanguageSettings.Current.DvdSubRip.MoveUp; @@ -993,16 +994,16 @@ namespace Nikse.SubtitleEdit.Forms.Assa AddStyle(listViewStorage, defaultStyle, _subtitle, _isSubStationAlpha); } - private void UpdateSelectedIndices(ListView listview, int startingIndex = -1, int numberOfSelectedItems = 1) + private static void UpdateSelectedIndices(ListView listView, int startingIndex = -1, int numberOfSelectedItems = 1) { if (numberOfSelectedItems == 0) { return; } - if (startingIndex == -1 || startingIndex >= listview.Items.Count) + if (startingIndex == -1 || startingIndex >= listView.Items.Count) { - startingIndex = listview.Items.Count - 1; + startingIndex = listView.Items.Count - 1; } if (startingIndex - numberOfSelectedItems < -1) @@ -1010,12 +1011,12 @@ namespace Nikse.SubtitleEdit.Forms.Assa return; } - listview.SelectedItems.Clear(); - for (int i = 0; i < numberOfSelectedItems; i++) + listView.SelectedItems.Clear(); + for (var i = 0; i < numberOfSelectedItems; i++) { - listview.Items[startingIndex - i].Selected = true; - listview.Items[startingIndex - i].EnsureVisible(); - listview.Items[startingIndex - i].Focused = true; + listView.Items[startingIndex - i].Selected = true; + listView.Items[startingIndex - i].EnsureVisible(); + listView.Items[startingIndex - i].Focused = true; } } @@ -1400,8 +1401,8 @@ namespace Nikse.SubtitleEdit.Forms.Assa var name = LanguageSettings.Current.SubStationAlphaStyles.New; if (GetSsaStyleFile(name) != null) { - int count = 2; - bool doRepeat = true; + var count = 2; + var doRepeat = true; while (doRepeat) { name = LanguageSettings.Current.SubStationAlphaStyles.New + count; @@ -1512,6 +1513,42 @@ namespace Nikse.SubtitleEdit.Forms.Assa CheckDuplicateStyles(); } + private void buttonRemoveAndReplaceWith_Click(object sender, EventArgs e) + { + if (listViewStyles.SelectedItems.Count != 1) + { + return; + } + + var idx = listViewStyles.SelectedIndices[0]; + var style = _currentFileStyles[idx]; + using (var form = new ReplaceStyleWith(style, _currentFileStyles, _storageCategories, _subtitle)) + { + if (form.ShowDialog(this) == DialogResult.OK) + { + _subtitle.Paragraphs.Clear(); + _subtitle.Paragraphs.AddRange(form.NewSubtitle.Paragraphs); + + _currentFileStyles.Remove(style); + if (form.NewStorageStyle != null) + { + AddStyle(listViewStyles, form.NewStorageStyle, _subtitle, _isSubStationAlpha); + AddStyleToHeader(form.NewStorageStyle); + _doUpdate = true; + UpdateSelectedIndices(listViewStyles); + SetControlsFromStyle(form.NewStorageStyle); + RenameActions.Add(new NameEdit(style.Name, form.NewStorageStyle.Name)); + InitializeStylesListView(form.NewStorageStyle.Name); + } + else + { + RenameActions.Add(new NameEdit(style.Name, form.NewFileStyle.Name)); + InitializeStylesListView(form.NewFileStyle.Name); + } + } + } + } + private void buttonRemoveAll_Click(object sender, EventArgs e) { var askText = listViewStyles.Items.Count == 1 ? @@ -2114,8 +2151,8 @@ namespace Nikse.SubtitleEdit.Forms.Assa var name = LanguageSettings.Current.SubStationAlphaStyles.New; if (_currentCategory.Styles.Any(p => p.Name == name)) { - int count = 2; - bool doRepeat = true; + var count = 2; + var doRepeat = true; while (doRepeat) { name = LanguageSettings.Current.SubStationAlphaStyles.New + count; @@ -2146,8 +2183,8 @@ namespace Nikse.SubtitleEdit.Forms.Assa var style = new SsaStyle(oldStyle) { Name = string.Format(LanguageSettings.Current.SubStationAlphaStyles.CopyOfY, styleName) }; // Copy contructor if (_currentCategory.Styles.Any(p => p.Name == style.Name)) { - int count = 2; - bool doRepeat = true; + var count = 2; + var doRepeat = true; while (doRepeat) { style.Name = string.Format(LanguageSettings.Current.SubStationAlphaStyles.CopyXOfY, count, styleName); @@ -2721,6 +2758,7 @@ namespace Nikse.SubtitleEdit.Forms.Assa var oneOrMoreSelected = listViewStyles.SelectedItems.Count > 0; deleteToolStripMenuItem.Visible = oneOrMoreSelected; + removeAndReplaceWithToolStripMenuItem.Visible = listViewStyles.SelectedItems.Count == 1; addToStorageToolStripMenuItem1.Visible = oneOrMoreSelected; toolStripSeparator4.Visible = oneOrMoreSelected; copyToolStripMenuItemCopy.Visible = oneOrMoreSelected; diff --git a/src/ui/Forms/Assa/AssaStyles.resx b/src/ui/Forms/Assa/AssaStyles.resx index c3169cb31..7a83a7033 100644 --- a/src/ui/Forms/Assa/AssaStyles.resx +++ b/src/ui/Forms/Assa/AssaStyles.resx @@ -138,4 +138,7 @@ 11, 22 + + 58 + \ No newline at end of file diff --git a/src/ui/Forms/Assa/ReplaceStyleWith.Designer.cs b/src/ui/Forms/Assa/ReplaceStyleWith.Designer.cs new file mode 100644 index 000000000..f6e1e8775 --- /dev/null +++ b/src/ui/Forms/Assa/ReplaceStyleWith.Designer.cs @@ -0,0 +1,161 @@ +namespace Nikse.SubtitleEdit.Forms.Assa +{ + partial class ReplaceStyleWith + { + /// + /// 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.buttonOK = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.comboBoxFrom = new System.Windows.Forms.ComboBox(); + this.labelFrom = new System.Windows.Forms.Label(); + this.comboboxStorageCategories = new System.Windows.Forms.ComboBox(); + this.labelStorageCategory = new System.Windows.Forms.Label(); + this.comboBoxStyle = new System.Windows.Forms.ComboBox(); + this.labelStyle = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // 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(247, 186); + this.buttonOK.Name = "buttonOK"; + this.buttonOK.Size = new System.Drawing.Size(75, 23); + this.buttonOK.TabIndex = 6; + 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(328, 186); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "C&ancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // comboBoxFrom + // + this.comboBoxFrom.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxFrom.FormattingEnabled = true; + this.comboBoxFrom.Location = new System.Drawing.Point(88, 29); + this.comboBoxFrom.Name = "comboBoxFrom"; + this.comboBoxFrom.Size = new System.Drawing.Size(180, 21); + this.comboBoxFrom.TabIndex = 12; + this.comboBoxFrom.SelectedIndexChanged += new System.EventHandler(this.comboBoxFrom_SelectedIndexChanged); + // + // labelFrom + // + this.labelFrom.AutoSize = true; + this.labelFrom.Location = new System.Drawing.Point(25, 31); + this.labelFrom.Name = "labelFrom"; + this.labelFrom.Size = new System.Drawing.Size(30, 13); + this.labelFrom.TabIndex = 11; + this.labelFrom.Text = "From"; + // + // comboboxStorageCategories + // + this.comboboxStorageCategories.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboboxStorageCategories.FormattingEnabled = true; + this.comboboxStorageCategories.Location = new System.Drawing.Point(88, 56); + this.comboboxStorageCategories.Name = "comboboxStorageCategories"; + this.comboboxStorageCategories.Size = new System.Drawing.Size(180, 21); + this.comboboxStorageCategories.TabIndex = 10; + this.comboboxStorageCategories.SelectedIndexChanged += new System.EventHandler(this.comboboxStorageCategories_SelectedIndexChanged); + // + // labelStorageCategory + // + this.labelStorageCategory.AutoSize = true; + this.labelStorageCategory.Location = new System.Drawing.Point(25, 58); + this.labelStorageCategory.Name = "labelStorageCategory"; + this.labelStorageCategory.Size = new System.Drawing.Size(49, 13); + this.labelStorageCategory.TabIndex = 9; + this.labelStorageCategory.Text = "Category"; + // + // comboBoxStyle + // + this.comboBoxStyle.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxStyle.FormattingEnabled = true; + this.comboBoxStyle.Location = new System.Drawing.Point(88, 83); + this.comboBoxStyle.Name = "comboBoxStyle"; + this.comboBoxStyle.Size = new System.Drawing.Size(180, 21); + this.comboBoxStyle.TabIndex = 14; + this.comboBoxStyle.SelectedIndexChanged += new System.EventHandler(this.comboBoxStyle_SelectedIndexChanged); + // + // labelStyle + // + this.labelStyle.AutoSize = true; + this.labelStyle.Location = new System.Drawing.Point(25, 85); + this.labelStyle.Name = "labelStyle"; + this.labelStyle.Size = new System.Drawing.Size(30, 13); + this.labelStyle.TabIndex = 13; + this.labelStyle.Text = "Style"; + // + // ReplaceStyleWith + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(415, 221); + this.Controls.Add(this.comboBoxStyle); + this.Controls.Add(this.labelStyle); + this.Controls.Add(this.comboBoxFrom); + this.Controls.Add(this.labelFrom); + this.Controls.Add(this.comboboxStorageCategories); + this.Controls.Add(this.labelStorageCategory); + this.Controls.Add(this.buttonOK); + this.Controls.Add(this.buttonCancel); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.KeyPreview = true; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "ReplaceStyleWith"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "ReplaceStyleWith"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button buttonOK; + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.ComboBox comboBoxFrom; + private System.Windows.Forms.Label labelFrom; + private System.Windows.Forms.ComboBox comboboxStorageCategories; + private System.Windows.Forms.Label labelStorageCategory; + private System.Windows.Forms.ComboBox comboBoxStyle; + private System.Windows.Forms.Label labelStyle; + } +} \ No newline at end of file diff --git a/src/ui/Forms/Assa/ReplaceStyleWith.cs b/src/ui/Forms/Assa/ReplaceStyleWith.cs new file mode 100644 index 000000000..f73abaa2d --- /dev/null +++ b/src/ui/Forms/Assa/ReplaceStyleWith.cs @@ -0,0 +1,193 @@ +using Nikse.SubtitleEdit.Core.Common; +using Nikse.SubtitleEdit.Logic; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace Nikse.SubtitleEdit.Forms.Assa +{ + public sealed partial class ReplaceStyleWith : Form + { + private readonly SsaStyle _style; + private readonly List _storageCategories; + private readonly List _currentFileStyles; + private readonly Subtitle _subtitle; + public Subtitle NewSubtitle { get; set; } + public SsaStyle NewStorageStyle { get; set; } + public SsaStyle NewFileStyle { get; set; } + + public ReplaceStyleWith(SsaStyle style, List currentFileStyles, List storageCategories, Subtitle subtitle) + { + UiUtil.PreInitialize(this); + InitializeComponent(); + UiUtil.FixFonts(this); + + _style = style; + _currentFileStyles = currentFileStyles; + _storageCategories = storageCategories; + _subtitle = subtitle; + + var l = LanguageSettings.Current.SubStationAlphaStyles; + Text = l.ReplaceWith.Trim('.'); + labelFrom.Text = LanguageSettings.Current.GoogleTranslate.From; + labelStorageCategory.Text = LanguageSettings.Current.SubStationAlphaStylesCategoriesManager.Category; + labelStyle.Text = LanguageSettings.Current.General.Style; + comboBoxFrom.Items.Clear(); + comboBoxFrom.Items.Add(l.StyleCurrentFile); + comboBoxFrom.Items.Add(l.StyleStorage); + + comboboxStorageCategories.Items.Clear(); + foreach (var category in storageCategories) + { + comboboxStorageCategories.Items.Add(category.Name); + } + + comboBoxFrom.SelectedIndex = 0; + + buttonOK.Text = LanguageSettings.Current.General.Ok; + buttonCancel.Text = LanguageSettings.Current.General.Cancel; + UiUtil.FixLargeFonts(this, buttonOK); + + UpdateButtonOkEnabled(); + } + + private void UpdateButtonOkEnabled() + { + buttonOK.Enabled = comboBoxStyle.SelectedIndex >= 0; + } + + private void comboBoxFrom_SelectedIndexChanged(object sender, EventArgs e) + { + comboBoxStyle.BeginUpdate(); + comboBoxStyle.Items.Clear(); + + if (comboBoxFrom.SelectedIndex == 0) + { + labelStorageCategory.Enabled = false; + comboboxStorageCategories.Enabled = false; + + foreach (var style in _currentFileStyles) + { + if (style.Name != _style.Name) + { + comboBoxStyle.Items.Add(style.Name); + } + } + + if (comboBoxStyle.Items.Count > 0) + { + comboBoxStyle.SelectedIndex = 0; + } + } + else if (comboBoxFrom.SelectedIndex == 1) + { + labelStorageCategory.Enabled = true; + comboboxStorageCategories.Enabled = true; + + if (_storageCategories.Count > 0) + { + comboboxStorageCategories.SelectedIndex = 0; + } + } + else + { + labelStorageCategory.Enabled = true; + comboboxStorageCategories.Enabled = true; + } + + comboBoxStyle.EndUpdate(); + } + + private void comboboxStorageCategories_SelectedIndexChanged(object sender, EventArgs e) + { + if (!comboboxStorageCategories.Enabled || comboboxStorageCategories.SelectedIndex < 0) + { + return; + } + + comboBoxStyle.BeginUpdate(); + comboBoxStyle.Items.Clear(); + + var cat = _storageCategories[comboboxStorageCategories.SelectedIndex]; + foreach (var style in cat.Styles) + { + comboBoxStyle.Items.Add(style.Name); + } + + comboBoxStyle.EndUpdate(); + + if (comboBoxStyle.Items.Count > 0) + { + comboBoxStyle.SelectedIndex = 0; + } + + UpdateButtonOkEnabled(); + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + } + + private void buttonOK_Click(object sender, EventArgs e) + { + var idx = comboBoxStyle.SelectedIndex; + if (idx < 0) + { + return; + } + + NewSubtitle = new Subtitle(_subtitle); + if (comboBoxFrom.SelectedIndex == 0) // current file styles + { + var style = _currentFileStyles[idx]; + foreach (var paragraph in NewSubtitle.Paragraphs) + { + if (paragraph.Extra == _style.Name) + { + paragraph.Extra = style.Name; + } + } + + NewFileStyle = style; + } + else if (comboBoxFrom.SelectedIndex == 1) // storage style + { + var category = _storageCategories[comboboxStorageCategories.SelectedIndex]; + var style = category.Styles[idx]; + foreach (var paragraph in NewSubtitle.Paragraphs) + { + if (paragraph.Extra == _style.Name) + { + paragraph.Extra = style.Name; + } + } + + NewStorageStyle = style; + if (_currentFileStyles.Any(p => p.Name == NewStorageStyle.Name)) + { + var count = 2; + var doRepeat = true; + while (doRepeat) + { + NewStorageStyle.Name = LanguageSettings.Current.SubStationAlphaStyles.New + count; + doRepeat = _currentFileStyles.Any(p => p.Name == NewStorageStyle.Name); + count++; + } + } + } + else + { + return; + } + + DialogResult = DialogResult.OK; + } + + private void comboBoxStyle_SelectedIndexChanged(object sender, EventArgs e) + { + UpdateButtonOkEnabled(); + } + } +} diff --git a/src/ui/Forms/Assa/ReplaceStyleWith.resx b/src/ui/Forms/Assa/ReplaceStyleWith.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/src/ui/Forms/Assa/ReplaceStyleWith.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index 2fb503c72..98894abd6 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -3800,10 +3800,10 @@ namespace Nikse.SubtitleEdit.Forms SubtitleListview1.SelectedIndexChanged -= SubtitleListview1_SelectedIndexChanged; RemoveOriginal(true, false); - //if (!format.HasStyleSupport) -- remove -- see https://www.nikse.dk/Home/Details/637741307830000000 - //{ - // SubtitleListview1.HideColumn(SubtitleListView.SubtitleColumn.Extra); - //} + if (format.HasStyleSupport && format.Name == AdvancedSubStationAlpha.NameOfFormat) + { + SubtitleListview1.ShowExtraColumn(_languageGeneral.Style); + } new BookmarkPersistence(newSubtitle, fileName).Load(); diff --git a/src/ui/Logic/Language.cs b/src/ui/Logic/Language.cs index f5a1c02d3..f11586222 100644 --- a/src/ui/Logic/Language.cs +++ b/src/ui/Logic/Language.cs @@ -3241,6 +3241,7 @@ can edit in same subtitle file (collaboration)", CopyOfY = "Copy of {0}", CopyXOfY = "Copy {0} of {1}", Remove = "Remove", + ReplaceWith = "Replace with...", RemoveAll = "Remove all", ImportStyleFromFile = "Import style from file...", ExportStyleToFile = "Export style to file... (will add style if file already exists)", diff --git a/src/ui/Logic/LanguageStructure.cs b/src/ui/Logic/LanguageStructure.cs index 06034b506..16bf42133 100644 --- a/src/ui/Logic/LanguageStructure.cs +++ b/src/ui/Logic/LanguageStructure.cs @@ -3090,6 +3090,7 @@ namespace Nikse.SubtitleEdit.Logic public string CopyXOfY { get; set; } public string New { get; set; } public string Remove { get; set; } + public string ReplaceWith { get; set; } public string RemoveAll { get; set; } public string ImportStyleFromFile { get; set; } public string ExportStyleToFile { get; set; } diff --git a/src/ui/SubtitleEdit.csproj b/src/ui/SubtitleEdit.csproj index a6ddb6464..6ce9a8ec1 100644 --- a/src/ui/SubtitleEdit.csproj +++ b/src/ui/SubtitleEdit.csproj @@ -180,6 +180,12 @@ ImageColorPicker.cs + + Form + + + ReplaceStyleWith.cs + Form @@ -1509,6 +1515,9 @@ ImageColorPicker.cs + + ReplaceStyleWith.cs + ResolutionResampler.cs