proc button3 { c x y } {
- global oper_mode env eid
+ global oper_mode env eid canvas_list node_list
set node [lindex [$c gettags {node && current}] 1]
- if { $node != "" && $oper_mode == "exec" } {
- set node_id $eid\_$node
+ if { $node == "" } {
+ return
+ }
+
+ .button3menu delete 0 end
+
+ #
+ # Configure node
+ #
+ .button3menu add command -label "Configure" \
+ -command "popupConfigDialog $c"
+
+ #
+ # Create a new link - can be between different canvases
+ #
+ .button3menu.connect delete 0 end
+ if { $oper_mode == "exec" } {
+ .button3menu add cascade -label "Create link to" \
+ -menu .button3menu.connect -state disabled
+ } else {
+ .button3menu add cascade -label "Create link to" \
+ -menu .button3menu.connect
+ }
+ .button3menu.connect add command -label "Canvas:" -state disabled
+ foreach canvas $canvas_list {
+ destroy .button3menu.connect.$canvas
+ menu .button3menu.connect.$canvas -tearoff 0
+ .button3menu.connect.$canvas add command \
+ -label "Node:" -state disabled
+ .button3menu.connect add cascade -label [getCanvasName $canvas] \
+ -menu .button3menu.connect.$canvas
+ }
+ foreach peer_node $node_list {
+ if { $node != $peer_node } {
+ set canvas [getNodeCanvas $peer_node]
+ .button3menu.connect.$canvas add command \
+ -label [getNodeName $peer_node]
+ }
+ }
+
+ #
+ # Delete selection
+ #
+ if { $oper_mode != "exec" } {
+ .button3menu add command -label "Delete" \
+ -command "delete_object $c $x $y"
+ } else {
+ .button3menu add command -label "Delete" \
+ -command "delete_object $c $x $y" -state disabled
+ }
+
+ #
+ # Shell selection
+ #
+ .button3menu.shell delete 0 end
+ if { $oper_mode == "exec" && [[typemodel $node].layer] == "NETWORK" } {
+ .button3menu add cascade -label "Shell window" \
+ -menu .button3menu.shell
set cmd [[typemodel $node].shellcmd $node]
- if { $cmd != "" } {
- nexec xterm -sb -rightbar \
- -T "IMUNES: [getNodeName $node] (console)" \
- -e "vimage $node_id $cmd" &
+ if { $cmd != "/bin/sh" && $cmd != "" } {
+ .button3menu.shell add command -label "$cmd" \
+ -command "spawnShell $node $cmd"
}
+ .button3menu.shell add command -label "/bin/sh" \
+ -command "spawnShell $node /bin/sh"
+ } else {
+ .button3menu add cascade -label "Shell window" \
+ -menu .button3menu.shell -state disabled
}
+
+ #
+ # Ethereal
+ #
+ .button3menu.ethereal delete 0 end
+ if { $oper_mode == "exec" && [[typemodel $node].layer] == "NETWORK" } {
+ .button3menu add cascade -label "Ethereal" \
+ -menu .button3menu.ethereal
+ foreach ifc [ifcList $node] {
+ .button3menu.ethereal add command -label "$ifc" \
+ -command "startethereal $node $ifc"
+ }
+ } else {
+ .button3menu add cascade -label "Ethereal" \
+ -menu .button3menu.ethereal -state disabled
+ }
+
+ #
+ # Finally post the popup menu on current pointer position
+ #
+ set x [winfo pointerx .]
+ set y [winfo pointery .]
+ tk_popup .button3menu $x $y
+
return
}
-proc startethereal { c } {
- global oper_mode eid
+proc spawnShell { node cmd } {
+ global eid
- if { $oper_mode != "exec" } {
- return
- }
- set interface ""
- set tk_type [lindex [$c gettags current] 0]
- set target [lindex [$c gettags current] 1]
- set n0 [lindex [linkPeers $target] 0]
- set n1 [lindex [linkPeers $target] 1]
- if { [[typemodel $n0].layer] == "NETWORK" } {
- set interface "[ifcByPeer $n0 $n1]@$eid\_$n0"
- } elseif { [[typemodel $n1].layer] == "NETWORK" } {
- set interface "[ifcByPeer $n1 $n0]@$eid\_$n1"
- }
- if { $interface != "" } {
- nexec ethereal -i $interface &
- }
+ set node_id $eid\_$node
+ nexec xterm -sb -rightbar \
+ -T "IMUNES: [getNodeName $node] (console)" \
+ -e "vimage $node_id $cmd" &
+}
+
+
+proc startethereal { node iface } {
+ global eid
+
+ set interface "$iface@$eid\_$node"
+ nexec ethereal -i $interface &
return
}
-value $canvas -variable curcanvas
}
}
+
.menubar.edit add separator
.menubar.edit add command -label "New canvas" -underline 0 \
-command {
- newCanvas unnamed
+ newCanvas ""
refreshCanvasMenu
}
}
}
+
+#
+# Left-side toolbar
+#
frame .left
pack .left -side left -fill y
$c bind node <Double-1> "popupConfigDialog $c"
$c bind nodelabel <Double-1> "popupConfigDialog $c"
$c bind link <Double-1> "popupConfigDialog $c"
-$c bind link <B3-ButtonRelease> "startethereal $c"
-$c bind linklabel <B3-ButtonRelease> "startethereal $c"
$c bind linklabel <Double-1> "popupConfigDialog $c"
bind $c <1> "button1 $c %x %y none"
bind $c <Control-Button-1> "button1 $c %x %y ctrl"
bind $c <5> "$c yview scroll -1 units"
+#
+# Popup-menu hierarchy
+#
+menu .button3menu -tearoff 0
+menu .button3menu.connect -tearoff 0
+menu .button3menu.shell -tearoff 0
+menu .button3menu.ethereal -tearoff 0
+
+
#
# Done with initialization, draw an empty canvas
#