Skip to content

Commit a41ac92

Browse files
committed
idDictionary saved as map variable
1 parent ada46f6 commit a41ac92

4 files changed

Lines changed: 72 additions & 45 deletions

File tree

Tutorial-o-Matic/Tutorial-o-Matic.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
<node TEXT="- better scrollspeed&#xa;- message when command no present in Menu for active map&#xa;- added execute_scripts_without_network_restriction: true so web images could be loaded&#xa;- improved showMenu to show actions in extended submenus&#xa;- changed &apos;Close tutorial&apos; to &apos;Stop tutorial&apos;&#xa;- tables have now black borders&#xa;- Codeblocks have special style in EditorPanes&#xa;- links in EditorPanes are now clickeable and open the default web browser&#xa;- added a listener to resize height of content panel when tabpanel width changes&#xa;- added newPage styles and functionality&#xa;- added Table of Contents styles and functionality&#xa;- added Table of Contents button to &apos;next page&apos; panel&#xa;- added GOTO style and its functionality&#xa;- added Action style and its functionality&#xa;- added groovy style and its functionality&#xa;- enables multiple tutorials in one map&#xa;- added &apos;copy&apos; style and its functionality&#xa;- added &apos;select&apos; style and its functionality&#xa;- added &apos;openMap&apos; style and its functionality&#xa;- added &apos;inspect tutorial map&apos; functionality" ID="ID_1550125378"/>
177177
</node>
178178
<node TEXT="v0.0.4" ID="ID_1654795865">
179-
<node TEXT="- corrected link to version.properties" ID="ID_312985717"/>
179+
<node TEXT="- corrected link to version.properties&#xa;- information of pasted nodes now is saved in each map for later exersizes and multiple exercizing maps" ID="ID_312985717"/>
180180
</node>
181181
</node>
182182
<node TEXT="license" FOLDED="true" POSITION="left" ID="ID_624388795">

Tutorial-o-Matic/src/main/groovy/ToM.groovy

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import org.freeplane.plugin.script.proxy.ScriptUtils
1111

1212

