Commits

Lynn Rees committed 224a806

- inject variables correctly

Comments (0)

Files changed (3)

scripts/org/hardknots/wikd/wikdshell/WikdShell.groovy

 import javax.swing.*
 
 import org.codehaus.groovy.control.CompilerConfiguration
-import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer
+import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer as ATC
 import org.codehaus.groovy.tools.LoaderConfiguration
 import org.codehaus.groovy.tools.RootLoader
-import org.freeplane.core.resources.ResourceController
+import org.freeplane.core.resources.ResourceController as RC
+import org.freeplane.plugin.script.FreeplaneScriptBaseClass as FSBC
 import org.freeplane.plugin.script.ScriptingConfiguration
 
 /**
 
 	static String MAP_NAME
 	final static String DEFAULT_WINDOW_TITLE = 'wikdShell'
-	File currentFileChooserDir = new File(ResourceController.getResourceController().getFreeplaneUserDirectory() + '/scripts')
+	File currentFileChooserDir = new File(
+		 "${RC.getResourceController().getFreeplaneUserDirectory()}/scripts"
+	)
 
 	static def frameWikdShellDelegates = [
 		rootContainerDelegate: {
 	@Override
 	void newScript(ClassLoader parent, Binding binding) {
 		config = new CompilerConfiguration()
-		if (threadInterrupt) config.addCompilationCustomizers(new ASTTransformationCustomizer(ThreadInterrupt))
+		if (threadInterrupt)
+			config.addCompilationCustomizers(new ATC(ThreadInterrupt))
 		def lc = new LoaderConfiguration()
+		config.setScriptBaseClass(FSBC.class.getName())
 		new ScriptingConfiguration().getClasspath().each { lc.addFile(it) }
 		shell = new GroovyShell(new RootLoader(lc), binding, config)
 	}
 	boolean askToSaveFile() {
 		if (scriptFile == null || !dirty)
 			return true
-		switch (JOptionPane.showConfirmDialog(
-		frame,
-		"Save changes to ${scriptFile.name}?",
-		DEFAULT_WINDOW_TITLE,
-		JOptionPane.YES_NO_CANCEL_OPTION)) {
+		switch (
+			JOptionPane.showConfirmDialog(
+				frame,
+				"Save changes to ${scriptFile.name}?",
+				DEFAULT_WINDOW_TITLE,
+				JOptionPane.YES_NO_CANCEL_OPTION
+			)
+		) {
 			case JOptionPane.YES_OPTION:
 				return fileSave()
 			case JOptionPane.NO_OPTION:
 	def askToInterruptScript() {
 		if(!scriptRunning) return true
 		def rc = JOptionPane.showConfirmDialog(
-				frame,
-				"Script executing. Press 'OK' to attempt to interrupt it before exiting.",
-				DEFAULT_WINDOW_TITLE,
-				JOptionPane.OK_CANCEL_OPTION
+			frame,
+			"Script executing. Press 'OK' to attempt to interrupt it before exiting.",
+			DEFAULT_WINDOW_TITLE,
+			JOptionPane.OK_CANCEL_OPTION
 		)
 		if (rc == JOptionPane.OK_OPTION) {
 			doInterrupt()
 		def version = GroovySystem.getVersion()
 		def pane = swing.optionPane()
 		// work around GROOVY-1048
-		pane.setMessage("Welcome to the ${DEFAULT_WINDOW_TITLE} for evaluating Groovy scripts\nVersion ${version}")
+		pane.setMessage(
+			"Welcome to the ${DEFAULT_WINDOW_TITLE} for evaluating Groovy scripts\nVersion ${version}"
+		)
 		def dialog = pane.createDialog(frame, "About ${DEFAULT_WINDOW_TITLE}")
 		dialog.show()
 	}

scripts/wikdShell.groovy

 import org.hardknots.wikd.wikdshell.WikdShell
 
 WikdShell console = new WikdShell(getBinding())
-console.setVariable('base', FreeplaneScriptBaseClass)
 console.setVariable('map', node.map)
 console.setVariable('root', node.map.root)
 console.run(node.map.name)
 <node TEXT="path improvements" ID="ID_1215329881" CREATED="1363657356410" MODIFIED="1363657365231">
 <attribute_layout NAME_WIDTH="100" VALUE_WIDTH="100"/>
 </node>
+<node TEXT="properly inject variables" ID="ID_241233608" CREATED="1364183394496" MODIFIED="1364183410811">
+<attribute_layout NAME_WIDTH="100" VALUE_WIDTH="100"/>
+</node>
 <node TEXT="trigger garbage collection" ID="ID_1030853563" CREATED="1364079814427" MODIFIED="1364080011682">
 <attribute_layout NAME_WIDTH="100" VALUE_WIDTH="100"/>
 </node>