home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
histwmttoo.tcl
< prev
next >
Wrap
Text File
|
1997-07-14
|
6KB
|
239 lines
#---------------------------------------------------------------------------
#
# (c) Cayenne Software Inc. 1997
#
# File: @(#)histwmttoo.tcl /main/titanic/1
# Author: <generated>
# Description:
#---------------------------------------------------------------------------
# SccsId = @(#)histwmttoo.tcl /main/titanic/1 14 Jul 1997 Copyright 1997 Cayenne Software Inc.
# Start user added include file section
# End user added include file section
require "wmttool.tcl"
Class HistWmtTool : {WmtTool} {
method destructor
constructor
method insertHistEntry
method removeHistEntry
method renumberHist
method loadHist
method saveHist
method addHistory
method removeHistory
attribute historySet
}
method HistWmtTool::destructor {this} {
# Start destructor user section
# End destructor user section
$this WmtTool::destructor
}
constructor HistWmtTool {class this name} {
set this [WmtTool::constructor $class $this $name]
$this historySet [List new]
return $this
}
method HistWmtTool::insertHistEntry {this entry} {
set l [[$this historySet] length]
if {[isCommand [$this exitButton]]} {
set index [llength [[[$this exitButton] menu] entrySet]]
incr index -3
incr index -$l
} else {
return
}
# entry does not need to exist
set entryLvlPth [$entry levelPath]
[$this historySet] foreach hist {
if {$entryLvlPth != [$hist levelPath]} {
continue
}
$this removeHistory $hist
$hist delete
}
[$this historySet] insert $entry
if {[[$this historySet] length] > 5} {
[[$this historySet] index end] delete
[$this historySet] remove end
}
$this renumberHist
[$this historySet] foreach hist {
$hist index $index
incr index
}
}
method HistWmtTool::removeHistEntry {this levelPath} {
[$this historySet] foreach hist {
if {$levelPath == [$hist levelPath]} {
$this removeHistory $hist
$hist delete
break
}
}
$this renumberHist
}
method HistWmtTool::renumberHist {this} {
set m 1
[$this historySet] foreach entry {
$entry config -label "$m [$entry abbrev]" -mnemonic $m
incr m
}
}
method HistWmtTool::loadHist {this context} {
set history [m4_var get M4_file_history -context $context]
if {"$history" == ""} {
return
}
if {[isCommand [$this exitButton]]} {
set index [[$this exitButton] index]
incr index -1
} else {
# no exit button -> no history
return
}
# be sure to have 5 entries only
set history [lrange $history 0 4]
set mnem 1
foreach levelPath $history {
if {[string index $history 0] != "/"} {
continue
}
set entry [$this mkHistEntry $levelPath $mnem]
$this addHistory $entry
$entry index $index
incr index
incr mnem
}
}
method HistWmtTool::saveHist {this context} {
set history ""
[$this historySet] foreach entry {
lappend history [$entry levelPath]
}
if {$history != [m4_var get M4_file_history -context $context]} {
m4_var set M4_file_history $history -context $context
}
}
proc HistWmtTool::abbrevLevelPath {levelPath} {
set shortPath ""
append levelPath "/"
for {set count 0; set slash [string first "/" $levelPath]} \
{$slash >= 0} \
{incr count; set slash [string first "/" $levelPath]} {
if {$slash != 0} {
set sep ""
set part2 ""
set befSlash $slash
incr befSlash -1
set level [string range $levelPath 0 $befSlash]
if {$count != 2} {
append shortPath "/"
}
case $count in {
1 {
# Corporate: leave out
set part1 ""
}
{2 3} {
# Project and ConfigVersion
set part1 $level
}
default {
# Typed object
set sep "."
}
}
if {$sep != ""} {
set sepPos [string last $sep $level]
if {$sepPos < 0} {
set sep ""
} else {
set befSepPos $sepPos
incr befSepPos -1
set part1 [string range $level \
0 $befSepPos]
if {$count == 4} {
# Do not show type of Phase
set sep ""
} else {
set aftSepPos $sepPos
incr aftSepPos
set part2 [string range \
$level $aftSepPos end]
}
}
}
set part2 [string range $part2 0 2]
append shortPath ${part1}${sep}$part2
}
set aftSlash $slash
incr aftSlash
set levelPath [string range $levelPath $aftSlash end]
}
set maxlen 32
set plen [string length $shortPath]
if {$count < 5 || $plen <= $maxlen} {
return $shortPath
}
set lvlLen ""
set lvlSet [split $shortPath /]
foreach level $lvlSet {
set l [string length $level]
incr l
lappend lvlLen $l
}
set llast [llength $lvlSet]
incr llast -1
set minlb 2
set minhb $llast
incr minhb -1
set minav $maxlen
incr minav -6
incr minav -[lindex $lvlLen 1]
incr minav -[lindex $lvlLen $llast]
if {$minav > 0} {
for {set lb 2} {$lb < $llast} {incr lb} {
set avail $maxlen
incr avail -$plen
incr avail -4
for {set hb $lb} {$hb < $llast} {incr hb} {
incr avail [lindex $lvlLen $hb]
if {$avail > -1} {
if {$avail < $minav} {
set minlb $lb
set minhb $hb
set minav $avail
}
break
}
}
}
}
set lvlSet [lreplace $lvlSet $minlb $minhb ...]
return [join $lvlSet /]
}
# Do not delete this line -- regeneration end marker
method HistWmtTool::addHistory {this newHistory} {
[$this historySet] append $newHistory
}
method HistWmtTool::removeHistory {this oldHistory} {
[$this historySet] removeValue $oldHistory
}