1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
#!/bin/sh
# the next line restarts using wish \
exec wish "$0" -- "$@"
# tkxxdiff
# V1.0, 18 Jun 2007
# A graphic file/directory selector for xxdiff
# philippe.corbes@laposte.net
#--------------------------------------------------
set name "TkxxDiff"
set version "1.0"
set diffappli xxdiff
set font {Helvetica 12}
array set drf {}
array set drd {}
#Init default paramaters
set rootdir "./"
set action "-f"
#Check paramaters
set i 0
set idir 1
while {$i < $argc} {
switch -exact -- [lindex $argv $i] {
"-h" {set action [lindex $argv $i]}
"-d" {set action [lindex $argv $i]}
"-f" {set action [lindex $argv $i]}
default {
set adir [lindex $argv $i]
if { [file isdirectory $adir] } {
set drf($idir) $adir
set drd($idir) $adir
incr idir
}
}
}
incr i
}
while {$idir <= 3} {
set drf($idir) $rootdir
set drd($idir) $rootdir
incr idir
}
#End of check parameters
#Open a new window
if {![info exists w]} {
# tk_messageBox -message "withdraw"
wm withdraw .
set w .tkxxdiff
}
## functions ##
proc compareFiles w {
global diffappli
set n 0
if [string compare [$w.1.ent get] ""] { incr n }
if [string compare [$w.2.ent get] ""] { incr n }
if [string compare [$w.3.ent get] ""] { incr n }
if [expr $n > 1] {
set cmd "$diffappli [$w.1.ent get] [$w.2.ent get] [$w.3.ent get]"
catch {eval exec $cmd }
}
}
proc fileDialog {w ent op} {
global drf
# Type names Extension(s)
#--------------------------------------------
set types {
{"All files" * }
{"text files" {.txt} }
{"source C" {.c} }
{"Include H" {.h} }
}
set fsel [tk_getOpenFile -filetypes $types -parent $w -title "Select file $op" -initialdir $drf($op)]
if [string compare $fsel ""] {
set drf($op) [file dirname $fsel]
$ent delete 0 end
$ent insert 0 $fsel
$ent xview end
};
}
proc compareDirectories w {
global diffappli
set n 0
if [string compare [$w.1.ent get] ""] { incr n}
if [string compare [$w.2.ent get] ""] { incr n}
if [expr $n > 1] {
set cmd "$diffappli [$w.1.ent get] [$w.2.ent get]"
catch {eval exec $cmd }
}
}
proc directoryDialog {w ent op} {
global drd
set d $drd($op)
set fsel [tk_chooseDirectory -title "Select directory $op" -initialdir $d]
if [string compare $fsel ""] {
set drd($op) $fsel
$ent delete 0 end
$ent insert 0 $fsel
$ent xview end
};
}
proc selectPage {{frame {}}} {
global w
if {$frame == ""} { set frame $w.fFiles }
pack forget $w.fFiles
pack forget $w.fDirectories
pack forget $w.fAbout
pack $frame -side right -fill both -expand y
if {$frame == "$w.fFiles"} {
bind $w <F1> [list $w.fFiles.1.but invoke]
bind $w <F2> [list $w.fFiles.2.but invoke]
bind $w <F3> [list $w.fFiles.3.but invoke]
bind $w <Return> [list $w.fFiles.buttons.compare invoke]
bind $w <Escape> [list $w.fFiles.buttons.dismiss invoke]
} else {
if {$frame == "$w.fDirectories"} {
bind $w <F1> [list $w.fDirectories.1.but invoke]
bind $w <F2> [list $w.fDirectories.2.but invoke]
bind $w <F3> continue
bind $w <Return> [list $w.fDirectories.buttons.compare invoke]
bind $w <Escape> [list $w.fDirectories.buttons.dismiss invoke]
} else {
bind $w <F1> continue
bind $w <F2> continue
bind $w <F3> continue
bind $w <Return> continue
bind $w <Escape> [list $w.fDirectories.buttons.dismiss invoke]
}
}
}
## Start to build interface
toplevel $w
wm title $w "$name"
wm iconname $w "$name"
wm geometry $w +100+100
# a series of checkbuttons to act as a poor mans notebook tab
frame $w.notebook -bd 0
pack $w.notebook -side top -fill x -pady 4
set pagelist {}
# Radiobuttons without indicators look rather sucky on MacOSX, so
# we'll tweak the style for that platform
if {$::tcl_platform(os) == "Darwin"} {
set indicatoron true
} else {
set indicatoron false
}
foreach page [list Files Directories About] {
set frame $w.f$page
lappend pagelist $frame
set rb $w.notebook.f$page
radiobutton $rb -command "selectPage $frame" \
-value $frame -height 2 -text $page \
-indicatoron $indicatoron -width 10 -borderwidth 1
pack $rb -side left
frame $frame -bd 2 -relief groove
}
bind $w <Control-f> { $w.notebook.fFiles select; selectPage $w.fFiles}
bind $w <Control-d> { $w.notebook.fDirectories select; selectPage $w.fDirectories}
bind $w <Control-a> { $w.notebook.fAbout select; selectPage $w.fAbout}
#Files panel
set frame $w.fFiles
frame $frame.infos
pack $frame.infos -side top -fill x -pady 20
label $frame.infos.msg -font $font -wraplength 7i -justify left -text "Click on \"Browse...\" buttons to select up to 3 files using a file selection dialog box.\nThen click \"Compare\""
pack $frame.infos.msg -side left -padx 1c
foreach i {1 2 3} {
set f [frame $frame.$i]
label $f.lab -text "File $i: " -anchor e
entry $f.ent -width 40
button $f.but -text "Browse..." -width 9 -command "fileDialog $frame $f.ent $i"
pack $f.lab -side left
pack $f.ent -side left -expand yes -fill x
pack $f.but -side left
pack $f -fill x -padx 1c -pady 3
}
frame $frame.buttons
pack $frame.buttons -side bottom -fill x -pady 2m
button $frame.buttons.dismiss -text Exit -width 8 -default normal -command { wm withdraw $w; exit 0 }
button $frame.buttons.compare -text Compare -width 8 -default active -command "compareFiles $frame"
pack $frame.buttons.compare -side right -padx 1c -pady 5
pack $frame.buttons.dismiss -side right -padx 10 -pady 5
pack forget $frame
#Directories panel
set frame $w.fDirectories
frame $frame.infos
pack $frame.infos -side top -fill x -pady 20
label $frame.infos.msg -font $font -wraplength 7i -justify left -text "Click on \"Browse...\" buttons to select 2 directories using a selection dialog box.\nThen click \"Compare\""
pack $frame.infos.msg -side left -padx 1c
foreach i {1 2} {
set f [frame $frame.$i]
label $f.lab -text "Directory $i: " -anchor e
entry $f.ent -width 40
$f.ent insert 0 $drd($i)
button $f.but -text "Browse..." -command "directoryDialog $frame $f.ent $i"
pack $f.lab -side left
pack $f.ent -side left -expand yes -fill x
pack $f.but -side left
pack $f -fill x -padx 1c -pady 3
}
frame $frame.buttons
pack $frame.buttons -side bottom -fill x -pady 2m
button $frame.buttons.dismiss -text Exit -width 8 -default normal -command { wm withdraw $w; exit 0 }
button $frame.buttons.compare -text Compare -width 8 -default active -command "compareDirectories $frame"
pack $frame.buttons.compare -side right -padx 1c -pady 5
pack $frame.buttons.dismiss -side right -padx 10 -pady 5
pack forget $frame
#About panel
set frame $w.fAbout
frame $frame.infos
pack $frame.infos -side top -fill x -pady 20
set text {$name $version
Copyright (C) 2007
Philippe Corbes
$name is a Tcl/Tk front-end for xxdiff.
Usage:
$argv0 [-f] [-d] [-a] [roots..]
-f Start un file selection mode
-d Star in directory selection mode
-h Display this help
roots Init up to 3 roots directories for file/directory selection
You can use keys:
- <Control-F>, <Control-D> and <Control-A> to switch panels,
- <F1>, <F2> and <F3> to select files and directories,
- <enter> to compare and <escape> to exit.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
set text [subst -nobackslashes -nocommands $text]
label $frame.infos.msg -font $font -wraplength 6i -justify left -text "$text"
pack $frame.infos.msg -side left -padx 1c
pack forget $frame
#Select asked panel
switch -- $action {
"-f" {selectPage $w.fFiles ; $w.notebook.fFiles select }
"-d" {selectPage $w.fDirectories ; $w.notebook.fDirectories select}
default {selectPage $w.fAbout ; $w.notebook.fAbout select}
}
|