home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
custedarea.tcl
< prev
next >
Wrap
Text File
|
1997-12-05
|
11KB
|
451 lines
#---------------------------------------------------------------------------
#
# (c) Cayenne Software Inc. 1997
#
# File: @(#)custedarea.tcl /main/titanic/9
# Author: <generated>
# Description:
#---------------------------------------------------------------------------
# SccsId = @(#)custedarea.tcl /main/titanic/9 5 Dec 1997 Copyright 1997 Cayenne Software Inc.
# Start user added include file section
require custfileut.tcl
# End user added include file section
Class CustEdArea : {Object} {
constructor
method destructor
method load
method edit
method save
method quit
method readCorporateObjects
method readUserObjects
method readUpperLevelsObjects
method readLevelObjects
method read
method deleteObjects
method redefineObject
method adjustCreatedObject
method setContext
method sortArea
method source
method filter
attribute isChanged
attribute isReadOnly
attribute userLevelAlwaysLast
attribute toolType
attribute _curName
attribute _curType
attribute _path
attribute _scope
attribute _level
attribute _module
attribute _repObj
attribute _filter
}
constructor CustEdArea {class this name} {
set this [Object::constructor $class $this $name]
$this isChanged 0
$this isReadOnly 0
$this userLevelAlwaysLast 0
$this toolType "browser"
# Start constructor user section
# End constructor user section
return $this
}
method CustEdArea::destructor {this} {
set ref [$this _filter]
if {$ref != ""} {
$ref _editorArea ""
}
# Start destructor user section
# End destructor user section
}
proc CustEdArea::indentList {list indentLevel protect} {
set indents ""
for {set i 0} {$i < $indentLevel} {incr i} {
set indents "$indents\t"
}
set indList " \{"
while {![lempty $list]} {
set key [lvarpop list]
set value [lvarpop list]
if {[string length $key] > 7} {
set tabs "\t"
} else {
set tabs "\t\t"
}
if {$protect == 1} {
set strVal [string trim $value]
if {[regexp {[ ]} $strVal]==1 || $strVal==""} {
set indList "$indList\n\t$indents$key$tabs\{$value\}"
} else {
set indList "$indList\n\t$indents$key$tabs$value"
}
} else {
set indList "$indList\n\t$indents$key$tabs$value"
}
}
set indList "$indList\n$indents\}\n"
return $indList
}
method CustEdArea::load {this obj} {
$this isReadOnly 1
$this isChanged 0
if [isCommand $obj] {
$this _repObj $obj
$this _curName [[[$this _repObj] customFile] name]
$this _curType [[[$this _repObj] customFile] type]
$this readUpperLevelsObjects
if [$this userLevelAlwaysLast] {
$this readLevelObjects
$this readUserObjects
} else {
$this readUserObjects
$this readLevelObjects
}
} else {
# if user or corporate is the case, the name of the
# file is given
# [$this _curName].[$this _curType]
$this _repObj ""
set index [string last "." $obj]
$this _curName [string range $obj 0 [expr {$index -1}]]
$this _curType [string range $obj [expr {$index +1}] end]
$this readCorporateObjects
if {"[$this _level]" == "user"} {
$this readUserObjects
}
}
$this sortArea
[$this filter] rehash
}
method CustEdArea::edit {this obj} {
$this isReadOnly 1
$this isChanged 0
if {[isCommand $obj]} {
# lock the object
if {[$this _repObj] != $obj || [.main currentlyReadOnly]} {
$obj edit
$this _repObj $obj
$this _curName [[[$this _repObj] customFile] name]
$this _curType [[[$this _repObj] customFile] type]
}
$this readUpperLevelsObjects
if [$this userLevelAlwaysLast] {
$this isReadOnly 0
$this readLevelObjects
$this isReadOnly 1
$this readUserObjects
$this isReadOnly 0
} else {
$this readUserObjects
$this isReadOnly 0
$this readLevelObjects
}
} else {
# if user or corporate is the case, the name of the
# file is given
# [$this _curName].[$this _curType]
$this _repObj ""
set index [string last "." $obj]
$this _curName [string range $obj 0 [expr {$index -1}]]
$this _curType [string range $obj [expr {$index +1}] end]
if {"[$this _level]" == "user"} {
$this readCorporateObjects
$this isReadOnly 0
$this readUserObjects
} else {
$this isReadOnly 0
$this readCorporateObjects
}
}
$this sortArea
[$this filter] rehash
}
method CustEdArea::save {this} {
set tmpFile [args_file {}]
set fid [open $tmpFile w]
foreach object [$this getObjects] {
if [$object editable] {
$this writeObject $object $fid
}
}
close $fid
if {[$this _level] == "user"} {
set file [path_name concat \
[path_name concat ~ icase] \
[$this _curName].[$this _curType] \
]
copy_text_file $tmpFile $file
} elseif {[$this _level] == "corporate"} {
set file [location [m4_var get M4_home] etc \
[$this _curName].[$this _curType]]
copy_text_file $tmpFile $file
} else {
[$this _repObj] upLoad $tmpFile
}
unlink $tmpFile
$this isChanged 0
}
method CustEdArea::quit {this} {
if [isCommand [$this _repObj]] {
[$this _repObj] quit
}
}
method CustEdArea::readCorporateObjects {this} {
set corp [[ClientContext::global] currentCorporate]
$this read $corp corporate
}
method CustEdArea::readUserObjects {this} {
eval "proc registerObject {spec} {$this createObject \$spec user}"
set file [path_name concat [path_name concat ~ icase] \
[$this _curName].[$this _curType]]
if [file exists $file] {
$this source $file
}
}
method CustEdArea::readUpperLevelsObjects {this} {
# read all the levels up to the current level
set name [$this _curName]
set type [$this _curType]
case [$this _level] in {
{corporate} {
}
{project} {
$this read [lindex [$this _path] 0] corporate
}
{configuration} {
$this read [lindex [$this _path] 0] corporate
$this read [lindex [$this _path] 1] project
}
{phase} {
$this read [lindex [$this _path] 0] corporate
$this read [lindex [$this _path] 1] project
$this read [lindex [$this _path] 2] configuration
}
{system} {
$this read [lindex [$this _path] 0] corporate
$this read [lindex [$this _path] 1] project
$this read [lindex [$this _path] 2] configuration
$this read [lindex [$this _path] 3] phase
}
}
}
method CustEdArea::readLevelObjects {this} {
eval "proc registerObject {spec} {$this createObject \$spec \
[$this _level]}"
if {![[$this _repObj] isNil]} {
set tmpFile [args_file {}]
[$this _repObj] downLoad $tmpFile
$this source $tmpFile
unlink $tmpFile
}
}
method CustEdArea::read {this object type} {
eval "proc registerObject {spec} {$this createObject \$spec $type}"
set custFile [CustFileUtilities::find $object [$this _curName] \
[$this _curType]]
if {"$custFile" == ""} return
if {"$object" == "" || [$object isA Corporate]} {
$this source $custFile
# read also the modules
set moduleHdlr [.main moduleHdlr]
set modules [$moduleHdlr moduleSpecSet]
foreach module $modules {
set files [$moduleHdlr getFiles etc \
[$this _curName].[$this _curType] $module]
foreach file $files {
$this _module [$module name]
$this source $file
}
}
$this _module ""
} else {
set tmpFile [args_file {}]
$custFile downLoad $tmpFile
$this source $tmpFile
unlink $tmpFile
}
}
method CustEdArea::deleteObjects {this objs} {
foreach i $objs {
$i delete
$this isChanged 1
}
.main selectionChanged
}
method CustEdArea::redefineObject {this obj} {
if {[$obj readOnly]} {
return "Object to redefine is read-only defined on level \
[$obj specLevel]"
}
set user 0
if {[$this _level] == "user"} {
set user 1
}
# use as much of the scope of the redefined object
set scope [$this _scope]
for {set i [llength $scope]} {$i < [llength [$obj scope]]} {incr i} {
lappend scope [lindex [$obj scope] $i]
}
# make an exact copy
set newObj [$this createObject [list displayName [$obj displayName] \
scope $scope \
specLevel [$this _level] \
name [$obj name] \
unregister [$obj unregister] \
type [$obj type] \
userDefined $user \
visible [$obj visible] \
objSpec [$obj objSpec]] \
[$this _level]]
$newObj editable 1
return $newObj
}
method CustEdArea::adjustCreatedObject {this obj level} {
if {![$this isReadOnly]} {
$obj editable 1
# if invalid scope (level) specified, set scope to corporate
if {$icaseLevel([llength [$obj scope]]) == ""} {
$obj scope ""
}
}
if {$level == "user"} {
$obj userDefined 1
}
if {[$this _module] != ""} {
$obj specModule "[$this _module]"
$obj specLevel "module: [$this _module]"
} else {
$obj specLevel $level
}
}
method CustEdArea::setContext {this} {
set cc [ClientContext::global]
set corp [$cc currentCorporate]
set proj [$cc currentProject]
set confV [$cc currentConfig]
set phaseV [$cc currentPhase]
set sysV [$cc currentSystem]
set path ""
set scope ""
if {! [$corp isNil]} {
$this _level corporate
lappend path $corp
if {! [$proj isNil]} {
$this _level project
lappend path $proj
lappend scope *
if {! [$confV isNil]} {
$this _level configuration
lappend path $confV
lappend scope *
if {! [$phaseV isNil]} {
$this _level phase
lappend path $phaseV
lappend scope *
if {! [$sysV isNil]} {
$this _level system
lappend path $sysV
lappend scope *
}
}
}
}
}
$this _scope $scope
$this _path $path
}
method CustEdArea::sortArea {this} {
# no sort done in general, only in specific cases
}
method CustEdArea::source {this fileName} {
if [catch {
set fid [open $fileName]
set l [List new -contents [read $fid]]
close $fid
set end [$l length]
for {set i 1} {$i <= $end} {incr i 2} {
registerObject [$l index $i]
}
} rsn] {
wmtkerror $rsn
}
}
# Do not delete this line -- regeneration end marker
method CustEdArea::filter {this args} {
if {$args == ""} {
return [$this _filter]
}
set ref [$this _filter]
if {$ref != ""} {
$ref _editorArea ""
}
set obj [lindex $args 0]
if {$obj != ""} {
$obj _editorArea $this
}
$this _filter $obj
}