Skip to content

Commit 71799b8

Browse files
committed
added groovy pane
1 parent c8844e3 commit 71799b8

3 files changed

Lines changed: 135 additions & 2 deletions

File tree

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ package edofro.tutorialomatic
33
import edofro.tutorialomatic.ToM_ui as tomui
44
import edofro.tutorialomatic.ToM_actions as toma
55

6+
import edofro.menuomatic.WSE_redux as WSE
7+
68
import org.freeplane.core.ui.components.UITools as ui
9+
import org.freeplane.plugin.script.proxy.ScriptUtils
10+
711

812

913
class ToM{
1014

15+
static final c = ScriptUtils.c()
1116
static final String tabName = 'Tutorial'
1217

1318
static final Map styles = [
@@ -20,6 +25,7 @@ class ToM{
2025
toc : 'ToM_TOC' ,
2126
goto : 'ToM_goto' ,
2227
action : 'ToM_menuAction',
28+
groovy : 'ToM_groovy' ,
2329
]
2430

2531
static final exeHowIcons = ['emoji-1F507', 'emoji-2328', 'emoji-1F5B1']
@@ -82,6 +88,9 @@ class ToM{
8288
case styles.action:
8389
addActionPane(myPanel, tutNode)
8490
break
91+
case styles.groovy:
92+
addGroovyPane(myPanel, tutNode)
93+
break
8594
default:
8695
ui.informationMessage('node style not defined')
8796
break
@@ -196,6 +205,32 @@ class ToM{
196205
}
197206
}
198207

208+
def static addGroovyPane(myP, nodoT){
209+
//TODO: addGroovyPane
210+
def enabled = enableBttn(nodoT)
211+
nodoT.children.findAll{n -> WSE.isGroovyNode(n)}.each{nodo ->
212+
def script = WSE.scriptFromNode(nodo)
213+
if (script){
214+
def scrText = script + "\n c.statusInfo = '---- script executed ----'".toString()
215+
def msgHtml = nodo.text //TODO: mejorar texto
216+
def bttnText = 'Execute script'
217+
def bttnToolTip = "Click to execute script on selected nodes"
218+
def bttnAction = { e ->
219+
def bttn = e.source
220+
bttn.setEnabled(enabled)
221+
c.script(scrText, "groovy").executeOn(c.selected)
222+
}
223+
224+
def buttonPanel = tomui.getButtonPanel(msgHtml,bttnText,bttnToolTip, bttnAction, false)
225+
buttonPanel.metaClass.pending = false
226+
myP.add(buttonPanel, tomui.GBC)
227+
} else {
228+
def textoHtml = '<html><body><p>Command not encountered in Menu for active map</p></body></html>'
229+
myP.add(tomui.createInstructionsPane(textoHtml), tomui.GBC)
230+
}
231+
}
232+
}
233+
199234
def static addActionPane(myP, nodo){
200235
def infoAcciones = []
201236
nodo.children.findAll{n -> toma.hasAction(n)}.each{n ->

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,26 @@ class ToM_ui{
9292
html = nodo.plainNote.startsWith('=')?nodo.note.plain:nodo.note.html
9393
break
9494
case 'markdown':
95-
html = "<html> ${Marked.marked(nodo.note.plain)} </html>"
95+
//html = "<html> ${Marked.marked(nodo.note.plain)} </html>"
96+
html = """<html>
97+
<style>
98+
table {border: 0; border-spacing: 0;}
99+
th, td {border: 1px solid;}
100+
pre {
101+
background-color: rgb(230, 230, 230);
102+
border: 1px solid rgb(0, 0, 0);
103+
display: block;
104+
padding: 10px;
105+
}
106+
code {
107+
font-family: Consolas,"courier new";
108+
color: rgb(0, 80, 0);
109+
}
110+
</style>
111+
<body>
112+
${Marked.marked(nodo.note.plain)}
113+
</body>
114+
</html>"""
96115
break
97116
default:
98117
html = "Node's note not recognized"
@@ -237,7 +256,7 @@ class ToM_ui{
237256
//nextButtonAction == null --> no 'Next page' button
238257
def static getNextButtonPanel(tabName, closeLabel, closeToolTip, nextLabel, nextToolTip, nextButtonAction, tocLabel = '', tocToolTip = '', tocButtonAction = null ){
239258
def panel = swing.panel(
240-
border : new LineBorder(Color.gray, 1),
259+
//border : new LineBorder(Color.gray, 1),
241260
name : myNextPanelName,
242261
) {
243262
borderLayout()
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package edofro.menuomatic
2+
3+
import org.freeplane.plugin.script.FreeplaneScriptBaseClass.ConfigProperties
4+
5+
6+
class WSE_redux{
7+
static final String attributeForExtensions = new ConfigProperties().getProperty('wikdShellExtension_attributeForExtensions','file_ext')
8+
9+
//region: get/set/is extension from selected node
10+
11+
def static extensionFromNode(n){
12+
extensionFromAttribute(n)?:extensionFromDetails(n)?:extensionFromText(n)?:null
13+
}
14+
15+
def static extensionFromAttribute(n){
16+
n[attributeForExtensions]?:null
17+
}
18+
19+
def static extensionFromDetails(n){
20+
n.details?.size()>1?n.details?[0]=='.'?n.details.drop(1).takeBefore(' ').takeBefore('\n')?:n.details.drop(1).takeBefore('\n')?:n.details.drop(1).takeBefore(' ')?:n.details.drop(1):null:null
21+
}
22+
23+
def static extensionFromText(n){
24+
n.text.reverse().takeBefore('.').reverse()
25+
}
26+
27+
def static extensionFromFilePath(filepath){
28+
return filepath.reverse().split("\\.")[0].reverse().toLowerCase()
29+
}
30+
31+
def static setExtension(n, ext){
32+
// If it's allready defined --> do nothing
33+
if(extensionFromAttribute(n)==ext || extensionFromDetails(n)==ext) return
34+
//I prefer it in this order:
35+
// only details
36+
// if details are beeing Used --> attribute
37+
if(!n.details){
38+
n.details = '.' + ext
39+
} else {
40+
n[attributeForExtensions] = ext
41+
}
42+
}
43+
44+
def static extensionFromNodeFile(n){
45+
(n.link && n.link.uri && n.link.uri.scheme == 'file')?extensionFromFilePath(n.link.uri.path):null
46+
}
47+
48+
def static isExtensionNode(n, extension){
49+
def ext = extensionFromNodeFile(n)?:extensionFromNode(n)
50+
return ext?ext==extension:false
51+
}
52+
53+
//end:
54+
55+
56+
//region: groovy Node
57+
58+
def static isGroovyNode(n){
59+
return (isExtensionNode(n, 'groovy') || n['script1']?true:false)
60+
}
61+
62+
def static scriptFromNode(n){
63+
def input = null
64+
if (isGroovyNode(n)){
65+
if ( extensionFromNodeFile(n) == 'groovy' ) {
66+
input = n.link.file.text
67+
} else if ( n['script1']?true:false ){
68+
input = n['script1'].plain.toString().trim()
69+
} else if ( n.note ){
70+
input = n.note.toString()
71+
}
72+
}
73+
return input
74+
}
75+
76+
//end:
77+
78+
}
79+

0 commit comments

Comments
 (0)