/plugins/NetRexxScript/tags/0.1.2a/src/NetRexxScriptMacroHandler.nrx

# · Unknown · 91 lines · 65 code · 26 blank · 0 comment · 0 complexity · 534d6000c3656852e6fecea53bd23d77 MD5 · raw file

  1. /*
  2. * NetRexxScriptMacroHandler.nrx - NetRexx jEdit Scripting Plugin Macro Handler
  3. * Copyright (C) 2009 Kermit Kiser
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. Version 0.1.2 (Nov. 19, 2009)
  19. * display error and return if plugin inactive
  20. Version 0.0.3 (Oct. 21, 2009)
  21. * change to call new "runmacro" entry point
  22. Version 0.0.2 (Sept. 2009)
  23. * added instruction to remove ".nrx" from macro labels in menu
  24. Version 0.0.1 (Sept. 2009)
  25. * First version worked on first try!
  26. */
  27. import org.gjt.sp.jedit
  28. class NetRexxScriptMacroHandler extends Macros.Handler
  29. method NetRexxScriptMacroHandler
  30. super("netrexx")
  31. method createMacro(macroName=String,path=String) returns Macros.Macro
  32. labelr=Rexx Macros.Macro.macroNameToLabel(macroName)
  33. label=String labelr.delstr(labelr.lastpos('.'))
  34. return Macros.Macro(this, macroName, label, path)
  35. method runMacro(view=View, macro=Macros.Macro)
  36. if jEdit.getPlugin("NetRexxScriptPlugin")=null then do
  37. Macros.error(view,"The NetRexx Script Plugin is not active.")
  38. return
  39. end
  40. -- find the 'runmacro' method; it takes a String as its argument
  41. ns=EditPlugin jEdit.getPlugin("NetRexxScriptPlugin")
  42. classes=Class[1]
  43. classes[0]=macro.getPath.getClass
  44. do
  45. runMethod=ns.getClass.getMethod('runmacro', classes)
  46. if runMethod=null then do
  47. say "NetRexx macro handler could not find run method"
  48. Macros.error(view,"The runmacro method could not be located.")
  49. return
  50. end
  51. catch e=Exception
  52. say e
  53. return
  54. end
  55. values=Object[1]
  56. values[0]=macro.getPath
  57. do
  58. runMethod.invoke(ns, values)
  59. catch error=Exception
  60. say "runmacro error="error
  61. say "cause="error.getCause
  62. -- error.getCause.printStackTrace
  63. end
  64. -- ns=NetRexxScriptPlugin jEdit.getPlugin("NetRexxScriptPlugin")
  65. -- ns.runmacro(macro.getPath)