Skip to content

Commit 0c1f08f

Browse files
committed
addShowMenuItemPane with multiple buttons
1 parent 986efbd commit 0c1f08f

2 files changed

Lines changed: 81 additions & 28 deletions

File tree

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

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class ToM{
118118
}
119119
break
120120
case styles.showMenu:
121-
addShowMenuItemPane(myPanel, tutNode.children)
121+
addShowMenuItemPane(myPanel, tutNode.children, options)
122122
break
123123
case styles.toc:
124124
addTOCPane(myPanel, tutNode)
@@ -253,14 +253,22 @@ class ToM{
253253
myP.add(nextButtonPanel, tomui.GBC)
254254
}
255255

256-
def static addShowMenuItemPane(myP, nodos){
256+
def static addShowMenuItemPane(myP, nodos, options){
257257
nodos.findAll{n -> toma.hasAction(n)}.each{nodo ->
258258
def infoAccion = toma.getActionInfoMap(nodo)
259259
if (infoAccion){
260-
def msgHtml = infoAccion.instructions
261-
def bttnText = 'Show it in the menu'
262-
def bttnToolTip = "Click to see where is ${toma.apos(infoAccion.label)} in Freeplane Menu"
263-
def bttnAction = { e ->
260+
def msgHtmlA = nodo.note?tomui.getHtmlFromNote(nodo, options):null
261+
def msgHtmlB = infoAccion.instructions
262+
def msgHtml = tomui.mergeHtml(msgHtmlA,msgHtmlB)
263+
def botones = []
264+
def bttnText
265+
def bttnToolTip
266+
def bttnAction
267+
def bttnIcon
268+
269+
bttnText = null //'Show me'
270+
bttnToolTip = "Click to see where is ${toma.apos(infoAccion.label)} in Freeplane Menu"
271+
bttnAction = { e ->
264272
def bttn = e.source
265273
def sel = bttn.isSelected()
266274
def bttnPanel = tomui.getButtonPanel(bttn)
@@ -271,12 +279,33 @@ class ToM{
271279
bttn.label = 'Close menu'
272280
tomui.setNextPagePanelEnabled(myP, false)
273281
} else {
274-
bttn.label = 'Show me'
282+
bttn.label = null // 'Show me'
275283
if(! tomui.anyCompPending(myP) ) tomui.setNextPagePanelEnabled(myP, true)
276284
}
277285
}
286+
bttnIcon = menuUtils.getMenuItemIcon('IconAction.emoji-1F50D')
287+
288+
botones << [bttnText, bttnToolTip, bttnAction, bttnIcon, true]
289+
290+
if(withExecute(nodo)){
291+
def enabled = !disableBttn(nodo)
292+
def exeHow = exeActionsHow(nodo)
293+
bttnText = null // 'Execute'
294+
bttnToolTip = "Click to execute the command on the selected nodes"
295+
bttnAction = { e ->
296+
def bttn = e.source
297+
bttn.setEnabled(enabled)
298+
toma.executeActions([] << infoAccion, exeHow)
299+
}
300+
bttnIcon = menuUtils.getMenuItemIcon('IconAction.launch')
301+
302+
botones << [bttnText, bttnToolTip, bttnAction, bttnIcon, true]
303+
}
278304

279-
def buttonPanel = tomui.createButtonPanel(msgHtml,bttnText,bttnToolTip, bttnAction, true)
305+
306+
def buttonPanel = tomui.createButtonPanel(msgHtml, botones)
307+
308+
280309
buttonPanel.metaClass.pending = false
281310
myP.add(buttonPanel, tomui.GBC)
282311
} else {
@@ -285,6 +314,12 @@ class ToM{
285314
}
286315
}
287316
}
317+
318+
def static withExecute( ApiNode nodo){
319+
return nodo.icons.icons.contains('emoji-1F525')
320+
}
321+
322+
288323

289324
def static addGotoPane(myP, ApiNode tNode, ApiNode backNode, options){
290325
backNode = withGoBack(tNode)?backNode:null

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

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import java.awt.Insets
1212
import java.awt.GridBagConstraints
1313
import java.awt.Dimension
1414
import java.awt.GridBagLayout
15+
import java.awt.GridLayout
1516
import java.awt.Point
1617
import java.awt.event.*
1718

@@ -263,7 +264,12 @@ class ToM_ui{
263264
}
264265

265266
// genera panel con botón
266-
def static createButtonPanel(htmlMsg, buttonLabel, buttonToolTip, buttonAction, boolean isToggleButton = false){
267+
def static createButtonPanel(String htmlMsg, buttonLabel, buttonToolTip, buttonAction, boolean isToggleButton = false){
268+
def botones = [] << [buttonLabel, buttonToolTip, buttonAction, null, isToggleButton]
269+
createButtonPanel(htmlMsg, botones)
270+
}
271+
272+
def static createButtonPanel(String htmlMsg, botones){
267273
def panel = swing.panel(
268274
border : new LineBorder(Color.gray, 1),
269275
name : myButtonPanelName,
@@ -279,33 +285,45 @@ class ToM_ui{
279285
constraints : CENTER,
280286
clientProperties: [(JEditorPane.HONOR_DISPLAY_PROPERTIES):true]
281287
)
282-
vbox(constraints:SOUTH) {
288+
if(botones.size()>0){
289+
panel(
290+
constraints:EAST,
291+
background: Color.white,
292+
) {
293+
borderLayout()
283294
panel(
284-
// border : new LineBorder(Color.black, 1),
285-
border : new EmptyBorder(2, 10, 2, 10), // <------- éste
286-
//border: new CompoundBorder(new LineBorder(Color.red, 1),new EmptyBorder(5, 10, 5, 10)) // éste es de prueba poder ver el borde
287-
//insets : new Insets(30,10,30,10),
288-
) {
289-
borderLayout()
290-
if (isToggleButton){
295+
constraints:SOUTH,
296+
background: Color.white,
297+
// // border : new LineBorder(Color.black, 1),
298+
border : new EmptyBorder(2, 2, 2, 2), // <------- éste
299+
// //border: new CompoundBorder(new LineBorder(Color.red, 1),new EmptyBorder(5, 10, 5, 10)) // éste es de prueba poder ver el borde
300+
// //insets : new Insets(30,10,30,10),
301+
) {
302+
gridLayout(new GridLayout(0,1))
303+
botones.each{ b ->
304+
if ( b[4] == true ){
291305
toggleButton(
292-
label : buttonLabel,
293-
constraints : EAST,
294-
margin : new Insets(10,15,10,15),
295-
toolTipText : buttonToolTip,
296-
actionPerformed : buttonAction,
306+
label : b[0],
307+
// constraints : EAST,
308+
margin : new Insets(3,6,3,6),
309+
toolTipText : b[1],
310+
actionPerformed : b[2],
311+
icon : b[3],
297312
)
298313
} else {
299314
button(
300-
label : buttonLabel,
301-
constraints : EAST,
302-
margin : new Insets(10,15,10,15),
303-
toolTipText : buttonToolTip,
304-
actionPerformed : buttonAction,
315+
label : b[0],
316+
// constraints : EAST,
317+
margin : new Insets(3,6,3,6),
318+
toolTipText : b[1],
319+
actionPerformed : b[2],
320+
icon : b[3],
305321
)
306322
}
307323
}
308-
}
324+
}
325+
}
326+
}
309327
}
310328
return panel
311329
}

0 commit comments

Comments
 (0)