11package edofro.tutorialomatic
22
3+ // import edofro.tutorialomatic.ToM_ui
4+
35import org.freeplane.core.ui.components.UITools as ui
46import org.freeplane.core.util.MenuUtils as menuUtils
57import org.freeplane.core.util.TextUtils as textUtils
@@ -13,6 +15,10 @@ class ToM_actions{
1315 static final name = ' tutorialOMatic'
1416 static final actionInstruction1 = " addons.${ name} .ActionInstruction1"
1517 static final actionInstruction2 = " addons.${ name} .ActionInstruction2"
18+ static final enum ex {
19+ muted, showHotKeys, showMenu
20+ }
21+ static final int pausa = 400
1622
1723
1824 // end: definitions
@@ -30,6 +36,31 @@ class ToM_actions{
3036 def static execute (java.util.ArrayList acciones ){
3137 menuUtils. executeMenuItems(acciones)
3238 }
39+
40+ def static executeAction (infoAccion , how ){
41+ switch (how){
42+ case ex. muted :
43+ execute(infoAccion. action)
44+ break
45+ case ex. showHotKeys :
46+ // looks if it has defined hotKeys
47+ if (infoAccion. keyStroke){
48+ ToM_ui . showTextMessage(" ${ infoAccion.keyStroke} : ${ infoAccion.label} " . toString(),3000 )
49+ execute(infoAccion. action)
50+ break // break is here, because if the action has not defined Hotkeys then it should show the menu way
51+ }
52+ case ex. showMenu :
53+ closeMenus(infoAccion. action)
54+ openMenus(infoAccion. action, pausa)
55+ def timer = new Timer ()
56+ def espera = (infoAccion. path. size()* 2 + 1 )* pausa
57+ timer. runAfter(espera){
58+ execute(infoAccion. action)
59+ closeMenus(infoAccion. action)
60+ }
61+ break
62+ }
63+ }
3364
3465 // end:
3566
@@ -47,20 +78,45 @@ class ToM_actions{
4778 def static getToolTip (mME ){
4879 mME. toolTipText
4980 }
81+
82+ def static getMenuPath (path ){
83+ path[1 .. -2 ]* . label. join(" '->'" )
84+ }
5085
5186 // end:
5287
5388 // region: ----- getting instructions for action ----------------------------
89+
90+ def static getActionInfoMap (org.freeplane.plugin.script.proxy.NodeProxy nodo ){
91+ def accion = action(nodo)
92+ getActionInfoMap(accion)
93+ }
5494
55- def static getActionInstructions ( accion ){
95+ def static getActionInfoMap ( String accion ){
5696 def miPath = getMenuEntryPath(accion)
57- def menuPath = miPath[1 .. -2 ]* . label. join(" '->'" )
58- def keyStroke = getKeyStroke(miPath[-1 ])
59- def label = getLabel(miPath[-1 ])
60- def instr1 = textUtils. format(actionInstruction1, apos(menuPath), apos(label))
61- def instr2 = keyStroke? textUtils. format(actionInstruction2, apos(keyStroke)): " "
62- return htmlUtils. join(instr1," " , instr2). replace(' \n ' ,' ' )
63- }
97+ Map myAction = [:]
98+ myAction
99+ << [ action : accion ]
100+ << [ path : miPath ]
101+ << [ keyStroke : getKeyStroke(miPath[-1 ]) ]
102+ << [ label : getLabel(miPath[-1 ]) ]
103+ << [ menuPath : getMenuPath(miPath) ]
104+ << [ toolTip : getToolTip(miPath[-1 ]) ]
105+ def instr1 = textUtils. format(actionInstruction1, apos(myAction. menuPath), apos(myAction. label))
106+ def instr2 = myAction. keyStroke? textUtils. format(actionInstruction2, apos(myAction. keyStroke)): " "
107+ myAction << [ instructions : instr2? htmlUtils. join(instr1," " , instr2). replace(' \n ' ,' ' ): instr1 ]
108+ return myAction
109+ }
110+
111+ // def static getActionInstructions(accion){
112+ // def miPath = getMenuEntryPath(accion)
113+ // def menuPath = getMenuPath(miPath)
114+ // def keyStroke = getKeyStroke(miPath[-1])
115+ // def label = getLabel(miPath[-1])
116+ // def instr1 = textUtils.format(actionInstruction1, apos(menuPath), apos(label))
117+ // def instr2 = keyStroke?textUtils.format(actionInstruction2, apos(keyStroke)):""
118+ // return htmlUtils.join(instr1,"", instr2).replace('\n','')
119+ // }
64120
65121 def static apos (String texto ){
66122 return " \' " + texto + " \' "
@@ -141,7 +197,7 @@ class ToM_actions{
141197 subMenu = subMenu. menuComponents. find{it. hasProperty(' text' ) && it. text == menuItem}
142198 }
143199 sleep(timeLapse)
144- subMenu. armed = true
200+ subMenu? . armed = true
145201 }
146202 }
147203 }
0 commit comments