-
Notifications
You must be signed in to change notification settings - Fork 1
/
ContextMenu.nls
94 lines (91 loc) · 3.51 KB
/
ContextMenu.nls
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
;---------------------------------------------------------------------------------------------------------
; Module with procedures to manage context menus
;---------------------------------------------------------------------------------------------------------
; Currently there are 2 contextual menus:
; a) Browser Menu: to navigate (show/hide/expand...) the graph
; b) Data Menu: to create/delete elements in the graph
; Reads and creates menu items
to setup-brwoser-menu
ask menu-items [die]
;[Name Icon Commands]
let menu
(list
(list "Expand" "expand" "browser" task [expand-topic self])
(list "Hide" "hide" "browser" task [hide-topics self ask menu-items [ht] ask links-menu[hide-link]])
(list "Leave" "leave" "browser" task [leave self])
(list "Select" "select" "browser" task [select-topic wait .5])
(list "Fix" "fix" "browser" task [Fix-topic wait .2])
(list "Label" "label" "browser" task [ifelse (label = "") [show-one-label] [set label ""] wait .2] )
(list "New Node" "NewNode" "data" task [add-topic wait .2])
(list "Delete Node" "DeleteNode" "data" task [delete-Node wait .2])
(list "Edit Node" "pencil" "data" task [])
;(list "New Hyper" "NewHyper" "data" task [])
(list "New Link" "NewLink" "data" task [add-link wait .2])
(list "Delete Link" "DeleteLink" "data" task [delete-link wait .2])
)
foreach menu
[
create-menu-items 1
[
set menu-item-Name (first ?)
set shape (item 1 ?)
set MType (item 2 ?)
set menu-Action (last ?)
ht
]
]
end
; Procedure to manage context menus
to Active-Menu [Menu-Type]
; If Topic-information? is enabled then shows the information fo the current topic (there is no need to click it)
if Topic-Information? [topic-inspect]
if mouse-down?
[
; take a candidate among visible topics and menu items
let candidate min-one-of (turtle-set T-Visible (menu-items with [not hidden?])) [distancexy mouse-xcor mouse-ycor]
if candidate != nobody
[
ifelse [distancexy mouse-xcor mouse-ycor] of candidate < 1
[
; if the candidate is a topic, then connect it to the menu items and enphasize its relations and start the action
; of moving the topic
if [breed] of candidate = topics
[
ask relations with [not hidden? and thickness > 0][set thickness 0]
ask links-menu [die]
ask candidate
[
create-links-menu-with menu-items with [MType = Menu-Type] [set color 115 set thickness 0 set shape "curve"]
ask my-relations [set thickness .3]
]
ask menu-items with [MType = Menu-Type] [st set Parent candidate]
repeat 100 [ layout-spring menu-items links-menu 1 1 1]
wait .1
move-topic candidate
]
; if the candidate is a menu item, then execute its action
if [breed] of candidate = menu-items
[
let par [ parent ] of candidate
let acc [ menu-Action ] of candidate
ask par [ run acc ]
if not (Run-out = "")
[
run Run-out
set Run-out ""
]
ask links-menu [die]
ask menu-items [ht]
]
]
; if the user clicks on an empty space, hides everything and start the action of moving the selected topics
[
ask informers [ht]
ask links-menu [die]
ask menu-items [ht]
ask relations with [not hidden? and thickness > 0][set thickness 0]
move-topics-selected
]
]
]
end