From bafdc8c5214948c494292e54935b07f12ad67003 Mon Sep 17 00:00:00 2001
From: Pat Thoyts <patthoyts@users.sourceforge.net>
Date: Wed, 9 Oct 2002 00:32:54 +0000
Subject: [PATCH] bug #533493: support trace under all comms types for scalar
 and array vars.

---
 ChangeLog        |  6 ++++++
 globals_list.tcl | 56 ++++++++++++++++++++++++++++++++++++++++++++++--
 tkinspect.tcl    | 16 +++++++++-----
 3 files changed, 71 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3d93ec9..03f00c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Oct 09 01:27:43 2002  Pat Thoyts <patthoyts@users.sourceforge.net>
+
+	* tkinspect.tcl:
+	* globals_list.tcl: Implemented trace for all the supported 'send'
+	varieties. This fixes bug #533493.
+	
 Sat Apr 20 01:27:46 2002  Pat Thoyts <patthoyts@users.sourceforge.net>
 
 	* windows_list.tcl: Fixed bug #546259: erroneous use of 'config'
diff --git a/globals_list.tcl b/globals_list.tcl
index 4dd0603..a8b1c5d 100644
--- a/globals_list.tcl
+++ b/globals_list.tcl
@@ -30,16 +30,18 @@ dialog variable_trace {
 	text $self.t -yscroll "$self.sb set" -setgrid 1
 	pack $self.sb -side right -fill y
 	pack $self.t -side right -fill both -expand 1
+        set where [set ::[subst $slot(main)](target,self)]
 	if {![send $slot(target) array exists $slot(variable)]} {
-	    set slot(trace_cmd) "send [winfo name .] $self update_scalar"
+	    set slot(trace_cmd) "send $where $self update_scalar"
 	    $self update_scalar "" "" w
 	    set slot(is_array) 0
 	    set title "Trace Scalar"
 	} else {
-	    set slot(trace_cmd) "send [winfo name .] $self update_array"
+	    set slot(trace_cmd) "send $where $self update_array"
 	    set slot(is_array) 1
 	    set title "Trace Array"
 	}
+        $self check_remote_send
 	send $slot(target) \
 	    [list trace variable $slot(variable) wu $slot(trace_cmd)]
 	wm title $self "$title: $slot(target)/$slot(variable)"
@@ -102,6 +104,56 @@ dialog variable_trace {
 	close $fp
 	$slot(main) status "Trace saved to \"$file\"."
     }
+    method check_remote_send {} {
+        # ensure that the current target has a valid send command
+        # This is commonly not the case under Windows.
+        set cmd [send $slot(target) [list info commands ::send]]
+        set type [set ::[subst $slot(main)](target,type)]
+
+        # If we called in using 'comm' then even if we do have a built
+        # in send we need to also support using comm.
+        if {[string match $type "comm"]} {
+            set script {
+                if [string match ::send [info command ::send]] {
+                    rename ::send ::tk_send
+                }
+                proc send {app args} {
+                    if [string match {[0-9]*} $app] {
+                        eval ::comm::comm send [list $app] $args
+                    } else {
+                        eval ::tk_send [list $app] $args
+                    }
+                }
+            }
+            set cmd [send $slot(target) $script]
+            $slot(main) status "comm: $cmd"
+        }
+
+        if {$cmd == {}} {
+            switch -exact -- $type {
+                winsend {
+                    set script {
+                        proc ::send {app args} {
+                            eval winsend send [list $app] $args
+                        }
+                    }
+                    send $slot(target) $script
+                }
+                dde {
+                    set script {
+                        proc send {app args} {
+                            eval dde eval [list $app] $args
+                        }
+                    }
+                    send $slot(target) $script
+                }
+                default {
+                    $slot(main) status "Target requires \"send\" command."
+                }
+            }
+        }
+        return $cmd
+    }
 }
 
 proc create_variable_trace {main target var} {
diff --git a/tkinspect.tcl b/tkinspect.tcl
index 814e2ef..51af45b 100644
--- a/tkinspect.tcl
+++ b/tkinspect.tcl
@@ -227,9 +227,15 @@ dialog tkinspect_main {
     method close {} {
 	after 0 destroy $self
     }
-    method set_target {target} {
+    method set_target {target {type send}} {
         global tkinspect
 	set slot(target) $target
+        set slot(target,type) $type
+        if {$type == "comm"} {
+            set slot(target,self) [comm::comm self]
+        } else {
+            set slot(target,self) [winfo name .]
+        }
 	$self update_lists
 	foreach cmdline $slot(cmdlines) {
 	    $cmdline set_target $target
@@ -271,7 +277,7 @@ dialog tkinspect_main {
             set winsend 1
             foreach interp [winsend interps] {
                 $m add command -label $interp \
-                    -command [list $self set_target $interp]
+                    -command [list $self set_target $interp winsend]
             }
         }
         if {[package provide dde] != {}} {
@@ -284,7 +290,7 @@ dialog tkinspect_main {
                     set app $label
                 }
                 $m add command -label $label \
-                    -command [list $self set_target $app]
+                    -command [list $self set_target $app dde]
             }
         } else {
             foreach interp [winfo interps] {
@@ -303,7 +309,7 @@ dialog tkinspect_main {
 		set label "$interp ([file tail [send $interp set argv0]])"
 	    }
 	    $m add command -label $label \
-		-command [list $self set_target $interp]
+		-command [list $self set_target $interp comm]
 	}
     }
     method status {msg} {
@@ -446,7 +452,7 @@ dialog connect_interp {
 	if ![string match {[0-9]*} $text] return
 	comm::comm connect $text
 	wm withdraw $self
-	$slot(value) set_target $text
+	$slot(value) set_target $text comm
     }
 }
 
-- 
2.23.0