From 48a5faf4dda715d9aa7cbfa4ccfcf54831a564f7 Mon Sep 17 00:00:00 2001 From: marko Date: Sun, 23 Oct 2005 23:26:11 +0000 Subject: [PATCH] Introduce a popup-menu bound to the right mouse button, currently used to spawn a shell, start ethereal etc. Creating a link to another node using this menu is currently a no-op. Deprecates the old binding model for spawining a shell and starting ethereal to the right mouse button. Bug found by: Submitted by: Requested by: Reviewed by: Approved by: Obtained from: --- canvas.tcl | 6 ++- editor.tcl | 131 ++++++++++++++++++++++++++++++++++++++++---------- hub.tcl | 6 --- initgui.tcl | 17 +++++-- lanswitch.tcl | 6 --- 5 files changed, 125 insertions(+), 41 deletions(-) diff --git a/canvas.tcl b/canvas.tcl index cbbb07f..df12d5f 100755 --- a/canvas.tcl +++ b/canvas.tcl @@ -47,7 +47,11 @@ proc newCanvas { name } { set canvas [newObjectId canvas] global $canvas lappend canvas_list $canvas - set $canvas [list "name $name"] + if { $name != "" } { + set $canvas [list "name $name"] + } else { + set $canvas [list "name Canvas[string range $canvas 1 end]"] + } return } diff --git a/editor.tcl b/editor.tcl index ccadcbd..af01351 100755 --- a/editor.tcl +++ b/editor.tcl @@ -430,41 +430,121 @@ proc selectNode { c obj } { 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 } @@ -1769,3 +1849,4 @@ proc refreshCanvasMenu {} { -value $canvas -variable curcanvas } } + diff --git a/hub.tcl b/hub.tcl index 7a249df..394451a 100755 --- a/hub.tcl +++ b/hub.tcl @@ -58,9 +58,3 @@ proc $MODULE.nghook { eid node ifc } { set ifunit [string range $ifc 1 end] return [list $eid\_$node link$ifunit] } - - -proc $MODULE.shellcmd { node } { - return -} - diff --git a/initgui.tcl b/initgui.tcl index 75f14e4..5af7a19 100755 --- a/initgui.tcl +++ b/initgui.tcl @@ -154,7 +154,7 @@ bind . redo .menubar.edit add separator .menubar.edit add command -label "New canvas" -underline 0 \ -command { - newCanvas unnamed + newCanvas "" refreshCanvasMenu } @@ -251,6 +251,10 @@ menu .menubar.help -tearoff 0 } } + +# +# Left-side toolbar +# frame .left pack .left -side left -fill y @@ -305,8 +309,6 @@ $c bind linklabel "anyLeave $c" $c bind node "popupConfigDialog $c" $c bind nodelabel "popupConfigDialog $c" $c bind link "popupConfigDialog $c" -$c bind link "startethereal $c" -$c bind linklabel "startethereal $c" $c bind linklabel "popupConfigDialog $c" bind $c <1> "button1 $c %x %y none" bind $c "button1 $c %x %y ctrl" @@ -323,6 +325,15 @@ bind $c <4> "$c yview scroll 1 units" 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 # diff --git a/lanswitch.tcl b/lanswitch.tcl index 115bcce..75c1bc3 100755 --- a/lanswitch.tcl +++ b/lanswitch.tcl @@ -58,9 +58,3 @@ proc $MODULE.nghook { eid node ifc } { set ifunit [string range $ifc 1 end] return [list $eid\_$node link$ifunit] } - - -proc $MODULE.shellcmd { node } { - return -} - -- 2.39.5