ITsiCommandItem.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using BluePointLilac.Controls;
  2. using BluePointLilac.Methods;
  3. using System.Windows.Forms;
  4. namespace ContextMenuManager.Controls.Interfaces
  5. {
  6. interface ITsiCommandItem
  7. {
  8. string ItemCommand { get; set; }
  9. ChangeCommandMenuItem TsiChangeCommand { get; set; }
  10. }
  11. sealed class ChangeCommandMenuItem : ToolStripMenuItem
  12. {
  13. public bool CommandCanBeEmpty { get; set; }
  14. public ChangeCommandMenuItem(ITsiCommandItem item) : base(AppString.Menu.ChangeCommand)
  15. {
  16. this.Click += (sender, e) =>
  17. {
  18. string command = ChangeCommand(item.ItemCommand);
  19. if(command != null) item.ItemCommand = command;
  20. };
  21. }
  22. private string ChangeCommand(string command)
  23. {
  24. using(InputDialog dlg = new InputDialog { Text = command, Title = AppString.Menu.ChangeCommand })
  25. {
  26. if(dlg.ShowDialog() != DialogResult.OK) return null;
  27. if(!CommandCanBeEmpty && string.IsNullOrEmpty(dlg.Text))
  28. {
  29. MessageBoxEx.Show(AppString.MessageBox.CommandCannotBeEmpty);
  30. return ChangeCommand(command);
  31. }
  32. else return dlg.Text;
  33. }
  34. }
  35. }
  36. }