From: sls Date: Fri, 10 Feb 1995 11:24:16 +0000 (+0000) Subject: Add save & load. X-Git-Tag: r5_1_1~59 X-Git-Url: https://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=656fd99090476b0842832dc2a96642691c57e58f;p=tkinspect Add save & load. --- diff --git a/value.tcl b/value.tcl index cd9beb1..fba5df3 100644 --- a/value.tcl +++ b/value.tcl @@ -34,10 +34,9 @@ widget value { set m [$slot(main) add_menu Value] $m add command -label "Send Value" -command "$self send_value" $m add command -label "Find..." -command "$self search_dialog" - $m add command -label "Save Value..." -state disabled - $m add command -label "Load Value..." -state disabled + $m add command -label "Save Value..." -command "$self save" + $m add command -label "Load Value..." -command "$self load" $m add command -label "Detach Window" -command "$self detach" - } method reconfig {} { $self.t config -width $slot(width) -height $slot(height) @@ -117,6 +116,31 @@ widget value { $slot(main) status "Search text not found." } } + method save {} { + filechooser $self.fc -newfile 1 -title "Save Value" + set file [$self.fc run] + if ![string length $file] { + $slot(main) status "Save cancelled." + return + } + set fp [open $file w] + puts $fp [$self.t get 1.0 end] + close $fp + $slot(main) status "Value saved to \"$file\"" + } + method load {} { + filechooser $self.fc -title "Load Value" + set file [$self.fc run] + if ![string length $file] { + $slot(main) status "Load cancelled." + return + } + $self.t delete 1.0 end + set fp [open $file r] + $self.t insert 1.0 [read $fp] + close $fp + $slot(main) status "Value read from \"$file\"" + } } dialog value_search {