NppPluginNETBase.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // NPP plugin platform for .Net v0.94.00 by Kasper B. Graversen etc.
  2. using System;
  3. namespace NppChnConvPlugin.NppPluginInfrastructure
  4. {
  5. public class PluginBase
  6. {
  7. public static NppData nppData;
  8. public static FuncItems _funcItems = new FuncItems();
  9. public static void SetCommand(int index, string commandName, NppFuncItemDelegate functionPointer)
  10. {
  11. SetCommand(index, commandName, functionPointer, new ShortcutKey(), false);
  12. }
  13. public static void SetCommand(int index, string commandName, NppFuncItemDelegate functionPointer, ShortcutKey shortcut)
  14. {
  15. SetCommand(index, commandName, functionPointer, shortcut, false);
  16. }
  17. public static void SetCommand(int index, string commandName, NppFuncItemDelegate functionPointer, bool checkOnInit)
  18. {
  19. SetCommand(index, commandName, functionPointer, new ShortcutKey(), checkOnInit);
  20. }
  21. public static void SetCommand(int index, string commandName, NppFuncItemDelegate functionPointer, ShortcutKey shortcut, bool checkOnInit)
  22. {
  23. FuncItem funcItem = new FuncItem();
  24. funcItem._cmdID = index;
  25. funcItem._itemName = commandName;
  26. if (functionPointer != null) funcItem._pFunc = new NppFuncItemDelegate(functionPointer);
  27. if (shortcut._key != 0) funcItem._pShKey = shortcut;
  28. funcItem._init2Check = checkOnInit;
  29. _funcItems.Add(funcItem);
  30. }
  31. public static IntPtr GetCurrentScintilla()
  32. {
  33. int curScintilla;
  34. Win32.SendMessage(nppData._nppHandle, (uint)NppMsg.NPPM_GETCURRENTSCINTILLA, 0, out curScintilla);
  35. return (curScintilla == 0) ? nppData._scintillaMainHandle : nppData._scintillaSecondHandle;
  36. }
  37. private static readonly Func<IScintillaGateway> gatewayFactory = () => new ScintillaGateway(GetCurrentScintilla());
  38. public static Func<IScintillaGateway> GetGatewayFactory()
  39. {
  40. return gatewayFactory;
  41. }
  42. }
  43. }