Skip to content

Commit 7194c91

Browse files
committed
Added command "import Tutorial-o-Matic Styles"
and some changes in template map
1 parent 7439af7 commit 7194c91

4 files changed

Lines changed: 183 additions & 6 deletions

File tree

Tutorial-o-Matic/history.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Added command: "Show tutorials from active map"
1111
* Added command: "Create new tutorial mind map"
1212
* addGroovyPane method updated
13+
* Added command "import Tutorial-o-Matic Styles"
1314

1415
## v0.0.5
1516

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import edofro.tutorialomatic.ToM as tom
2+
import edofro.pseudofreeplaneapi.UserStyles as us
3+
4+
//region: opens tutorial map
5+
6+
def sep = File.separator
7+
def userDir = c.userDirectory.path
8+
def mapFileName = "tutorial_styles_template.mm"
9+
def pathName = userDir + sep + "templates" + sep + "Tutorial-o-Matic" + sep + mapFileName
10+
def sourceMap = tom.getMapFromPath(pathName, false) //usar mapa indicado (pero oculto)
11+
12+
// return tutMap.class
13+
def targetMap = node.map
14+
us.copyUserStyles(sourceMap, targetMap)
15+
16+
//Other use case examples on how to use edofro.pseudofreeplaneapi.UserStyles.copyUserStyles
17+
/*
18+
def myString = 'ToM_goto'
19+
def myList = 'ToM_nextPage,ToM_goto,ToM_showNode'.split(',')
20+
def myClosure = {it.text.contains('u')}
21+
22+
23+
us.copyUserStyles(sourceMap, targetMap, myString)
24+
us.copyUserStyles(sourceMap, targetMap, myList)
25+
us.copyUserStyles(sourceMap, targetMap, myClosure)
26+
*/
27+
28+
29+
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package edofro.pseudofreeplaneapi
2+
3+
//region: imports
4+
5+
import org.freeplane.api.MindMap as ApiMindMap
6+
//import org.freeplane.api.Node as ProxyNode
7+
//import org.freeplane.plugin.script.proxy.Proxy.Node as ProxyNode
8+
import org.freeplane.plugin.script.proxy.NodeProxy as ProxyNode
9+
import org.freeplane.core.ui.components.UITools as ui
10+
import org.freeplane.features.map.MapModel;
11+
import org.freeplane.features.map.NodeModel;
12+
import org.freeplane.features.mode.Controller;
13+
import org.freeplane.features.styles.MapStyleModel;
14+
import org.freeplane.plugin.script.ScriptContext
15+
import org.freeplane.plugin.script.proxy.ScriptUtils
16+
17+
18+
class UserStyles {
19+
20+
//region: properties
21+
22+
//end:
23+
24+
//region: copyUserStyles
25+
26+
def static copyUserStyles(sourceMap, targetMap, boolean showMessage, groovy.lang.Closure closure){
27+
def stylesToImport = getUserDefinedStylesParentNode(sourceMap).children.findAll(closure)
28+
def styleNamesToImport = stylesToImport*.text
29+
def texto = new StringBuilder("The following styles were imported \n from map '${sourceMap.name}.mm' \n into current map '${targetMap.name}.mm':\n\n")
30+
styleNamesToImport.each{styleName ->
31+
targetMap.copyStyleFrom(sourceMap, styleName)
32+
def sourceStyleNode = getUserStyleNode(sourceMap, styleName )
33+
def targetStyleNode = getUserStyleNode(targetMap, styleName )
34+
copyIcons(sourceStyleNode, targetStyleNode)
35+
copyAttributes(sourceStyleNode, targetStyleNode)
36+
texto << " - $styleName\n"
37+
}
38+
texto << "\n\n"
39+
if(showMessage) ui.informationMessage(texto.toString())
40+
}
41+
42+
def static copyUserStyles(sourceMap, targetMap, boolean showMessage = true){
43+
copyUserStyles(sourceMap, targetMap, showMessage, {true})
44+
}
45+
46+
def static copyUserStyles(sourceMap, targetMap, groovy.lang.Closure closure){
47+
copyUserStyles(sourceMap, targetMap, true, closure)
48+
}
49+
50+
def static copyUserStyles(sourceMap, targetMap, String[] lista){
51+
copyUserStyles(sourceMap, targetMap, true, lista)
52+
}
53+
54+
def static copyUserStyles(sourceMap, targetMap, boolean showMessage, String[] lista){
55+
def closure = {it.text in lista}
56+
copyUserStyles(sourceMap, targetMap, showMessage, closure)
57+
}
58+
59+
def static copyUserStyles(sourceMap, targetMap, String texto){
60+
copyUserStyles(sourceMap, targetMap, true, texto)
61+
}
62+
63+
def static copyUserStyles(sourceMap, targetMap, boolean showMessage, String texto){
64+
def closure = {it.text == texto}
65+
copyUserStyles(sourceMap, targetMap, showMessage, closure)
66+
}
67+
68+
//end:
69+
70+
//region: copy other things from node to node
71+
72+
def static copyIcons(sourceNode, targetNode, boolean doClear = true){
73+
if(doClear) targetNode.icons.clear()
74+
targetNode.icons.addAll(sourceNode.icons.icons)
75+
}
76+
77+
def static copyAttributes(sourceNode, targetNode, boolean doClear = true){
78+
if(doClear) targetNode.attributes.clear()
79+
sourceNode.attributes.each{a ->
80+
targetNode.attributes.add(a.key, a.value)
81+
}
82+
}
83+
84+
//end:
85+
86+
//region: getting an UserStyleNode as ProxyNode from active map
87+
88+
// public
89+
def static getUserStyleNode( String userStyle ){
90+
return getUserStyleNode( null, userStyle )
91+
}
92+
93+
def static getUserStyleNode(ApiMindMap mapaProxy, String userStyle ){
94+
return getUserDefinedStylesParentNode(mapaProxy).children.find{it.text == userStyle}
95+
}
96+
97+
98+
def static getUserDefinedStylesParentNode(x = null){
99+
return getUserDefinedStylesParentNode((ScriptContext) null)
100+
}
101+
102+
def static getUserDefinedStylesParentNode(MapModel mapa){
103+
return getUserDefinedStylesParentNode(mapa, null)
104+
}
105+
106+
def static getUserDefinedStylesParentNode(ApiMindMap mapaProxy){
107+
return getUserDefinedStylesParentNode(mapaProxy.delegate, null)
108+
}
109+
110+
111+
def static getUserDefinedStylesParentNode(ScriptContext scriptContext){
112+
MapModel mapa = Controller.getCurrentController().getMap();
113+
return getUserDefinedStylesParentNode(mapa, scriptContext)
114+
}
115+
116+
def static getUserDefinedStylesParentNode(ApiMindMap mapaProxy, ScriptContext scriptContext){
117+
return getUserDefinedStylesParentNode(mapaProxy.delegate, scriptContext)
118+
}
119+
120+
def static getUserDefinedStylesParentNode(MapModel mapa, ScriptContext scriptContext){
121+
if(!mapa) {
122+
return getUserDefinedStylesParentNode(scriptContext)
123+
}
124+
MapStyleModel styleModel = MapStyleModel.getExtension(mapa);
125+
MapModel styleMap = styleModel.getStyleMap();
126+
NodeModel userStyleParentNode = styleModel.getStyleNodeGroup(styleMap, MapStyleModel.STYLES_USER_DEFINED);
127+
def userDefinedParentNode = new ProxyNode(userStyleParentNode, scriptContext)
128+
return userDefinedParentNode
129+
}
130+
131+
//end:
132+
133+
}
134+

