Merge pull request #8251 from ivandrofly/feature/listview-operators

Refactor list view item checking actions
This commit is contained in:
Nikolaj Olsson 2024-04-27 19:09:30 +02:00 committed by GitHub
commit bb9b53a995
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 70 additions and 181 deletions

View File

@ -338,21 +338,9 @@ namespace Nikse.SubtitleEdit.Forms
} }
} }
private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e) private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e) => listViewFixes.CheckAll();
{
foreach (ListViewItem item in listViewFixes.Items)
{
item.Checked = true;
}
}
private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e) private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e) => listViewFixes.InvertCheck();
{
foreach (ListViewItem item in listViewFixes.Items)
{
item.Checked = !item.Checked;
}
}
private void checkBoxCheckShotChanges_CheckedChanged(object sender, EventArgs e) private void checkBoxCheckShotChanges_CheckedChanged(object sender, EventArgs e)
{ {

View File

@ -125,20 +125,8 @@ namespace Nikse.SubtitleEdit.Forms.Assa
} }
} }
private void ToolStripMenuItemSelectAll_Click(object sender, EventArgs e) private void ToolStripMenuItemSelectAll_Click(object sender, EventArgs e) => listViewCategories.CheckAll();
{
foreach (ListViewItem item in listViewCategories.Items)
{
item.Checked = true;
}
}
private void ToolStripMenuItemInverseSelection_Click(object sender, EventArgs e) private void ToolStripMenuItemInverseSelection_Click(object sender, EventArgs e) => listViewCategories.InvertCheck();
{
foreach (ListViewItem item in listViewCategories.Items)
{
item.Checked = !item.Checked;
}
}
} }
} }

View File

@ -251,18 +251,12 @@ namespace Nikse.SubtitleEdit.Forms
private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e) private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.CheckAll();
{
item.Checked = true;
}
} }
private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e) private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
private void AutoBreakUnbreakLines_FormClosing(object sender, FormClosingEventArgs e) private void AutoBreakUnbreakLines_FormClosing(object sender, FormClosingEventArgs e)

View File

@ -3977,18 +3977,12 @@ namespace Nikse.SubtitleEdit.Forms
private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e) private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewConvertOptions.Items) listViewConvertOptions.CheckAll();
{
item.Checked = true;
}
} }
private void inverseSelectionToolStripMenuItem_Click(object sender, EventArgs e) private void inverseSelectionToolStripMenuItem_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewConvertOptions.Items) listViewConvertOptions.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
private void listViewInputFiles_ColumnClick(object sender, ColumnClickEventArgs e) private void listViewInputFiles_ColumnClick(object sender, ColumnClickEventArgs e)

View File

@ -335,18 +335,12 @@ namespace Nikse.SubtitleEdit.Forms
private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e) private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.CheckAll();
{
item.Checked = true;
}
} }
private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e) private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
private void toolStripMenuItem1SelectAll_Click(object sender, EventArgs e) private void toolStripMenuItem1SelectAll_Click(object sender, EventArgs e)

View File

@ -1145,21 +1145,9 @@ namespace Nikse.SubtitleEdit.Forms
listViewFixes.Sort(); listViewFixes.Sort();
} }
private void ButtonSelectAllClick(object sender, EventArgs e) private void ButtonSelectAllClick(object sender, EventArgs e) => listView1.CheckAll();
{
foreach (ListViewItem item in listView1.Items)
{
item.Checked = true;
}
}
private void ButtonInverseSelectionClick(object sender, EventArgs e) private void ButtonInverseSelectionClick(object sender, EventArgs e) => listView1.InvertCheck();
{
foreach (ListViewItem item in listView1.Items)
{
item.Checked = !item.Checked;
}
}
private void ListViewFixesSelectedIndexChanged(object sender, EventArgs e) private void ListViewFixesSelectedIndexChanged(object sender, EventArgs e)
{ {
@ -1370,18 +1358,12 @@ namespace Nikse.SubtitleEdit.Forms
private void ButtonFixesSelectAllClick(object sender, EventArgs e) private void ButtonFixesSelectAllClick(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.CheckAll();
{
item.Checked = true;
}
} }
private void ButtonFixesInverseClick(object sender, EventArgs e) private void ButtonFixesInverseClick(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
private void ButtonFixesApplyClick(object sender, EventArgs e) private void ButtonFixesApplyClick(object sender, EventArgs e)
@ -1948,18 +1930,12 @@ namespace Nikse.SubtitleEdit.Forms
private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e) private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.CheckAll();
{
item.Checked = true;
}
} }
private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e) private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
private void setCurrentFixesAsDefaultToolStripMenuItem_Click(object sender, EventArgs e) private void setCurrentFixesAsDefaultToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -346,18 +346,12 @@ namespace Nikse.SubtitleEdit.Forms
private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e) private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.CheckAll();
{
item.Checked = true;
}
} }
private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e) private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
} }
} }

