Allow import/export shortcuts

This commit is contained in:
Nikolaj Olsson 2020-10-10 20:24:14 +02:00
parent 14d926e1d3
commit 57c8c753cb
3 changed files with 95 additions and 3 deletions

View File

@ -386,6 +386,10 @@
this.openFileDialogFFmpeg = new System.Windows.Forms.OpenFileDialog();
this.buttonReset = new System.Windows.Forms.Button();
this.toolTipContinuationPreview = new System.Windows.Forms.ToolTip(this.components);
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.importShortcutsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportShortcutsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.tabControlSettings.SuspendLayout();
this.tabPageGeneral.SuspendLayout();
this.groupBoxMiscellaneous.SuspendLayout();
@ -1607,14 +1611,17 @@
// contextMenuStripShortcuts
//
this.contextMenuStripShortcuts.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItemShortcutsCollapse});
this.toolStripMenuItemShortcutsCollapse,
this.toolStripSeparator1,
this.importShortcutsToolStripMenuItem,
this.exportShortcutsToolStripMenuItem});
this.contextMenuStripShortcuts.Name = "contextMenuStripShortcuts";
this.contextMenuStripShortcuts.Size = new System.Drawing.Size(120, 26);
this.contextMenuStripShortcuts.Size = new System.Drawing.Size(120, 76);
//
// toolStripMenuItemShortcutsCollapse
//
this.toolStripMenuItemShortcutsCollapse.Name = "toolStripMenuItemShortcutsCollapse";
this.toolStripMenuItemShortcutsCollapse.Size = new System.Drawing.Size(119, 22);
this.toolStripMenuItemShortcutsCollapse.Size = new System.Drawing.Size(180, 22);
this.toolStripMenuItemShortcutsCollapse.Text = "Collapse";
this.toolStripMenuItemShortcutsCollapse.Click += new System.EventHandler(this.toolStripMenuItemShortcutsCollapse_Click);
//
@ -4687,6 +4694,25 @@
this.toolTipContinuationPreview.InitialDelay = 500;
this.toolTipContinuationPreview.ReshowDelay = 100;
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(177, 6);
//
// importShortcutsToolStripMenuItem
//
this.importShortcutsToolStripMenuItem.Name = "importShortcutsToolStripMenuItem";
this.importShortcutsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.importShortcutsToolStripMenuItem.Text = "Import...";
this.importShortcutsToolStripMenuItem.Click += new System.EventHandler(this.importShortcutsToolStripMenuItem_Click);
//
// exportShortcutsToolStripMenuItem
//
this.exportShortcutsToolStripMenuItem.Name = "exportShortcutsToolStripMenuItem";
this.exportShortcutsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.exportShortcutsToolStripMenuItem.Text = "Export...";
this.exportShortcutsToolStripMenuItem.Click += new System.EventHandler(this.exportShortcutsToolStripMenuItem_Click);
//
// Settings
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -5184,5 +5210,9 @@
private System.Windows.Forms.Button buttonGapChoose;
private System.Windows.Forms.CheckBox checkBoxSpellCheckAutoChangeNamesViaSuggestions;
private System.Windows.Forms.ComboBox comboBoxBoxBingTokenEndpoint;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem importShortcutsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exportShortcutsToolStripMenuItem;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
}
}

View File

@ -18,6 +18,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
namespace Nikse.SubtitleEdit.Forms
{
@ -950,6 +951,8 @@ namespace Nikse.SubtitleEdit.Forms
MakeShortcutsTreeView(language);
ShowShortcutsTreeView();
toolStripMenuItemShortcutsCollapse.Text = Configuration.Settings.Language.General.Collapse;
importShortcutsToolStripMenuItem.Text = Configuration.Settings.Language.MultipleReplace.Import;
exportShortcutsToolStripMenuItem.Text = Configuration.Settings.Language.MultipleReplace.Export;
labelShortcutsSearch.Text = Configuration.Settings.Language.General.Search;
buttonShortcutsClear.Text = Configuration.Settings.Language.DvdSubRip.Clear;
textBoxShortcutSearch.Left = labelShortcutsSearch.Left + labelShortcutsSearch.Width + 5;
@ -1447,6 +1450,7 @@ namespace Nikse.SubtitleEdit.Forms
treeViewShortcuts.ExpandAll();
treeViewShortcuts.EndUpdate();
treeViewShortcuts.SelectedNode = treeViewShortcuts.Nodes[0];
}
private void AddNode(TreeNode parentNode, string text, ShortcutHelper shortcut)
@ -3410,5 +3414,60 @@ namespace Nikse.SubtitleEdit.Forms
}
}
}
private void importShortcutsToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialogFFmpeg.Title = null;
openFileDialogFFmpeg.Filter = "Xml files|*.xml";
openFileDialogFFmpeg.FileName = "SE_Shortcuts";
if (openFileDialogFFmpeg.ShowDialog(this) != DialogResult.OK)
{
return;
}
try
{
var r = new StreamReader(openFileDialogFFmpeg.FileName);
var s = new XmlSerializer(typeof(Shortcuts));
Configuration.Settings.Shortcuts = (Shortcuts)s.Deserialize(r);
r.Close();
MakeShortcutsTreeView(Configuration.Settings.Language.Settings);
ShowShortcutsTreeView();
}
catch (Exception exception)
{
MessageBox.Show("Shortcuts not imported!" + Environment.NewLine + Environment.NewLine + exception.Message);
SeLogger.Error(exception, "Failed to import shortcuts");
}
}
private void exportShortcutsToolStripMenuItem_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = "Xml files|*.xml";
saveFileDialog1.FileName = "SE_Shortcuts";
if (saveFileDialog1.ShowDialog(this) != DialogResult.OK)
{
return;
}
try
{
var shortcuts = new Shortcuts();
foreach (var kvp in _newShortcuts)
{
kvp.Key.Shortcut.SetValue(shortcuts, kvp.Value, null);
}
var s = new XmlSerializer(typeof(Shortcuts));
var w = new StreamWriter(saveFileDialog1.FileName);
s.Serialize(w, shortcuts);
w.Close();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
SeLogger.Error(exception, "Failed to export shortcuts");
}
}
}
}

View File

@ -129,4 +129,7 @@
<metadata name="toolTipContinuationPreview.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>664, 17</value>
</metadata>
<metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>867, 17</value>
</metadata>
</root>