Work on assa tag helper custom tags

This commit is contained in:
Nikolaj Olsson 2021-06-13 09:32:38 +02:00
parent 5d4e442c33
commit bf9ff514a7
11 changed files with 888 additions and 19 deletions

View File

@ -2364,7 +2364,8 @@ can edit in same subtitle file (collaboration)</Information>
<MainTextBoxAutoBreakFromPosAndGoToNext>Break at first space from cursor position and go to next</MainTextBoxAutoBreakFromPosAndGoToNext>
<MainTextBoxUnbreak>Unbreak text</MainTextBoxUnbreak>
<MainTextBoxUnbreakNoSpace>Unbreak without space (CJK)</MainTextBoxUnbreakNoSpace>
<MainTextBoxAssaIntellisense>Show ASSA intellisense</MainTextBoxAssaIntellisense>
<MainTextBoxAssaIntellisense>Show ASSA tag helper</MainTextBoxAssaIntellisense>
<MainTextBoxAssaRemoveTag>Remove ASSA tag at cursor</MainTextBoxAssaRemoveTag>
<MainFileSaveAll>Save all</MainFileSaveAll>
<Miscellaneous>Misc.</Miscellaneous>
<CpsIncludesSpace>Chars/sec (CPS) includes spaces</CpsIncludesSpace>

View File

@ -11,7 +11,7 @@ namespace Test.AssaTagHelper
public void RemoveTag1()
{
var tb = new SETextBox { Text = "{\\an1}Hallo!", SelectionStart = 1 };
AssaIntellisense.RemoveTagAtCursor(tb);
Nikse.SubtitleEdit.Logic.AssaTagHelper.RemoveTagAtCursor(tb);
Assert.AreEqual("Hallo!", tb.Text);
}
@ -19,7 +19,7 @@ namespace Test.AssaTagHelper
public void RemoveTag2()
{
var tb = new SETextBox { Text = "{\\an1\\i1}Hallo!", SelectionStart = 1 };
AssaIntellisense.RemoveTagAtCursor(tb);
Nikse.SubtitleEdit.Logic.AssaTagHelper.RemoveTagAtCursor(tb);
Assert.AreEqual("{\\i1}Hallo!", tb.Text);
}
@ -27,7 +27,7 @@ namespace Test.AssaTagHelper
public void RemoveTag3()
{
var tb = new SETextBox { Text = "{\\an1\\i1}Hallo!", SelectionStart = 6 };
AssaIntellisense.RemoveTagAtCursor(tb);
Nikse.SubtitleEdit.Logic.AssaTagHelper.RemoveTagAtCursor(tb);
Assert.AreEqual("{\\an1}Hallo!", tb.Text);
}
@ -35,7 +35,7 @@ namespace Test.AssaTagHelper
public void RemoveTag4()
{
var tb = new SETextBox { Text = "{\\an1\\i1\\b1}Hallo!", SelectionStart = 6 };
AssaIntellisense.RemoveTagAtCursor(tb);
Nikse.SubtitleEdit.Logic.AssaTagHelper.RemoveTagAtCursor(tb);
Assert.AreEqual("{\\an1\\b1}Hallo!", tb.Text);
}
@ -43,7 +43,7 @@ namespace Test.AssaTagHelper
public void RemoveTag5()
{
var tb = new SETextBox { Text = "{\\an1\\i1\\b1}Hallo!", SelectionStart = 2 };
AssaIntellisense.RemoveTagAtCursor(tb);
Nikse.SubtitleEdit.Logic.AssaTagHelper.RemoveTagAtCursor(tb);
Assert.AreEqual("{\\i1\\b1}Hallo!", tb.Text);
}
}

View File

@ -0,0 +1,8 @@
namespace Nikse.SubtitleEdit.Core.Common
{
public class AssaTemplateItem
{
public string Tag { get; set; }
public string Hint { get; set; }
}
}

View File

