home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / vssystem.tcl < prev    next >
Text File  |  1997-06-06  |  10KB  |  394 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1997
  4. #
  5. #      File:           @(#)vssystem.tcl    /main/hindenburg/8
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)vssystem.tcl    /main/hindenburg/8   6 Jun 1997 Copyright 1997 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12. # End user added include file section
  13.  
  14.  
  15. # This class represents a VCM aware system.
  16.  
  17. Class VSSystem : {Object} {
  18.     constructor
  19.     method destructor
  20.     method vsFiles
  21.     method path
  22.     method getPathList
  23.     method updatePath
  24.     method localFileVersions
  25.     method copy
  26.     method findVSFile
  27.     method createVSFile
  28.     method importVSFile
  29.     method getFileName
  30.     method getObjectName
  31.     method objectToFileName
  32.     method getType
  33.     method getTypeSpec
  34.     method typeMapper
  35.  
  36.     # Cache for path name of this system in user
  37.     # environment.
  38.     #
  39.     attribute _path
  40.  
  41.     attribute _OTPath
  42.  
  43.     # Path list for this system.
  44.     #
  45.     attribute _pathList
  46.     attribute _typeMapper
  47. }
  48.  
  49. constructor VSSystem {class this name} {
  50.     set this [Object::constructor $class $this $name]
  51.     # Start constructor user section
  52.     # End constructor user section
  53.     return $this
  54. }
  55.  
  56. method VSSystem::destructor {this} {
  57.     set ref [$this _typeMapper]
  58.     if {$ref != ""} {
  59.         $ref _system ""
  60.     }
  61.     # Start destructor user section
  62.     # End destructor user section
  63. }
  64.  
  65.  
  66. # Returns all the vsFiles in this system, using
  67. # VCM specific list mechanisms implemented in fileList.
  68. # For each file found a VSFile is created and the result
  69. # is a list containing all these objects.
  70. #
  71. method VSSystem::vsFiles {this} {
  72.     set vsFileList {}
  73.  
  74.     # find VS files and return them
  75.     foreach fileName [$this fileList [$this getPathList]] {
  76.     set name [path_name base $fileName]
  77.     set type [$this getType $name [path_name type $fileName]]
  78.     set objectName [$this getObjectName $name $type]
  79.     if { ![isCommand $objectName] } {
  80.         set vsFile [VSFile new $objectName $type $this]
  81.         $this promoteFile $vsFile
  82.     }
  83.     # only show files of known type
  84.     if { [$objectName type] != "" } {
  85.         lappend vsFileList $objectName
  86.     }
  87.     }
  88.     return $vsFileList
  89. }
  90.  
  91.  
  92. # Redefinition of default path method that uses
  93. # vsObjectUserPath.
  94. #
  95. method VSSystem::path {this} {
  96.     set needUpdate 0
  97.     if { [$this _path] == "" } {
  98.     set needUpdate 1
  99.     } else {
  100.     # check if cached path is still valid by checking OTpath
  101.     if { [$this _OTPath] != [$this SystemVersion::path] } {
  102.         set needUpdate 1
  103.     }
  104.     } 
  105.  
  106.     if $needUpdate {
  107.     $this _path [$this vsUserPath]
  108.     $this _OTPath [$this SystemVersion::path]
  109.     }
  110.  
  111.     return [$this _path]
  112. }
  113.  
  114.  
  115. # Returns list of paths where files of this system are stored.
  116. #
  117. method VSSystem::getPathList {this} {
  118.     set needUpdate 0
  119.     if { [$this _pathList] == "" } {
  120.     set needUpdate 1
  121.     } else {
  122.     # check if cached path is still valid by checking OTpath
  123.     if { [$this _OTPath] != [$this SystemVersion::path] } {
  124.         set needUpdate 1
  125.     }
  126.     } 
  127.  
  128.     if $needUpdate {
  129.     $this updatePath
  130.     $this _OTPath [$this SystemVersion::path]
  131.     set pathList {}
  132.     foreach type [[$this typeMapper] typeList] {
  133.         set filePath [path_name directory [$this vsFileUserPath dummy $type]]
  134.         # check existence of path. This cannot be done with lsearch
  135.         # because it does not work well with windows pathnames
  136.         set existsInList 0
  137.         foreach path $pathList {
  138.         if { [file_split $path] == [file_split $filePath] } {
  139.             set existsInList 1
  140.         }
  141.         }
  142.         if !$existsInList {
  143.         lappend pathList $filePath
  144.         }
  145.     }
  146.     $this _pathList $pathList
  147.     }
  148.  
  149.     return [$this _pathList]
  150. }
  151.  
  152.  
  153. # Forces system to update its path (stored in _path).
  154. #
  155. method VSSystem::updatePath {this} {
  156.     $this _path ""
  157.     $this _pathList ""
  158. }
  159.  
  160.  
  161. # Return localFileVersions of a VCM aware system.
  162. #
  163. method VSSystem::localFileVersions {this} {
  164.     return ""
  165. }
  166.  
  167.  
  168. # Perform copy of VSFile to this system.
  169. # Needed for Edit and drag'n drop operations.
  170. #
  171. method VSSystem::copy {this vsFile} {
  172.     # make new object
  173.     set type [$vsFile type]
  174.     set objectName [$this getObjectName [$vsFile name] $type]
  175.     set newVSFile [VSFile new $objectName $type $this]
  176.     
  177.     # check if copy succeeded
  178.     if { $newVSFile == "" } {
  179.     return ""
  180.     }
  181.  
  182.     $this promoteFile $newVSFile
  183.  
  184.     # if creation in the VCM system fails remove the object
  185.     if { ![$this fileExists [$vsFile name] $type] } {
  186.     set comment "Copied from [$vsFile vsPath]"
  187.     if { ![$newVSFile createInVS [list "$comment"]] } {
  188.         # check if it really was not created
  189.         if { ![$this fileExists [$vsFile name] $type] } {
  190.         $newVSFile delete
  191.         return ""
  192.         }
  193.     }    
  194.     } else {
  195.     wmtkinfo "File [$vsFile vsPath] already exists"
  196.     return ""
  197.     }
  198.  
  199.     # check out if necessary
  200.     set userPath [$newVSFile path]
  201.     if { ![$newVSFile isCheckedOut] } {
  202.     set comment "Copied from [$vsFile vsPath]"
  203.     if { ![$newVSFile checkOut $comment] } {
  204.         return ""
  205.     }
  206.     }
  207.  
  208.     # get reference to old file and perform the copy
  209.     set source [$vsFile getReference]
  210.     if [catch { BasicFS::copyFile $source $userPath } message] {
  211.     vsCommandHandler error "Copying [$vsFile path]: $message"
  212.     }
  213.     $vsFile deleteReference $source
  214.  
  215.     # copy class attribute
  216.     $newVSFile setClass [$vsFile getClass]
  217.     return $newVSFile
  218. }
  219.  
  220.  
  221. # Find the object for the VSFile with the given name
  222. # and return it.
  223. #
  224. method VSSystem::findVSFile {this name type} {
  225.     set object [$this getObjectName $name $type]
  226.     if [isCommand $object] {
  227.         return $object
  228.     }
  229.     return ""
  230. }
  231.  
  232.  
  233. # Creates the file with the given name in this system 
  234. # and in the VCM environment. Returns resulting object.
  235. # If this action succeeds a checked out copy is in the 
  236. # user environment.
  237. #
  238. method VSSystem::createVSFile {this name type args} {
  239.     set objectName [$this getObjectName $name $type]
  240.     set newVSFile [VSFile new $objectName $type $this]
  241.     if { $newVSFile == "" } {
  242.     return ""
  243.     }
  244.  
  245.     # promote it to a specific VCM object
  246.     $this promoteFile $newVSFile
  247.  
  248.     # if creation in the VCM system fails remove the object
  249.     if { ![$newVSFile createInVS $args] } {
  250.     # check if the file does not exist, keep the link if it does
  251.     if { ![$this fileExists $name $type] } {
  252.         $newVSFile delete
  253.         return ""
  254.     }
  255.     }
  256.  
  257.     return $newVSFile
  258. }
  259.  
  260.  
  261. # Creates an object for the file specified by name and type (precondition: it exists in the VCM)
  262. # and returns the resulting VSFile object. 
  263. #
  264. method VSSystem::importVSFile {this name type} {
  265.     set objectName [$this getObjectName $name $type]
  266.     set newVSFile [VSFile new $objectName $type $this]
  267.     if { $newVSFile == "" } {
  268.     return ""
  269.     }
  270.  
  271.     # promote it to a specific VCM object
  272.     $this promoteFile $newVSFile
  273.     return $newVSFile
  274. }
  275.  
  276.  
  277. # Create the specified path in the VCM environment
  278. # by calling the createVSDirectory for each
  279. # path name component that does not yet
  280. # exist. This indicates the class of this system, used
  281. # to work around limitations of OO Tcl.
  282. #
  283. proc VSSystem::createVSPath {this path} {
  284.     set dirList ""
  285.     while { ![file isdirectory $path] } {
  286.     set dirList "[quoteIf [path_name file $path]] $dirList"
  287.     set path [path_name directory $path]
  288.     }
  289.  
  290.     # create the directories one by one
  291.     foreach directory $dirList {
  292.     set path [path_name concat $path $directory]
  293.     if { ![$this::createVSDirectory $path] } {
  294.         return 0
  295.     }
  296.     }
  297.     return 1
  298. }
  299.  
  300.  
  301. # Create the specified path in the user environment
  302. # by calling createUserDirectory for each
  303. # path name component that does not yet exist.
  304. #
  305. proc VSSystem::createUserPath {this path} {
  306.     set dirList ""
  307.     while { ![file isdirectory $path] } {
  308.     set dirList "[quoteIf [path_name file $path]] $dirList"
  309.     set path [path_name directory $path]
  310.     }
  311.  
  312.     # create the directories one by one
  313.     foreach directory $dirList {
  314.     set path [path_name concat $path $directory]
  315.     if { ![$this::createUserDirectory $path] } {
  316.         return 0
  317.     }
  318.     }
  319.     return 1
  320. }
  321.  
  322.  
  323. # Returns the (file system) file name for a file with 
  324. # the given name and (browser) type.
  325. #
  326. method VSSystem::getFileName {this name type} {
  327.     set fsExtension [[$this typeMapper] getExtension $type]
  328.     if { $fsExtension == "" } {
  329.     return $name
  330.     }
  331.     return "$name.$fsExtension"
  332. }
  333.  
  334.  
  335. # Get object name for file object with given name
  336. # and type.
  337. #
  338. method VSSystem::getObjectName {this name type} {
  339.     regsub -all {\.} [$this identity] "_" sysId
  340.     if { $type == "" } {
  341.         return "${sysId}_VSFile:$name"
  342.     }
  343.     return "${sysId}_VSFile:${name}_$type"
  344. }
  345.  
  346.  
  347. # Maps an object id of a VSFile to a filename.
  348. #
  349. method VSSystem::objectToFileName {this objectId} {
  350.     regsub {.*_VSFile:} $objectId "" fileSpec
  351.     regsub {_[^_]*} $fileSpec "" name
  352.     return $name
  353. }
  354.  
  355.  
  356. # Returns ObjectTeam type for file with given
  357. # name and file system extension.
  358. #
  359. method VSSystem::getType {this name extension} {
  360.     return [[$this typeMapper] getType $name $extension]
  361. }
  362.  
  363.  
  364. # Gets the object specification for the specified browserType.
  365. #
  366. method VSSystem::getTypeSpec {this browserType} {
  367.     set typeSpec [[$this getObjHandler] getObjectSpec ExternalFileVersion \
  368.             $browserType]
  369.  
  370.     if { $typeSpec == "" } {
  371.         vsCommandHandler error "Unknown object type '$browserType'"
  372.     }
  373.  
  374.     return $typeSpec
  375. }
  376.  
  377. # Do not delete this line -- regeneration end marker
  378.  
  379. method VSSystem::typeMapper {this args} {
  380.     if {$args == ""} {
  381.         return [$this _typeMapper]
  382.     }
  383.     set ref [$this _typeMapper]
  384.     if {$ref != ""} {
  385.         $ref _system ""
  386.     }
  387.     set obj [lindex $args 0]
  388.     if {$obj != ""} {
  389.         $obj _system $this
  390.     }
  391.     $this _typeMapper $obj
  392. }
  393.  
  394.