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

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cadre Technologies Inc.    1996
  4. #
  5. #      File:           @(#)docsection.tcl    /main/3
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)docsection.tcl    /main/3   5 Jun 1996 Copyright 1996 Cadre Technologies Inc.
  10.  
  11. # Start user added include file section
  12. # End user added include file section
  13.  
  14.  
  15. Class DocSection : {Object} {
  16.     method destructor
  17.     constructor
  18.     method promoter
  19.     method edit
  20.     method show
  21.     method print
  22.     method preview
  23.     method docType
  24.     method escape
  25.     method execute
  26.     method isDocDirUpToDate
  27.     method updateDocDir
  28.     method isDocDirTreeUpToDate
  29.     method docLocation
  30.     method docTitle
  31.     method getTree
  32.     method parentSection
  33.     method childSectionSet
  34.     method addChildSection
  35.     method removeChildSection
  36.     attribute uiType
  37.     attribute initContents
  38.     attribute operationClass
  39.     attribute extension
  40.     attribute indentation
  41.     attribute _parentSection
  42.     attribute document
  43.     attribute _childSectionSet
  44. }
  45.  
  46. method DocSection::destructor {this} {
  47.     set ref [$this _parentSection]
  48.     if {$ref != ""} {
  49.         [$ref _childSectionSet] removeValue $this
  50.     }
  51.     foreach ref [[$this _childSectionSet] contents] {
  52.         $ref _parentSection ""
  53.     }
  54.     # Start destructor user section
  55.     # End destructor user section
  56. }
  57.  
  58. constructor DocSection {class this name document} {
  59.     set this [Object::constructor $class $this $name]
  60.  
  61.     # Don't call promoter twice
  62.     if {! [$this isA BrowsUiObj]} {
  63.         $this promoter
  64.     }
  65.  
  66.     return $this
  67. }
  68.  
  69. method DocSection::promoter {this document} {
  70.     $this document $document
  71.     $this _childSectionSet [List new]
  72.  
  73.     # the default operationClass of a section is import 
  74.     $this operationClass import
  75.     # the default document filetype is an ascii one
  76.     $this indentation 0
  77.  
  78.     set name ""
  79.     regsub -all " |\t" [$this uiName] "" name
  80.  
  81.     if {[$this getPropertyValue fileSystemPath] == ""} {
  82.         set type [$this type]
  83.         if {[regsub -all {:}  $name {_} new]} {set name $new}
  84.         if {[$this extension] != ""} {
  85.             set name ${name}_$type.[$this extension]
  86.         } else {
  87.             set name ${name}_$type
  88.         }
  89.         $this setProperty fileSystemPath $name
  90.     }
  91. }
  92.  
  93. method DocSection::edit {this} {
  94.  
  95.     # default no edit possible
  96.     wmtkerror "No edit possible for this section."
  97. }
  98.  
  99. method DocSection::show {this} {
  100.  
  101.     # default no show possible
  102.     wmtkerror "No show possible for this section."
  103. }
  104.  
  105. method DocSection::print {this} {
  106.     
  107.     # default no print possible
  108.     wmtkerror "No print possible for this section."
  109. }
  110.  
  111. method DocSection::preview {this} {
  112.     
  113.     # default no preview possible
  114.     wmtkerror "No preview possible for this section."
  115. }
  116.  
  117. method DocSection::docType {this} {
  118.  
  119.     # default the doctype and the type are the same
  120.     return [$this type]
  121. }
  122.  
  123. method DocSection::escape {this command} {
  124.  
  125.      set sn $command
  126.      #if {[regsub -all {'}  $sn {\\'}  snn]} {set sn $snn}
  127.      #if {[regsub -all {`}  $sn {\\`}  snn]} {set sn $snn}
  128.      #if {[regsub -all {"}  $sn {\\"}  snn]} {set sn $snn}
  129.      #if {[regsub -all {>}  $sn {\\>}  snn]} {set sn $snn}
  130.      #if {[regsub -all {<}  $sn {\\<}  snn]} {set sn $snn}
  131.      #if {[regsub -all {!}  $sn {\\!}  snn]} {set sn $snn}
  132.      #if {[regsub -all {&}  $sn {\\&}  snn]} {set sn $snn}
  133.      if {[regsub -all {\(}  $sn {\\(}  snn]} {set sn $snn}
  134.      if {[regsub -all {\)}  $sn {\\)}  snn]} {set sn $snn}
  135.      return $sn
  136. }
  137.  
  138. method DocSection::execute {this args} {
  139.  
  140.     # return 0 on error, 1 on succes
  141.  
  142.     if {$args == ""} {
  143.         return 0
  144.     }
  145.  
  146.     set cmd [lindex $args 0]
  147.     set kind [lindex $args 1]
  148.     case "$kind" in {
  149.         {mtool xtool} {
  150.         set msg "Starting `[lindex $cmd 0]`"
  151.         $wmttoolObj startCommand $kind "$cmd" "" "$msg" {0 0} 0
  152.         return 1
  153.         }
  154.         {m4} {
  155.         set m4Cmd [lindex $cmd 0]
  156.         set m4CmdArgs [lindex $cmd 1]
  157.         set obj [lindex $cmd 2]
  158.         $wmttoolObj startM4Command \
  159.             "[$this escape $m4Cmd]" \
  160.             "[$this escape $m4CmdArgs]" \
  161.             "" "$obj"
  162.         return 1
  163.         }
  164.         {default} {
  165.         set sysCmd [lindex $cmd 0]
  166.         set obj [lindex $cmd 1]
  167.         if [system [$this escape "$sysCmd"]] {
  168.             wmtkmessage \
  169.                 "Executing '[lindex $sysCmd 0]' for '$obj' failed"
  170.             return 0
  171.         } else {
  172.             return 1
  173.         }
  174.         }
  175.     }
  176. }
  177.  
  178. method DocSection::isDocDirUpToDate {this} {
  179.     
  180.     # default alway uptodate
  181.     return 1
  182. }
  183.  
  184. method DocSection::updateDocDir {this} {
  185.     
  186.     # default nothing happens
  187.     return 1
  188. }
  189.  
  190. method DocSection::isDocDirTreeUpToDate {this} {
  191.     
  192.     set tree [$this getTree]
  193.     set notUpToDate ""
  194.  
  195.     foreach node $tree {
  196.         if {![$node isDocDirUpToDate]} {
  197.             set notUpToDate "$notUpToDate $node"
  198.         }
  199.     }
  200.  
  201.     return $notUpToDate
  202. }
  203.  
  204. method DocSection::docLocation {this} {
  205.  
  206.     return [$this pathName]
  207. }
  208.  
  209. method DocSection::docTitle {this} {
  210.  
  211.     return [$this uiName]
  212. }
  213.  
  214. method DocSection::getTree {this} {
  215.  
  216.     set tree {}
  217.  
  218.     [$this childSectionSet] foreach sect {    
  219.         set tree "$tree $sect [$sect getTree]"
  220.     }
  221.  
  222.     return $tree
  223. }
  224.  
  225. proc DocSection::isAscii {} {
  226.     return 1
  227. }
  228.  
  229. # Do not delete this line -- regeneration end marker
  230.  
  231. method DocSection::parentSection {this args} {
  232.     if {$args == ""} {
  233.         return [$this _parentSection]
  234.     }
  235.     set ref [$this _parentSection]
  236.     if {$ref != ""} {
  237.         [$ref _childSectionSet] removeValue $this
  238.     }
  239.     set obj [lindex $args 0]
  240.     if {$obj != ""} {
  241.         [$obj _childSectionSet] append $this
  242.     }
  243.     $this _parentSection $obj
  244. }
  245.  
  246. method DocSection::childSectionSet {this} {
  247.     return [$this _childSectionSet]
  248. }
  249.  
  250. method DocSection::addChildSection {this newChildSection} {
  251.     [$this _childSectionSet] append $newChildSection
  252.     $newChildSection _parentSection $this
  253. }
  254.  
  255. method DocSection::removeChildSection {this oldChildSection} {
  256.     $oldChildSection _parentSection ""
  257.     [$this _childSectionSet] removeValue $oldChildSection
  258. }
  259.  
  260.