@ -109,6 +109,7 @@ namespace Nikse.SubtitleEdit.Core.Common
public class ToolsSettings
{
public List<AssaTemplateItem> AssaTagTemplates { get; set; }
public int StartSceneIndex { get; set; }
public int EndSceneIndex { get; set; }
public int VerifyPlaySeconds { get; set; }
@ -331,6 +332,7 @@ namespace Nikse.SubtitleEdit.Core.Common
public ToolsSettings()
{
AssaTagTemplates = new List<AssaTemplateItem>();
StartSceneIndex = 1;
EndSceneIndex = 1;
VerifyPlaySeconds = 2;
@ -3752,6 +3754,27 @@ $HorzAlign = Center
// Tools
node = doc.DocumentElement.SelectSingleNode("Tools");
// ASSA templates (by user)
int assaTagTemplateCount = 0;
foreach (XmlNode listNode in node.SelectNodes("AssTagTemplates/Template"))
{
if (assaTagTemplateCount == 0)
{
settings.Tools.AssaTagTemplates = new List<AssaTemplateItem>();
}
var template = new AssaTemplateItem();
template.Tag = listNode.SelectSingleNode("Tag")?.InnerText;
template.Hint = listNode.SelectSingleNode("Hint")?.InnerText;
if (!string.IsNullOrEmpty(template.Tag))
{
settings.Tools.AssaTagTemplates.Add(template);
}
assaTagTemplateCount++;
}
subNode = node.SelectSingleNode("StartSceneIndex");
if (subNode != null)
{
@ -8429,6 +8452,17 @@ $HorzAlign = Center
textWriter.WriteEndElement();
textWriter.WriteStartElement("Tools", string.Empty);
textWriter.WriteStartElement("AssTagTemplates", string.Empty);
foreach (var template in settings.Tools.AssaTagTemplates)
{
textWriter.WriteStartElement("Template");
textWriter.WriteElementString("Tag", template.Tag);
textWriter.WriteElementString("Hint", template.Hint);
textWriter.WriteEndElement();
}
textWriter.WriteEndElement();
textWriter.WriteElementString("StartSceneIndex", settings.Tools.StartSceneIndex.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("EndSceneIndex", settings.Tools.EndSceneIndex.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("VerifyPlaySeconds", settings.Tools.VerifyPlaySeconds.ToString(CultureInfo.InvariantCulture));

View File

@ -0,0 +1,363 @@

namespace Nikse.SubtitleEdit.Forms.Assa
{
partial class AssaTagTemplate
{
/// <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.components = new System.ComponentModel.Container();
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.columnHeaderTag = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeaderHint = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.listViewTemplates = new System.Windows.Forms.ListView();
this.buttonRemove = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonRemoveAll = new System.Windows.Forms.Button();
this.buttonCopy = new System.Windows.Forms.Button();
this.textBoxTag = new System.Windows.Forms.TextBox();
this.labelTag = new System.Windows.Forms.Label();
this.groupBoxTemplateItem = new System.Windows.Forms.GroupBox();
this.textBoxHint = new System.Windows.Forms.TextBox();
this.labelHint = new System.Windows.Forms.Label();
this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemRemoveAll = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator8 = new System.Windows.Forms.ToolStripSeparator();
this.moveUpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.moveDownToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.moveTopToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.moveBottomToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.newToolStripMenuItemNew = new System.Windows.Forms.ToolStripMenuItem();
this.copyToolStripMenuItemCopy = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStripFile = new System.Windows.Forms.ContextMenuStrip(this.components);
this.groupBoxTemplateItem.SuspendLayout();
this.contextMenuStripFile.SuspendLayout();
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(757, 484);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 23);
this.buttonOK.TabIndex = 214;
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(838, 484);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 215;
this.buttonCancel.Text = "C&ancel";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// columnHeaderTag
//
this.columnHeaderTag.Text = "Tag";
this.columnHeaderTag.Width = 250;
//
// columnHeaderHint
//
this.columnHeaderHint.Text = "Hint";
this.columnHeaderHint.Width = 250;
//
// listViewTemplates
//
this.listViewTemplates.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.listViewTemplates.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeaderTag,
this.columnHeaderHint});
this.listViewTemplates.ContextMenuStrip = this.contextMenuStripFile;
this.listViewTemplates.FullRowSelect = true;
this.listViewTemplates.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.listViewTemplates.HideSelection = false;
this.listViewTemplates.Location = new System.Drawing.Point(12, 12);
this.listViewTemplates.MultiSelect = false;
this.listViewTemplates.Name = "listViewTemplates";
this.listViewTemplates.Size = new System.Drawing.Size(535, 432);
this.listViewTemplates.TabIndex = 206;
this.listViewTemplates.UseCompatibleStateImageBehavior = false;
this.listViewTemplates.View = System.Windows.Forms.View.Details;
this.listViewTemplates.SelectedIndexChanged += new System.EventHandler(this.listViewTemplates_SelectedIndexChanged);
//
// buttonRemove
//
this.buttonRemove.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRemove.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonRemove.Location = new System.Drawing.Point(367, 450);
this.buttonRemove.Name = "buttonRemove";
this.buttonRemove.Size = new System.Drawing.Size(82, 23);
this.buttonRemove.TabIndex = 210;
this.buttonRemove.Text = "Remove";
this.buttonRemove.UseVisualStyleBackColor = true;
this.buttonRemove.Click += new System.EventHandler(this.buttonRemove_Click);
//
// buttonAdd
//
this.buttonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonAdd.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonAdd.Location = new System.Drawing.Point(279, 450);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(82, 23);
this.buttonAdd.TabIndex = 208;
this.buttonAdd.Text = "New";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// buttonRemoveAll
//
this.buttonRemoveAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRemoveAll.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonRemoveAll.Location = new System.Drawing.Point(455, 450);
this.buttonRemoveAll.Name = "buttonRemoveAll";
this.buttonRemoveAll.Size = new System.Drawing.Size(92, 23);
this.buttonRemoveAll.TabIndex = 211;
this.buttonRemoveAll.Text = "Remove all";
this.buttonRemoveAll.UseVisualStyleBackColor = true;
this.buttonRemoveAll.Click += new System.EventHandler(this.buttonRemoveAll_Click);
//
// buttonCopy
//
this.buttonCopy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCopy.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonCopy.Location = new System.Drawing.Point(191, 450);
this.buttonCopy.Name = "buttonCopy";
this.buttonCopy.Size = new System.Drawing.Size(82, 23);
this.buttonCopy.TabIndex = 207;
this.buttonCopy.Text = "Copy";
this.buttonCopy.UseVisualStyleBackColor = true;
this.buttonCopy.Click += new System.EventHandler(this.buttonCopy_Click);
//
// textBoxTag
//
this.textBoxTag.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.textBoxTag.Location = new System.Drawing.Point(82, 15);
this.textBoxTag.Name = "textBoxTag";
this.textBoxTag.Size = new System.Drawing.Size(265, 20);
this.textBoxTag.TabIndex = 212;
this.textBoxTag.TextChanged += new System.EventHandler(this.textBoxTag_TextChanged);
//
// labelTag
//
this.labelTag.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.labelTag.AutoSize = true;
this.labelTag.Location = new System.Drawing.Point(10, 18);
this.labelTag.Name = "labelTag";
this.labelTag.Size = new System.Drawing.Size(26, 13);
this.labelTag.TabIndex = 209;
this.labelTag.Text = "Tag";
//
// groupBoxTemplateItem
//
this.groupBoxTemplateItem.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBoxTemplateItem.Controls.Add(this.textBoxHint);
this.groupBoxTemplateItem.Controls.Add(this.labelHint);
this.groupBoxTemplateItem.Controls.Add(this.textBoxTag);
this.groupBoxTemplateItem.Controls.Add(this.labelTag);
this.groupBoxTemplateItem.Location = new System.Drawing.Point(553, 12);
this.groupBoxTemplateItem.Name = "groupBoxTemplateItem";
this.groupBoxTemplateItem.Size = new System.Drawing.Size(360, 432);
this.groupBoxTemplateItem.TabIndex = 213;
this.groupBoxTemplateItem.TabStop = false;
//
// textBoxHint
//
this.textBoxHint.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.textBoxHint.Location = new System.Drawing.Point(82, 41);
this.textBoxHint.Name = "textBoxHint";
this.textBoxHint.Size = new System.Drawing.Size(265, 20);
this.textBoxHint.TabIndex = 214;
this.textBoxHint.TextChanged += new System.EventHandler(this.textBoxHint_TextChanged);
//
// labelHint
//
this.labelHint.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.labelHint.AutoSize = true;
this.labelHint.Location = new System.Drawing.Point(10, 44);
this.labelHint.Name = "labelHint";
this.labelHint.Size = new System.Drawing.Size(26, 13);
this.labelHint.TabIndex = 213;
this.labelHint.Text = "Hint";
//
// deleteToolStripMenuItem
//
this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem";
this.deleteToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Delete;
this.deleteToolStripMenuItem.Size = new System.Drawing.Size(215, 22);
this.deleteToolStripMenuItem.Text = "Remove";
this.deleteToolStripMenuItem.Click += new System.EventHandler(this.deleteToolStripMenuItem_Click);
//
// toolStripMenuItemRemoveAll
//
this.toolStripMenuItemRemoveAll.Name = "toolStripMenuItemRemoveAll";
this.toolStripMenuItemRemoveAll.Size = new System.Drawing.Size(215, 22);
this.toolStripMenuItemRemoveAll.Text = "Remove all";
this.toolStripMenuItemRemoveAll.Click += new System.EventHandler(this.toolStripMenuItemRemoveAll_Click);
//
// toolStripSeparator8
//
this.toolStripSeparator8.Name = "toolStripSeparator8";
this.toolStripSeparator8.Size = new System.Drawing.Size(212, 6);
//
// moveUpToolStripMenuItem
//
this.moveUpToolStripMenuItem.Name = "moveUpToolStripMenuItem";
this.moveUpToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Up)));
this.moveUpToolStripMenuItem.Size = new System.Drawing.Size(215, 22);
this.moveUpToolStripMenuItem.Text = "Move up";
this.moveUpToolStripMenuItem.Click += new System.EventHandler(this.moveUpToolStripMenuItem_Click);
//
// moveDownToolStripMenuItem
//
this.moveDownToolStripMenuItem.Name = "moveDownToolStripMenuItem";
this.moveDownToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Down)));
this.moveDownToolStripMenuItem.Size = new System.Drawing.Size(215, 22);
this.moveDownToolStripMenuItem.Text = "Move down";
this.moveDownToolStripMenuItem.Click += new System.EventHandler(this.moveDownToolStripMenuItem_Click);
//
// moveTopToolStripMenuItem
//
this.moveTopToolStripMenuItem.Name = "moveTopToolStripMenuItem";
this.moveTopToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Home)));
this.moveTopToolStripMenuItem.Size = new System.Drawing.Size(215, 22);
this.moveTopToolStripMenuItem.Text = "Move to top";
this.moveTopToolStripMenuItem.Click += new System.EventHandler(this.moveTopToolStripMenuItem_Click);
//
// moveBottomToolStripMenuItem
//
this.moveBottomToolStripMenuItem.Name = "moveBottomToolStripMenuItem";
this.moveBottomToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.End)));
this.moveBottomToolStripMenuItem.Size = new System.Drawing.Size(215, 22);
this.moveBottomToolStripMenuItem.Text = "Move to bottom";
this.moveBottomToolStripMenuItem.Click += new System.EventHandler(this.moveBottomToolStripMenuItem_Click);
//
// toolStripSeparator3
//
this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(212, 6);
//
// newToolStripMenuItemNew
//
this.newToolStripMenuItemNew.Name = "newToolStripMenuItemNew";
this.newToolStripMenuItemNew.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N)));
this.newToolStripMenuItemNew.Size = new System.Drawing.Size(215, 22);
this.newToolStripMenuItemNew.Text = "New";
this.newToolStripMenuItemNew.Click += new System.EventHandler(this.newToolStripMenuItemNew_Click);
//
// copyToolStripMenuItemCopy
//
this.copyToolStripMenuItemCopy.Name = "copyToolStripMenuItemCopy";
this.copyToolStripMenuItemCopy.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C)));
this.copyToolStripMenuItemCopy.Size = new System.Drawing.Size(215, 22);
this.copyToolStripMenuItemCopy.Text = "Copy";
this.copyToolStripMenuItemCopy.Click += new System.EventHandler(this.copyToolStripMenuItemCopy_Click);
//
// contextMenuStripFile
//
this.contextMenuStripFile.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.deleteToolStripMenuItem,
this.toolStripMenuItemRemoveAll,
this.toolStripSeparator8,
this.moveUpToolStripMenuItem,
this.moveDownToolStripMenuItem,
this.moveTopToolStripMenuItem,
this.moveBottomToolStripMenuItem,
this.toolStripSeparator3,
this.newToolStripMenuItemNew,
this.copyToolStripMenuItemCopy});
this.contextMenuStripFile.Name = "contextMenuStrip1";
this.contextMenuStripFile.Size = new System.Drawing.Size(216, 192);
//
// AssaTagTemplate
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(925, 519);
this.Controls.Add(this.groupBoxTemplateItem);
this.Controls.Add(this.buttonCopy);
this.Controls.Add(this.buttonRemoveAll);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.buttonRemove);
this.Controls.Add(this.listViewTemplates);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
this.KeyPreview = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "AssaTagTemplate";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "AssaTagTemplate";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.AssaTagTemplate_KeyDown);
this.groupBoxTemplateItem.ResumeLayout(false);
this.groupBoxTemplateItem.PerformLayout();
this.contextMenuStripFile.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.ColumnHeader columnHeaderTag;
private System.Windows.Forms.ColumnHeader columnHeaderHint;
private System.Windows.Forms.ListView listViewTemplates;
private System.Windows.Forms.Button buttonRemove;
private System.Windows.Forms.Button buttonAdd;
private System.Windows.Forms.Button buttonRemoveAll;
private System.Windows.Forms.Button buttonCopy;
private System.Windows.Forms.TextBox textBoxTag;
private System.Windows.Forms.Label labelTag;
private System.Windows.Forms.GroupBox groupBoxTemplateItem;
private System.Windows.Forms.TextBox textBoxHint;
private System.Windows.Forms.Label labelHint;
private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemRemoveAll;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator8;
private System.Windows.Forms.ToolStripMenuItem moveUpToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem moveDownToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem moveTopToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem moveBottomToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
private System.Windows.Forms.ToolStripMenuItem newToolStripMenuItemNew;
private System.Windows.Forms.ToolStripMenuItem copyToolStripMenuItemCopy;
private System.Windows.Forms.ContextMenuStrip contextMenuStripFile;
}
}

