Skip to content

Commit

Permalink
Merge pull request #139 from sifran-github/main
Browse files Browse the repository at this point in the history
Added Scripting Examples, including structure and examples
  • Loading branch information
sifran-github authored Dec 14, 2023
2 parents 26a8499 + e9ddf97 commit dfcf5b1
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@
- [IntelliJ IDEA setup](scripting/intellij-idea-setup.md)
- [Add-ons (Development)](scripting/Add-ons_(Develop).md)
- [Security considerations](scripting/Security_considerations.md)
- [Scripting (Examples By Category)](scripting_examples/_scripting_examples.md)
- [Node Attributes](scripting_examples/_category_node.md)
- [Text, Details (TBD)]()
- [Note (TBD)]()
- [Fonts (TBD)]()
- [Links](scripting_examples/links.md)
- [Icons](scripting_examples/icons.md)
- [Attributes (TBD)]()
- [Cloud (TBD)]()
- [Shape, Border (TBD)]()
- [Edges (TBD)]()
- [Layout (TBD)]()
- [Style (TBD)]()
- [Mind Map](scripting_examples/_category_map.md)
- [Mindmap Traversal](scripting_examples/traverse.md)
- [Selection](scripting_examples/selection.md)
- [Alias](scripting_examples/alias.md)
- [Filters (TBD)]()
- [Others](scripting_examples/_category_others.md)
- [Clipboard](scripting_examples/clipboard.md)
- [GUI](scripting_examples/gui.md)
- [Coding](coding/Git_howto.md)
- [Git howto](coding/Git_howto.md)
- [How to build Freeplane](coding/How_to_build_Freeplane.md)
Expand Down
5 changes: 5 additions & 0 deletions src/docs/scripting_examples/_category_map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Scripts about the Entire Mind Map

Everything that has to do with multiple nodes.

Navigating nodes, selecting nodes etc'.
3 changes: 3 additions & 0 deletions src/docs/scripting_examples/_category_node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Scripts about Node Attributes

Every attribute that is related to one specific node.
5 changes: 5 additions & 0 deletions src/docs/scripting_examples/_category_others.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Others

Miscellaneous examples. Not related to one node, or the mind map.

For example: calling external APIs, external libraries.
4 changes: 4 additions & 0 deletions src/docs/scripting_examples/_scripting_examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Scripting Examples

Scripting Examples by categories.

7 changes: 7 additions & 0 deletions src/docs/scripting_examples/alias.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Alias
First, set an alias for a node. right click, choose "Set node alias" and type "alias1".
Then, in another node, you can reference the first node using the following code:
```groovy
node.details=node.at("/**/~alias1").text
```

12 changes: 12 additions & 0 deletions src/docs/scripting_examples/clipboard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Copy link to clipboard
```groovy
// @ExecutionModes({ON_SINGLE_NODE})
def link = node.link.text
if (link) {
textUtils.copyToClipboard(node.link.text)
c.statusInfo = "Hyperlink Copied."
} else {
c.statusInfo = "no link in ${node.text}"
}
```

17 changes: 17 additions & 0 deletions src/docs/scripting_examples/gui.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# GUI
Using simple GUI to display information on the screen, integrated into freeplane.

### Simple YES/NO Question

```groovy
import org.freeplane.core.ui.components.UITools;
def result = UITools.showConfirmDialog(node.delegate, "Simple Yes/No Question", "window title",0)
c.statusInfo=result
```

### Simple Msgbox
```groovy
script1 import org.freeplane.core.ui.components.UITools;
UITools.informationMessage('Simple Messagebox')
```
13 changes: 13 additions & 0 deletions src/docs/scripting_examples/icons.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Add custom checkbox (switch between completed and not completed), with icons.
```groovy
// @ExecutionModes({ON_SELECTED_NODE})
if (node.icons.icons.contains("unchecked")) {
node.icons.remove("unchecked")
node.icons.add("button_ok")
} else {
node.icons.remove("button_ok")
node.icons.add("unchecked")
}
```


2 changes: 2 additions & 0 deletions src/docs/scripting_examples/links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# LINKS - TBD
content will be taken from here: [setting-links](../scripting/Scripting.html#setting-links)
10 changes: 10 additions & 0 deletions src/docs/scripting_examples/selection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Select children nodes

This scripts select the children nodes of the selected nodes.

```groovy
// @ExecutionModes({ON_SINGLE_NODE})
def toSelect = c.selecteds.collect{ node -> node.find {it.parent == node} }.sum()
c.selectMultipleNodes(toSelect)
```

29 changes: 29 additions & 0 deletions src/docs/scripting_examples/traverse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Created+ Modified HTML Table
Create an HTML Table of "created" and "modified" dates of all subnodes, from the selected node. Save the result to current node's note.

```groovy
def date_format(date) {
return date ? date.format('yyyy-MM-dd HH:mm:ss'): 'N/A'
}
def node_to_html_table(starting_node) {
def table = "<html><body><table><tr><th>Node</th><th>Created</th><th>Modified</th></tr>"
starting_node.findAll().each { n -> table += "<tr><td>${n.text}</td><td>${date_format(n.getCreatedAt())}</td><td>${date_format(n.getLastModifiedAt())}</td></tr>" }
table += "</table></body></html>"
return table
}
node.note = node_to_html_table(node)
```

## Count number of nodes with the word "ok" in the entire map.
```groovy
def matches = c.find{ it.text.contains('ok') }
c.statusInfo = matches.size() + " nodes contain 'ok'"
```

## Create a child node with all icons of all subnodes
```groovy
def usedIcons = node.findAll()*.icons*.icons.flatten().unique().sort()
node.createChild("<-- all icons'").icons.addAll(usedIcons)
```

0 comments on commit dfcf5b1

Please sign in to comment.