Advertisement
ivandrofly

Subtitle Edit: Keydown handler with dictionary

Jun 4th, 2024
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1.  
  2.         private readonly IReadOnlyDictionary<Keys, Action<ListViewItem>> _keyCombination = new Dictionary<Keys, Action<ListViewItem>>()
  3.         {
  4.             { Keys.A | Keys.Control, item => { item.Checked = true; item.Selected = true; } },
  5.             { Keys.D | Keys.Control, item => { item.Checked = false; item.Selected = false; } },
  6.             { Keys.I | Keys.Control | Keys.Shift, item => { item.Checked = !item.Checked; item.Selected = !item.Selected; } },
  7.         };
  8.  
  9.         private void listView1_KeyDown(object sender, KeyEventArgs e)
  10.         {
  11.             if (!_keyCombination.TryGetValue(e.KeyData, out var handler))
  12.             {
  13.                 return;
  14.             }
  15.  
  16.             foreach (ListViewItem item in listView1.Items)
  17.             {
  18.                 handler.Invoke(item);
  19.             }
  20.  
  21.             e.SuppressKeyPress = true;
  22.         }
  23.  
  24. FixCommonError.cs:private void listView1_KeyDown(object sender, KeyEventArgs e)
  25. https://github.com/SubtitleEdit/subtitleedit/blob/7008be78ab6fbe9e1c58cb6501854f555b6df35f/src/libse/Forms/FixCommonErrors/FixContinuationStyle.cs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement