Skip to content

Commit 51c4c2e

Browse files
committed
added textUtils for translations
1 parent b87770e commit 51c4c2e

2 files changed

Lines changed: 75 additions & 17 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,10 @@ For each menu item with an icon add an attribute with the icon key (use develope
329329
</html>
330330
</richcontent>
331331
<node TEXT="en" ID="ID_1998059292">
332-
<attribute_layout NAME_WIDTH="84 pt" VALUE_WIDTH="85.5 pt"/>
332+
<attribute_layout NAME_WIDTH="162 pt" VALUE_WIDTH="281.24999 pt"/>
333333
<attribute NAME="addons.${name}" VALUE="Tutorial-o-Matic"/>
334+
<attribute NAME="addons.${name}.ActionInstruction1" VALUE="&lt;html&gt;In submenu &lt;b&gt;{0}&lt;/b&gt; &lt;br&gt;click on &lt;b&gt;{1}&lt;/b&gt;&lt;/html&gt;"/>
335+
<attribute NAME="addons.${name}.ActionInstruction2" VALUE="&lt;html&gt;You can also use de keyboard shortcut &lt;b&gt;{0}&lt;/b&gt; for this command&lt;/html&gt;"/>
334336
</node>
335337
</node>
336338
<node TEXT="deinstall" POSITION="left" ID="ID_378917294">

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

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
package edofro.tutorialomatic
22

3-
import org.freeplane.core.ui.components.UITools as ui
4-
import org.freeplane.core.util.MenuUtils as menuUtils
3+
import org.freeplane.core.ui.components.UITools as ui
4+
import org.freeplane.core.util.MenuUtils as menuUtils
5+
import org.freeplane.core.util.TextUtils as textUtils
6+
import org.freeplane.core.util.HtmlUtils as htmlUtils
7+
import org.freeplane.plugin.script.proxy.ScriptUtils
58

69
class ToM_actions{
10+
// region: definitions
711

8-
// ----------------------- execute actions ----------------------
12+
static final c = ScriptUtils.c()
13+
static final name = 'tutorialOMatic'
14+
static final actionInstruction1 = "addons.${name}.ActionInstruction1"
15+
static final actionInstruction2 = "addons.${name}.ActionInstruction2"
16+
17+
18+
// end: definitions
19+
20+
21+
// ----------------- Methods -------------------------------------
22+
23+
// region: ------ execute actions ----------------------
924

1025
def static execute(String accion){
1126
def acciones =[] + accion
@@ -16,11 +31,13 @@ class ToM_actions{
1631
menuUtils.executeMenuItems(acciones)
1732
}
1833

19-
// ---------------- getting label / keyStroke / toolTipText from menuEntry -------------------
34+
// end:
35+
36+
// region: ----- getting label / keyStroke / toolTipText from menuEntry -------------------
2037

2138
def static getKeyStroke(myMenuEntry){
2239
def kS = myMenuEntry.keyStroke
23-
return kS?menuUtils.formatKeyStroke(kS):null
40+
return kS?menuUtils.formatKeyStroke(kS).replace('+',' + '):null
2441
}
2542

2643
def static getLabel(mME){
@@ -31,19 +48,27 @@ class ToM_actions{
3148
mME.toolTipText
3249
}
3350

34-
// ------------- obtener texto de acción ----------------------------
51+
// end:
52+
53+
// region: ----- getting instructions for action ----------------------------
3554

3655
def static getActionInstructions(accion){
37-
def miPath = getMenuEntryPath(accion)
38-
def menuPath = miPath[1..-2]*.label.join("' > '")
56+
def miPath = getMenuEntryPath(accion)
57+
def menuPath = miPath[1..-2]*.label.join("'>'")
3958
def keyStroke = getKeyStroke(miPath[-1])
40-
def label = getLabel(miPath[-1])
41-
def instr1 = "In submenu \n '${menuPath}'\nclick on \n '${label}'"
42-
def instr2 = keyStroke?"\n\nYou can also use de keyboard shortcut '${keyStroke}' for this command":""
43-
return instr1 + instr2
44-
}
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+
}
64+
65+
def static apos(String texto){
66+
return "\'" + texto + "\'"
67+
}
4568

46-
// ----- getting actions from nodes ----------------------
69+
// end:
70+
71+
// region: ----- getting actions from nodes ----------------------
4772
def static action(n){
4873
return (n.link?.uri?.scheme == 'menuitem')?n.link.uri.schemeSpecificPart.drop(1):null
4974
}
@@ -52,7 +77,9 @@ class ToM_actions{
5277
return (n.link?.uri?.scheme == 'menuitem')
5378
}
5479

55-
// --- getting MenuEntryTree -------------------
80+
// end:
81+
82+
// region: ----- getting MenuEntryTree -------------------
5683

5784
def static getMenuEntryPath(miAccion){
5885
return getMenuEntryPath(getMenuEntryTree(), miAccion)
@@ -96,7 +123,9 @@ class ToM_actions{
96123
return null
97124
}
98125

99-
// ------------------- displaying menu --------------------
126+
// end:
127+
128+
// region: ----- displaying submenus --------------------
100129

101130
def static openMenus(accion, timeLapse){
102131
timeLapse = timeLapse<25?25:timeLapse>3000?3000:timeLapse
@@ -144,5 +173,32 @@ class ToM_actions{
144173
return componentes
145174
}
146175

176+
// end:
177+
178+
// region: ----- working with nodes ---------------------
179+
180+
def static simulateTextInputInNode(nodo, texto, timeLapse, step){ //TODO: find a way that doesn't fire listener until the end
181+
def timer = new Timer()
182+
c.select(nodo) //TODO: what if nodo is not visible?
183+
for(def i = 0 ; i <= texto.size() + step; i += step){
184+
def subTexto = texto.take(i)
185+
timer.runAfter(i * timeLapse) {
186+
nodo.text = subTexto
187+
}
188+
}
189+
timer.runAfter((texto.size()/step * timeLapse) as int) {
190+
c.select(nodo)
191+
}
192+
}
193+
194+
// end:
195+
196+
// region:
197+
198+
// end:
199+
200+
// region:
201+
202+
// end:
147203

148204
}

0 commit comments

Comments
 (0)