ManagedExportsBridge.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Kbg.NppPluginNET.PluginInfrastructure;
  2. using System;
  3. using System.Runtime.InteropServices;
  4. namespace NppMarkdownRenderer
  5. {
  6. public class ManagedExportsBridge
  7. {
  8. private static IntPtr PtrPluginName = IntPtr.Zero;
  9. public static bool IsUnicode()
  10. {
  11. return true;
  12. }
  13. public static void SetInfo(NppData notepadPlusData)
  14. {
  15. PluginBase.nppData = notepadPlusData;
  16. AnyCpuBridgeMain.CommandMenuInit();
  17. }
  18. public static IntPtr GetFuncsArray(ref int nbF)
  19. {
  20. nbF = PluginBase._funcItems.Items.Count;
  21. return PluginBase._funcItems.NativePointer;
  22. }
  23. public static uint MessageProc(uint message, IntPtr wParam, IntPtr lParam)
  24. {
  25. return 1;
  26. }
  27. public static IntPtr GetName()
  28. {
  29. if (PtrPluginName == IntPtr.Zero)
  30. PtrPluginName = Marshal.StringToHGlobalUni(AnyCpuBridgeMain.PluginName);
  31. return PtrPluginName;
  32. }
  33. public static void BeNotified(IntPtr notifyCode)
  34. {
  35. var notification = (ScNotification)Marshal.PtrToStructure(notifyCode, typeof(ScNotification));
  36. if (notification.Header.Code == (uint)NppMsg.NPPN_TBMODIFICATION)
  37. {
  38. PluginBase._funcItems.RefreshItems();
  39. AnyCpuBridgeMain.SetToolBarIcon();
  40. }
  41. else if (notification.Header.Code == (uint)NppMsg.NPPN_SHUTDOWN)
  42. {
  43. AnyCpuBridgeMain.PluginCleanUp();
  44. Marshal.FreeHGlobal(PtrPluginName);
  45. }
  46. else
  47. {
  48. AnyCpuBridgeMain.OnNotification(notification);
  49. }
  50. }
  51. }
  52. }