From c9ce0e46543527b7b51ed8b46cc89aeeb72ff113 Mon Sep 17 00:00:00 2001 From: ivandrofly Date: Sun, 6 Sep 2015 11:02:59 +0100 Subject: [PATCH] [UI] - Add button (Remove/Remove All) --- LanguageMaster.xml | 2 ++ libse/Language.cs | 2 ++ libse/LanguageStructure.cs | 2 ++ src/Forms/ImportImages.Designer.cs | 33 ++++++++++++++++++++ src/Forms/ImportImages.cs | 49 +++++++++++++++++++++++++++--- src/Forms/ImportImages.resx | 3 ++ src/Logic/LanguageDeserializer.cs | 6 ++++ 7 files changed, 93 insertions(+), 4 deletions(-) diff --git a/LanguageMaster.xml b/LanguageMaster.xml index b0e7f9b81..0884539a5 100644 --- a/LanguageMaster.xml +++ b/LanguageMaster.xml @@ -672,6 +672,8 @@ Note: Do check free disk space. Image files Input Choose input files (browse or drag-n-drop) + Remove + Remove all Import scene changes diff --git a/libse/Language.cs b/libse/Language.cs index 85e95076d..37f86150b 100644 --- a/libse/Language.cs +++ b/libse/Language.cs @@ -866,6 +866,8 @@ namespace Nikse.SubtitleEdit.Core Input = "Input", InputDescription = "Choose input files (browse or drag-n-drop)", ImageFiles = "Image files", + Remove = "Remove", + RemoveAll = "Remove all" }; ImportSceneChanges = new LanguageStructure.ImportSceneChanges diff --git a/libse/LanguageStructure.cs b/libse/LanguageStructure.cs index 02540ee6d..4df010667 100644 --- a/libse/LanguageStructure.cs +++ b/libse/LanguageStructure.cs @@ -747,6 +747,8 @@ public string ImageFiles { get; set; } public string Input { get; set; } public string InputDescription { get; set; } + public string Remove { get; set; } + public string RemoveAll { get; set; } } public class ImportSceneChanges diff --git a/src/Forms/ImportImages.Designer.cs b/src/Forms/ImportImages.Designer.cs index 6f5d05e6b..b8cb86daf 100644 --- a/src/Forms/ImportImages.Designer.cs +++ b/src/Forms/ImportImages.Designer.cs @@ -28,6 +28,7 @@ /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.groupBoxInput = new System.Windows.Forms.GroupBox(); this.buttonInputBrowse = new System.Windows.Forms.Button(); this.labelChooseInputFiles = new System.Windows.Forms.Label(); @@ -40,7 +41,11 @@ this.buttonOK = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.removeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.removeAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.groupBoxInput.SuspendLayout(); + this.contextMenuStrip1.SuspendLayout(); this.SuspendLayout(); // // groupBoxInput @@ -90,6 +95,7 @@ this.columnHeaderStartTime, this.columnHeaderEndTime, this.columnHeaderDuration}); + this.listViewInputFiles.ContextMenuStrip = this.contextMenuStrip1; this.listViewInputFiles.FullRowSelect = true; this.listViewInputFiles.HideSelection = false; this.listViewInputFiles.Location = new System.Drawing.Point(8, 41); @@ -153,6 +159,29 @@ // this.openFileDialog1.FileName = "openFileDialog1"; // + // contextMenuStrip1 + // + this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.removeToolStripMenuItem, + this.removeAllToolStripMenuItem}); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(133, 48); + this.contextMenuStrip1.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip1_Opening); + // + // removeToolStripMenuItem + // + this.removeToolStripMenuItem.Name = "removeToolStripMenuItem"; + this.removeToolStripMenuItem.Size = new System.Drawing.Size(132, 22); + this.removeToolStripMenuItem.Text = "Remove"; + this.removeToolStripMenuItem.Click += new System.EventHandler(this.removeToolStripMenuItem_Click); + // + // removeAllToolStripMenuItem + // + this.removeAllToolStripMenuItem.Name = "removeAllToolStripMenuItem"; + this.removeAllToolStripMenuItem.Size = new System.Drawing.Size(132, 22); + this.removeAllToolStripMenuItem.Text = "Remove all"; + this.removeAllToolStripMenuItem.Click += new System.EventHandler(this.removeAllToolStripMenuItem_Click); + // // ImportImages // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -170,6 +199,7 @@ this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ImportImages_KeyDown); this.groupBoxInput.ResumeLayout(false); this.groupBoxInput.PerformLayout(); + this.contextMenuStrip1.ResumeLayout(false); this.ResumeLayout(false); } @@ -188,5 +218,8 @@ private System.Windows.Forms.Button buttonCancel; private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.ColumnHeader columnHeaderDuration; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; + private System.Windows.Forms.ToolStripMenuItem removeToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem removeAllToolStripMenuItem; } } \ No newline at end of file diff --git a/src/Forms/ImportImages.cs b/src/Forms/ImportImages.cs index 155fde9fa..044c887ef 100644 --- a/src/Forms/ImportImages.cs +++ b/src/Forms/ImportImages.cs @@ -2,14 +2,14 @@ using System; using System.IO; using System.Windows.Forms; -using System.Collections; +using System.Collections.Generic; namespace Nikse.SubtitleEdit.Forms { public sealed partial class ImportImages : PositionAndSizeForm { public Subtitle Subtitle { get; private set; } - private readonly Hashtable FilesAlreadyInList; + private readonly HashSet FilesAlreadyInList; public ImportImages() { InitializeComponent(); @@ -17,6 +17,8 @@ namespace Nikse.SubtitleEdit.Forms Text = Configuration.Settings.Language.ImportImages.Title; groupBoxInput.Text = Configuration.Settings.Language.ImportImages.Input; labelChooseInputFiles.Text = Configuration.Settings.Language.ImportImages.InputDescription; + removeToolStripMenuItem.Text = Configuration.Settings.Language.ImportImages.Remove; + removeAllToolStripMenuItem.Text = Configuration.Settings.Language.ImportImages.RemoveAll; columnHeaderFName.Text = Configuration.Settings.Language.JoinSubtitles.FileName; columnHeaderSize.Text = Configuration.Settings.Language.General.Size; columnHeaderStartTime.Text = Configuration.Settings.Language.General.StartTime; @@ -24,7 +26,7 @@ namespace Nikse.SubtitleEdit.Forms columnHeaderDuration.Text = Configuration.Settings.Language.General.Duration; buttonOK.Text = Configuration.Settings.Language.General.Ok; buttonCancel.Text = Configuration.Settings.Language.General.Cancel; - FilesAlreadyInList = new Hashtable(); + FilesAlreadyInList = new HashSet(); } private void buttonInputBrowse_Click(object sender, EventArgs e) @@ -54,7 +56,7 @@ namespace Nikse.SubtitleEdit.Forms var ext = fi.Extension.ToLowerInvariant(); if (ext == ".png" || ext == ".jpg" || ext == ".bmp" || ext == ".gif" || ext == ".tif" || ext == ".tiff") { - FilesAlreadyInList.Add(fileName, null); + FilesAlreadyInList.Add(fileName); SetTimeCodes(fileName, item); listViewInputFiles.Items.Add(item); } @@ -136,5 +138,44 @@ namespace Nikse.SubtitleEdit.Forms } } + private void contextMenuStrip1_Opening(object sender, System.ComponentModel.CancelEventArgs e) + { + if (listViewInputFiles.Items.Count == 0) + e.Cancel = true; + else + removeToolStripMenuItem.Visible = listViewInputFiles.SelectedItems.Count > 0; + } + + private void RemoveSelection(bool removeAll = false) + { + if (listViewInputFiles.Items.Count == 0) + return; + if (removeAll) + { + foreach (ListViewItem item in listViewInputFiles.Items) + { + item.Remove(); + FilesAlreadyInList.Remove(item.Text); + } + } + else if (listViewInputFiles.SelectedItems.Count > 0) + { + foreach (ListViewItem item in listViewInputFiles.SelectedItems) + { + item.Remove(); + FilesAlreadyInList.Remove(item.Text); + } + } + } + + private void removeToolStripMenuItem_Click(object sender, EventArgs e) + { + RemoveSelection(); + } + + private void removeAllToolStripMenuItem_Click(object sender, EventArgs e) + { + RemoveSelection(true); + } } } \ No newline at end of file diff --git a/src/Forms/ImportImages.resx b/src/Forms/ImportImages.resx index 3a7d67153..2bd4597e5 100644 --- a/src/Forms/ImportImages.resx +++ b/src/Forms/ImportImages.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 157, 17 + 17, 17 diff --git a/src/Logic/LanguageDeserializer.cs b/src/Logic/LanguageDeserializer.cs index d442f7190..4ba660ea7 100644 --- a/src/Logic/LanguageDeserializer.cs +++ b/src/Logic/LanguageDeserializer.cs @@ -1763,6 +1763,12 @@ namespace Nikse.SubtitleEdit.Logic case "ImportImages/InputDescription": language.ImportImages.InputDescription = reader.Value; break; + case "ImportImages/Remove": + language.ImportImages.Remove = reader.Value; + break; + case "ImportImages/RemoveAll": + language.ImportImages.RemoveAll = reader.Value; + break; case "ImportSceneChanges/Title": language.ImportSceneChanges.Title = reader.Value; break;