home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / m4optdlgel.tcl < prev    next >
Encoding:
Text File  |  1997-06-04  |  4.8 KB  |  185 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1996
  4. #
  5. #      File:           @(#)m4optdlgel.tcl    /main/hindenburg/3
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)m4optdlgel.tcl    /main/hindenburg/3   4 Jun 1997 Copyright 1996 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12. # End user added include file section
  13.  
  14.  
  15. Class M4OptDlgElem : {DlgColumn} {
  16.     constructor
  17.     method destructor
  18.     method options
  19.     method addOption
  20.     method delOption
  21.     attribute list
  22.     attribute text
  23. }
  24.  
  25. constructor M4OptDlgElem {class this name} {
  26.     set this [DlgColumn::constructor $class $this $name]
  27.     # Start constructor user section
  28.  
  29.     $this verStretchFactor 100
  30.  
  31.         interface DlgColumn $this.gui {
  32.         verStretchFactor 100
  33.             TextList list {
  34.                 rowCount 4
  35.                 selectionPolicy BROWSE
  36.         verStretchFactor 100
  37.                 entrySet { }
  38.             }
  39.             DlgRow r {
  40.         horStretchFactor 100
  41.         verStretchFactor 0
  42.         spaceType NONE
  43.                 DlgColumn t {
  44.             spaceType EVEN
  45.             verStretchFactor 0
  46.             SingleLineText text {
  47.             horStretchFactor 100
  48.             verStretchFactor 0
  49.             columnCount 20
  50.             text "M4_"
  51.             cursorIndex 3
  52.             }
  53.                 }
  54.         PushButton add {
  55.             label "Add"
  56.             sensitive 0
  57.         }
  58.         PushButton del {
  59.             label "Delete"
  60.             sensitive 0
  61.                 }
  62.             }
  63.     }
  64.  
  65.         $this list $this.gui.list
  66.         $this text $this.gui.r.t.text
  67.         set add $this.gui.r.add
  68.         set del $this.gui.r.del
  69.  
  70.         [$this list] selectionChanged "
  71.             set selected \[lindex \[%this selectedSet] 0]
  72.             [$this text] text \$selected
  73.         if \[lempty \$selected] {
  74.         $add sensitive 0
  75.         $del sensitive 0
  76.             } else {
  77.         eval \[[$this text] textModified]
  78.         $del sensitive 1
  79.             }"
  80.  
  81.         [$this text] textModified "
  82.             set t \[%this text]
  83.             set n \[string length \$t]
  84.             if {\$n >= 4 && \[string range \$t 0 2] == \"M4_\"} {
  85.         $add sensitive 1
  86.             } else {
  87.         $add sensitive 0
  88.             }"
  89.  
  90.         $add activated "$this addOption"
  91.         $del activated "$this delOption"
  92.  
  93.     # End constructor user section
  94.     return $this
  95. }
  96.  
  97. method M4OptDlgElem::destructor {this} {
  98.     # Start destructor user section
  99.     # End destructor user section
  100. }
  101.  
  102. method M4OptDlgElem::options {this {list {}}} {
  103.     if [lempty $list] {
  104.         set entrySet {}
  105.         foreach entry [[$this list] entrySet] {
  106.             lappend entrySet [M4OptDlgElem::normalize $entry 0]
  107.         }
  108.         return $entrySet
  109.     } else {
  110.         set entrySet {}
  111.         foreach entry $list {
  112.             lappend entrySet [M4OptDlgElem::normalize $entry]
  113.         }
  114.         [$this list] entrySet $entrySet
  115.     }
  116. }
  117.  
  118. proc M4OptDlgElem::normalize {option {quote 1}} {
  119.     # Remove all spaces before the '=',
  120.     #
  121.     set list [split $option =]
  122.     regsub -all {[ "]} [lindex $list 0] {} name
  123.     set value [join [lrange $list 1 end] =]
  124.  
  125.     # Remove all leading and trailing spaces.
  126.     #
  127.     set value [string trim $value]
  128.  
  129.     # Remove any double quotes since we'll quote the entire option
  130.     # ourselves later if it contains spaces.
  131.     #
  132.     regsub -all {"} $value {} value
  133.  
  134.     if {$quote && [string first " " $value] != -1} {
  135.         set value "\"$value\""
  136.     }
  137.  
  138.     return [join [list $name $value] =]
  139. }
  140.  
  141. method M4OptDlgElem::addOption {this} {
  142.     set option [M4OptDlgElem::normalize [[$this text] text]]
  143.     [$this list] entrySet [concat [list $option] [[$this list] entrySet]]
  144.     [$this list] selectedIndexSet 0
  145.     [$this list] makeIndexVisible 0
  146.     $this.gui.r.del sensitive 1
  147. }
  148.  
  149. method M4OptDlgElem::delOption {this} {
  150.     set index [[$this list] selectedIndexSet]
  151.     set entries [[$this list] entrySet]
  152.     set count [llength $entries]
  153.     if {$index == 0} {
  154.         [$this list] entrySet [lrange $entries 1 end]
  155.     } else {
  156.         set i $index
  157.         incr i -1
  158.         set head [lrange $entries 0 $i]
  159.         incr i 2
  160.         set tail [lrange $entries $i end]
  161.         [$this list] entrySet [concat $head $tail]
  162.  
  163.     if {$index == $count - 1} {
  164.         incr index -1
  165.         }
  166.     }
  167.     set newEntry [lindex [[$this list] entrySet] $index]
  168.     [$this list] selectedIndexSet $index
  169.     [$this text] text $newEntry
  170.     [$this text] cursorIndex [string length $newEntry]
  171.  
  172.     if [lempty [[$this list] selectedIndexSet]] {
  173.     $this.gui.r.add sensitive 0
  174.     $this.gui.r.del sensitive 0
  175.  
  176.     [$this text] text "M4_"
  177.     [$this text] cursorIndex 3
  178.     } else {
  179.     $this.gui.r.del sensitive 1
  180.     }
  181. }
  182.  
  183. # Do not delete this line -- regeneration end marker
  184.  
  185.