From a6b4d3502588a293d33c44e807af40cea4cb557f Mon Sep 17 00:00:00 2001
From: William Joye <wjoye@cfa.harvard.edu>
Date: Wed, 3 Jan 2018 14:34:25 -0500
Subject: upgrade to tcl/tk 8.6.8

---
 ds9/library/tkfbox.tcl | 23 +++++++++++++----------
 ds9/library/xmfbox.tcl | 21 +++++++++++----------
 2 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/ds9/library/tkfbox.tcl b/ds9/library/tkfbox.tcl
index 66cd74e..50a9d6c 100644
--- a/ds9/library/tkfbox.tcl
+++ b/ds9/library/tkfbox.tcl
@@ -310,6 +310,7 @@ proc ::tk::dialog::file::Config {dataName type argList} {
 
     # 5. Parse the -filetypes option
     #
+    set data(origfiletypes) $data(-filetypes)
     set data(-filetypes) [::tk::FDGetFileTypes $data(-filetypes)]
 
     if {![winfo exists $data(-parent)]} {
@@ -748,17 +749,17 @@ proc ::tk::dialog::file::ResolveFile {context text defaultext {expandEnv 1}} {
 	set path "$path$defaultext"
     }
 
-     # we want to strip any filtering/ext/blocking instructions 
-     # from the file name
-     
-     set aa [string first "\[" $path]
-     if {$aa > 0} {
+    # we want to strip any filtering/ext/blocking instructions 
+    # from the file name
+    
+    set aa [string first "\[" $path]
+    if {$aa > 0} {
   	set fn [string range $path 0 [expr $aa-1]]
-     } else {
+    } else {
   	set fn $path
-     }
- 
-     if {[catch {file exists $fn}]} {
+    }
+    
+    if {[catch {file exists $fn}]} {
 	# This "if" block can be safely removed if the following code stop
 	# generating errors.
 	#
@@ -1129,7 +1130,9 @@ proc ::tk::dialog::file::Done {w {selectFilePath ""}} {
 	    && [info exists data(filterType)] && $data(filterType) ne ""
 	} then {
 	    upvar #0 $data(-typevariable) typeVariable
-	    set typeVariable [lindex $data(filterType) 0]
+	    set typeVariable [lindex $data(origfiletypes) \
+	            [lsearch -exact $data(-filetypes) $data(filterType)] 0]
+
 	}
     }
     bind $data(okBtn) <Destroy> {}
diff --git a/ds9/library/xmfbox.tcl b/ds9/library/xmfbox.tcl
index fb821c8..41726ce 100644
--- a/ds9/library/xmfbox.tcl
+++ b/ds9/library/xmfbox.tcl
@@ -156,7 +156,7 @@ proc ::tk::MotifFDialog_FileTypes {w} {
     # The filetypes radiobuttons
     # set data(fileType) $data(-defaulttype)
     # Default type to first entry
-    set initialTypeName [lindex $data(-filetypes) 0 0]
+    set initialTypeName [lindex $data(origfiletypes) 0 0]
     if {$data(-typevariable) ne ""} {
 	upvar #0 $data(-typevariable) typeVariable
 	if {[info exists typeVariable]} {
@@ -165,7 +165,7 @@ proc ::tk::MotifFDialog_FileTypes {w} {
     }
     set ix 0
     set data(fileType) 0
-    foreach fltr $data(-filetypes) {
+    foreach fltr $data(origfiletypes) {
 	set fname [lindex $fltr 0]
 	if {[string first $initialTypeName $fname] == 0} {
 	    set data(fileType) $ix
@@ -185,7 +185,7 @@ proc ::tk::MotifFDialog_FileTypes {w} {
     set cnt 0
     if {$data(-filetypes) ne {}} {
 	foreach type $data(-filetypes) {
-	    set title  [lindex [lindex $type 0] 0]
+	    set title  [lindex $type 0]
 	    set filter [lindex $type 1]
 	    ttk::radiobutton $f.b$cnt \
 		-text $title \
@@ -299,6 +299,7 @@ proc ::tk::MotifFDialog_Config {dataName type argList} {
     #    file dialog, but we check for validity of the value to make sure
     #    the application code also runs fine with the TK file dialog.
     #
+    set data(origfiletypes) $data(-filetypes)
     set data(-filetypes) [::tk::FDGetFileTypes $data(-filetypes)]
 
     if {![info exists data(filter)]} {
@@ -739,10 +740,10 @@ proc ::tk::MotifFDialog_BrowseFList {w} {
     $data(fEnt) delete 0 end
     $data(fEnt) insert 0 [::tk::dialog::file::JoinFile $data(selectPath) \
 	    $data(filter)]
-#    $data(fEnt) xview end
- 
-    # if it's a multiple selection box, just put in the filenames 
-    # otherwise put in the full path as usual 
+    $data(fEnt) xview end
+
+    # if it's a multiple selection box, just put in the filenames
+    # otherwise put in the full path as usual
     $data(sEnt) delete 0 end
     if {$data(-multiple) != 0} {
 	$data(sEnt) insert 0 $data(selectFile)
@@ -750,7 +751,7 @@ proc ::tk::MotifFDialog_BrowseFList {w} {
 	$data(sEnt) insert 0 [::tk::dialog::file::JoinFile $data(selectPath) \
 		[lindex $data(selectFile) 0]]
     }
-#    $data(sEnt) xview end
+    $data(sEnt) xview end
 }
 
 # ::tk::MotifFDialog_ActivateFList --
@@ -855,7 +856,7 @@ proc ::tk::MotifFDialog_ActivateSEnt {w} {
    	} else {
    	    set fn $item
    	}
- 	
+
 	if {![file exists $fn]} {
 	    if {$data(type) eq "open"} {
 		tk_messageBox -icon warning -type ok \
@@ -880,7 +881,7 @@ proc ::tk::MotifFDialog_ActivateSEnt {w} {
     if {[info exists data(-typevariable)] && $data(-typevariable) ne ""
 	    && [info exists data(-filetypes)] && $data(-filetypes) ne ""} {
 	upvar #0 $data(-typevariable) typeVariable
-	set typeVariable [lindex $data(-filetypes) $data(fileType) 0]
+	set typeVariable [lindex $data(origfiletypes) $data(fileType) 0]
     }
 
     if {$data(-multiple) != 0} {
-- 
cgit v0.12