?? wizard.tcl
字號:
if {[exists $path $node]} {
return -code error "item \"$node\" already exists"
}
eval _insert_$type $path $idx $args
}
proc Wizard::back { path } {
Widget::getVariable $path data
Widget::getVariable $path items
set step [$path raise]
if {![string equal $step ""]} {
set cmd [Widget::cget $items($step) -backcommand]
if {![string equal $cmd ""]} {
set res [uplevel #0 $cmd]
if {!$res} { return }
}
}
set data(order) [lreplace $data(order) end end]
set item [lindex $data(order) end]
$path raise $item
event generate $path <<WizardStep>>
event generate $path <<WizardBack>>
return $item
}
proc Wizard::next { path } {
Widget::getVariable $path data
Widget::getVariable $path items
set step [$path raise]
if {![string equal $step ""]} {
set cmd [Widget::cget $items($step) -nextcommand]
if {![string equal $cmd ""]} {
set res [uplevel #0 $cmd]
if {!$res} { return }
}
}
set item [step $path next]
if {[Widget::cget $items($item) -appendorder]} {
lappend data(order) $item
}
$path raise $item
event generate $path <<WizardStep>>
event generate $path <<WizardNext>>
return $item
}
proc Wizard::cancel { path } {
Widget::getVariable $path items
set step [$path raise]
if {![string equal $step ""]} {
set cmd [Widget::cget $items($step) -cancelcommand]
if {![string equal $cmd ""]} {
set res [uplevel #0 $cmd]
if {!$res} { return }
}
}
event generate $path <<WizardCancel>>
}
proc Wizard::finish { path } {
Widget::getVariable $path items
set step [$path raise]
if {![string equal $step ""]} {
set cmd [Widget::cget $items($step) -finishcommand]
if {![string equal $cmd ""]} {
set res [uplevel #0 $cmd]
if {!$res} { return }
}
}
event generate $path <<WizardFinish>>
}
proc Wizard::help { path } {
Widget::getVariable $path items
set step [$path raise]
if {![string equal $step ""]} {
set cmd [Widget::cget $items($step) -helpcommand]
if {![string equal $cmd ""]} {
uplevel #0 $cmd
}
}
event generate $path <<WizardHelp>>
}
proc Wizard::step { path node {start ""} {traverse 1} } {
Widget::getVariable $path data
Widget::getVariable $path items
Widget::getVariable $path branches
if {![string equal $start ""]} {
if {![exists $path $start]} {
return -code error "item \"$start\" does not exist"
}
}
switch -- $node {
"current" {
set item [$path raise]
}
"end" - "last" {
## Keep looping through 'next' until we hit the end.
set item [$path step next]
while {![string equal $item ""]} {
set last $item
set item [$path step next $item]
}
set item $last
}
"back" - "previous" {
if {[string equal $start ""]} {
set item [lindex $data(order) end-1]
} else {
set idx [lsearch $data(order) $start]
incr idx -1
if {$idx < 0} { return }
set item [lindex $data(order) $idx]
}
}
"next" {
set step [$path raise]
if {![string equal $start ""]} { set step $start }
set branch [$path branch $step]
if {$traverse && [_is_branch $path $step]} {
## This step is a branch. Let's figure out where to go next.
if {[traverse $path $step]} {
## It's ok to traverse into this branch.
## Set step to null so that we'll end up finding the
## first step in the branch.
set branch $step
set step ""
}
}
set idx [lsearch $branches($branch) $step]
incr idx
set item [lindex $branches($branch) $idx]
if {$idx >= [llength $branches($branch)]} {
## We've reached the end of this branch.
## If it's the root branch, or this branch terminates we return.
if {[string equal $branch "root"]
|| [Widget::cget $items($branch) -action] == "terminate"} {
return
}
## We want to merge back with our parent branch.
set item [step $path next $branch 0]
}
## If this step is a branch, find the next step after it.
if {$traverse && [_is_branch $path $item]} {
set item [$path step next $item]
}
}
default {
if {![exists $path $node]} {
return -code error "item \"$node\" does not exist"
}
set item $node
}
}
return $item
}
proc Wizard::nodes { path branch {first ""} {last ""} } {
Widget::getVariable $path data
Widget::getVariable $path branches
if {$first == ""} { return $branches($branch) }
if {$last == ""} { return [lindex $branches($branch) $first] }
return [lrange $data(steps) $first $last]
}
proc Wizard::index { path item } {
Widget::getVariable $path branches
set branch [$path branch $item]
return [lsearch $branches($branch) $item]
}
proc Wizard::raise { path {item ""} } {
Widget::getVariable $path data
Widget::getVariable $path items
set steps $path.steps
set buttons $path.buttons
if {[string equal $item ""]} { return $data(current) }
$path createStep $item
## Eval the global raisecommand if we have one, appending the item.
set cmd [Widget::cget $path -raisecommand]
if {![string equal $cmd ""]} {
uplevel #0 $cmd [list $item]
}
## Eval this item's raisecommand if we have one.
set cmd [Widget::cget $items($item) -raisecommand]
if {![string equal $cmd ""]} {
uplevel #0 $cmd
}
set title [getoption $path $item -title]
wm title [winfo toplevel $path] $title
if {[Widget::cget $path -separator]} {
set txt [getoption $path $item -separatortext]
$path itemconfigure separatortext -text $txt
}
set default [Widget::cget $items($item) -default]
set button [lsearch $data(buttons) $default]
$buttons setfocus $button
$steps raise $item
set data(current) $item
set back [$path step back]
set next [$path step next]
if {[Widget::cget $path -autobuttons]} {
set txt [Widget::cget $items($item) -backtext]
$path itemconfigure back -text $txt -state normal
set txt [Widget::cget $items($item) -nexttext]
$path itemconfigure next -text $txt -state normal
set txt [Widget::cget $items($item) -canceltext]
$path itemconfigure cancel -text $txt -state normal
if {[Widget::cget $path -helpbutton]} {
set txt [Widget::cget $items($item) -helptext]
$path itemconfigure help -text $txt
}
if {[Widget::cget $path -finishbutton]} {
set txt [Widget::cget $items($item) -finishtext]
$path itemconfigure finish -text $txt -state disabled
}
if {[string equal $back ""]} {
$path itemconfigure back -state disabled
}
if {[string equal $next ""]} {
if {[Widget::cget $path -finishbutton]} {
$path itemconfigure next -state disabled
$path itemconfigure finish -state normal
} else {
set txt [Widget::cget $items($item) -finishtext]
$path itemconfigure next -text $txt -command [list $path finish]
}
$path itemconfigure back -state disabled
$path itemconfigure cancel -state disabled
} else {
set txt [Widget::cget $items($item) -nexttext]
$path itemconfigure next -text $txt -command [list $path next]
}
}
event generate $path <<WizardStep>>
if {[string equal $next ""]} { event generate $path <<WizardLastStep>> }
if {[string equal $back ""]} { event generate $path <<WizardFirstStep>> }
return $item
}
proc Wizard::widgets { path command args } {
Widget::getVariable $path items
Widget::getVariable $path widgets
Widget::getVariable $path stepWidgets
switch -- $command {
"set" {
set node [lindex $args 0]
if {[string equal $node ""]} {
set err [BWidget::wrongNumArgsString \
"$path widgets set <name> ?option ..?"]
return -code error $err
}
set args [lreplace $args 0 0]
set item $path.#widget#$node
Widget::init Wizard::Widget $item $args
set step [Widget::cget $item -step]
set widget [Widget::cget $item -widget]
if {[string equal $step ""]} {
set widgets($node) $widget
} else {
set stepWidgets($step,$node) $widget
}
return $widget
}
"get" {
set node [lindex $args 0]
if {[string equal $node ""]} {
return [array names widgets]
}
set args [lreplace $args 0 0]
array set map [list Wizard::Widget {}]
array set map [Widget::parseArgs Wizard::Widget $args]
array set data $map(Wizard::Widget)
if {[info exists data(-step)]} {
set step $data(-step)
} else {
set step [$path step current]
}
## If a widget exists for this step, return it.
if {[info exists stepWidgets($step,$node)]} {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -