Search in sources :

Example 6 with ScriptMetaData

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

the class ScriptingConfigurationTest method testAnalyseScriptContentForFormula.

@Test
public void testAnalyseScriptContentForFormula() {
    String content = // 
    "=\"blabla\"" + "\n//   @CacheScriptContent ( true\t ) ";
    ScriptMetaData metaData = new ScriptingConfiguration().analyseScriptContent(content, scriptName);
    assertEquals("single node mode should be removed for '=' scripts", 2, metaData.getExecutionModes().size());
    assertTrue("ON_SELECTED_NODE shouldn't been removed", metaData.getExecutionModes().contains(ExecutionMode.ON_SELECTED_NODE));
    assertTrue("ON_SELECTED_NODE_RECURSIVELY shouldn't been removed", metaData.getExecutionModes().contains(ExecutionMode.ON_SELECTED_NODE_RECURSIVELY));
    assertTrue("CacheScriptContent was set to true", metaData.cacheContent());
// assert that duplicate entries do no harm
}
Also used : ScriptMetaData(org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData) Test(org.junit.Test)

Example 7 with ScriptMetaData

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

the class ScriptingConfigurationTest method testAnalyseScriptContent1.

@Test
public void testAnalyseScriptContent1() {
    // it's case insensitive
    // it's tolerant on white space
    String content = // 
    "// some comment" + // 
    "//@ExecutionModes (\t{  ExecutionMode.ON_selECTED_NODE" + // 
    ", \tON_SelECTED_NODE_RECURSIVELY = \"/menu_bar/help\" } )" + // 
    "//  @CacheScriptContent ( true\t ) " + " def test() {}";
    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));
    assertTrue("ON_SELECTED_NODE_RECURSIVELY was set", metaData.getExecutionModes().contains(ExecutionMode.ON_SELECTED_NODE_RECURSIVELY));
    assertEquals("menu location for ON_SELECTED_NODE_RECURSIVELY was set explicitely", "/menu_bar/help", metaData.getMenuLocation(ExecutionMode.ON_SELECTED_NODE_RECURSIVELY));
    assertTrue("CacheScriptContent was set to true", metaData.cacheContent());
}
Also used : ScriptMetaData(org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData) Test(org.junit.Test)

Example 8 with ScriptMetaData

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

the class ScriptingMenuContributor method registerScript.

private void registerScript(final String scriptName, final String scriptPath) {
    final ScriptMetaData metaData = configuration.getMenuTitleToMetaDataMap().get(scriptName);
    for (final ExecutionMode executionMode : metaData.getExecutionModes()) {
        final String location = getLocation(scriptName, metaData, executionMode);
        addSubMenu(parentLocation(location), location, getMenuTitle(metaData, executionMode));
        addMenuItem(location, scriptName, scriptPath, executionMode, metaData);
    }
}
Also used : ScriptMetaData(org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData) ExecutionMode(org.freeplane.plugin.script.ExecuteScriptAction.ExecutionMode)

Example 9 with ScriptMetaData

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

the class ScriptingRibbonsContributor method createScriptButton.

private JCommandMenuButton createScriptButton(final String scriptName, final String scriptPath, ExecutionMode executionMode) {
    final ScriptMetaData metaData = configuration.getMenuTitleToMetaDataMap().get(scriptName);
    final String title = scriptNameToMenuItemTitle(scriptName);
    AFreeplaneAction action = new ExecuteScriptAction(scriptName, title, scriptPath, executionMode, metaData.cacheContent(), metaData.getPermissions());
    ResizableIcon icon = ActionUtils.getActionIcon(action);
    final JCommandMenuButton scriptEntry = new JCommandMenuButton(title, icon);
    scriptEntry.setActionRichTooltip(createRichTooltip(title, metaData));
    scriptEntry.addActionListener(action);
    scriptEntry.setFocusable(false);
    scriptEntry.setEnabled(metaData.getExecutionModes().contains(executionMode));
    return scriptEntry;
}
Also used : JCommandMenuButton(org.pushingpixels.flamingo.api.common.JCommandMenuButton) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) ScriptMetaData(org.freeplane.plugin.script.ScriptingConfiguration.ScriptMetaData) ImageWrapperResizableIcon(org.pushingpixels.flamingo.api.common.icon.ImageWrapperResizableIcon) ResizableIcon(org.pushingpixels.flamingo.api.common.icon.ResizableIcon)

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