📄 dialog.tcl
字号:
#
# Tcl Library for TkCVS
#
#
# Smallish dialogs - add, tag
#
if {[catch "image type arr_dn"]} {
workdir_images
}
# Creates the widgets for the dynamic form dialog
proc dialog_FormCreate { title form_data } {
global cvscfg
global dynamic_dialog
global dialog_action
set font_star $cvscfg(dialogfont)
set font_normal $cvscfg(listboxfont)
set font_bold $cvscfg(dialogfont)
set font_italic [font create -family Helvetica -size -12 -slant italic]
if {[winfo exists .dynamic_dialog]} {
destroy .dynamic_dialog
}
set w .dynamic_dialog
toplevel $w
frame $w.form
pack $w.form -side top -fill x
set row 0
foreach {field req type labeltext data} $form_data {
# If you wanted another default, set it in the calling function
if {! [info exists dynamic_dialog($field)]} {
set dynamic_dialog($field) {}
}
if {$type == {l}} {
# Section label
frame $w.form.rule$field -relief groove -borderwidth 2 -height 4
label $w.form.l$field -font $font_bold -text $labeltext
grid $w.form.rule$field -column 0 -row [incr row] -columnspan 3 -sticky ew
grid $w.form.l$field -column 0 -row [incr row] -sticky w
} else {
# It's something else. It has a label and a req though.
label $w.form.l$field -anchor w -text " $labeltext"
label $w.form.r$field -anchor e -foreground red \
-font $font_star -text [expr {$req ? "*" : " "}]
grid $w.form.l$field -column 0 -row [incr row] -sticky w
grid $w.form.r$field -column 1 -row $row -sticky w
if {$type == {t}} {
# It's an entry
entry $w.form.e$field -width 65 \
-textvariable dynamic_dialog($field)
grid $w.form.e$field -column 2 -row $row -sticky w
} elseif {$type == {r}} {
# It's a radiobutton
frame $w.form.f$field
set k 1
foreach {text value} $data {
radiobutton $w.form.f$field$k -text $text -value $value \
-variable dynamic_dialog($field)
pack $w.form.f$field$k -in $w.form.f$field -side left
incr k
}
grid $w.form.f$field -column 2 -row $row -sticky ew
}
}
}
incr row
label $w.form.xstar -anchor e -foreground red \
-font $font_italic -text "* = required field"
grid $w.form.xstar -column 1 -columnspan 2 -row $row -sticky w
frame $w.buttons -relief groove -bd 2
pack $w.buttons -side top -fill x
button $w.ok -text "OK" \
-command "
if {\[dialog_FormComplete $w [list $form_data]\] } {
destroy $w
$dialog_action
exit_cleanup 0
}
"
button $w.apply -text "Apply" \
-command "
if {\[dialog_FormComplete $w [list $form_data]\] } {
$dialog_action
}
"
button $w.close -text "Cancel" \
-command "
destroy $w
exit_cleanup 0
"
pack $w.close $w.apply $w.ok -in $w.buttons -side right \
-ipadx 2 -ipady 2 -padx 4 -pady 4 -fill both -expand 1
wm title $w $title
wm minsize $w 1 1
return
}
proc dialog_FormComplete { w form_data } {
global dynamic_dialog
gen_log:log T "ENTER ($w ...)"
foreach a [array names dynamic_dialog] {
gen_log:log D "$a $dynamic_dialog($a)"
}
set section {}
foreach {field req type labeltext data} $form_data {
if {$type == {l}} {
set section $dynamic_dialog($field)
} else {
if {$req && [set dynamic_dialog($field)] == {}} {
cvsok "$field may not be blank" $w.form
return 0
}
}
}
return 1
}
# Check out a CVS module from the Repository Browser
proc dialog_cvs_checkout { cvsroot module {revtag {} } } {
global dynamic_dialog
global dialog_action
gen_log:log T "ENTER ($cvsroot $module $revtag)"
# Remember tags from last time
if {$revtag == {} && [info exists dynamic_dialog(revtag)]} {
set revtag $dynamic_dialog(revtag)
}
set dir [pwd]
set dynamic_dialog(cvsroot) $cvsroot
set dynamic_dialog(module) $module
set dynamic_dialog(revtag) $revtag
set dynamic_dialog(dir) $dir
set dynamic_dialog(prune) {-P}
set dynamic_dialog(kflag) {}
# field req type labeltext data
set dialog_form_checkout {
1 0 l {CVS Repository} 1
cvsroot 1 t {CVSROOT} {}
2 0 l {Module} 1
module 1 t {Name/Path} {}
revtag 0 t {Revision/Tag} {}
date 0 t {Date} {}
3 0 l {Destination} 1
dir 1 t {Current Directory} {}
target 0 t {Working Directory} {}
4 0 l {Merge } 0
mtag1 0 t {Old tag} {}
mtag2 0 t {New tag} {}
5 0 l {Advanced} 0
prune 0 r {Empty Directories} {{Create} {}
{Don't Create} {-P}}
kflag 0 r {Keyword Expansion} {{Default} {}
{Keep as-is} {-ko}
{Treat files as binary} {-kb}
{Keywords only} {-kk}}
}
# Action function
set dialog_action {cvs_checkout $dynamic_dialog(dir) \
$dynamic_dialog(cvsroot) \
$dynamic_dialog(prune) $dynamic_dialog(kflag) \
$dynamic_dialog(revtag) $dynamic_dialog(date) $dynamic_dialog(target) \
$dynamic_dialog(mtag1) $dynamic_dialog(mtag2) $dynamic_dialog(module)
}
set form [dialog_FormCreate "Checkout Module" $dialog_form_checkout]
gen_log:log T "LEAVE"
}
# Export a CVS module from the Repository Browser
proc dialog_cvs_export { cvsroot module {revtag {}} } {
global dynamic_dialog
global dialog_action
gen_log:log T "ENTER ($cvsroot $module $revtag)"
# Remember tags from last time
if {$revtag == {} && [info exists dynamic_dialog(revtag)]} {
set revtag $dynamic_dialog(revtag)
}
set dir [pwd]
set dynamic_dialog(cvsroot) $cvsroot
set dynamic_dialog(module) $module
set dynamic_dialog(revtag) $revtag
set dynamic_dialog(dir) $dir
# field req type labeltext data
set dialog_form_export {
1 0 l {CVS Repository} 1
cvsroot 1 t {CVSROOT} {}
2 0 l {Module} 1
module 1 t {Name/Path} {}
revtag 0 t {Revision/Tag} {}
date 0 t {Date} {}
3 0 l {Destination} 1
dir 1 t {Current Directory} {}
target 0 t {Target Directory} {}
4 0 l {Advanced} 0
kflag 0 r {Keyword Expansion} {{Default} {}
{Keep as-is} {-ko}
{Treat files as binary} {-kb}
{Keywords only} {-kk}}
}
# Action function
set dialog_action {cvs_export $dynamic_dialog(dir) \
$dynamic_dialog(cvsroot) $dynamic_dialog(kflag) \
$dynamic_dialog(revtag) $dynamic_dialog(date) \
$dynamic_dialog(target) $dynamic_dialog(module)
}
set form [dialog_FormCreate "Export Module" $dialog_form_export]
gen_log:log T "LEAVE"
}
# Checkout or Export a SVN module from the Repository Browser
proc dialog_svn_checkout { svnroot path command } {
global dynamic_dialog
global dialog_action
if {[info exists dynamic_dialog(rev)]} {
set rev $dynamic_dialog(rev)
}
set dir [pwd]
set dynamic_dialog(path) $path
set dynamic_dialog(svnroot) $svnroot
set dynamic_dialog(command) $command
set dynamic_dialog(dir) $dir
# field req type labeltext data
set dialog_form_export {
1 0 l {SVN Repository} 1
svnroot 1 t {SVN URL} {}
path 1 t {Path in Repository} {}
rev 0 t {Revision/Date} {}
2 0 l {Destination} 1
dir 1 t {Current Directory} {}
target 0 t {Target Directory} {}
3 0 l {Working Copy or Unversioned Copy} {}
command 0 r {Versioning} {{Versioned (Checkout)} {checkout}
{Un-Versioned (Export)} {export}}
}
# Action function
set dialog_action {svn_checkout $dynamic_dialog(dir) \
$dynamic_dialog(svnroot) $dynamic_dialog(path) \
$dynamic_dialog(rev) $dynamic_dialog(target) \
$dynamic_dialog(command)
}
set form [dialog_FormCreate "Checkout or Export" $dialog_form_export]
gen_log:log T "LEAVE"
}
# Make a branch or tag (svn copy) from the Repository Browser
proc dialog_svn_copy { svnroot path kind } {
global dynamic_dialog
global dialog_action
set dynamic_dialog(path) $path
set dynamic_dialog(svnroot) $svnroot
set dynamic_dialog(dir) $svnroot/$kind
#set dynamic_dialog(kind) $kind
# field req type labeltext data
set dialog_form_copy {
1 0 l {SVN Repository} 1
svnroot 1 t {SVN URL} {}
path 1 t {Path in Repository} {}
2 0 l {Destination} 1
dir 1 t {Destination URL} {}
target 1 t {New Branch/Tag} {}
}
# Action function
set dialog_action {svn_rcopy $dynamic_dialog(svnroot)/$dynamic_dialog(path) \
$dynamic_dialog(dir)/$dynamic_dialog(target)
}
set form [dialog_FormCreate "SVN Copy" $dialog_form_copy]
gen_log:log T "LEAVE"
}
# Compare two revisions of a module, from the module browser
# Can make a patch file or send a summary to the screen
proc dialog_cvs_patch { cvsroot module summary {revtagA {}} {revtagB {}} } {
global dynamic_dialog
global dialog_action
gen_log:log T "ENTER ( $cvsroot $module $summary $revtagA $revtagB )"
# Remember tags
if {$revtagA == {} && [info exists dynamic_dialog(revtagA)]} {
set revtagA $dynamic_dialog(revtagA)
}
if {$revtagB == {} && [info exists dynamic_dialog(revtagB)]} {
set revtagB $dynamic_dialog(revtagB)
}
set dynamic_dialog(cvsroot) $cvsroot
set dynamic_dialog(module) $module
set dynamic_dialog(revtagA) $revtagA
set dynamic_dialog(revtagB) $revtagB
set dynamic_dialog(outfile) "$module.patch"
if {$summary} {
set dynamic_dialog(outmode) 0
set dynamic_dialog(difffmt) {-s}
} else {
set dynamic_dialog(outmode) 1
set dynamic_dialog(difffmt) {}
}
# field req type labeltext data
set dialog_form_patch {
1 0 l {CVS Repository} 1
cvsroot 1 t {CVSROOT} {}
2 0 l {Module} 1
module 1 t {Name/Path} {}
3 0 l {Destination} 1
outmode 0 r {Output Mode} {{To Screen} 0 {To File} 1}
outfile 0 t {Output File} {outfile}
4 0 l {Old Revision} 1
revtagA 0 t {Revision/Tag} {}
dateA 0 t {Date} {}
5 0 l {New Revision} 1
revtagB 0 t {Revision/Tag} {}
dateB 0 t {Date} {}
6 0 l {Format} 1
difffmt 0 r {Diff Format} {{Default} {}
{Context diff} {-c}
{Unidiff} {-u}
{One liner} {-s}}
}
# Action function
set dialog_action {cvs_patch $dynamic_dialog(cvsroot) \
$dynamic_dialog(module) $dynamic_dialog(difffmt) \
$dynamic_dialog(revtagA) $dynamic_dialog(dateA) \
$dynamic_dialog(revtagB) $dynamic_dialog(dateB) \
$dynamic_dialog(outmode) $dynamic_dialog(outfile)
}
set form [dialog_FormCreate "Diff/Patch Module" $dialog_form_patch]
gen_log:log T "LEAVE"
}
# Compare two revisions, from the module browser
# Can make a patch file or send a summary to the screen
proc dialog_svn_patch { cvsroot pathA pathB summary } {
global dynamic_dialog
global dialog_action
gen_log:log T "ENTER ( $cvsroot $pathA $pathB $summary )"
set dynamic_dialog(cvsroot) $cvsroot
set dynamic_dialog(pathA) $pathA
set dynamic_dialog(pathB) $pathB
if {$summary} {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -