home *** CD-ROM | disk | FTP | other *** search
/ PC World 1998 October / PCWorld_1998-10_cd.bin / software / prehled / komix / DATA.Z / editpastec.tcl < prev    next >
Text File  |  1997-10-07  |  7KB  |  315 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1997
  4. #
  5. #      File:           @(#)editpastec.tcl    /main/titanic/11
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)editpastec.tcl    /main/titanic/11   7 Oct 1997 Copyright 1997 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12. # End user added include file section
  13.  
  14. require "undocomman.tcl"
  15.  
  16. Class EditPasteCmd : {UndoCommand} {
  17.     constructor
  18.     method destructor
  19.     method do
  20.     method redo
  21.     method undo
  22.     method doCut
  23.     method undoCut
  24.     method operation
  25.     method selectVersion
  26.     method levelValidate
  27.     method operatesOn
  28.     method addObject
  29.     method removeObject
  30.     method addDeselected
  31.     method removeDeselected
  32.     method addSource
  33.     method removeSource
  34.     attribute _operation
  35.     attribute deselectedSet
  36.     attribute sourceObj
  37.     attribute sourceSet
  38. }
  39.  
  40. constructor EditPasteCmd {class this name} {
  41.     set this [UndoCommand::constructor $class $this $name]
  42.     $this deselectedSet [List new]
  43.     $this sourceSet [List new]
  44.     # Start constructor user section
  45.     # End constructor user section
  46.     return $this
  47. }
  48.  
  49. method EditPasteCmd::destructor {this} {
  50.     # Start destructor user section
  51.  
  52.     global editPasteObjects
  53.     if [info exists editPasteObjects] {
  54.         unset editPasteObjects
  55.     }
  56.  
  57.     # End destructor user section
  58.     $this UndoCommand::destructor
  59. }
  60.  
  61. method EditPasteCmd::do {this} {
  62.     busy {
  63.     set currentObj [.main currentObj]
  64.     if {! [isCommand $currentObj]} {
  65.         set currentObj [lindex [[.main treeView] rootSet] 0]
  66.     }
  67.     $this currentObj $currentObj
  68.  
  69.     $this levelValidate $currentObj
  70.  
  71.     if {! [[.main flatView] requestClipboardValue]} {
  72.         $this currentObj ""
  73.         wmtkinfo "No matching clipboard format found."
  74.     }
  75.     }
  76. }
  77.  
  78. method EditPasteCmd::redo {this} {
  79.     if {! [isCommand [$this currentObj]]} {
  80.     return
  81.     }
  82.     set errorStack ""
  83.  
  84.     busy {
  85.     if {"[$this operation]" == "cut"} {
  86.         set errorStack [$this doCut]
  87.     }
  88.  
  89.     set currentObj [$this currentObj]
  90.     set browsUiObj [$currentObj browsUiObj]
  91.     [$this deselectedSet] foreach obj {
  92.         if [catch {$browsUiObj deselectVersion $obj} msg] {
  93.         if {"$errorStack" != ""} {
  94.             append errorStack "\n"
  95.         }
  96.         append errorStack $msg
  97.         }
  98.     }
  99.     set confV [$currentObj getParent ConfigVersion]
  100.     set sectionList ""
  101.     set removeList ""
  102.     [$this objectSet] foreach obj {
  103.         set catched [$this selectVersion $browsUiObj $obj msg]
  104.         if $catched {
  105.         if {"$errorStack" != ""} {
  106.             append errorStack "\n"
  107.         }
  108.         append errorStack $msg
  109.         }
  110.     }
  111.     foreach obj $removeList {
  112.         $this removeObject $obj
  113.     }
  114.     foreach obj $sectionList {
  115.         $this addObject $obj
  116.     }
  117.     }
  118.     if {"$errorStack" != ""} {
  119.     wmtkerror $errorStack
  120.     }
  121.     .main updateView
  122.     wmtkmessage ""
  123. }
  124.  
  125. method EditPasteCmd::undo {this} {
  126.     if {! [isCommand [$this currentObj]]} {
  127.     return
  128.     }
  129.     set errorStack ""
  130.  
  131.     busy {
  132.     if {"[$this operation]" == "cut"} {
  133.         set errorStack [$this undoCut]
  134.     }
  135.  
  136.     set currentObj [$this currentObj]
  137.     set browsUiObj [$currentObj browsUiObj]
  138.     [$this objectSet] foreach obj {
  139.         if [$obj isA SystemFileReference] {
  140.         set catched [catch {
  141.             $obj setInfo FileVersion [$obj referredFileVersion]
  142.             $browsUiObj removeObject $obj
  143.         } msg]
  144.         } else {
  145.         set catched [catch {$browsUiObj deselectVersion $obj} msg]
  146.         }
  147.         if $catched {
  148.         if {"$errorStack" != ""} {
  149.             append errorStack "\n"
  150.         }
  151.         append errorStack $msg
  152.         }
  153.     }
  154.     set confV [$currentObj getParent ConfigVersion]
  155.     [$this deselectedSet] foreach obj {
  156.         if [catch {$browsUiObj selectVersion $obj $confV} msg] {
  157.         if {"$errorStack" != ""} {
  158.             append errorStack "\n"
  159.         }
  160.         append errorStack $msg
  161.         }
  162.     }
  163.     }
  164.     if {"$errorStack" != ""} {
  165.     wmtkerror $errorStack
  166.     }
  167.     .main updateView
  168.     wmtkmessage ""
  169. }
  170.  
  171. method EditPasteCmd::doCut {this} {
  172.     if {! [isCommand [$this sourceObj]]} {
  173.     return
  174.     }
  175.     set errorStack ""
  176.  
  177.     set sourceObj [$this sourceObj]
  178.     set sourceName [$sourceObj getInfo Name]
  179.     set sourceType [$sourceObj getInfo Type]
  180.     [$this sourceSet] foreach obj {
  181.     if [catch {$sourceObj deselectVersion $obj} msg] {
  182.         if {"$errorStack" != ""} {
  183.         append errorStack "\n"
  184.         }
  185.         append errorStack $msg
  186.     } else {
  187.         wmtkmessage "\
  188.         Deselected [$obj getInfo Type] '[$obj getInfo Name]'\
  189.         from $sourceType '$sourceName'"
  190.     }
  191.     }
  192.     return $errorStack
  193. }
  194.  
  195. method EditPasteCmd::undoCut {this} {
  196.     if {! [isCommand [$this sourceObj]]} {
  197.     return
  198.     }
  199.     set errorStack ""
  200.  
  201.     set sourceObj [$this sourceObj]
  202.     [$this sourceSet] foreach obj {
  203.     if [catch {$sourceObj selectVersion $obj} msg] {
  204.         if {"$errorStack" != ""} {
  205.         append errorStack "\n"
  206.         }
  207.         append errorStack $msg
  208.     }
  209.     }
  210.     return $errorStack
  211. }
  212.  
  213.  
  214. # Sets _operation to value if value is specified,
  215. # otherwise returns _operation.
  216. #
  217. method EditPasteCmd::operation {this {value ""}} {
  218.     if { $value == "" } {
  219.     return [$this _operation]
  220.     }
  221.  
  222.     $this _operation $value
  223.     if { $value == "cut" } {
  224.     $this commandName "Move"
  225.     } else {
  226.     $this commandName "Copy"
  227.     }
  228.  
  229.     $this setUndoLabel undo
  230. }
  231.  
  232. method EditPasteCmd::selectVersion {this currentObj obj msg} {
  233.     upvar $msg message
  234.     if [$obj isA SystemFileReference] {
  235.     # ignore (must be handled by a module)
  236.     set catched 0
  237.     } else {
  238.     set catched [catch {$currentObj selectVersion $obj $confV} message]
  239.     }
  240.  
  241.     return $catched
  242. }
  243.  
  244. method EditPasteCmd::levelValidate {this currentObj} {
  245.     # empty
  246. }
  247.  
  248. method EditPasteCmd::operatesOn {this object} {
  249.     if {! [isCommand $object]} {
  250.     return 0
  251.     }
  252.  
  253.     global editPasteObjects
  254.     if [info exists editPasteObjects($object)] {
  255.     return 1
  256.     }
  257.  
  258.     set sourceObj [$this sourceObj]
  259.     if {[isCommand $sourceObj] && $object == $sourceObj} {
  260.     return 1
  261.     }
  262.  
  263.     set currentObj [$this currentObj]
  264.     if {[isCommand $currentObj] && $object == $currentObj} {
  265.     return 1
  266.     }
  267.  
  268.     return 0
  269. }
  270.  
  271. method EditPasteCmd::addObject {this newObject} {
  272.     $this UndoCommand::addObject $newObject
  273.     global editPasteObjects
  274.     set editPasteObjects($newObject) 1
  275. }
  276.  
  277. method EditPasteCmd::removeObject {this oldObject} {
  278.     $this UndoCommand::removeObject $oldObject
  279.     global editPasteObjects
  280.     if [info exists editPasteObjects($oldObject)] {
  281.     unset editPasteObjects($oldObject)
  282.     }
  283. }
  284.  
  285. method EditPasteCmd::addDeselected {this newDeselected} {
  286.     [$this deselectedSet] append $newDeselected
  287.     global editPasteObjects
  288.     set editPasteObjects($newDeselected) 1
  289. }
  290.  
  291. method EditPasteCmd::removeDeselected {this oldDeselected} {
  292.     [$this deselectedSet] removeValue $oldDeselected
  293.     global editPasteObjects
  294.     if [info exists editPasteObjects($oldDeselected)] {
  295.     unset editPasteObjects($oldDeselected)
  296.     }
  297. }
  298.  
  299. method EditPasteCmd::addSource {this newSource} {
  300.     [$this sourceSet] append $newSource
  301.     global editPasteObjects
  302.     set editPasteObjects($newSource) 1
  303. }
  304.  
  305. method EditPasteCmd::removeSource {this oldSource} {
  306.     [$this sourceSet] removeValue $oldSource
  307.     global editPasteObjects
  308.     if [info exists editPasteObjects($oldSource)] {
  309.     unset editPasteObjects($oldSource)
  310.     }
  311. }
  312.  
  313. # Do not delete this line -- regeneration end marker
  314.  
  315.