Fix rename ass style name bug - thx Jamakmake :)

This commit is contained in:
Nikolaj Olsson 2019-03-12 21:51:49 +01:00
parent c00dd6bc07
commit 2024b918b5
2 changed files with 66 additions and 17 deletions

View File

@ -7287,6 +7287,10 @@ namespace Nikse.SubtitleEdit.Forms
private void RefreshSelectedParagraph()
{
var idx = FirstSelectedIndex;
if (idx == -1 && _subtitle?.Paragraphs?.Count > 0)
{
idx = 0;
}
var p = _subtitle.GetParagraphOrDefault(idx);
_subtitleListViewIndex = -1;
SubtitleListview1_SelectedIndexChanged(null, null);
@ -24107,17 +24111,27 @@ namespace Nikse.SubtitleEdit.Forms
_subtitle.Header = styles.Header;
var styleList = AdvancedSubStationAlpha.GetStylesFromHeader(_subtitle.Header);
if (styleList.Count > 0)
if ((styles as SubStationAlphaStyles).RenameActions.Count > 0)
{
for (var i = 0; i < _subtitle.Paragraphs.Count; i++)
foreach (var renameAction in (styles as SubStationAlphaStyles).RenameActions)
{
var p = _subtitle.Paragraphs[i];
if (p.Extra == null || !styleList.Any(s => s.Equals(p.Extra == "*Default" ? "Default" : p.Extra, StringComparison.OrdinalIgnoreCase)))
for (var i = 0; i < _subtitle.Paragraphs.Count; i++)
{
p.Extra = styleList[0];
SubtitleListview1.SetExtraText(i, p.Extra, SubtitleListview1.ForeColor);
var p = _subtitle.Paragraphs[i];
if (p.Extra == renameAction.OldName)
{
p.Extra = renameAction.NewName;
}
}
}
CleanRemovedStyles(styleList);
SaveSubtitleListviewIndices();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
RestoreSubtitleListviewIndices();
}
else
{
CleanRemovedStyles(styleList);
}
}
}
@ -24142,6 +24156,19 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private void CleanRemovedStyles(List<string> styleList)
{
for (var i = 0; i < _subtitle.Paragraphs.Count; i++)
{
var p = _subtitle.Paragraphs[i];
if (p.Extra == null || !styleList.Any(s => s.Equals(p.Extra == "*Default" ? "Default" : p.Extra, StringComparison.OrdinalIgnoreCase)))
{
p.Extra = styleList[0];
SubtitleListview1.SetExtraText(i, p.Extra, SubtitleListview1.ForeColor);
}
}
}
private void toolStripMenuItemSubStationAlpha_Click(object sender, EventArgs e)
{
if (tabControlSubtitle.SelectedIndex == TabControlSourceView)

View File

@ -14,6 +14,20 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
public sealed partial class SubStationAlphaStyles : StylesForm
{
public class NameEdit
{
public NameEdit(string oldName, string newName)
{
OldName = oldName;
NewName = newName;
}
public string OldName { get; set; }
public string NewName { get; set; }
}
public List<NameEdit> RenameActions { get; set; } = new List<NameEdit>();
private string _startName = null;
private string _editedName = null;
private string _header;
private bool _doUpdate;
private string _oldSsaName;
@ -208,7 +222,7 @@ namespace Nikse.SubtitleEdit.Forms.Styles
}
else
{
left = ((float)(bmp.Width - measuredWidth * 0.8 + 15) / 2);
left = (float)(bmp.Width - measuredWidth * 0.8 + 15) / 2;
}
float top;
@ -486,14 +500,19 @@ namespace Nikse.SubtitleEdit.Forms.Styles
private void buttonNextFinish_Click(object sender, EventArgs e)
{
LogNameChanges();
DialogResult = DialogResult.OK;
}
private void listViewStyles_SelectedIndexChanged(object sender, EventArgs e)
{
LogNameChanges();
if (listViewStyles.SelectedItems.Count == 1)
{
string styleName = listViewStyles.SelectedItems[0].Text;
_startName = styleName;
_editedName = null;
_oldSsaName = styleName;
SsaStyle style = GetSsaStyle(styleName);
SetControlsFromStyle(style);
@ -509,6 +528,16 @@ namespace Nikse.SubtitleEdit.Forms.Styles
}
}
private void LogNameChanges()
{
if (_startName != null && _editedName != null && _startName != _editedName)
{
RenameActions.Add(new NameEdit(_startName, _editedName));
_startName = null;
_editedName = null;
}
}
private void SetControlsFromStyle(SsaStyle style)
{
textBoxStyleName.Text = style.Name;
@ -529,14 +558,7 @@ namespace Nikse.SubtitleEdit.Forms.Styles
panelPrimaryColor.BackColor = style.Primary;
panelSecondaryColor.BackColor = style.Secondary;
if (_isSubStationAlpha)
{
panelOutlineColor.BackColor = style.Tertiary;
}
else
{
panelOutlineColor.BackColor = style.Outline;
}
panelOutlineColor.BackColor = _isSubStationAlpha ? style.Tertiary : style.Outline;
panelBackColor.BackColor = style.Background;
if (style.OutlineWidth >= 0 && style.OutlineWidth <= numericUpDownOutline.Maximum)
@ -901,6 +923,7 @@ namespace Nikse.SubtitleEdit.Forms.Styles
}
_oldSsaName = textBoxStyleName.Text;
_editedName = _oldSsaName;
}
else
{
@ -1272,9 +1295,8 @@ namespace Nikse.SubtitleEdit.Forms.Styles
if (openFileDialogImport.ShowDialog(this) == DialogResult.OK)
{
Encoding encoding;
var s = new Subtitle();
var format = s.LoadSubtitle(openFileDialogImport.FileName, out encoding, null);
var format = s.LoadSubtitle(openFileDialogImport.FileName, out _, null);
if (format != null && format.HasStyleSupport)
{
var styles = AdvancedSubStationAlpha.GetStylesFromHeader(s.Header);