home *** CD-ROM | disk | FTP | other *** search
/ PC World 1998 October / PCWorld_1998-10_cd.bin / software / prehled / komix / DATA.Z / groupdefin.tcl < prev    next >
Encoding:
Text File  |  1997-11-14  |  5.9 KB  |  227 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1997
  4. #
  5. #      File:           @(#)groupdefin.tcl    /main/titanic/3
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)groupdefin.tcl    /main/titanic/3   14 Nov 1997 Copyright 1997 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12. require "gdrfilesel.tcl"
  13. require "gdritemsel.tcl"
  14. require "gdrfile.tcl"
  15. # End user added include file section
  16.  
  17. require "groupdialo.tcl"
  18.  
  19. Class GroupDefinitionFileDialog : {GroupDialog} {
  20.     method destructor
  21.     constructor
  22.     method handleDelete
  23.     method handleApplyNow
  24.     method modeChanged
  25.     method showFileSelectors
  26.     method showItemSelectors
  27.     method popUp
  28.     attribute fileName
  29. }
  30.  
  31. method GroupDefinitionFileDialog::destructor {this} {
  32.     # Start destructor user section
  33.     # End destructor user section
  34.     $this GroupDialog::destructor
  35. }
  36.  
  37. constructor GroupDefinitionFileDialog {class this name file} {
  38.     set this [GroupDialog::constructor $class $this $name]
  39.  
  40.     $this groupV [GDRFile new $file]
  41.  
  42.     # adjust group structure interface for gdr files
  43.     $this.top.menu.delete label Delete
  44.     $this.top.menu.show delete
  45.  
  46.     # add description part
  47.     Label new $this.top.descLabel -text "Description:"
  48.     SingleLineText new $this.top.description
  49.  
  50.     set view $this.top.view
  51.     $view columnCount 80
  52.  
  53.     # delete action
  54.     $this.top.menu.delete sensitive 0
  55.     $view selectionChanged {
  56.     if { ([llength [%this selectedSet]] > 0) \
  57.         && [[[%this parent] parent] editable] } {
  58.         [%this parent].menu.delete sensitive 1
  59.     } else {
  60.         [%this parent].menu.delete sensitive 0
  61.     }
  62.     }
  63.     $this.top.menu.delete activated "$this handleDelete"
  64.  
  65.     # extra customization buttons
  66.     PushButton new $this.applynow \
  67.     -label "Apply Now" \
  68.     -activated "$this handleApplyNow"
  69.  
  70.     PushButton new $this.cancel \
  71.     -label "Cancel" \
  72.     -activated "$this popDown; $this delete"
  73.  
  74.     $this okPressed {
  75.     if [%this editable] {
  76.         [%this groupV] description [%this.top.description text]
  77.         [%this groupV] write
  78.     }
  79.     %this delete
  80.     }
  81.  
  82.     return $this
  83. }
  84.  
  85. method GroupDefinitionFileDialog::handleDelete {this} {
  86.     set selectedSet [$this.top.view selectedSet]
  87.     foreach object $selectedSet {
  88.     # find related selector object
  89.     regsub {.*\.} $object "" selector
  90.     $selector file ""
  91.     }
  92.  
  93.     $this modeChanged
  94. }
  95.  
  96. method GroupDefinitionFileDialog::handleApplyNow {this} {
  97.     if { ![$this editable] } {
  98.     return
  99.     }
  100.  
  101.     set gdrFile [$this groupV]
  102.     $gdrFile description [$this.top.description text]
  103.     $gdrFile write
  104. }
  105.  
  106. method GroupDefinitionFileDialog::modeChanged {this {forceFlag 1}} {
  107.     set currentMode [$this.top.mode.optmenu selected]
  108.     $this currentMode $currentMode
  109.  
  110.     set contentsLabel $this.top.contentsLab
  111.     case $currentMode in {
  112.     {"item selector"} {
  113.         $contentsLabel text "Item Selectors:"
  114.         $this showItemSelectors
  115.     } 
  116.     {"file selector"} {
  117.         $contentsLabel text "File Selectors:"
  118.         $this showFileSelectors
  119.     }
  120.     }
  121. }
  122.  
  123. method GroupDefinitionFileDialog::showFileSelectors {this} {
  124.     set view $this.top.view
  125.     foreach header [$view headerSet] {
  126.     $header delete
  127.     }
  128.     foreach object [$view objectSet] {
  129.     $object delete
  130.     }
  131.  
  132.     BrowsHeader new $view.h1 -label "Item Type" -width 12
  133.     BrowsHeader new $view.h2 -label "Decomposition Flags" -width 31
  134.     BrowsHeader new $view.h3 -label "File Types" -width 37
  135.  
  136.     [[$this groupV] fileSelectorSet] foreach fileSelector {
  137.     set details [list [$fileSelector decompFlags]]
  138.     lappend details [$fileSelector fileTypes]
  139.     BrowsObject new $view.$fileSelector \
  140.         -label [$fileSelector itemType] \
  141.         -details $details
  142.     
  143.     }
  144.  
  145.     # Sort the view
  146.     set sortSpec "\
  147.     -column {$this.top.view.h1 ascii increasing} \
  148.     -column {$this.top.view.h2 ascii increasing} \
  149.     -column {$this.top.view.h3 ascii increasing}"
  150.     eval $view sort $sortSpec
  151. }
  152.  
  153. method GroupDefinitionFileDialog::showItemSelectors {this} {
  154.     set view $this.top.view
  155.     foreach header [$view headerSet] {
  156.     $header delete
  157.     }
  158.     foreach object [$view objectSet] {
  159.     $object delete
  160.     }
  161.  
  162.     BrowsHeader new $view.h1 -label "File Type" -width 12
  163.     BrowsHeader new $view.h2 -label "Item Type" -width 12
  164.     BrowsHeader new $view.h3 -label "Qualified" -width 12
  165.  
  166.     [[$this groupV] itemSelectorSet] foreach itemSelector {
  167.     set details [list [$itemSelector itemType]]
  168.     lappend details [$itemSelector qualified]
  169.     BrowsObject new $view.$itemSelector \
  170.         -label [$itemSelector fileType] \
  171.         -details $details
  172.     
  173.     }
  174.  
  175.     # Sort the view
  176.     set sortSpec "\
  177.     -column {$this.top.view.h1 ascii increasing} \
  178.     -column {$this.top.view.h2 ascii increasing} \
  179.     -column {$this.top.view.h3 ascii increasing}"
  180.     eval $view sort $sortSpec
  181. }
  182.  
  183. method GroupDefinitionFileDialog::popUp {this} {
  184.     if {[$this editable] && [catch {[$this groupV] edit} errorMsg]} {
  185.     if [info exists errorInfo] {
  186.         set errorTrace $errorInfo
  187.         set errorCodeCopy $errorCode
  188.     } else {
  189.         set errorTrace ""
  190.         set errorCodeCopy ""
  191.     }
  192.     $this editable 0
  193.     } else {
  194.     set errorMsg ""
  195.     }
  196.  
  197.     $this.top.mode.optmenu entrySet \
  198.         { "file selector" "item selector"}
  199.  
  200.     $this title "Edit [$this fileName]"
  201.  
  202.     # disable buttons if not editable
  203.     if { ![$this editable] } {
  204.     $this.top.menu.delete sensitive 0
  205.     $this.top.menu.new sensitive 0
  206.     $this.applynow sensitive 0
  207.     $this.top.description sensitive 0
  208.     }
  209.  
  210.     # read file and show contents
  211.     [$this groupV] read
  212.     $this modeChanged
  213.     $this.top.description text [[$this groupV] description]
  214.  
  215.     $this TemplateDialog::popUp
  216.  
  217.     if {"$errorMsg" != ""} {
  218.     global errorInfo errorCode
  219.     set errorInfo $errorTrace
  220.     set errorCode $errorCodeCopy
  221.     wmtkerror $errorMsg
  222.     }    
  223. }
  224.  
  225. # Do not delete this line -- regeneration end marker
  226.  
  227.