home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / namechange.tcl < prev    next >
Text File  |  1997-02-25  |  4KB  |  148 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cadre Technologies Inc.    1996
  4. #
  5. #      File:           @(#)namechange.tcl    /main/hindenburg/3
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)namechange.tcl    /main/hindenburg/3   25 Feb 1997 Copyright 1996 Cadre Technologies Inc.
  10.  
  11. # Start user added include file section
  12.  
  13. global illegalCharacters
  14.  
  15. set illegalCharacters(cl)    {[/$:=,(){}]}
  16. set illegalCharacters(de)    {[]/$*:=,(){}[]}
  17. set illegalCharacters(pe)    {[]/$:=,(){}[]}
  18. set illegalCharacters(et)    {[/:,]}
  19. set illegalCharacters(st)    {[/,]}
  20. set illegalCharacters(rs)    {}
  21. set illegalCharacters(doc)    {}
  22. set illegalCharacters(section)    {,}
  23. set illegalCharacters(name)    {}
  24.  
  25. require nameconfli.tcl
  26.  
  27. # End user added include file section
  28.  
  29.  
  30. Class NameChangeDialog : {TemplateDialog} {
  31.     constructor
  32.     method destructor
  33.     method popUp
  34.     method text
  35.     method handleTextModified
  36.     method handleOk
  37.     method popUpConflict
  38.     attribute configV
  39.     attribute keeper
  40.     attribute item
  41.     attribute prevText
  42.     attribute illegalCharacters
  43.     attribute tool
  44. }
  45.  
  46. constructor NameChangeDialog {class this name tool} {
  47.     set this [TemplateDialog::constructor $class $this $name]
  48.     $this tool $tool
  49.     # Start constructor user section
  50.  
  51.     interface DlgColumn $this.c {
  52.         Label message {
  53.             text "New Name:"
  54.         }
  55.         SingleLineText name {
  56.             columnCount 30
  57.         }
  58.     }
  59.     $this.c.name textModified "$this handleTextModified"
  60.     $this config -okPressed "$this handleOk" \
  61.              -helpPressed {.main helpOnName changeName} \
  62.              -cancelPressed "$this delete" \
  63.              -title "Change Name" \
  64.              -autoPopDown 0 \
  65.              -modal 1
  66.  
  67.     # End constructor user section
  68.     return $this
  69. }
  70.  
  71. method NameChangeDialog::destructor {this} {
  72.     # Start destructor user section
  73.     $this popDown
  74.     # End destructor user section
  75. }
  76.  
  77. method NameChangeDialog::popUp {this} {
  78.     global illegalCharacters
  79.     if { "[$this item]" != "" } {
  80.     $this illegalCharacters $illegalCharacters([[$this item] type])
  81.     } else {
  82.     $this illegalCharacters $illegalCharacters(name)
  83.     }
  84.     $this TemplateDialog::popUp
  85. }
  86.  
  87. method NameChangeDialog::text {this {newText ,}} {
  88.     if {$newText == ","} {
  89.         return [$this.c.name text]
  90.     }
  91.     $this.c.name text $newText
  92.     $this prevText $newText
  93. }
  94.  
  95. method NameChangeDialog::handleTextModified {this} {
  96.     if { ("[$this illegalCharacters]" != "") && \
  97.         [regexp [$this illegalCharacters] [$this.c.name text]] } {
  98.         set cursorIndex [$this.c.name cursorIndex]
  99.         $this.c.name text [$this prevText]
  100.         $this.c.name cursorIndex [expr $cursorIndex - 1]
  101.     } else {
  102.         $this prevText [$this.c.name text]
  103.     }
  104. }
  105.  
  106. method NameChangeDialog::handleOk {this} {
  107.     set newName [$this.c.name text]
  108.     set configV [$this configV]
  109.     set keeper [$this keeper]
  110.     set oldItem [$this item]
  111.  
  112.     # name change for objects without item
  113.     if { "$oldItem" == "" } {
  114.     $this changeObjectName
  115.     return
  116.     }
  117.  
  118.     set itemType [$oldItem type]
  119.     set itemQual [$oldItem qualifier]
  120.     if [$itemQual isNil] {
  121.     set newItem [$keeper findDeclaration \
  122.         $newName $itemType $configV]
  123.     } else {
  124.     set newItem [$keeper findDeclaration $itemQual \
  125.         $newName $itemType $configV]
  126.     }
  127.     if [$newItem isNil] {
  128.     $this changeName 1
  129.     return
  130.     }
  131.     if {[$newItem item] != $oldItem} {
  132.     $this popUpConflict
  133.     return
  134.     }
  135.     wmtkerror "Name not changed: Specified name equals original name"
  136. }
  137.  
  138. method NameChangeDialog::popUpConflict {this} {
  139.     set conflict [$this tool].nameConflict
  140.     if {![isCommand $conflict]} {
  141.         NameConflictDialog new $conflict $this
  142.     }
  143.     $conflict popUp
  144. }
  145.  
  146. # Do not delete this line -- regeneration end marker
  147.  
  148.