ITsiTextItem.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using BulePointLilac.Controls;
  2. using BulePointLilac.Methods;
  3. using System.Windows.Forms;
  4. namespace ContextMenuManager.Controls.Interfaces
  5. {
  6. interface ITsiTextItem
  7. {
  8. string Text { get; set; }
  9. string ItemText { get; set; }
  10. ChangeTextMenuItem TsiChangeText { get; set; }
  11. }
  12. sealed class ChangeTextMenuItem : ToolStripMenuItem
  13. {
  14. public ChangeTextMenuItem(ITsiTextItem item) : base(AppString.Menu.ChangeText)
  15. {
  16. this.Click += (sender, e) =>
  17. {
  18. string name = ChangeText(item.Text);
  19. if(name != null) item.ItemText = name;
  20. };
  21. }
  22. public static string ChangeText(string text)
  23. {
  24. using(InputDialog dlg = new InputDialog { Text = text, Title = AppString.Menu.ChangeText })
  25. {
  26. if(dlg.ShowDialog() != DialogResult.OK) return null;
  27. if(dlg.Text.Length == 0)
  28. {
  29. MessageBoxEx.Show(AppString.MessageBox.TextCannotBeEmpty);
  30. return ChangeText(text);
  31. }
  32. else if(ResourceString.GetDirectString(dlg.Text).Length == 0)
  33. {
  34. MessageBoxEx.Show(AppString.MessageBox.StringParsingFailed);
  35. return ChangeText(text);
  36. }
  37. else return dlg.Text;
  38. }
  39. }
  40. }
  41. }