1#!/bin/sh 2# \ 3exec wish "$0" "$@" 4 5# browser.tcl -- 6# 7# A mini XML browser 8# 9# Copyright (c) 2003 Zveno Pty Ltd 10# http://www.zveno.com/ 11# 12# Zveno makes this software and all associated data and documentation 13# ('Software') available free of charge for any purpose. 14# Copies may be made of this software but all of this notice must be included 15# on any copy. 16# 17# The software was developed for research purposes only and Zveno does not 18# warrant that it is error free or fit for any purpose. Zveno disclaims any 19# liability for all claims, expenses, losses, damages and costs any user may 20# incur as a result of using, copying or modifying this software. 21# 22# $Id: browser.tcl,v 1.2 2003/01/17 23:43:29 balls Exp $ 23 24package require dom 25package require domtree 26package require domtext 27 28proc Open {} { 29 global tree text doc view 30 31 set fname [tk_getOpenFile] 32 if {![string length $fname]} { 33 return {} 34 } 35 36 set ch [open $fname] 37 set newdoc [dom::parse [read $ch]] 38 close $ch 39 40 $tree configure -rootnode {} 41 $text configure -rootnode {} 42 catch {dom::destroy $doc} 43 44 set doc $newdoc 45 if {[lsearch $view tree] >= 0} { 46 $tree configure -rootnode $doc 47 } 48 if {[lsearch $view text] >= 0} { 49 $text configure -rootnode $doc 50 } 51 52 return {} 53} 54 55proc View:tree {} { 56 global view 57 58 set view tree 59 60 .controls.view configure -text {Tree & Text} -command View:both 61 62 return {} 63} 64proc View:both {} { 65 global view 66 67 set view {tree text} 68 69 .controls.view configure -text {Tree Only} -command View:tree 70 71 return {} 72} 73 74frame .controls 75button .controls.open -text Open -command Open 76button .controls.view 77View:both 78grid .controls.open .controls.view -sticky w 79 80set p [panedwindow .panes -orient horizontal] 81 82grid .controls -row 0 -column 0 -sticky ew 83grid $p -row 1 -column 0 -sticky news 84grid rowconfigure . 1 -weight 1 85grid columnconfigure . 0 -weight 1 86 87labelframe $p.tree -text {Tree View} 88$p add $p.tree -minsize 200 89set tree [domtree::create $p.tree.t \ 90 -yscrollcommand [list $p.tree.y set] \ 91 -xscrollcommand [list $p.tree.x set]] 92scrollbar $p.tree.y -orient vertical -command [list $p.tree.t yview] 93scrollbar $p.tree.x -orient horizontal -command [list $p.tree.t xview] 94grid $p.tree.t -row 0 -column 0 -sticky news 95grid $p.tree.y -row 0 -column 1 -sticky ns 96grid $p.tree.x -row 1 -column 0 -sticky ew 97grid rowconfigure $p.tree 0 -weight 1 98grid columnconfigure $p.tree 0 -weight 1 99 100labelframe $p.text -text {Source View} 101$p add $p.text -minsize 200 102set text [domtext::create $p.text.t \ 103 -yscrollcommand [list $p.text.y set] \ 104 -xscrollcommand [list $p.text.x set]] 105scrollbar $p.text.y -orient vertical -command [list $p.text.t yview] 106scrollbar $p.text.x -orient horizontal -command [list $p.text.t xview] 107grid $p.text.t -row 0 -column 0 -sticky news 108grid $p.text.y -row 0 -column 1 -sticky ns 109grid $p.text.x -row 1 -column 0 -sticky ew 110grid rowconfigure $p.text 0 -weight 1 111grid columnconfigure $p.text 0 -weight 1 112 113