home *** CD-ROM | disk | FTP | other *** search
/ PC World 1998 October / PCWorld_1998-10_cd.bin / software / prehled / komix / DATA.Z / repunardia.tcl < prev    next >
Text File  |  1997-11-28  |  9KB  |  323 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1997
  4. #
  5. #      File:           @(#)repunardia.tcl    /main/titanic/13
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)repunardia.tcl    /main/titanic/13   28 Nov 1997 Copyright 1997 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12. # End user added include file section
  13.  
  14. require "reptooldia.tcl"
  15.  
  16. Class RepUnarDialog : {RepToolDialog} {
  17.     constructor
  18.     method destructor
  19.     method popUp
  20.     method checkOk
  21.     method pressedOk
  22.     method unarchiveFinished
  23.     method browseDirectory
  24.     method browseArchive
  25.     method browseCommand
  26.     method setSource
  27.     method setDirectory
  28.     method setCommand
  29.         method doUnarchive
  30.     attribute srcField
  31.     attribute cmdField
  32.     attribute dirField
  33.     attribute dirLabel
  34.     attribute shutdownButton
  35.     attribute unarchivedDirectory
  36.     attribute intoDir
  37.     attribute oldDirs
  38.     attribute currentRepositoryName
  39.     attribute currentRepositoryDir
  40. }
  41.  
  42. constructor RepUnarDialog {class this name view} {
  43.     set this [RepToolDialog::constructor $class $this $name $view]
  44.     # Start constructor user section
  45.  
  46.         $this autoPopDown 0
  47.  
  48.         interface DlgColumn $this.c {
  49.         Label l {
  50.         text "Source"
  51.         horStretchFactor 100
  52.         }
  53.         DlgRow s {
  54.         spaceType NONE
  55.         horStretchFactor 100
  56.         DlgColumn s {
  57.             spaceType EVEN
  58.             horStretchFactor 100
  59.             SingleLineText src {
  60.             horStretchFactor 100
  61.             columnCount 30
  62.             text ""
  63.             }
  64.         }
  65.         DlgColumn b {
  66.             spaceType EVEN
  67.             horStretchFactor 0
  68.             PushButton browse {
  69.             horStretchFactor 0
  70.             label "Browse..."
  71.             }
  72.         }
  73.         }
  74.         Label l { text "Command" }
  75.         DlgRow c {
  76.         spaceType NONE
  77.         horStretchFactor 100
  78.         DlgColumn c {
  79.             spaceType EVEN
  80.             horStretchFactor 100
  81.             SingleLineText cmd {
  82.             text ""
  83.             horStretchFactor 100
  84.             columnCount 30
  85.             }
  86.         }
  87.         DlgColumn b {
  88.             spaceType EVEN
  89.             horStretchFactor 0
  90.             PushButton browse {
  91.             horStretchFactor 0
  92.             label "Browse..."
  93.             }
  94.         }
  95.         }
  96.         CheckButton shut {
  97.         label "Shutdown dbservers before unarchiving."
  98.         state 1
  99.         }
  100.         Label dirLabel { text "Directory" }
  101.         DlgRow r {
  102.         spaceType NONE
  103.         DlgColumn n {
  104.             spaceType EVEN
  105.             horStretchFactor 100
  106.             SingleLineText dir {
  107.             text ""
  108.                         editable 0
  109.             columnCount 30
  110.             horStretchFactor 100
  111.             }
  112.         }
  113.         }
  114.         Label note { 
  115.         font times-normal-14
  116.                 text "Note: the unarchive command runs in this directory."
  117.             }
  118.         }
  119.  
  120.     $this srcField $this.c.s.s.src
  121.     $this cmdField $this.c.c.c.cmd
  122.         $this dirLabel $this.c.dirLabel
  123.         $this dirField $this.c.r.n.dir
  124.         $this shutdownButton $this.c.shut
  125.  
  126.         $this okPressed "$this pressedOk"
  127.         [$this srcField] textModified "$this checkOk"
  128.         [$this dirField] textModified "$this checkOk"
  129.         [$this cmdField] textModified "$this checkOk"
  130.         $this.c.s.b.browse activated "$this browseArchive"
  131.         $this.c.c.b.browse activated "$this browseCommand"
  132.  
  133.     # End constructor user section
  134.     return $this
  135. }
  136.  
  137. method RepUnarDialog::destructor {this} {
  138.     # Start destructor user section
  139.     # End destructor user section
  140.     $this RepToolDialog::destructor
  141. }
  142.  
  143. method RepUnarDialog::popUp {this} {
  144.     set ctx [string tolower [$this objType]]
  145.     [$this cmdField] text [m4_var get M4_unarchive_cmd -context $ctx]
  146.  
  147.     $this checkOk
  148.     $this RepToolDialog::popUp
  149. }
  150.  
  151. method RepUnarDialog::checkOk {this} {
  152.     $this okSensitive [expr {
  153.         [[$this srcField] text] != "" &&
  154.         [[$this cmdField] text] != "" &&
  155.         [[$this dirField] text] != ""
  156.     }]
  157. }
  158.  
  159. method RepUnarDialog::pressedOk {this} {
  160.     $this busy 1
  161.  
  162.     set ctx [string tolower [$this objType]]
  163.     m4_var set M4_unarchive_cmd [[$this cmdField] text] -context $ctx
  164.  
  165.     # Save these values before shutdown for use by subclasses later on.
  166.     #
  167.     set rep [[$this view] rep]
  168.     $this currentRepositoryName [$rep currentName]
  169.     if ![[$rep currentCorporate] isNil] {
  170.     $this currentRepositoryDir  [$rep currentRepDir]
  171.     } else {
  172.         $this currentRepositoryDir ""
  173.     }
  174.  
  175.     if [[$this shutdownButton] state] {
  176.         set name [$this currentRepositoryName]
  177.     if {$name != "" && ![$rep shutdownDbServers $name]} {
  178.         $this busy 0
  179.             return
  180.         }
  181.     }    
  182.  
  183.     set dir [Repository::expandDirName [[$this dirField] text]]
  184.     if ![file exists $dir] {
  185.     set dlg [$this view].createDir
  186.         if ![isCommand $dlg] {
  187.         QuestionDialog new $dlg \
  188.         -title "Create Directory" \
  189.         -okPressed "$this doUnarchive 1" \
  190.         -cancelPressed "$this busy 0; return"
  191.         }
  192.     $dlg message "Directory '$dir' does not exist.\nCreate it?"
  193.     $dlg delHelpButton
  194.     $dlg popUp
  195.     return
  196.     }
  197.  
  198.     $this doUnarchive 0
  199. }
  200.  
  201. proc RepUnarDialog::findNewDirs {oldDirs curDirs} {
  202.     return [listSubtract $curDirs $oldDirs]
  203. }
  204.  
  205. method RepUnarDialog::browseDirectory {this} {
  206.     set dirBrowser [$this view].dirBrowser
  207.     if ![isCommand $dirBrowser] {
  208.         RepDirBrowser new $dirBrowser 0 1 \
  209.             -title "Select Directory To Store [$this objType] Directory" \
  210.             -okPressed "%this handleOk ; $this setDirectory \[%this selected]"
  211.     }
  212.  
  213.     $dirBrowser selected [[$this dirField] text]
  214.     $dirBrowser popUp
  215. }
  216.  
  217. method RepUnarDialog::browseArchive {this} {
  218.     set archiveBrowser [$this view].unArchiveBrowser
  219.     if ![isCommand $archiveBrowser] {
  220.         FileChooser new $archiveBrowser \
  221.             -selectionPolicy BROWSE \
  222.             -title "Select Source Archive" \
  223.             -okPressed "$this setSource \[lindex \[%this selectedSet] 0]"
  224.         $archiveBrowser delHelpButton
  225.     }
  226.  
  227.     set file [Repository::expandFileName [[$this srcField] text]]
  228.     Repository::expandDirName [file dir $file] existingDir
  229.  
  230.     $archiveBrowser selectedSet [list $file]
  231.     $archiveBrowser directory $existingDir
  232.     $archiveBrowser popUp
  233. }
  234.  
  235. method RepUnarDialog::browseCommand {this} {
  236.     set commandBrowser [$this view].commandBrowser
  237.     if ![isCommand $commandBrowser] {
  238.         FileChooser new $commandBrowser \
  239.             -selectionPolicy BROWSE \
  240.             -title "Select Unarchive Command" \
  241.             -okPressed "$this setCommand \[lindex \[%this selectedSet] 0]"
  242.         $commandBrowser delHelpButton
  243.     }
  244.  
  245.     set cmdText [[$this cmdField] text]
  246.     protect_backslashes {cmdText cmd} { set cmd [lindex $cmdText 0] }
  247.  
  248.     set file [Repository::expandFileName $cmd]
  249.     Repository::expandDirName [file dir $file] existingDir
  250.  
  251.     $commandBrowser selectedSet [list $file]
  252.     $commandBrowser directory $existingDir
  253.     $commandBrowser popUp
  254. }
  255.  
  256. method RepUnarDialog::setSource {this file} {
  257.     [$this srcField] text $file
  258.     $this checkOk
  259. }
  260.  
  261. method RepUnarDialog::setDirectory {this dir} {
  262.     [$this dirField] text $dir
  263.     $this checkOk
  264. }
  265.  
  266. method RepUnarDialog::setCommand {this cmd} {
  267.     set contents [[$this cmdField] text]
  268.     if [lempty $contents] {
  269.         set contents $cmd
  270.     } else {
  271.     protect_backslashes {cmd contents} {
  272.         set old [lindex $contents 0]
  273.         set oldEnd [string length [quoteIf $old]]
  274.         incr oldEnd
  275.         set contents "[quoteIf $cmd] [string range $contents $oldEnd end]"
  276.     }
  277.     }
  278.     [$this cmdField] text $contents
  279.     $this checkOk
  280. }
  281.  
  282. method RepUnarDialog::doUnarchive {this {makeDir 0}} {
  283.     $this intoDir [Repository::expandDirName [[$this dirField] text]]
  284.     if $makeDir {
  285.         if [catch {BasicFS::makeDir [$this intoDir]} error] {
  286.         $this busy 0
  287.             error $error
  288.             return
  289.         }
  290.     }
  291.  
  292.     $this oldDirs [BasicFS::readDir [$this intoDir]]
  293.  
  294.     if ![$this unarchive] {
  295.         $this busy 0
  296.     }
  297. }
  298.  
  299. method RepUnarDialog::unarchiveFinished {this exitCode} {
  300.     $this busy 0
  301.     if {$exitCode == 0} {
  302.     $this popDown
  303.         [$this view] message "Unarchived [$this objDescription] successfully."
  304.     } else {
  305.         [$this view] message "Failed to unarchive [$this objDescription]."
  306.     }
  307.  
  308.     set dir [Repository::expandDirName [[$this dirField] text]]
  309.     set curDirs [BasicFS::readDir [$this intoDir]]
  310.     set newDirs [RepUnarDialog::findNewDirs [$this oldDirs] $curDirs]
  311.     if {[llength $newDirs] > 1} {
  312.     [$this view] warning "Found more than one new directory after\
  313.         unarchiving, using first one ('[lindex $newDirs 0]')."
  314.     }
  315.  
  316.     if ![lempty $newDirs] {
  317.         $this unarchivedDirectory [location [$this intoDir] [lindex $newDirs 0]]
  318.     }
  319. }
  320.  
  321. # Do not delete this line -- regeneration end marker
  322.  
  323.