ITsiFilePathItem.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using BulePointLilac.Methods;
  2. using System.IO;
  3. using System.Windows.Forms;
  4. using static BulePointLilac.Methods.ObjectPath;
  5. namespace ContextMenuManager.Controls.Interfaces
  6. {
  7. interface ITsiFilePathItem
  8. {
  9. string ItemFilePath { get; }
  10. ContextMenuStrip ContextMenuStrip { get; set; }
  11. FileLocationMenuItem TsiFileLocation { get; set; }
  12. FilePropertiesMenuItem TsiFileProperties { get; set; }
  13. }
  14. sealed class FileLocationMenuItem : ToolStripMenuItem
  15. {
  16. public FileLocationMenuItem(ITsiFilePathItem item) : base(AppString.Menu.FileLocation)
  17. {
  18. bool FileExists() => File.Exists(item.ItemFilePath);
  19. bool DirExists() => Directory.Exists(item.ItemFilePath);
  20. item.ContextMenuStrip.Opening += (sender, e)
  21. => this.Visible = FileExists() || DirExists();
  22. this.Click += (sender, e) =>
  23. {
  24. if(FileExists()) ShowPath(item.ItemFilePath, PathType.File);
  25. else if(DirExists()) ShowPath(item.ItemFilePath, PathType.Directory);
  26. };
  27. }
  28. }
  29. sealed class FilePropertiesMenuItem : ToolStripMenuItem
  30. {
  31. public FilePropertiesMenuItem(ITsiFilePathItem item) : base(AppString.Menu.FileProperties)
  32. {
  33. item.ContextMenuStrip.Opening += (sender, e)
  34. => this.Visible = File.Exists(item.ItemFilePath) || Directory.Exists(item.ItemFilePath);
  35. this.Click += (sender, e) => PropertiesDialog.Show(item.ItemFilePath);
  36. }
  37. }
  38. }