NotepadPPGateway.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // NPP plugin platform for .Net v0.94.00 by Kasper B. Graversen etc.
  2. using System.Text;
  3. namespace NppChnConvPlugin.NppPluginInfrastructure
  4. {
  5. public interface INotepadPPGateway
  6. {
  7. void FileNew();
  8. string GetCurrentFilePath();
  9. unsafe string GetFilePath(int bufferId);
  10. void SetCurrentLanguage(LangType language);
  11. /// <summary>
  12. /// Returns the response from NPPM_GETFILENAME
  13. /// </summary>
  14. /// <returns></returns>
  15. string GetCurrentFileName();
  16. /// <summary>
  17. /// Returns the response from NPPM_GETCURRENTDIRECTORY
  18. /// </summary>
  19. /// <returns></returns>
  20. string GetCurrentDirectory();
  21. }
  22. /// <summary>
  23. /// This class holds helpers for sending messages defined in the Msgs_h.cs file. It is at the moment
  24. /// incomplete. Please help fill in the blanks.
  25. /// </summary>
  26. public class NotepadPPGateway : INotepadPPGateway
  27. {
  28. private const int Unused = 0;
  29. public void FileNew()
  30. {
  31. Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_MENUCOMMAND, Unused, NppMenuCmd.IDM_FILE_NEW);
  32. }
  33. /// <summary>
  34. /// Returns the response from NPPM_GETCURRENTDIRECTORY
  35. /// </summary>
  36. /// <returns></returns>
  37. public string GetCurrentDirectory()
  38. {
  39. StringBuilder path = new StringBuilder(Win32.MAX_PATH);
  40. Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETCURRENTDIRECTORY, 0, path);
  41. return path.ToString();
  42. }
  43. /// <summary>
  44. /// Returns the response from NPPM_GETFILENAME
  45. /// </summary>
  46. /// <returns></returns>
  47. public string GetCurrentFileName()
  48. {
  49. StringBuilder fileName = new StringBuilder(Win32.MAX_PATH);
  50. Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETFILENAME, 0, fileName);
  51. return fileName.ToString();
  52. }
  53. /// <summary>
  54. /// Gets the path of the current document.
  55. /// </summary>
  56. public string GetCurrentFilePath()
  57. {
  58. var path = new StringBuilder(2000);
  59. Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_GETFULLCURRENTPATH, 0, path);
  60. return path.ToString();
  61. }
  62. /// <summary>
  63. /// Gets the path of the current document.
  64. /// </summary>
  65. public unsafe string GetFilePath(int bufferId)
  66. {
  67. var path = new StringBuilder(2000);
  68. Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_GETFULLPATHFROMBUFFERID, bufferId, path);
  69. return path.ToString();
  70. }
  71. public void SetCurrentLanguage(LangType language)
  72. {
  73. Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_SETCURRENTLANGTYPE, Unused, (int) language);
  74. }
  75. }
  76. /// <summary>
  77. /// This class holds helpers for sending messages defined in the Resource_h.cs file. It is at the moment
  78. /// incomplete. Please help fill in the blanks.
  79. /// </summary>
  80. class NppResource
  81. {
  82. private const int Unused = 0;
  83. public void ClearIndicator()
  84. {
  85. Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) Resource.NPPM_INTERNAL_CLEARINDICATOR, Unused, Unused);
  86. }
  87. }
  88. }