Search in sources :

Example 1 with ScriptMetaData

use of org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData in project freeplane by freeplane.

the class ScriptingConfigurationTest method testAnalyseScriptContentRemoveDuplicates.

@Test
public void testAnalyseScriptContentRemoveDuplicates() {
    String content = "// some comment" + "\n//   @ExecutionModes (\t{\n  ExecutionMode.ON_selECTED_NODE_recursively,\n \tON_SelECTED_NODE_RECURSIVELY } )";
    ScriptMetaData metaData = new ScriptingConfiguration().analyseScriptContent(content, scriptName);
    assertEquals("duplicated modes should not matter", 1, metaData.getExecutionModes().size());
    assertTrue("ON_SELECTED_NODE_RECURSIVELY was set", metaData.getExecutionModes().contains(ExecutionMode.ON_SELECTED_NODE_RECURSIVELY));
    assertTrue("CacheScriptContent=false is the default", !metaData.cacheContent());
}
Also used : ScriptMetaData(org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData) Test(org.junit.Test)

Example 2 with ScriptMetaData

use of org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData in project freeplane by freeplane.

the class ScriptingConfigurationTest method testAnalyseScriptContentWithTitleKey.

@Test
public void testAnalyseScriptContentWithTitleKey() {
    // it's case insensitive
    // it's tolerant on white space
    String content = // 
    "// some comment" + // 
    "\n//@ExecutionModes (\t{\n  ExecutionMode.ON_selECTED_NODE=\"/menu_bar/help[icon_button_ok]\"" + // 
    ",\n \tON_SelECTED_NODE_RECURSIVELY = \"/menu_bar/help[Test_Script]\" } )" + "\n def test() {}\n";
    ScriptMetaData metaData = new ScriptingConfiguration().analyseScriptContent(content, scriptName);
    assertEquals("expected only modes set in the script", 2, metaData.getExecutionModes().size());
    assertTrue("ON_SELECTED_NODE was set", metaData.getExecutionModes().contains(ExecutionMode.ON_SELECTED_NODE));
    assertEquals("wrong menu location", "/menu_bar/help", metaData.getMenuLocation(ExecutionMode.ON_SELECTED_NODE));
    assertEquals("wrong title key", "icon_button_ok", metaData.getTitleKey(ExecutionMode.ON_SELECTED_NODE));
    assertTrue("ON_SELECTED_NODE_RECURSIVELY was set", metaData.getExecutionModes().contains(ExecutionMode.ON_SELECTED_NODE_RECURSIVELY));
    assertEquals("wrong menu location", "/menu_bar/help", metaData.getMenuLocation(ExecutionMode.ON_SELECTED_NODE_RECURSIVELY));
    assertEquals("wrong title key", "Test_Script", metaData.getTitleKey(ExecutionMode.ON_SELECTED_NODE_RECURSIVELY));
}
Also used : ScriptMetaData(org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData) Test(org.junit.Test)

Example 3 with ScriptMetaData

use of org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData in project freeplane by freeplane.

the class ScriptingMenuEntryVisitor method createEntry.

private Entry createEntry(final String scriptName, final String scriptPath, ExecutionMode executionMode) {
    final ScriptMetaData metaData = configuration.getMenuTitleToMetaDataMap().get(scriptName);
    final String title = scriptNameToMenuItemTitle(scriptName);
    return createEntry(createAction(scriptName, scriptPath, executionMode, metaData, title));
}
Also used : ScriptMetaData(org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData)

Example 4 with ScriptMetaData

use of org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData in project freeplane by freeplane.

the class ScriptingMenuEntryVisitor method visit.

/**
 * builds menu entries for scripts without a special menu location.
 */
@Override
public void visit(Entry target) {
    initEntryNavigator(target);
    for (final Map.Entry<String, String> entry : configuration.getMenuTitleToPathMap().entrySet()) {
        String scriptName = entry.getKey();
        final ScriptMetaData metaData = configuration.getMenuTitleToMetaDataMap().get(scriptName);
        if (!metaData.hasMenuLocation()) {
            for (final ExecutionMode executionMode : metaData.getExecutionModes()) {
                target.addChild(createEntry(scriptName, entry.getValue(), executionMode));
            }
        }
    // else: see buildPhaseFinished
    }
    if (target.isLeaf()) {
        target.addChild(createNoScriptsAvailableAction());
    }
}
Also used : ScriptMetaData(org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData) ExecutionMode(org.freeplane.plugin.script.ExecuteScriptAction.ExecutionMode) Map(java.util.Map)

Example 5 with ScriptMetaData

use of org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData in project freeplane by freeplane.

the class ScriptingConfigurationTest method testParseExecutionModes.

@Test
public void testParseExecutionModes() throws Exception {
    ScriptMetaData metaData = new ScriptMetaData("test");
    ScriptingConfiguration.setExecutionModes("@ExecutionModes({on_selected_node=\"/menu/bla/blupp\",on_single_node=\"/menu/hi/ho\"})", metaData);
    ScriptingConfiguration.setExecutionModes("@ExecutionModes({on_selected_node=\"/menu/bla/blupp\"on_single_node=\"/menu/hi/ho\"})", metaData);
    ScriptingConfiguration.setExecutionModes("@ExecutionModes({on_single_node=\"/menu/hi/ho\"})", metaData);
    ScriptingConfiguration.setExecutionModes("@ExecutionModes({on_single_node})", metaData);
    ScriptingConfiguration.setExecutionModes("@ExecutionModes({\"/menu/hi/ho\"})", metaData);
    ScriptingConfiguration.setExecutionModes("@ExecutionModes({})", metaData);
}
Also used : ScriptMetaData(org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData) Test(org.junit.Test)

Aggregations

ScriptMetaData (org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData)9 Test (org.junit.Test)5 ExecutionMode (org.freeplane.plugin.script.ExecuteScriptAction.ExecutionMode)2 Map (java.util.Map)1 AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)1 JCommandMenuButton (org.pushingpixels.flamingo.api.common.JCommandMenuButton)1 ImageWrapperResizableIcon (org.pushingpixels.flamingo.api.common.icon.ImageWrapperResizableIcon)1 ResizableIcon (org.pushingpixels.flamingo.api.common.icon.ResizableIcon)1