-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathToggleBlockViewForAllSiblings.groovy
More file actions
166 lines (115 loc) · 4.01 KB
/
ToggleBlockViewForAllSiblings.groovy
File metadata and controls
166 lines (115 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// @ExecutionModes({on_single_node="/menu_bar/format/menu_coreFormat/NodeWidth"})
import org.freeplane.view.swing.map.NodeView
// Source: https://freeplane.sourceforge.io/wiki/index.php/Scripts_collection#toggle_block_view_for_all_siblings
// Author: Nnamdi Kohn
//
// configuration
//
// set default node identifier
def strIdentifier = "" // e.g. "[" for regarding only nodes with cores starting with "["
// width raster for the maximum width to get snatched
def width_grid = 20
// offset to be added to maximum node width
def width_offset = 10
//
// local variables
//
// get map zoom factor
def zoomfactor = c.getZoom()
// maximum width (with default value)
def maxwidth = 0
// node with maximum width (with default value)
def maxnode = node
// save current node object
def current_node_style = node.style.name
// node view
def nodeView = 0
// setting for regarding style setting
def bRegardStyleSetting = 1
// get parent node from selected node
def nodeParent = node.getParent()
// widthcompare
def widthcompare = 0
// get current width of component
def width = 0
// get list of siblings
lstSiblings = nodeParent.getChildren()
// if there are more than one nodes selected ...
if( c.selecteds.size() > 1 ) {
// list of siblings will be all selected nodes
lstSiblings = c.selecteds
// don't regard the node's styles
bRegardStyleSetting = 0
}
// set default for marker
def bLeaveFunctionHereafter = 0
//
// check if any relevant node has minimum width setting and reset setting
//
// take every sibling and ...
lstSiblings.each{
// only regard nodes with fitting style ...
if( it.style.name == current_node_style || bRegardStyleSetting == 0 ){
// if any minimum width is set ...
if( it.style.getMinNodeWidth() > 1 ){
// if node start character specifics are fitting ...
if( it.getPlainText().startsWith( strIdentifier ) ){
// set marker
bLeaveFunctionHereafter = 1
// reset minimum node width
it.style.setMinNodeWidth( -1 )
}
}
}
}
// if marker was previously set ...
if( bLeaveFunctionHereafter == 0 ){
//
// determine maximum current node width of all siblings
//
// take every sibling and ...
lstSiblings.each{
// only regard nodes with fitting style ...
if( it.style.name == current_node_style || bRegardStyleSetting == 0 ){
// get nodeView
nodeView = it.delegate.viewers.find() {it instanceof NodeView}
// get current width of component
width = nodeView?.mainView?.width
// if its current width is the biggest so far ...
if( width > maxwidth ){
// if node start character specifics are fitting ...
if( it.getPlainText().startsWith( strIdentifier ) ){
// update maximum width variable with current node width
maxwidth = width
// set max width node
maxnode = it
}
}
}
}
// jump to node with maximum width
//c.select( maxnode )
//
// set minimum width value for all siblibngs
//
// set starting width
widthcompare = width_grid
// fit maxwidth to raster
while( maxwidth.div( zoomfactor ) + width_offset > widthcompare ){
// increment width compare value
widthcompare += width_grid
}
// take every sibling and ...
lstSiblings.each{
// only regard nodes with fitting style ...
if( it.style.name == current_node_style || bRegardStyleSetting == 0 ){
// if node start character specifics are fitting ...
if( it.getPlainText().startsWith( strIdentifier ) ){
// set its minimum width to the maximum current plus delta
it.style.minNodeWidth = widthcompare
}
}
}
}
// printout status
c.statusInfo = "zoom: $zoomfactor ; maxwidth: $maxwidth ; width: $width ; widthcompare: $widthcompare"