]> git.entuzijast.net Git - imunes.git/commitdiff
Introduce a popup-menu bound to the right mouse button, currently used to
authormarko <marko>
Sun, 23 Oct 2005 23:26:11 +0000 (23:26 +0000)
committermarko <marko>
Sun, 23 Oct 2005 23:26:11 +0000 (23:26 +0000)
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
editor.tcl
hub.tcl
initgui.tcl
lanswitch.tcl

index cbbb07f9ecf7b2e31d7ea9f03dc98f6a91a06f3c..df12d5f2caf152502c2e9c9b213a6ff2a63e46c5 100755 (executable)
@@ -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
 }
 
index ccadcbdaa422e6b8fb2542362f915c5bd248959d..af01351f32dc19f5c7fd28fb490ea63a6ca2346d 100755 (executable)
@@ -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 7a249dff36d86ec2eeb2c2a5298de7c546e5ea1f..394451ac1e1c6a2f1dbca208a48de0929a8f87e3 100755 (executable)
--- 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
-}
-
index 75f14e49726a84db78cf76072516c2c16730d3d8..5af7a19d781089c408edba6f73a95a30bd139b86 100755 (executable)
@@ -154,7 +154,7 @@ bind . <Control-y> 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 <Any-Leave> "anyLeave $c"
 $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"
@@ -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
 #
index 115bcceb01871284c96c34e8618286203203ccc5..75c1bc32d5aa6910d3de441ffc1bc707a5cd0c8b 100755 (executable)
@@ -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
-}
-