NotepadPPGateway.cs 3.1 KB

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