1313
class ToM{
14-
14+
1515
// region: properties
1616
// this region has all the properties for the ToM class
17-
17+
1818
static final String version = '0.0.4'
1919
static final c = ScriptUtils.c()
2020
static final String tabName = 'Tutorial'
21+
static final String idDictStorage = 'ToM_idDictionary'
2122

2223
static final Map styles = [
2324
tutorial : 'ToM-Tutorial' ,
@@ -35,11 +36,11 @@ class ToM{
3536
openMap : 'ToM_openMap' ,
3637
openTutMap: 'ToM_openTutMap',
3738
]
38-
39+
3940
static final exeHowIcons = ['emoji-1F507', 'emoji-2328', 'emoji-1F5B1']
40-
41+
4142
// end:
42-
43+
4344
// region: getting tutorial components nodes
4445
//The methods in this region get the nodes from the mindmap that contain the information needed to build the tutorial
4546

@@ -61,12 +62,12 @@ class ToM{
6162
def static getNewPageNodes(nTutorial){
6263
return nTutorial.find{it.style.name == styles.newPage}
6364
}
64-
65+
6566
// end:
66-
67+
6768
// region: loop fill contentPane
68-
// this region contains the methods that loop over the "tutorial nodes" and builds a tutorial page
69-
69+
// this region contains the methods that loop over the "tutorial nodes" and builds a tutorial page
70+
7071
def static fillContentPane(myPanel, nextTutNodes, boolean doClear = true){
7172
def interruptLoop = false
7273
def startingNewPage = true
@@ -126,25 +127,25 @@ class ToM{
126127
if(!interruptLoop) addNextPagePane(myPanel, nextTutNodes[-1], false, false)
127128
tomui.adjustHeight(myPanel, doClear)
128129
}
129-
130+
130131
def static fillPage(myP, nodo, included, doClear){
131132
def nextNodes = getNextTutNodes(nodo, included)
132133
fillContentPane(myP, nextNodes, doClear)
133134
}
134-
135+
135136
// end:
136-
137+
137138
// region: adding tutorial components nodes as contentPanes to tutorial tab
138139
//methods that create the contentPanes used to build a tutorial page
139-
140+
140141
def static addNotes(myP, nodos){
141142
nodos.each{n ->
142143
if(n.note) {
143144
myP.add(tomui.createInstructionsPane(n), tomui.GBC)
144145
}
145146
}
146147
}
147-
148+
148149
def static addPageTitle(myP, String texto){
149150
def html = "<html><style>h1 {color: rgb(240, 240, 240);background-color: rgb(100, 100, 150);display: block;padding: 10px;}</style><body><h1>${texto}</h1></body></html>"
150151
myP.add(tomui.createInstructionsPane(html), tomui.GBC)
@@ -163,11 +164,11 @@ class ToM{
163164
def tocLabel = 'Table of Contents'
164165
def tocToolTip = 'Click to show the Table of Contents of the tutorial'
165166
def tocBttnAction = { e -> showTOC(myP,lastNode) }
166-
167+
167168
def nextButtonPanel = tomui.getNextButtonPanel(tabName, closeLabel, closeToolTip, nextLabel, nextToolTip , bttnAction, tocLabel, tocToolTip, tocBttnAction)
168169
myP.add(nextButtonPanel, tomui.GBC)
169170
}
170-
171+
171172
def static addShowMenuItemPane(myP, nodos){
172173
nodos.findAll{n -> toma.hasAction(n)}.each{nodo ->
173174
def infoAccion = toma.getActionInfoMap(nodo)
@@ -190,7 +191,7 @@ class ToM{
190191
if(! tomui.anyCompPending(myP) ) tomui.setNextPagePanelEnabled(myP, true)
191192
}
192193
}
193-
194+
194195
def buttonPanel = tomui.getButtonPanel(msgHtml,bttnText,bttnToolTip, bttnAction, true)
195196
buttonPanel.metaClass.pending = false
196197
myP.add(buttonPanel, tomui.GBC)
@@ -199,8 +200,8 @@ class ToM{
199200
myP.add(tomui.createInstructionsPane(textoHtml), tomui.GBC)
200201
}
201202
}
202-
}
203-
203+
}
204+
204205
def static addGotoPane(myP, nodos){
205206
nodos.findAll{n -> n.link.node?true:false}.each{nodo ->
206207
def targetNode = nodo.link.node
@@ -212,7 +213,7 @@ class ToM{
212213
myP.add(buttonPanel, tomui.GBC)
213214
}
214215
}
215-
216+
216217
def static addGroovyPane(myP, nodoT){
217218
def enabled = !disableBttn(nodoT)
218219
nodoT.children.findAll{n -> WSE.isGroovyNode(n)}.each{nodo ->
@@ -227,7 +228,7 @@ class ToM{
227228
bttn.setEnabled(enabled)
228229
c.script(scrText, "groovy").executeOn(c.selected)
229230
}
230-
231+
231232
def buttonPanel = tomui.getButtonPanel(msgHtml,bttnText,bttnToolTip, bttnAction, false)
232233
buttonPanel.metaClass.pending = false
233234
myP.add(buttonPanel, tomui.GBC)
@@ -237,20 +238,20 @@ class ToM{
237238
}
238239
}
239240
}
240-
241+
241242
def static getGroovyHtml(nodo, script){
242243
def showScript = nodo.icons.icons.contains('emoji-1F50D')
243244
uiMsg("showScript ${showScript}")
244245
def html = showScript? tomui.getHtmlFromGroovyNode(nodo, script) : nodo.text
245246
uiMsg("html ${html}")
246247
return html
247248
}
248-
249+
249250
def static addActionPane(myP, nodo){
250251
def infoAcciones = []
251252
nodo.children.findAll{n -> toma.hasAction(n)}.each{n ->
252253
def infoAccion = toma.getActionInfoMap(n)
253-
infoAcciones << infoAccion
254+
infoAcciones << infoAccion
254255
}
255256
def msgHtml = nodo.note?tomui.getHtmlFromNote(nodo):null
256257
def bttnText = 'Execute'
@@ -266,18 +267,18 @@ class ToM{
266267
def buttonPanel = ToM_ui.getButtonPanel(msgHtml,bttnText,bttnToolTip, bttnAction, false)
267268
myP.add(buttonPanel, tomui.GBC)
268269
}
269-
270+
270271
def static exeActionsHow(nodo){
271272
def iconos = nodo.icons.icons
272273
def iconitos = iconos.intersect(exeHowIcons)
273-
if(iconitos){
274+
if(iconitos){
274275
def index = exeHowIcons.indexOf(iconitos[0])
275276
return toma.ex.values()[index]
276277
} else {
277278
return toma.ex.showHotKeys
278279
}
279280
}
280-
281+
281282
def static disableBttn(nodo){
282283
def iconos = nodo.icons.icons
283284
return iconos.contains('emoji-1F56F')
@@ -298,9 +299,15 @@ class ToM{
298299
}
299300
def idSource = ( nodoSource.findAll() - nodoSource )*.id
300301
def idTarget = ( nodoTarget.findAll() - existentesNodoTarget )*.id
302+
//carga idDictionary desde mapa.storage
303+
def mapa = nodoTarget.map
304+
def idDictionary = getIdDictionary(mapa)
305+
//actualiza idDictionary
301306
for (def i = 0; i < idSource.size() ; i++){
302-
myP.idDictionary[ idSource[i] ] = idTarget[i]
307+
idDictionary[ idSource[i] ] = idTarget[i]
303308
}
309+
//guarda idDictionary en mapa
310+
setIdDictionary(mapa, idDictionary)
304311
}
305312
def buttonPanel = tomui.getButtonPanel(msgHtml,bttnText,bttnToolTip, bttnAction, false)
306313
myP.add(buttonPanel, tomui.GBC)
@@ -314,22 +321,25 @@ class ToM{
314321
def bttnAction = { e ->
315322
def bttn = e.source
316323
bttn.setEnabled(enabled)
324+
//carga idDictionary desde mapa.storage
325+
def mapa = c.selected.map
326+
def idDictionary = getIdDictionary(mapa)
317327
def nodos = []
318328
(nodo.findAll()- nodo).each{ n ->
319329
//get list of clones ids
320330
uiMsg("n.Id ${n.id}")
321331
def clonesIds = n.getNodesSharingContent()*.id
322332
uiMsg("clonesIds $clonesIds")
323333
//intersect with list of dist.keySet
324-
def keySet = myP.idDictionary.keySet()
334+
def keySet = idDictionary.keySet()
325335
uiMsg("keySet $keySet")
326336
def sourceId = keySet.intersect(clonesIds)
327337
uiMsg("sourceId $sourceId")
328-
//get Target id
329-
def targetId = sourceId?myP.idDictionary[ sourceId[0] ]:null
338+
//get Target id
339+
def targetId = sourceId?idDictionary[ sourceId[0] ]:null
330340
uiMsg("targetId $targetId")
331341
//get node
332-
def targetNode = targetId?c.selected.map.node(targetId):null
342+
def targetNode = targetId?mapa.node(targetId):null
333343
uiMsg("targetNode $targetNode")
334344
//add node to nodes list
335345
if(targetNode) nodos += targetNode
@@ -343,6 +353,26 @@ class ToM{
343353
myP.add(buttonPanel, tomui.GBC)
344354
}
345355

356+
def static getIdDictionary(mapa){
357+
def dict = [:]
358+
def textoDict = mapa.storage[idDictStorage]
359+
if(textoDict){
360+
textoDict.toString().split(';').each{e ->
361+
def (k,v) = e.split(':')
362+
dict[k] = v
363+
}
364+
}
365+
return dict
366+
}
367+
368+
def static setIdDictionary(mapa, dict){
369+
def texto = new StringBuilder()
370+
dict.each{k,v ->
371+
texto << "${k}:${v};"
372+
}
373+
mapa.storage[idDictStorage] = texto
374+
}
375+
346376
def static addOpenMapPane(myP, tutNode){
347377
def sep = File.separator
348378
def nodoMapa = tutNode.children.find{it.text.endsWith('.mm')}
@@ -388,7 +418,7 @@ class ToM{
388418
}
389419
myP.add(pane, tomui.GBC)
390420
}
391-
421+
392422
def static addTutorialsPane(myP, mapa){
393423
def nodosTutoriales = mapa.root.find{it.style.name == styles.tutorial}
394424
if ( nodosTutoriales.size() != 1 ){
@@ -397,7 +427,7 @@ class ToM{
397427
addPageTitle(myP, "${pre}utorials present in '${mapa.name}' map".toString())
398428
nodosTutoriales.each{ nT ->
399429
def title = nT.text
400-
def bttnAction = { e ->
430+
def bttnAction = { e ->
401431
def tutNodes = getTutNodes(nT)
402432
if(tutNodes) {
403433
fillContentPane(myP, tutNodes)
@@ -421,7 +451,7 @@ class ToM{
421451
}
422452
}
423453
}
424-
454+
425455
// end:
426456

427457
// region: showing other content in Tutorial Tab
@@ -431,15 +461,15 @@ class ToM{
431461
myP.removeAll()
432462
tomui.resizeContentPanel(myP,tomui.maxContentPaneHeigth)
433463
addTOCPane(myP,nodo)
434-
tomui.adjustHeight(myP, true)
464+
tomui.adjustHeight(myP, true)
435465
}
436466

437467
def static showTutorials(mapa){
438-
def myP = tomui.getContentPaneFromMyTab(tabName, true)
468+
def myP = tomui.getContentPaneFromMyTab(tabName, true)
439469
myP.removeAll()
440470
tomui.resizeContentPanel(myP,tomui.maxContentPaneHeigth)
441471
addTutorialsPane(myP, mapa)
442-
tomui.adjustHeight(myP, true)
472+
tomui.adjustHeight(myP, true)
443473
}
444474

445475

@@ -459,9 +489,9 @@ class ToM{
459489
def static exists(String path){new File(path).isFile()}
460490

461491
// end:
462-
492+
463493
// region: help / debug
464-
494+
465495
def static uiMsg(texto){
466496
//ui.informationMessage(texto.toString())
467497
}

Tutorial-o-Matic/src/main/groovy/ToM_actions.groovy

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class ToM_actions{
1515
static final name = 'tutorialOMatic'
1616
static final actionInstruction1 = "addons.${name}.ActionInstruction1"
1717
static final actionInstruction2 = "addons.${name}.ActionInstruction2"
18-
static final enum ex{
19-
muted, showHotKeys, showMenu
20-
}
18+
static final enum ex{ muted, showHotKeys, showMenu }
2119
static final int pausa = 400
2220

2321
static boolean waiting = false

Tutorial-o-Matic/src/main/groovy/ToM_ui.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ class ToM_ui{
200200
// background: Color.gray
201201
){}
202202
contentPane.addComponentListener(new CustomComponentListener())
203-
contentPane.metaClass.idDictionary = [:]
204203
def panel = swing.panel(
205204
layout: new GridBagLayout(),
206205
preferredSize: new Dimension(minContentPaneWidth, maxContentPaneHeigth),

0 commit comments

Comments
 (0)