View File

@ -297,18 +297,12 @@ namespace Nikse.SubtitleEdit.Forms
private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e) private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.CheckAll();
{
item.Checked = true;
}
} }
private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e) private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
private void checkBoxMakeDialog_CheckedChanged(object sender, EventArgs e) private void checkBoxMakeDialog_CheckedChanged(object sender, EventArgs e)

View File

@ -691,18 +691,12 @@ namespace Nikse.SubtitleEdit.Forms
private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e) private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.CheckAll();
{
item.Checked = true;
}
} }
private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e) private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
private void ModifySelection_Resize(object sender, EventArgs e) private void ModifySelection_Resize(object sender, EventArgs e)

View File

@ -570,18 +570,12 @@ namespace Nikse.SubtitleEdit.Forms
private void buttonReplacesSelectAll_Click(object sender, EventArgs e) private void buttonReplacesSelectAll_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.CheckAll();
{
item.Checked = true;
}
} }
private void buttonReplacesInverseSelection_Click(object sender, EventArgs e) private void buttonReplacesInverseSelection_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
private void contextMenuStrip1_Opening(object sender, System.ComponentModel.CancelEventArgs e) private void contextMenuStrip1_Opening(object sender, System.ComponentModel.CancelEventArgs e)
@ -1446,18 +1440,12 @@ namespace Nikse.SubtitleEdit.Forms
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e) private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewRules.Items) listViewRules.CheckAll();
{
item.Checked = true;
}
} }
private void inverseSelectionToolStripMenuItem_Click(object sender, EventArgs e) private void inverseSelectionToolStripMenuItem_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewRules.Items) listViewRules.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
private void ContextMenuStripListViewFixesOpening(object sender, System.ComponentModel.CancelEventArgs e) private void ContextMenuStripListViewFixesOpening(object sender, System.ComponentModel.CancelEventArgs e)

View File

@ -136,18 +136,12 @@ namespace Nikse.SubtitleEdit.Forms
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e) private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewExportStyles.Items) listViewExportStyles.CheckAll();
{
item.Checked = true;
}
} }
private void inverseSelectionToolStripMenuItem_Click(object sender, EventArgs e) private void inverseSelectionToolStripMenuItem_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewExportStyles.Items) listViewExportStyles.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
} }
} }

View File

@ -328,12 +328,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void SelectAll_Click(object sender, EventArgs e) private void SelectAll_Click(object sender, EventArgs e)
{ {
listViewFonts.BeginUpdate(); listViewFonts.CheckAll();
foreach (ListViewItem fontItem in listViewFonts.Items)
{
fontItem.Checked = true;
}
listViewFonts.EndUpdate();
} }
public void InitializeDetectFont(BinaryOcrBitmap bob, string text) public void InitializeDetectFont(BinaryOcrBitmap bob, string text)

View File