View File

@ -0,0 +1,308 @@
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 partial class AssaTagTemplate : Form
{
private readonly List<AssaTemplateItem> _templates = new List<AssaTemplateItem>();
private AssaTemplateItem _activeTemplate;
public AssaTagTemplate()
{
UiUtil.PreInitialize(this);
InitializeComponent();
UiUtil.FixFonts(this);
listViewTemplates_SelectedIndexChanged(null, null);
_templates.AddRange(Configuration.Settings.Tools.AssaTagTemplates);
ShowTemplates(_templates, null);
buttonOK.Text = LanguageSettings.Current.General.Ok;
buttonCancel.Text = LanguageSettings.Current.General.Cancel;
UiUtil.FixLargeFonts(this, buttonOK);
}
private void ShowTemplates(List<AssaTemplateItem> templates, AssaTemplateItem focusTemplate)
{
listViewTemplates.BeginUpdate();
listViewTemplates.Items.Clear();
for (var index = 0; index < templates.Count; index++)
{
var template = templates[index];
var item = new ListViewItem { Text = template.Tag, Tag = template };
item.SubItems.Add(template.Hint);
listViewTemplates.Items.Add(item);
if (template == focusTemplate)
{
listViewTemplates.Items[index].Selected = true;
}
}
listViewTemplates.EndUpdate();
if (templates.Count > 0 && listViewTemplates.SelectedItems.Count == 0)
{
listViewTemplates.Items[0].Selected = true;
}
}
private void SaveTemplates()
{
Configuration.Settings.Tools.AssaTagTemplates.Clear();
Configuration.Settings.Tools.AssaTagTemplates.AddRange(_templates);
}
private void AssaTagTemplate_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
}
private void buttonOK_Click(object sender, EventArgs e)
{
SaveTemplates();
DialogResult = DialogResult.OK;
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var newItem = new AssaTemplateItem { Tag = "{\\}" };
_templates.Add(newItem);
ShowTemplates(_templates, newItem);
textBoxTag.Focus();
}
private void listViewTemplates_SelectedIndexChanged(object sender, EventArgs e)
{
if (listViewTemplates.SelectedItems.Count == 0)
{
_activeTemplate = null;
textBoxTag.Text = string.Empty;
textBoxHint.Text = string.Empty;
groupBoxTemplateItem.Enabled = false;
buttonCopy.Enabled = false;
return;
}
var idx = listViewTemplates.SelectedItems[0].Index;
_activeTemplate = listViewTemplates.Items[idx].Tag as AssaTemplateItem;
if (_activeTemplate != null)
{
textBoxTag.Text = _activeTemplate.Tag;
textBoxHint.Text = _activeTemplate.Hint;
groupBoxTemplateItem.Enabled = true;
buttonCopy.Enabled = true;
}
}
private void textBoxTag_TextChanged(object sender, EventArgs e)
{
if (_activeTemplate == null)
{
return;
}
_activeTemplate.Tag = textBoxTag.Text;
UpdateListView();
}
private void UpdateListView()
{
if (_activeTemplate == null)
{
return;
}
foreach (ListViewItem item in listViewTemplates.Items)
{
if (item.Tag as AssaTemplateItem != _activeTemplate)
{
continue;
}
item.SubItems[0].Text = _activeTemplate.Tag;
item.SubItems[1].Text = _activeTemplate.Hint;
break;
}
}
private void textBoxHint_TextChanged(object sender, EventArgs e)
{
if (_activeTemplate == null)
{
return;
}
_activeTemplate.Hint = textBoxHint.Text;
UpdateListView();
}
private void buttonRemove_Click(object sender, EventArgs e)
{
if (listViewTemplates.SelectedItems.Count == 0)
{
return;
}
_activeTemplate = null;
var idx = listViewTemplates.SelectedItems[0].Index;
_templates.RemoveAt(idx);
var focusItem = _templates.Count > idx ? _templates[idx] : _templates.LastOrDefault();
ShowTemplates(_templates, focusItem);
}
private void buttonRemoveAll_Click(object sender, EventArgs e)
{
_activeTemplate = null;
_templates.Clear();
ShowTemplates(_templates, null);
}
private void buttonCopy_Click(object sender, EventArgs e)
{
if (listViewTemplates.SelectedItems.Count == 0)
{
return;
}
_activeTemplate = null;
var idx = listViewTemplates.SelectedItems[0].Index;
var template = _templates[idx];
var newItem = new AssaTemplateItem { Tag = template.Tag, Hint = template.Hint };
_templates.Add(newItem);
ShowTemplates(_templates, newItem);
}
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
buttonRemove_Click(null, null);
}
private void toolStripMenuItemRemoveAll_Click(object sender, EventArgs e)
{
buttonRemoveAll_Click(null, null);
}
private void newToolStripMenuItemNew_Click(object sender, EventArgs e)
{
buttonAdd_Click(null, null);
}
private void copyToolStripMenuItemCopy_Click(object sender, EventArgs e)
{
buttonCopy_Click(null, null);
}
private void MoveUp(ListView listView)
{
if (listView.SelectedItems.Count == 0)
{
return;
}
var idx = listView.SelectedItems[0].Index;
if (idx == 0)
{
return; // already top
}
var item = _templates[idx];
_templates.RemoveAt(idx);
idx--;
_templates.Insert(idx, item);
ShowTemplates(_templates, item);
}
private void MoveDown(ListView listView)
{
if (listView.SelectedItems.Count == 0)
{
return;
}
var idx = listView.SelectedItems[0].Index;
if (idx >= listView.Items.Count - 1)
{
return; // already last
}
var item = _templates[idx];
_templates.RemoveAt(idx);
idx++;
_templates.Insert(idx, item);
ShowTemplates(_templates, item);
}
private void MoveToTop(ListView listView)
{
if (listView.SelectedItems.Count == 0)
{
return;
}
var idx = listView.SelectedItems[0].Index;
if (idx == 0)
{
return; // already top
}
var item = _templates[idx];
_templates.RemoveAt(idx);
idx = 0;
_templates.Insert(idx, item);
ShowTemplates(_templates, item);
}
private void MoveToBottom(ListView listView)
{
if (listView.SelectedItems.Count == 0)
{
return;
}
var idx = listView.SelectedItems[0].Index;
if (idx == listView.Items.Count - 1)
{
return; // already last
}
var item = _templates[idx];
_templates.RemoveAt(idx);
_templates.Add(item);
ShowTemplates(_templates, item);
}
private void moveUpToolStripMenuItem_Click(object sender, EventArgs e)
{
MoveUp(listViewTemplates);
}
private void moveDownToolStripMenuItem_Click(object sender, EventArgs e)
{
MoveDown(listViewTemplates);
}
private void moveTopToolStripMenuItem_Click(object sender, EventArgs e)
{
MoveToTop(listViewTemplates);
}
private void moveBottomToolStripMenuItem_Click(object sender, EventArgs e)
{
MoveToBottom(listViewTemplates);
}
}
}

