home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / extfuiobj.tcl < prev    next >
Encoding:
Text File  |  1996-12-02  |  11.4 KB  |  458 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1996
  4. #
  5. #      File:           @(#)extfuiobj.tcl    /main/hindenburg/2
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)extfuiobj.tcl    /main/hindenburg/2   2 Dec 1996 Copyright 1996 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12. # End user added include file section
  13.  
  14. require "browsuiobj.tcl"
  15.  
  16. Class ExtFUiObj : {BrowsUiObj} {
  17.     constructor
  18.     method destructor
  19.     method addExternalFile
  20.     method browserType
  21.     method editFile
  22.     method externalFiles
  23.     method hasChildren
  24.     method initializeInfo
  25.     method openFile
  26.     method printObjects
  27.     method referredFile
  28.     method removeObjects
  29.     method showFile
  30.     attribute directory
  31.     attribute isAscii
  32.     attribute isDirectory
  33.     attribute pattern
  34. }
  35.  
  36. global ExtFUiObj::uiClass
  37. set ExtFUiObj::uiClass "ExternalFile"
  38.  
  39.  
  40. constructor ExtFUiObj {class this name} {
  41.     set this [BrowsUiObj::constructor $class $this $name]
  42.     $this isAscii 1
  43.     $this isDirectory 0
  44.     $this pattern "*"
  45.     # Start constructor user section
  46.     # End constructor user section
  47.     return $this
  48. }
  49.  
  50. method ExtFUiObj::destructor {this} {
  51.     # Start destructor user section
  52.     # End destructor user section
  53.     $this BrowsUiObj::destructor
  54. }
  55.  
  56. method ExtFUiObj::addExternalFile {this} {
  57.     if {! [$this isDirectory]} {
  58.     return
  59.     }
  60.  
  61.     foreach childType [HCustFUiObj::externalFileNames] {
  62.     set externalFileList($childType) 1
  63.     }
  64.     foreach externalFile [$this getChildSet externalFiles] {
  65.     set type [$externalFile uiName]
  66.     if [info exists externalFileList($type)] {
  67.         unset externalFileList($type)
  68.     }
  69.     }
  70.     if [info exists externalFileList] {
  71.     set entrySet [lsort [array names externalFileList]]
  72.     } else {
  73.     set entrySet ""
  74.     }
  75.  
  76.     require "editseldia.tcl"
  77.     set box .main.newExternalF
  78.     ClassMaker::extend EditSelDialog NewExternalFileEditSelDialog uiObj
  79.     NewExternalFileEditSelDialog new $box \
  80.     -title "New External File" \
  81.     -message "External File:" \
  82.     -entrySet $entrySet \
  83.     -uiObj $this \
  84.     -okPressed {
  85.         set dir ""
  86.         set uiObj [%this uiObj]
  87.         while {"$uiObj" != ""} {
  88.         if {! [$uiObj isA ExtFUiObj]} break
  89.         if {"$dir" == ""} {
  90.             set dir [$uiObj getInfo Name]
  91.         } else {
  92.             set dir [path_name concat [$uiObj getInfo Name] $dir]
  93.         }
  94.         set uiObj [$uiObj parent]
  95.         }
  96.         set file [%this text]
  97.         set selection [splitFileName $file]
  98.         set name [lindex $selection 0]
  99.         set type [lindex $selection 1]
  100.         set script "global HCustFUiObj:custF"
  101.         append script " ;"
  102.         append script " set HCustFUiObj:custF \[CustFileUtilities::make \
  103.         [.main corporateObj] \
  104.         [list $name] [list $type] [list $dir] \
  105.         \]"
  106.         require "custfileut.tcl"
  107.         .main startCommand tcl \
  108.         "$script" "" \
  109.         "Creating external file '$file'" \
  110.         {1 0} 1
  111.         %this delete
  112.     } \
  113.     -editPressed {
  114.         if [info exists HCustFUiObj:custF] {
  115.         if [file isfile ${HCustFUiObj:custF}] {
  116.             regsub -all " |\\." "[$this text]" "_" fileId
  117.             [$this uiObj].ExternalFile:$fileId editFile
  118.         }
  119.         }
  120.     }
  121.     $box popUp
  122. }
  123.  
  124. proc ExtFUiObj::associations {} {
  125.     return {externalFiles}
  126. }
  127.  
  128. method ExtFUiObj::browserType {this} {
  129.     if [$this isDirectory] {
  130.     return ExternalDirectory
  131.     } else {
  132.     return [$this BrowsUiObj::browserType]
  133.     }
  134. }
  135.  
  136. proc ExtFUiObj::childTypes {assoc} {
  137.     if {[lsearch -exact "[ExtFUiObj::associations]" "$assoc"] == -1} {
  138.     return ""
  139.     }
  140.     set childTypes [BrowserProcs::childTypes $assoc]
  141.     case "$childTypes" in {
  142.     {ExternalFile} {
  143.         return {ExternalDirectory ExternalFile}
  144.     }
  145.     {default} {
  146.         return "$childTypes"
  147.     }
  148.     }
  149. }
  150.  
  151. method ExtFUiObj::editFile {this} {
  152.     if [$this isDirectory] {
  153.     return
  154.     }
  155.  
  156.     set path [$this getInfo Path]
  157.     if {! [file writable $path]} {
  158.     $this showFile
  159.     return
  160.     }
  161.  
  162.     set file [splitFileName "[$this uiName]"]
  163.     set name [lindex "$file" 0]
  164.     set type [lindex "$file" 1]
  165.     if [[$this parent] isA UCustFUiObj] {
  166.     set level "user"
  167.     } else {
  168.     set level "corporate"
  169.     }
  170.     case "$type" in {
  171.     {mnu vie objtype} {
  172.         if {"[$this referredFile]" != "$path"} {
  173.         .main startM4Command editor "$path" "" "[$this uiName]"
  174.         return
  175.         }
  176.         set script "SystemUtilities::fork otk uce \
  177.         -c [list [get_comm_name]] \
  178.         -fi $level [list $name] [list $type]"
  179.         .main startCommand tcl \
  180.         "$script" "" \
  181.         "Starting uce for '$name.$type'" \
  182.         {0 0} 1
  183.     }
  184.     {opendefs openlocs propdefs proplocs} {
  185.         if {$level == "user" || "[$this referredFile]" != "$path"} {
  186.         .main startM4Command editor "$path" "" "[$this uiName]"
  187.         return
  188.         }
  189.         set script "SystemUtilities::fork otk uce \
  190.         -c [list [get_comm_name]] \
  191.         -fi $level [list $name] [list $type]"
  192.         .main startCommand tcl \
  193.         "$script" "" \
  194.         "Starting uce for '$name.$type'" \
  195.         {0 0} 1
  196.     }
  197.     {pnl} {
  198.         if {"[$this referredFile]" != "$path"} {
  199.         .main startM4Command editor "$path" "" "[$this uiName]"
  200.         return
  201.         }
  202.             require "ctrlpnldia.tcl"
  203.         global classCount
  204.         incr classCount
  205.         set dlgName .main.ctrlPnlDialog$classCount
  206.         CtrlPnlDialog new $dlgName \
  207.         -helpPressed ".main helpOnName ctrlPnlDialog" \
  208.         -lvlObj [$this getParent Corporate] \
  209.         -fileName $name \
  210.         -fileType $type \
  211.         -editable 1
  212.         $dlgName popUp
  213.     }
  214.     {default} {
  215.         case "$name" in {
  216.         {checkconfig} {
  217.             if {"[$this referredFile]" != "$path"} {
  218.             .main startM4Command editor "$path" "" "[$this uiName]"
  219.             return
  220.             }
  221.                 require "custcheckd.tcl"
  222.             global classCount
  223.             incr classCount
  224.             set dlgName .main.custCheckDialog$classCount
  225.             CustCheckDialog new $dlgName
  226.             $dlgName edit [$this getParent CustomLevelVersion]
  227.         }
  228.            {default} {
  229.             .main startM4Command editor "$path" "" "[$this uiName]"
  230.         }
  231.         }
  232.     }
  233.     }
  234. }
  235.  
  236. method ExtFUiObj::externalFiles {this} {
  237.     if {! [$this isDirectory]} {
  238.     return ""
  239.     }
  240.  
  241.     set externalFiles ""
  242.     set externalDirectories ""
  243.     set directory [$this getInfo Path]
  244.     set crntPath [pwd]
  245.     cd $directory
  246.     if [catch {set files [glob [$this pattern]]}] {
  247.     set files ""
  248.     }
  249.     cd $crntPath
  250.  
  251.     foreach file [lsort $files] {
  252.     regsub -all " |\\." "$file" "_" fileId
  253.     set externalFile $this.${ExtFUiObj::uiClass}:$fileId
  254.     set isDirectory [file isdirectory [path_name concat $directory $file]]
  255.     if {! [isCommand $externalFile]} {
  256.         ExtFUiObj new $externalFile \
  257.         -parent $this \
  258.         -uiName "$file" \
  259.         -directory "$directory" \
  260.         -isDirectory $isDirectory
  261.     }
  262.     if $isDirectory {
  263.         lappend externalDirectories $externalFile
  264.     } else {
  265.         lappend externalFiles $externalFile
  266.     }
  267.     }
  268.     return [concat $externalDirectories $externalFiles]
  269. }
  270.  
  271. method ExtFUiObj::hasChildren {this} {
  272.     if [$this isDirectory] {
  273.     return 1
  274.     } else {
  275.     return 0
  276.     }
  277. }
  278.  
  279. proc ExtFUiObj::infoProperties {} {
  280.     return [concat \
  281.     [BrowserProcs::infoProperties] \
  282.     {Directory Path} \
  283.     ]
  284. }
  285.  
  286. method ExtFUiObj::initializeInfo {this dummy} {
  287.     set directory [$this directory]
  288.     set file [$this uiName]
  289.     set path [path_name concat $directory $file]
  290.     if {! [file exists $path]} {
  291.     set path $file
  292.     $this directory [path_name directory $path]
  293.     $this uiName [path_name file $path]
  294.     }
  295.  
  296.     case "[lindex [splitFileName [$this uiName]] 1]" in {
  297.     {dot con tlb} {
  298.         $this isAscii 0
  299.     }
  300.     }
  301.  
  302.     $this BrowsUiObj::initializeInfo $dummy
  303.     $this setInfo Text "external file '$path'"
  304.     $this setInfo Directory "[$this directory]"
  305.     $this setInfo Path "$path"
  306. }
  307.  
  308. method ExtFUiObj::openFile {this} {
  309.     if {[$this isDirectory] || (! [$this isAscii])} {
  310.     BrowserProcs::showInfo
  311.     } elseif {! [file writable [$this getInfo Path]]} {
  312.     $this showFile
  313.     } else {
  314.     $this editFile
  315.     }
  316. }
  317.  
  318. method ExtFUiObj::printObjects {this} {
  319.     if {! [$this isDirectory]} {
  320.     return
  321.     }
  322.  
  323.     set parent [$this getParent HCustFUiObj]
  324.     if {"$parent" == ""} {
  325.     set parent [$this getParent UCustFUiObj]
  326.     }
  327.     $parent printObjects
  328. }
  329.  
  330. method ExtFUiObj::referredFile {this {showWarning 0}} {
  331.     set path [$this getInfo Path]
  332.     if {[$this getParent UCustFUiObj] != ""} {
  333.     return $path
  334.     }
  335.  
  336.     set file [splitFileName "[$this uiName]"]
  337.     set name [lindex "$file" 0]
  338.     set type [lindex "$file" 1]
  339.     set uiObj [$this parent]
  340.     set dir ""
  341.     while {"$uiObj" != ""} {
  342.     if {! [$uiObj isA ExtFUiObj]} break
  343.     set dir [$uiObj getInfo Name]
  344.     set uiObj [$uiObj parent]
  345.     }
  346.     if {"$dir" == ""} {
  347.     return $path
  348.     }
  349.  
  350.     require "custfileut.tcl"
  351.     set custF "[CustFileUtilities::find \
  352.     [.main corporateObj] [list $name] [list $type] [list $dir]]"
  353.     if {"$custF" == ""} {
  354.     return $path
  355.     }
  356.     if {$showWarning && ("$path" != "$custF")} {
  357.     wmtkwarning "\
  358.         Customization file '$name.$type' already exists in \
  359.         the intallation directory.\nUsing file '$custF'"
  360.     }
  361.     return $custF
  362. }
  363.  
  364. method ExtFUiObj::removeObjects {this} {
  365.     if {! [$this isDirectory]} {
  366.     return
  367.     }
  368.  
  369.     set parent [$this getParent HCustFUiObj]
  370.     if {"$parent" == ""} {
  371.     set parent [$this getParent UCustFUiObj]
  372.     }
  373.     $parent removeObjects
  374. }
  375.  
  376. method ExtFUiObj::showFile {this} {
  377.     if [$this isDirectory] {
  378.     return
  379.     }
  380.  
  381.     set path [$this getInfo Path]
  382.     set file [splitFileName "[$this uiName]"]
  383.     set name [lindex "$file" 0]
  384.     set type [lindex "$file" 1]
  385.     if [[$this parent] isA UCustFUiObj] {
  386.     set level "user"
  387.     } else {
  388.     set level "corporate"
  389.     }
  390.     case "$type" in {
  391.     {mnu vie objtype} {
  392.         if {"[$this referredFile]" != "$path"} {
  393.         .main startM4Command viewer "$path" "" "[$this uiName]"
  394.         return
  395.         }
  396.         set script "SystemUtilities::fork otk uce -r \
  397.         -c [list [get_comm_name]] \
  398.         -fi $level [list $name] [list $type]"
  399.         .main startCommand tcl \
  400.         "$script" "" \
  401.         "Starting uce for '$name.$type'" \
  402.         {0 0} 1
  403.     }
  404.     {opendefs openlocs propdefs proplocs} {
  405.         if {$level == "user" || "[$this referredFile]" != "$path"} {
  406.         .main startM4Command viewer "$path" "" "[$this uiName]"
  407.         return
  408.         }
  409.         set script "SystemUtilities::fork otk uce -r \
  410.         -c [list [get_comm_name]] \
  411.         -fi $level [list $name] [list $type]"
  412.         .main startCommand tcl \
  413.         "$script" "" \
  414.         "Starting uce for '$name.$type'" \
  415.         {0 0} 1
  416.     }
  417.     {pnl} {
  418.         if {"[$this referredFile]" != "$path"} {
  419.         .main startM4Command viewer "$path" "" "[$this uiName]"
  420.         return
  421.         }
  422.             require "ctrlpnldia.tcl"
  423.         global classCount
  424.         incr classCount
  425.         set dlgName .main.ctrlPnlDialog$classCount
  426.         CtrlPnlDialog new $dlgName \
  427.         -helpPressed ".main helpOnName ctrlPnlDialog" \
  428.         -lvlObj [$this getParent Corporate] \
  429.         -fileName $name \
  430.         -fileType $type \
  431.         -editable 0
  432.         $dlgName popUp
  433.     }
  434.     {default} {
  435.         case "$name" in {
  436.         {checkconfig} {
  437.             if {"[$this referredFile]" != "$path"} {
  438.             .main startM4Command viewer "$path" "" "[$this uiName]"
  439.             return
  440.             }
  441.                 require "custcheckd.tcl"
  442.             global classCount
  443.             incr classCount
  444.             set dlgName .main.custCheckDialog$classCount
  445.             CustCheckDialog new $dlgName
  446.             $dlgName show [$this getParent CustomLevelVersion]
  447.         }
  448.            {default} {
  449.             .main startM4Command viewer "$path" "" "[$this uiName]"
  450.         }
  451.         }
  452.     }
  453.     }
  454. }
  455.  
  456. # Do not delete this line -- regeneration end marker
  457.  
  458.