From c61afd21b4e30f0c21eef2db653b89379d793f9b Mon Sep 17 00:00:00 2001 From: niksedk Date: Thu, 13 Jan 2022 08:50:44 +0100 Subject: [PATCH] Try to improve disabled edit controls when no sub is loaded - thx darnn :) Related to #5686 --- src/ui/Forms/Main.Designer.cs | 3 +- src/ui/Forms/Main.cs | 111 ++++++++++++++++++++++++++----- src/ui/Forms/Main.resx | 2 +- src/ui/Logic/Ocr/OcrFixEngine.cs | 2 +- 4 files changed, 99 insertions(+), 19 deletions(-) diff --git a/src/ui/Forms/Main.Designer.cs b/src/ui/Forms/Main.Designer.cs index 43a0b2991..ea827b6b5 100644 --- a/src/ui/Forms/Main.Designer.cs +++ b/src/ui/Forms/Main.Designer.cs @@ -2569,7 +2569,7 @@ namespace Nikse.SubtitleEdit.Forms this.toolStripMenuItemSelectedLines, this.toolStripMenuItemGoogleMicrosoftTranslateSelLine}); this.contextMenuStripListView.Name = "contextMenuStripListView"; - this.contextMenuStripListView.Size = new System.Drawing.Size(285, 798); + this.contextMenuStripListView.Size = new System.Drawing.Size(285, 776); this.contextMenuStripListView.Closed += new System.Windows.Forms.ToolStripDropDownClosedEventHandler(this.MenuClosed); this.contextMenuStripListView.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuStripListViewOpening); this.contextMenuStripListView.Opened += new System.EventHandler(this.MenuOpened); @@ -5483,6 +5483,7 @@ namespace Nikse.SubtitleEdit.Forms this.ResizeEnd += new System.EventHandler(this.Main_ResizeEnd); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MainKeyDown); this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.MainKeyUp); + this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Main_MouseDown); this.Resize += new System.EventHandler(this.Main_Resize); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index a25a7fa24..d1c7e84f3 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -557,6 +557,11 @@ namespace Nikse.SubtitleEdit.Forms } } + if (string.IsNullOrEmpty(_fileName)) + { + EnableOrDisableEditControls(); + } + // Initialize events etc. for audio waveform audioVisualizer.OnDoubleClickNonParagraph += AudioWaveform_OnDoubleClickNonParagraph; audioVisualizer.OnPositionSelected += AudioWaveform_OnPositionSelected; @@ -5047,15 +5052,16 @@ namespace Nikse.SubtitleEdit.Forms _sourceViewChange = false; - _subtitleListViewIndex = -1; - textBoxListViewText.Text = string.Empty; - textBoxListViewTextOriginal.Text = string.Empty; - textBoxListViewText.Enabled = false; - textBoxListViewText.BackColor = SystemColors.ActiveBorder; - textBoxListViewTextOriginal.BackColor = SystemColors.ActiveBorder; - labelTextLineLengths.Text = string.Empty; - labelCharactersPerSecond.Text = string.Empty; - labelTextLineTotal.Text = string.Empty; + //harboe _subtitleListViewIndex = -1; + //textBoxListViewText.Text = string.Empty; + //textBoxListViewTextOriginal.Text = string.Empty; + //textBoxListViewText.Enabled = false; + //textBoxListViewText.BackColor = SystemColors.ActiveBorder; + //textBoxListViewTextOriginal.BackColor = SystemColors.ActiveBorder; + //labelTextLineLengths.Text = string.Empty; + //labelCharactersPerSecond.Text = string.Empty; + //labelTextLineTotal.Text = string.Empty; + EnableOrDisableEditControls(); _listViewTextUndoLast = null; _listViewOriginalTextUndoLast = null; @@ -6968,8 +6974,9 @@ namespace Nikse.SubtitleEdit.Forms MakeHistoryForUndo(_language.BeforeChangesMadeInSourceView); _sourceViewChange = false; _subtitle.Paragraphs.Clear(); - textBoxListViewText.Text = string.Empty; - textBoxListViewText.Enabled = false; + //harboe textBoxListViewText.Text = string.Empty; + //textBoxListViewText.Enabled = false; + EnableOrDisableEditControls(); } _subtitleListViewIndex = -1; @@ -6991,8 +6998,9 @@ namespace Nikse.SubtitleEdit.Forms MakeHistoryForUndo(_language.BeforeChangesMadeInSourceView); _subtitle.Paragraphs.Clear(); SubtitleListview1.Items.Clear(); - textBoxListViewText.Text = string.Empty; - textBoxListViewText.Enabled = false; + //textBoxListViewText.Text = string.Empty; + //textBoxListViewText.Enabled = false; + EnableOrDisableEditControls(); return; } @@ -7779,6 +7787,7 @@ namespace Nikse.SubtitleEdit.Forms timerOriginalTextUndo.Start(); SetTitle(); SetListViewStateImages(); + EnableOrDisableEditControls(); } } @@ -9155,14 +9164,14 @@ namespace Nikse.SubtitleEdit.Forms MakeHistoryForUndo(historyText); DeleteSelectedLines(); - ResetTextInfoIfEmpty(); + EnableOrDisableEditControls(); ShowStatus(statusText); UpdateSourceView(); } } - private void ResetTextInfoIfEmpty() + private void EnableOrDisableEditControls() { if (_subtitle.Paragraphs.Count == 0) { @@ -9190,6 +9199,55 @@ namespace Nikse.SubtitleEdit.Forms labelOriginalCharactersPerSecond.Text = string.Empty; labelTextOriginalLineLengths.Text = string.Empty; labelTextOriginalLineTotal.Text = string.Empty; + numericUpDownDuration.Value = 0; + timeUpDownStartTime.TimeCode = new TimeCode(0); + + textBoxListViewText.Enabled = false; + textBoxListViewTextOriginal.Enabled = false; + timeUpDownStartTime.Enabled = false; + numericUpDownDuration.Enabled = false; + buttonPrevious.Enabled = false; + buttonNext.Enabled = false; + buttonUnBreak.Enabled = false; + buttonAutoBreak.Enabled = false; + if (!Configuration.Settings.General.UseDarkTheme) + { + labelText.Enabled = false; + labelStartTime.Enabled = false; + labelDuration.Enabled = false; + } + else + { + var foreColor = Configuration.Settings.General.DarkThemeForeColor; + var slightDarker = Color.FromArgb(Math.Max(0, foreColor.R - 75), Math.Max(0, foreColor.G - 75), Math.Max(0, foreColor.B - 75)); + labelText.ForeColor = slightDarker; + labelStartTime.ForeColor = slightDarker; + labelDuration.ForeColor = slightDarker; + } + } + else if (!numericUpDownDuration.Enabled) + { + textBoxListViewText.BackColor = SystemColors.WindowFrame; + textBoxListViewTextOriginal.BackColor = SystemColors.WindowFrame; + + textBoxListViewText.Enabled = true; + textBoxListViewTextOriginal.Enabled = true; + timeUpDownStartTime.Enabled = true; + numericUpDownDuration.Enabled = true; + buttonPrevious.Enabled = true; + buttonNext.Enabled = true; + buttonUnBreak.Enabled = true; + buttonAutoBreak.Enabled = true; + labelText.Enabled = true; + labelStartTime.Enabled = true; + labelDuration.Enabled = true; + if (Configuration.Settings.General.UseDarkTheme) + { + var foreColor = Configuration.Settings.General.DarkThemeForeColor; + labelText.ForeColor = foreColor; + labelStartTime.ForeColor = foreColor; + labelDuration.ForeColor = foreColor; + } } } @@ -9264,7 +9322,7 @@ namespace Nikse.SubtitleEdit.Forms } } - ResetTextInfoIfEmpty(); + EnableOrDisableEditControls(); SetListViewStateImages(); } @@ -12183,6 +12241,7 @@ namespace Nikse.SubtitleEdit.Forms { textBoxListViewText.Enabled = true; textBoxListViewText.BackColor = textBoxListViewText.Focused ? SystemColors.Highlight : SystemColors.WindowFrame; + EnableOrDisableEditControls(); } StartUpdateListSyntaxColoring(); @@ -23427,6 +23486,14 @@ namespace Nikse.SubtitleEdit.Forms _timerSlow.Start(); } + private void GroupBoxEdit_MouseClick(object sender, MouseEventArgs e) + { + if (!textBoxListViewText.Enabled) + { + InsertLineToolStripMenuItemClick(null, null); + } + } + private void TextBoxListViewText_MouseDown(object sender, MouseEventArgs e) { if (!textBoxListViewText.Enabled) @@ -33111,5 +33178,17 @@ namespace Nikse.SubtitleEdit.Forms SubtitleListview1.SelectIndexAndEnsureVisibleFaster(idx); } } + + private void Main_MouseDown(object sender, MouseEventArgs e) + { + if (e.X > 72 && e.X <= (122 + textBoxListViewText.Height)) + { + if (!textBoxListViewText.Enabled) + { + InsertLineToolStripMenuItemClick(null, null); + return; + } + } + } } } \ No newline at end of file diff --git a/src/ui/Forms/Main.resx b/src/ui/Forms/Main.resx index 2e5058ef9..fadb545ea 100644 --- a/src/ui/Forms/Main.resx +++ b/src/ui/Forms/Main.resx @@ -791,7 +791,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD2 - CAAAAk1TRnQBSQFMAgEBAgEAAeQBLAHkASwBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + CAAAAk1TRnQBSQFMAgEBAgEAARwBLQEcAS0BEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA diff --git a/src/ui/Logic/Ocr/OcrFixEngine.cs b/src/ui/Logic/Ocr/OcrFixEngine.cs index 6d94c82d4..14858b7b7 100644 --- a/src/ui/Logic/Ocr/OcrFixEngine.cs +++ b/src/ui/Logic/Ocr/OcrFixEngine.cs @@ -404,7 +404,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr } } - private string[] LoadWordSplitList(string threeLetterIsoLanguageName, NameList nameList) + private static string[] LoadWordSplitList(string threeLetterIsoLanguageName, NameList nameList) { var fileName = $"{Configuration.DictionariesDirectory}{threeLetterIsoLanguageName}_WordSplitList.txt"; if (!File.Exists(fileName))