Tutorial-o-Matic/zips/templates/Tutorial-o-Matic/tutorial_styles_template.mm

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<map version="freeplane 1.9.13">
22
<!--To view this file, download free mind mapping software Freeplane from https://www.freeplane.org -->
3-
<node TEXT="New Mindmap" FOLDED="false" ID="ID_258304564" STYLE="oval"><hook NAME="MapStyle" background="#ffffff">
3+
<node TEXT="New Mindmap" FOLDED="false" ID="ID_258304564" STYLE="oval">
4+
<font SIZE="18"/>
5+
<hook NAME="MapStyle" background="#ffffff">
46
<properties show_icon_for_attributes="true" edgeColorConfiguration="#808080ff,#ff0000ff,#0000ffff,#00ff00ff,#ff00ffff,#00ffffff,#7c0000ff,#00007cff,#007c00ff,#7c007cff,#007c7cff,#7c7c00ff" mapUsesOwnSaveOptions="true" save_modification_times="false" save_last_visited_node="default" show_note_icons="true" save_folding="default" fit_to_viewport="false"/>
57

68
<map_styles>
@@ -41,60 +43,72 @@
4143
<icon BUILTIN="edit"/>
4244
<richcontent TYPE="NOTE" CONTENT-TYPE="plain/markdown"/>
4345
</stylenode>
44-
<stylenode TEXT="ToM-Tutorial" ID="ID_1317696283" ICON_SIZE="20 pt" BACKGROUND_COLOR="#f3d0c5" STYLE="rectangle" BORDER_WIDTH="3 px">
46+
<stylenode TEXT="ToM-Tutorial" ID="ID_1317696283" ICON_SIZE="24 pt" COLOR="#000000" BACKGROUND_COLOR="#fbcbbc" STYLE="rectangle" BORDER_WIDTH="3 px">
4547
<icon BUILTIN="emoji-1F989"/>
48+
<cloud COLOR="#f2ded8" SHAPE="ROUND_RECT"/>
49+
<attribute NAME="ToM_TabLabel" VALUE=" "/>
4650
</stylenode>
47-
<stylenode TEXT="ToM_TOC" ID="ID_1160910212" ICON_SIZE="12 pt" BACKGROUND_COLOR="#f5ff95" STYLE="rectangle" BORDER_WIDTH="3 px">
51+
<stylenode TEXT="ToM_TOC" ID="ID_1160910212" ICON_SIZE="16 pt" COLOR="#000000" BACKGROUND_COLOR="#f5ff95" STYLE="rectangle" BORDER_WIDTH="3 px">
4852
<icon BUILTIN="emoji-1F989"/>
4953
<icon BUILTIN="emoji-25B6"/>
5054
</stylenode>
51-
<stylenode TEXT="ToM_newPage" ID="ID_1643366420" ICON_SIZE="12 pt" BACKGROUND_COLOR="#95d9ff" STYLE="rectangle" BORDER_WIDTH="3 px">
55+
<stylenode TEXT="ToM_newPage" ID="ID_1643366420" ICON_SIZE="16 pt" COLOR="#000000" BACKGROUND_COLOR="#95d9ff" STYLE="rectangle" BORDER_WIDTH="3 px">
5256
<icon BUILTIN="emoji-1F989"/>
5357
<icon BUILTIN="emoji-25B6"/>
5458
</stylenode>
55-
<stylenode TEXT="ToM_nextPage" ID="ID_318145687" ICON_SIZE="12 pt" BACKGROUND_COLOR="#ff9595" STYLE="rectangle" BORDER_WIDTH="3 px">
59+
<stylenode TEXT="ToM_nextPage" ID="ID_318145687" ICON_SIZE="16 pt" COLOR="#000000" BACKGROUND_COLOR="#ff9595" STYLE="rectangle" BORDER_WIDTH="3 px">
5660
<icon BUILTIN="emoji-1F989"/>
5761
<icon BUILTIN="emoji-25B6"/>
5862
</stylenode>
5963
<stylenode TEXT="ToM_note" ID="ID_1031812973" ICON_SIZE="16 pt" STYLE="rectangle" BORDER_WIDTH="3 px">
6064
<icon BUILTIN="emoji-1F989"/>
6165
<icon BUILTIN="emoji-1F4F0"/>
66+
<cloud COLOR="#f9f9b9" SHAPE="ROUND_RECT"/>
6267
</stylenode>
6368
<stylenode TEXT="ToM_showMenu" ID="ID_723735694" ICON_SIZE="16 pt" STYLE="rectangle" BORDER_WIDTH="3 px">
6469
<icon BUILTIN="emoji-1F989"/>
6570
<icon BUILTIN="emoji-1F5B1"/>
71+
<cloud COLOR="#f9f9b9" SHAPE="ROUND_RECT"/>
6672
</stylenode>
6773
<stylenode TEXT="ToM_goto" ID="ID_1953218925" ICON_SIZE="16 pt" STYLE="rectangle" BORDER_WIDTH="3 px">
6874
<icon BUILTIN="emoji-1F989"/>
6975
<icon BUILTIN="emoji-2197"/>
76+
<cloud COLOR="#f9f9b9" SHAPE="ROUND_RECT"/>
7077
</stylenode>
7178
<stylenode TEXT="ToM_menuAction" ID="ID_1981660950" ICON_SIZE="16 pt" STYLE="rectangle" BORDER_WIDTH="3 px">
7279
<icon BUILTIN="emoji-1F989"/>
7380
<icon BUILTIN="emoji-1F525"/>
81+
<cloud COLOR="#f9f9b9" SHAPE="ROUND_RECT"/>
7482
</stylenode>
7583
<stylenode TEXT="ToM_groovy" ID="ID_1578586059" ICON_SIZE="16 pt" STYLE="rectangle" BORDER_WIDTH="3 px">
7684
<icon BUILTIN="emoji-1F989"/>
7785
<icon BUILTIN="emoji-1F951"/>
86+
<cloud COLOR="#f9f9b9" SHAPE="ROUND_RECT"/>
7887
</stylenode>
7988
<stylenode TEXT="ToM_copy" ID="ID_691299161" ICON_SIZE="16 pt" STYLE="rectangle" BORDER_WIDTH="3 px">
8089
<icon BUILTIN="emoji-1F989"/>
8190
<icon BUILTIN="emoji-1F4CB"/>
91+
<cloud COLOR="#f9f9b9" SHAPE="ROUND_RECT"/>
8292
</stylenode>
8393
<stylenode TEXT="ToM_select" ID="ID_1792407381" ICON_SIZE="16 pt" STYLE="rectangle" BORDER_WIDTH="3 px">
8494
<icon BUILTIN="emoji-1F989"/>
8595
<icon BUILTIN="emoji-2B55"/>
96+
<cloud COLOR="#f9f9b9" SHAPE="ROUND_RECT"/>
8697
</stylenode>
8798
<stylenode TEXT="ToM_openMap" ID="ID_323134366" ICON_SIZE="16 pt" STYLE="rectangle" BORDER_WIDTH="3 px">
8899
<icon BUILTIN="emoji-1F989"/>
89100
<icon BUILTIN="mindmap"/>
101+
<cloud COLOR="#f9f9b9" SHAPE="ROUND_RECT"/>
90102
</stylenode>
91103
<stylenode TEXT="ToM_openTutMap" ID="ID_255978903" ICON_SIZE="16 pt" STYLE="rectangle" BORDER_WIDTH="3 px">
92104
<icon BUILTIN="emoji-1F989"/>
93105
<icon BUILTIN="links/file/freeplane_mindmap"/>
106+
<cloud COLOR="#f9f9b9" SHAPE="ROUND_RECT"/>
94107
</stylenode>
95108
<stylenode TEXT="ToM_showNode" ID="ID_1304839137" ICON_SIZE="16 pt" STYLE="rectangle" BORDER_WIDTH="3 px">
96109
<icon BUILTIN="emoji-1F989"/>
97110
<icon BUILTIN="emoji-1F517"/>
111+
<cloud COLOR="#f9f9b9" SHAPE="ROUND_RECT"/>
98112
</stylenode>
99113
</stylenode>
100114
<stylenode LOCALIZED_TEXT="styles.AutomaticLayout" POSITION="right" STYLE="bubble">
@@ -124,6 +138,5 @@
124138
</stylenode>
125139
</map_styles>
126140
</hook>
127-
<font SIZE="18"/>
128141
</node>
129142
</map>

0 commit comments

Comments
 (0)