NppPluginNETBase.cs 2.1 KB

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