Work on choose profile

Related to #3679
This commit is contained in:
nikolaj.olsson@visma.com 2019-08-07 07:58:01 +02:00
parent 0ad16a4315
commit b2eff032a2
4 changed files with 95 additions and 40 deletions

View File

@ -41,7 +41,7 @@
* Include more Unicode spaces in "Spell check" word split - thx Greg
* Improve handling of font tags in auto translation - thx Martin
* Allow negative video offset - thx Marcello
* Update in program download of Tesseract 4.0.0 to 4.1.0
* Update in-program-download of Tesseract 4.0.0 to 4.1.0
* FIXED:
* Fix for minor change in Google translate V1
* Fix "Change all" for whole text in OCR - thx wtester7

View File

@ -4733,12 +4733,21 @@ namespace Nikse.SubtitleEdit.Forms
labelStatus.Text = string.Empty;
}
private bool ShowProfileInStatusBar
{
get
{
return Configuration.Settings.General.CurrentProfile != "Default";
}
}
private void ShowSourceLineNumber()
{
if (tabControlSubtitle.SelectedIndex == TabControlSourceView)
{
var profile = Configuration.Settings.General.CurrentProfile + " ";
if (profile.TrimEnd() == "Default")
if (!ShowProfileInStatusBar)
{
profile = string.Empty;
}
@ -7489,7 +7498,7 @@ namespace Nikse.SubtitleEdit.Forms
toolStripMenuItemUnbreakLines.Visible = true;
toolStripMenuItemAutoBreakLines.Visible = true;
toolStripSeparatorBreakLines.Visible = true;
toolStripMenuItemSurroundWithMusicSymbols.Visible = IsUnicode || Configuration.Settings.Tools.MusicSymbol == "#" || Configuration.Settings.Tools.MusicSymbol == "*";
toolStripMenuItemSurroundWithMusicSymbols.Visible = IsUnicode || Configuration.Settings.Tools.MusicSymbol == "#" || Configuration.Settings.Tools.MusicSymbol == "*";
if (SubtitleListview1.SelectedItems.Count == 1)
{
toolStripMenuItemMergeLines.Visible = false;
@ -7564,7 +7573,7 @@ namespace Nikse.SubtitleEdit.Forms
if (string.IsNullOrEmpty(Configuration.Settings.Tools.MusicSymbol))
{
toolStripMenuItemSurroundWithMusicSymbols.Visible = false;
}
}
}
private void tsi_Click(object sender, EventArgs e)
@ -8426,7 +8435,7 @@ namespace Nikse.SubtitleEdit.Forms
private void ShowLineInformationListView()
{
var profile = Configuration.Settings.General.CurrentProfile + " ";
if (profile.TrimEnd() == "Default")
if (!ShowProfileInStatusBar)
{
profile = string.Empty;
}
@ -13468,20 +13477,7 @@ namespace Nikse.SubtitleEdit.Forms
}
else if (_mainGeneralChooseProfile == e.KeyData)
{
using (var form = new ProfileChoose(Configuration.Settings.General.Profiles, Configuration.Settings.General.CurrentProfile))
{
if (form.ShowDialog(this) == DialogResult.OK)
{
SubtitleListview1.BeginUpdate();
for (int i = 0; i < _subtitle.Paragraphs.Count; i++)
{
SubtitleListview1.SyntaxColorLine(_subtitle.Paragraphs, i, _subtitle.Paragraphs[i]);
}
SubtitleListview1.EndUpdate();
ShowLineInformationListView();
ShowSourceLineNumber();
}
}
ChooseProfile();
e.Handled = true;
e.SuppressKeyPress = true;
}
@ -25365,9 +25361,44 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private void ChooseProfile()
{
using (var form = new ProfileChoose(Configuration.Settings.General.Profiles, Configuration.Settings.General.CurrentProfile))
{
if (form.ShowDialog(this) == DialogResult.OK)
{
SubtitleListview1.BeginUpdate();
for (int i = 0; i < _subtitle.Paragraphs.Count; i++)
{
SubtitleListview1.SyntaxColorLine(_subtitle.Paragraphs, i, _subtitle.Paragraphs[i]);
}
SubtitleListview1.EndUpdate();
ShowLineInformationListView();
ShowSourceLineNumber();
}
}
}
private void toolStripSelected_Click(object sender, EventArgs e)
{
labelStatus_Click(sender, e);
if (!ShowProfileInStatusBar)
{
labelStatus_Click(sender, e);
return;
}
var x = statusStrip1.PointToClient(Cursor.Position).X;
var textWidth = TextRenderer.MeasureText(toolStripSelected.Text, toolStripSelected.Font).Width;
var min = statusStrip1.Width - textWidth - 20;
var max = min + TextRenderer.MeasureText(Configuration.Settings.General.CurrentProfile, toolStripSelected.Font).Width + 10;
if (x >= min && x <= max)
{
ChooseProfile(); // profile name in status bar clicked
}
else
{
labelStatus_Click(sender, e);
}
}
private void contextMenuStripWaveform_Closing(object sender, ToolStripDropDownClosingEventArgs e)

View File

@ -1,6 +1,6 @@
namespace Nikse.SubtitleEdit.Forms
{
partial class ProfileChoose
sealed partial class ProfileChoose
{
/// <summary>
/// Required designer variable.
@ -60,6 +60,7 @@
this.listViewProfiles.UseCompatibleStateImageBehavior = false;
this.listViewProfiles.View = System.Windows.Forms.View.Details;
this.listViewProfiles.DoubleClick += new System.EventHandler(this.listViewProfiles_DoubleClick);
this.listViewProfiles.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listViewProfiles_KeyDown);
//
// columnHeaderName
//
@ -127,6 +128,7 @@
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "ProfileChoose";
this.Shown += new System.EventHandler(this.ProfileChoose_Shown);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ProfileChoose_KeyDown);
this.ResumeLayout(false);

View File

@ -8,9 +8,9 @@ using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Forms
{
public partial class ProfileChoose : Form
public sealed partial class ProfileChoose : Form
{
private List<RulesProfile> _rulesProfiles { get; set; }
private List<RulesProfile> RulesProfiles { get; set; }
public ProfileChoose(List<RulesProfile> rulesProfiles, string name)
{
@ -30,10 +30,10 @@ namespace Nikse.SubtitleEdit.Forms
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;
UiUtil.FixLargeFonts(this, buttonOK);
_rulesProfiles = rulesProfiles;
if (_rulesProfiles.Count == 0)
RulesProfiles = rulesProfiles;
if (RulesProfiles.Count == 0)
{
_rulesProfiles.AddRange(new GeneralSettings().Profiles);
RulesProfiles.AddRange(new GeneralSettings().Profiles);
}
ShowRulesProfiles(rulesProfiles.FirstOrDefault(p => p.Name == name));
}
@ -41,10 +41,10 @@ namespace Nikse.SubtitleEdit.Forms
private void ShowRulesProfiles(RulesProfile itemToFocus)
{
var idx = listViewProfiles.SelectedItems.Count > 0 ? listViewProfiles.SelectedItems[0].Index : -1;
_rulesProfiles = _rulesProfiles.OrderBy(p => p.Name).ToList();
RulesProfiles = RulesProfiles.OrderBy(p => p.Name).ToList();
listViewProfiles.BeginUpdate();
listViewProfiles.Items.Clear();
foreach (var profile in _rulesProfiles)
foreach (var profile in RulesProfiles)
{
var item = new ListViewItem { Text = profile.Name };
item.SubItems.Add(profile.SubtitleLineMaximumLength.ToString(CultureInfo.InvariantCulture));
@ -69,6 +69,7 @@ namespace Nikse.SubtitleEdit.Forms
idx = listViewProfiles.Items.Count - 1;
}
listViewProfiles.Items[idx].Selected = true;
listViewProfiles.Items[idx].Focused = true;
}
}
@ -83,21 +84,21 @@ namespace Nikse.SubtitleEdit.Forms
private void buttonOK_Click(object sender, EventArgs e)
{
var idx = listViewProfiles.SelectedIndices[0];
Configuration.Settings.General.CurrentProfile = _rulesProfiles[idx].Name;
Configuration.Settings.General.SubtitleLineMaximumLength = _rulesProfiles[idx].SubtitleLineMaximumLength;
Configuration.Settings.General.SubtitleOptimalCharactersPerSeconds = (double)_rulesProfiles[idx].SubtitleOptimalCharactersPerSeconds;
Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds = (double)_rulesProfiles[idx].SubtitleMaximumCharactersPerSeconds;
Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds = _rulesProfiles[idx].SubtitleMinimumDisplayMilliseconds;
Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds = _rulesProfiles[idx].SubtitleMaximumDisplayMilliseconds;
Configuration.Settings.General.MinimumMillisecondsBetweenLines = _rulesProfiles[idx].MinimumMillisecondsBetweenLines;
Configuration.Settings.General.MaxNumberOfLines = _rulesProfiles[idx].MaxNumberOfLines;
Configuration.Settings.General.SubtitleMaximumWordsPerMinute = (double)_rulesProfiles[idx].SubtitleMaximumWordsPerMinute;
Configuration.Settings.General.CharactersPerSecondsIgnoreWhiteSpace = !_rulesProfiles[idx].CpsIncludesSpace;
Configuration.Settings.General.MergeLinesShorterThan = _rulesProfiles[idx].MergeLinesShorterThan;
Configuration.Settings.General.CurrentProfile = RulesProfiles[idx].Name;
Configuration.Settings.General.SubtitleLineMaximumLength = RulesProfiles[idx].SubtitleLineMaximumLength;
Configuration.Settings.General.SubtitleOptimalCharactersPerSeconds = (double)RulesProfiles[idx].SubtitleOptimalCharactersPerSeconds;
Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds = (double)RulesProfiles[idx].SubtitleMaximumCharactersPerSeconds;
Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds = RulesProfiles[idx].SubtitleMinimumDisplayMilliseconds;
Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds = RulesProfiles[idx].SubtitleMaximumDisplayMilliseconds;
Configuration.Settings.General.MinimumMillisecondsBetweenLines = RulesProfiles[idx].MinimumMillisecondsBetweenLines;
Configuration.Settings.General.MaxNumberOfLines = RulesProfiles[idx].MaxNumberOfLines;
Configuration.Settings.General.SubtitleMaximumWordsPerMinute = (double)RulesProfiles[idx].SubtitleMaximumWordsPerMinute;
Configuration.Settings.General.CharactersPerSecondsIgnoreWhiteSpace = !RulesProfiles[idx].CpsIncludesSpace;
Configuration.Settings.General.MergeLinesShorterThan = RulesProfiles[idx].MergeLinesShorterThan;
DialogResult = DialogResult.OK;
}
private void buttonCancel_Click(object sender, System.EventArgs e)
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
@ -109,5 +110,26 @@ namespace Nikse.SubtitleEdit.Forms
buttonOK_Click(sender, e);
}
}
private void listViewProfiles_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
buttonOK_Click(sender, e);
}
}
private void ProfileChoose_Shown(object sender, EventArgs e)
{
if (listViewProfiles.SelectedIndices.Count == 0)
{
return;
}
listViewProfiles.Focus();
var idx = listViewProfiles.SelectedIndices[0];
listViewProfiles.Items[idx].Selected = true;
listViewProfiles.Items[idx].Focused = true;
}
}
}