View File

@ -0,0 +1,123 @@
<?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>
<metadata name="contextMenuStripFile.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -9792,7 +9792,7 @@ namespace Nikse.SubtitleEdit.Forms
else if (_shortcuts.MainTextBoxAssaRemoveTag == e.KeyData && IsAssa())
{
MakeHistoryForUndo("text change"); //TODO: fix language tag
AssaIntellisense.RemoveTagAtCursor(textBoxListViewText);
AssaTagHelper.RemoveTagAtCursor(textBoxListViewText);
e.SuppressKeyPress = true;
return;
}
@ -9989,11 +9989,11 @@ namespace Nikse.SubtitleEdit.Forms
{
if (args.KeyCode == Keys.Tab && intellisenseListBox.SelectedIndex >= 0)
{
var item = intellisenseListBox.Items[intellisenseListBox.SelectedIndex] as AssaIntellisense.IntellisenseItem;
var item = intellisenseListBox.Items[intellisenseListBox.SelectedIndex] as AssaTagHelper.IntellisenseItem;
if (item != null)
{
MakeHistoryForUndo(string.Format(_language.BeforeAddingTagX, item.Value));
AssaIntellisense.CompleteItem(tb, item);
AssaTagHelper.CompleteItem(tb, item);
ShowStatus(string.Format(_language.TagXAdded, item.Value));
}
@ -10005,11 +10005,11 @@ namespace Nikse.SubtitleEdit.Forms
{
if (args.KeyCode == Keys.Enter && intellisenseListBox.SelectedIndex >= 0)
{
var item = intellisenseListBox.Items[intellisenseListBox.SelectedIndex] as AssaIntellisense.IntellisenseItem;
var item = intellisenseListBox.Items[intellisenseListBox.SelectedIndex] as AssaTagHelper.IntellisenseItem;
if (item != null)
{
MakeHistoryForUndo(string.Format(_language.BeforeAddingTagX, item.Value));
AssaIntellisense.CompleteItem(tb, item);
AssaTagHelper.CompleteItem(tb, item);
ShowStatus(string.Format(_language.TagXAdded, item.Value));
}
@ -10029,11 +10029,11 @@ namespace Nikse.SubtitleEdit.Forms
int index = intellisenseListBox.IndexFromPoint((args as MouseEventArgs).Location);
if (index != ListBox.NoMatches)
{
var item = intellisenseListBox.Items[index] as AssaIntellisense.IntellisenseItem;
var item = intellisenseListBox.Items[index] as AssaTagHelper.IntellisenseItem;
if (item != null)
{
MakeHistoryForUndo(string.Format(_language.BeforeAddingTagX, item.Value));
AssaIntellisense.CompleteItem(tb, item);
AssaTagHelper.CompleteItem(tb, item);
ShowStatus(string.Format(_language.TagXAdded, item.Value));
}
@ -10058,14 +10058,14 @@ namespace Nikse.SubtitleEdit.Forms
tb.Focus();
SendKeys.SendWait(x);
args.Handled = true;
AssaIntellisense.AutoCompleteTextBox(tb, intellisenseListBox);
AssaTagHelper.AutoCompleteTextBox(tb, intellisenseListBox);
intellisenseListBox.Focus();
}
};
intellisenseListBox.LostFocus += (o, args) => intellisenseListBox.Hide();
}
if (AssaIntellisense.AutoCompleteTextBox(tb, intellisenseListBox))
if (AssaTagHelper.AutoCompleteTextBox(tb, intellisenseListBox))
{
var p = GetPositionInForm(tb);
intellisenseListBox.Location = new Point(p.X + 10, p.Y + 40); //TODO: improve position
@ -25584,7 +25584,7 @@ namespace Nikse.SubtitleEdit.Forms
else if (_shortcuts.MainTextBoxAssaRemoveTag == e.KeyData && IsAssa())
{
MakeHistoryForUndo("text change"); //TODO: fix language tag
AssaIntellisense.RemoveTagAtCursor(textBoxListViewTextOriginal);
AssaTagHelper.RemoveTagAtCursor(textBoxListViewTextOriginal);
e.SuppressKeyPress = true;
return;
}

View File

@ -5,10 +5,11 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Forms.Assa;
namespace Nikse.SubtitleEdit.Logic
{
public static class AssaIntellisense
public static class AssaTagHelper
{
public class IntellisenseItem
{
@ -43,6 +44,8 @@ namespace Nikse.SubtitleEdit.Logic
return v + "\t " + Hint;
}
}
public static IntellisenseItem IntellisenseItemEdit = new IntellisenseItem("- Edit custom templates -", string.Empty, false);
}
private static readonly List<IntellisenseItem> Keywords = new List<IntellisenseItem>
@ -141,6 +144,17 @@ namespace Nikse.SubtitleEdit.Logic
public static void CompleteItem(SETextBox tb, IntellisenseItem item)
{
if (item == IntellisenseItem.IntellisenseItemEdit)
{
using (var form = new AssaTagTemplate())
{
form.ShowDialog();
}
return;
}
tb.SuspendLayout();
// remove old tag if any
@ -280,7 +294,10 @@ namespace Nikse.SubtitleEdit.Logic
var textBeforeCursor = string.IsNullOrEmpty(textBox.Text) ? string.Empty : textBox.Text.Substring(0, textBox.SelectionStart);
var activeTagAtCursor = GetInsideTag(textBox, textBeforeCursor);
var activeTagToCursor = GetLastString(textBeforeCursor) ?? string.Empty;
var keywords = (activeTagToCursor.StartsWith('\\') ? Keywords.Select(p => new IntellisenseItem(p.Value.TrimStart('{'), p.Hint, p.AllowInTransformations)) : Keywords.Select(p => p)).ToList();
var keywords = Configuration.Settings.Tools.AssaTagTemplates.Select(p => new IntellisenseItem(p.Tag, p.Hint, false)).ToList();
keywords.AddRange(Keywords);
keywords = (activeTagToCursor.StartsWith('\\') ? keywords.Select(p => new IntellisenseItem(p.Value.TrimStart('{'), p.Hint, p.AllowInTransformations)) : keywords.Select(p => p)).ToList();
if (textBeforeCursor.EndsWith("\\t(", StringComparison.Ordinal))
{
@ -336,6 +353,9 @@ namespace Nikse.SubtitleEdit.Logic
}
}
IntellisenseItem.IntellisenseItemEdit.Font = textBox.Font;
listBox.Items.Add(IntellisenseItem.IntellisenseItemEdit);
if (Configuration.Settings.General.UseDarkTheme)
{
DarkTheme.SetDarkTheme(listBox);

View File

@ -6505,6 +6505,9 @@ namespace Nikse.SubtitleEdit.Logic
case "Settings/MainTextBoxAssaIntellisense":
language.Settings.MainTextBoxAssaIntellisense = reader.Value;
break;
case "Settings/MainTextBoxAssaRemoveTag":
language.Settings.MainTextBoxAssaRemoveTag = reader.Value;
break;
case "Settings/MainFileSaveAll":
language.Settings.MainFileSaveAll = reader.Value;
break;

View File

@ -115,6 +115,12 @@
<Compile Include="Forms\AlignmentPickerJapanese.Designer.cs">
<DependentUpon>AlignmentPickerJapanese.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Assa\AssaTagTemplate.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\Assa\AssaTagTemplate.Designer.cs">
<DependentUpon>AssaTagTemplate.cs</DependentUpon>
</Compile>
<Compile Include="Forms\BatchConvertMkvEnding.cs">
<SubType>Form</SubType>
</Compile>
@ -1135,7 +1141,7 @@
<Compile Include="Forms\YouTubeAnnotationsImport.Designer.cs">
<DependentUpon>YouTubeAnnotationsImport.cs</DependentUpon>
</Compile>
<Compile Include="Logic\AssaIntellisense.cs" />
<Compile Include="Logic\AssaTagHelper.cs" />
<Compile Include="Logic\ColorChooser\ColorChangedEventArgs.cs" />
<Compile Include="Logic\ColorChooser\ColorHandler.cs" />
<Compile Include="Logic\ColorChooser\ColorWheel.cs" />
@ -1234,6 +1240,9 @@
<EmbeddedResource Include="Forms\AlignmentPickerJapanese.resx">
<DependentUpon>AlignmentPickerJapanese.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Assa\AssaTagTemplate.resx">
<DependentUpon>AssaTagTemplate.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\BatchConvertMkvEnding.resx">
<DependentUpon>BatchConvertMkvEnding.cs</DependentUpon>
</EmbeddedResource>