@ -143,11 +143,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void buttonFixesSelectAll_Click(object sender, EventArgs e) private void buttonFixesSelectAll_Click(object sender, EventArgs e)
{ {
listView1.ItemChecked -= listView1_ItemChecked; listView1.ItemChecked -= listView1_ItemChecked;
listView1.CheckAll();
foreach (ListViewItem item in listView1.Items)
{
item.Checked = true;
}
foreach (ListViewData d in _data) foreach (ListViewData d in _data)
{ {

View File

@ -76,18 +76,12 @@ namespace Nikse.SubtitleEdit.Forms.Options
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e) private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewExportStyles.Items) listViewExportStyles.CheckAll();
{
item.Checked = true;
}
} }
private void inverseSelectionToolStripMenuItem_Click(object sender, EventArgs e) private void inverseSelectionToolStripMenuItem_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewExportStyles.Items) listViewExportStyles.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
} }
} }

View File

@ -718,10 +718,7 @@ namespace Nikse.SubtitleEdit.Forms
private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e) private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e)
{ {
listViewFixes.ItemChecked -= listViewFixes_ItemChecked; listViewFixes.ItemChecked -= listViewFixes_ItemChecked;
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.CheckAll();
{
item.Checked = true;
}
listViewFixes.ItemChecked += listViewFixes_ItemChecked; listViewFixes.ItemChecked += listViewFixes_ItemChecked;
GeneratePreview(false); GeneratePreview(false);
} }
@ -729,10 +726,7 @@ namespace Nikse.SubtitleEdit.Forms
private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e) private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e)
{ {
listViewFixes.ItemChecked -= listViewFixes_ItemChecked; listViewFixes.ItemChecked -= listViewFixes_ItemChecked;
foreach (ListViewItem item in listViewFixes.Items) listViewFixes.InvertCheck();
{
item.Checked = !item.Checked;
}
listViewFixes.ItemChecked += listViewFixes_ItemChecked; listViewFixes.ItemChecked += listViewFixes_ItemChecked;
GeneratePreview(false); GeneratePreview(false);
} }

View File

@ -186,18 +186,12 @@ namespace Nikse.SubtitleEdit.Forms.Styles
private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e) private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewExportStyles.Items) listViewExportStyles.CheckAll();
{
item.Checked = true;
}
} }
private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e) private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewExportStyles.Items) listViewExportStyles.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
} }
} }

View File

@ -145,18 +145,12 @@ namespace Nikse.SubtitleEdit.Forms.VTT
private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e) private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewExportStyles.Items) listViewExportStyles.CheckAll();
{
item.Checked = true;
}
} }
private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e) private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewExportStyles.Items) listViewExportStyles.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
} }
} }

View File

@ -57,18 +57,12 @@ namespace Nikse.SubtitleEdit.Forms.VTT
private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e) private void toolStripMenuItemSelectAll_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewExportStyles.Items) listViewExportStyles.CheckAll();
{
item.Checked = true;
}
} }
private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e) private void toolStripMenuItemInverseSelection_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem item in listViewExportStyles.Items) listViewExportStyles.InvertCheck();
{
item.Checked = !item.Checked;
}
} }
private void listViewExportStyles_SelectedIndexChanged(object sender, EventArgs e) private void listViewExportStyles_SelectedIndexChanged(object sender, EventArgs e)

View File

@ -1121,6 +1121,36 @@ namespace Nikse.SubtitleEdit.Logic
public static void AutoSizeLastColumn(this ListView listView) => public static void AutoSizeLastColumn(this ListView listView) =>
listView.Columns[listView.Columns.Count - 1].Width = -2; listView.Columns[listView.Columns.Count - 1].Width = -2;
public static void CheckAll(this ListView lv)
{
lv.BeginUpdate();
foreach (ListViewItem item in lv.Items)
{
item.Checked = true;
}
lv.EndUpdate();
}
public static void InvertCheck(this ListView lv)
{
lv.BeginUpdate();
foreach (ListViewItem item in lv.Items)
{
item.Checked = !item.Checked;
}
lv.EndUpdate();
}
public static void UncheckAll(this ListView lv)
{
lv.BeginUpdate();
foreach (ListViewItem item in lv.Items)
{
item.Checked = false;
}
lv.EndUpdate();
}
public static void SelectAll(this ListView lv) public static void SelectAll(this ListView lv)
{ {
lv.BeginUpdate(); lv.BeginUpdate();