home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / clmtool.tcl < prev    next >
Text File  |  1996-12-09  |  15KB  |  501 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1996
  4. #
  5. #      File:           @(#)clmtool.tcl    /main/hindenburg/21
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)clmtool.tcl    /main/hindenburg/21   9 Dec 1996 Copyright 1996 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12. require "asciiprint.tcl"
  13. require "classmaker.tcl"
  14. require "m4vardescr.tcl"
  15. require "showversio.tcl"
  16. # End user added include file section
  17.  
  18. require "exetool.tcl"
  19.  
  20. # Definition of the Mtool class.
  21. # The mtool is an output-only exetool. Output from
  22. # host commands is shown in a multi-line text widget.
  23.  
  24. Class ClMtool : {Exetool MainWindow} {
  25.     method destructor
  26.     constructor
  27.     method messageAreaPresent
  28.     method toolBarPresent
  29.     method addToolBar
  30.     method setToolBarPresence
  31.     method saveToolBarPresence
  32.     method addMessageArea
  33.     method setMessageAreaPresence
  34.     method saveMessageAreaPresence
  35.     method cmdStarted
  36.     method cmdFinished
  37.     method updateTitle
  38.     method execute
  39.     method stop
  40.     method handleReusableChanged
  41.     method toolName
  42.     attribute reusable
  43.     attribute m4VarDes
  44.     attribute winFont
  45.     attribute aPrinter
  46.     attribute saveFile
  47.     attribute suspendButton
  48.     attribute reuseButton
  49.     attribute win
  50.     attribute top
  51. }
  52.  
  53. method ClMtool::destructor {this} {
  54.     # Start destructor user section
  55.     $this saveMessageAreaPresence
  56.     $this saveToolBarPresence
  57.     set geom [$this geometry]
  58.     if {$geom != [m4_var get M4_geometry -context mtool]} {
  59.         m4_var set M4_geometry $geom -context mtool
  60.     }
  61.     m4_var save
  62.     # End destructor user section
  63.     $this Exetool::destructor
  64. }
  65.  
  66. constructor ClMtool {class this name dispatcher cmd {dir ""}} {
  67.     set this [MainWindow::constructor $class $this $name]
  68.     set this [Exetool::constructor $class $this $name $dispatcher]
  69.     $this config \
  70.     -closed {%this stop} \
  71.     -title "ObjectTeam Monitoring Window" \
  72.     -icon mtool_64 \
  73.     -iconTitle "ObjectTeam Monitoring Window" \
  74.     -reusable [m4_var get M4_reuse_tool -context mtool] \
  75.     -geometry [m4_var get M4_geometry -context mtool]
  76.  
  77.     # create work-area
  78.     MenuBar new $this.menubar
  79.     $this top [DlgColumn new $this.top]
  80.     $this win [OutTermWindow new [$this top].win \
  81.     -horStretchFactor 10 \
  82.     -verStretchFactor 10 \
  83.     -horShrinkFactor 10 \
  84.     -verShrinkFactor 10 \
  85.     -font "[m4_var get M4_font -context mtool]" \
  86.     -clearScreen [m4_var get M4_clear_screen] \
  87.     -rowCount 24 \
  88.     -columnCount 80 \
  89.     -started {
  90.          .main cmdStarted "Executing '[%this command]' ..."
  91.     } \
  92.     -finished {
  93.         set exitStatusList [.main exitStatusList]
  94.         lappend exitStatusList [%this exitStatus]
  95.         .main exitStatusList $exitStatusList
  96.     } \
  97.     -stopped {
  98.         .main cmdFinished "Executing '[%this command]' failed"
  99.     } \
  100.     -ready {
  101.         .main cmdFinished "Command Ready"
  102.     } \
  103.     -selectionChanged {
  104.         [.main menuBar].edit.menu.copy sensitive \
  105.             [expr {[string length [%this selectedText]] > 0}]
  106.     }]
  107.  
  108.     # create menus
  109.     set fileMenuButton [MenuBarButton new [$this menuBar].file \
  110.     -label File -mnemonic F]
  111.     set fileMenu [Menu new $fileMenuButton.menu \
  112.     -pinnable yes]
  113.     MenuPushButton new $fileMenu.save \
  114.     -label "Save Output..." -mnemonic S -accelerator "Ctrl+o" \
  115.     -toolBarPixmap save \
  116.     -activated {[.main saveFile] popUp} \
  117.     -hintText "Saves mtool contents to a file."
  118.     MenuPushButton new $fileMenu.print \
  119.     -label "Print" \
  120.     -mnemonic P \
  121.     -accelerator "Ctrl+p" \
  122.     -toolBarPixmap print_16 \
  123.     -activated {
  124.         set printer [[[.main aPrinter] cmdField] text]
  125.         set printfile [args_file {}]
  126.         set msg "Sending output to $printer ..."
  127.         [.main win] saveOutput $printfile
  128.         wmtkmessage $msg
  129.         if [system "$printer $printfile"] {
  130.         wmtkmessage "Executing '$printer' failed"
  131.         } else {
  132.         wmtkmessage "Done"
  133.         }
  134.         unlink $printfile
  135.     } \
  136.     -hintText "Prints mtool contents."
  137.     MenuSeparator new $fileMenu.sep
  138.     MenuPushButton new $fileMenu.exit \
  139.     -label "Exit" -mnemonic x \
  140.     -activated {.main stop} \
  141.     -toolBarPixmap exit_16 \
  142.     -hintText "Quits the mtool."
  143.  
  144.     # Edit Menu.
  145.     MenuBarButton new [$this menuBar].edit -label Edit -mnemonic E
  146.     Menu new [$this menuBar].edit.menu
  147.     MenuPushButton new [$this menuBar].edit.menu.copy \
  148.     -label Copy -mnemonic C -accelerator Ctrl+C -toolBarPixmap copy \
  149.     -sensitive 0 -activated {[.main win] setClipboardValue}
  150.     if $win95 {
  151.     set mnemonic A
  152.     set accelerator Ctrl+A
  153.     } else {
  154.     set mnemonic S
  155.     set accelerator Ctrl+/
  156.     }
  157.     MenuPushButton new [$this menuBar].edit.menu.selectall \
  158.     -label "Select All" -mnemonic $mnemonic -accelerator $accelerator \
  159.     -activated {
  160.         [.main win] setSelectedText 0 -1
  161.     }
  162.  
  163.     # View menu.
  164.     set viewMenuButton [MenuBarButton new [$this menuBar].view \
  165.     -label View -mnemonic V]
  166.     set viewMenu [Menu new $viewMenuButton.menu]
  167.     MenuCheckButton new $viewMenu.toolbar \
  168.     -label "ToolBar" -mnemonic T -state 1 \
  169.     -stateChanged {
  170.         .main toolBarPresent [[.main menuBar].view.menu.toolbar state]
  171.     } \
  172.     -hintText "Shows or hides the toolbar."
  173.     MenuCheckButton new $viewMenu.messagearea \
  174.     -label "Message Area" -mnemonic M -state 1 \
  175.     -stateChanged {
  176.         .main messageAreaPresent [[.main menuBar].view.menu.messagearea state]
  177.     } \
  178.     -hintText "Shows or hides the message area."
  179.     set optionsMenuButton [MenuBarButton new [$this menuBar].options \
  180.     -label Options -mnemonic O]
  181.     set optionsMenu [Menu new $optionsMenuButton.menu \
  182.     -pinnable yes]
  183.     MenuPushButton new $optionsMenu.font \
  184.     -label "Font..." -mnemonic F \
  185.     -activated {
  186.         busy {
  187.         [.main winFont] value "[m4_var get M4_font -context mtool]"
  188.         [.main winFont] popUp
  189.         }
  190.     } \
  191.     -hintText "Changes the mtool font (M4_font__mtool)."
  192.     MenuPushButton new $optionsMenu.printer \
  193.     -label "Printer Setup..." -mnemonic P \
  194.     -activated {
  195.         [.main aPrinter] popUp
  196.     } \
  197.     -hintText "Changes settings for the printer."
  198.     MenuCheckButton new $optionsMenu.clearscreen \
  199.     -label "Clear Screen" \
  200.     -mnemonic C \
  201.     -toolBarPixmap cls_16 \
  202.     -state [m4_var get M4_clear_screen] \
  203.     -stateChanged {
  204.         [.main win] clearScreen [%this state]
  205.         m4_var set M4_clear_screen [%this state]
  206.     }
  207.     $this reuseButton [MenuCheckButton new $optionsMenu.reuse \
  208.     -label "Reuse" \
  209.     -mnemonic R \
  210.     -toolBarPixmap recycl_16 \
  211.     -state [m4_var get M4_reuse_tool -context mtool] \
  212.     -stateChanged {.main handleReusableChanged}]
  213.     $this suspendButton [MenuCheckButton new $optionsMenu.suspendoutput \
  214.     -label "Suspend Output" \
  215.     -mnemonic S \
  216.     -toolBarPixmap stop_16 \
  217.     -stateChanged {[.main win] suspend [%this state]}]
  218.     set processMenuButton [MenuBarButton new [$this menuBar].process \
  219.     -label Process -mnemonic P]
  220.     set processMenu [Menu new $processMenuButton.menu \
  221.     -pinnable yes]
  222.     MenuPushButton new $processMenu.terminate \
  223.     -label "Terminate" -mnemonic T -sensitive no \
  224.     -activated {[.main win] abort 15} \
  225.     -hintText "Terminates the running process."
  226.     if {! $win95} {
  227.     MenuPushButton new $processMenu.abort \
  228.         -label "Abort" -mnemonic A -sensitive no \
  229.         -activated {[.main win] abort 6}
  230.     MenuPushButton new $processMenu.kill \
  231.         -label "Kill" -mnemonic K -sensitive no \
  232.         -activated {[.main win] abort 9}
  233.     }
  234.  
  235.     # Help menu
  236.     [$this menuBar] helpEntry [MenuBarButton new [$this menuBar].help \
  237.     -label Help -mnemonic H]
  238.     interface Menu [$this menuBar].help.menu {
  239.     pinnable 1
  240.     MenuPushButton whatsthis {
  241.         label "What's This?"
  242.         mnemonic W
  243.         activated {showHelp MTO/tl_mto.html}
  244.         hintText "Shows context sensitive help."
  245.     }
  246.     }
  247.     if {!$win95} {
  248.     MenuPushButton new [$this menuBar].help.menu.onhelp \
  249.         -label "On Help" \
  250.         -mnemonic H \
  251.         -activated {showHelp GEN/tl_hlp.html}
  252.     }
  253.     MenuPushButton new [$this menuBar].help.menu.helptopics \
  254.     -label "Help Topics" \
  255.     -mnemonic T \
  256.     -activated {showHelpTopics} \
  257.     -hintText "Shows help topics."
  258.     MenuPushButton new [$this menuBar].help.menu.abouthelptool \
  259.     -label "About Monitoring Window" \
  260.     -mnemonic A \
  261.     -activated {showVersionDialog [%this label]} \
  262.     -hintText "Shows version information."
  263.  
  264.     $this setMessageAreaPresence
  265.     $this setToolBarPresence
  266.  
  267.     # create save-output file-chooser using full pathnames
  268.     set M4_repdir [m4_var get M4_repdir]
  269.     set directory $M4_repdir
  270.     for {set root [path_name directory $directory]} 1 {set directory $root} {
  271.     if {"$root" == "$directory" ||
  272.         "[path_name base $directory]" == "$directory"} break
  273.     }
  274.     case "$root" in {
  275.     "." {
  276.         if {"$directory" == "."} {
  277.         set M4_repdir [string range $M4_repdir 2 end]
  278.         }
  279.         set M4_repdir [path_name concat [pwd] $M4_repdir]
  280.     }
  281.     ".." {
  282.         set M4_repdir [path_name concat [pwd] $M4_repdir]
  283.     }
  284.     }
  285.     $this saveFile [FileChooser new $this.saveOutput \
  286.     -title "Save Output" \
  287.     -selectionPolicy BROWSE \
  288.     -filter "*" \
  289.     -directory "$M4_repdir" \
  290.     -selectedSet "[list [path_name concat $M4_repdir mtool_log.[pid]]]" \
  291.     -helpPressed {showHelp MTO/m_svou.html#dialogbox} \
  292.     -okPressed {
  293.         set logFile [lindex [%this selectedSet] 0]
  294.         set logDir [path_name directory $logFile]
  295.         if {"$logDir" != "[m4_var get M4_repdir]"} {
  296.         catch {m4_var set M4_repdir $logDir}
  297.         }
  298.         if {[[.main win] saveOutput $logFile] == -1} {
  299.         # show error message
  300.         open $logFile w
  301.         }
  302.     }]
  303.  
  304.     # create font-chooser
  305.     $this winFont [FontChooser new $this.winFont \
  306.     -title "Monitoring Window Font" \
  307.     -okPressed {
  308.         [.main win] font [%this value]
  309.         if {"[m4_var get M4_font -context mtool]" != "[%this value]"} {
  310.         catch {m4_var set M4_font "[%this value]" -context mtool}
  311.         }
  312.     }]
  313.     [$this winFont] delHelpButton
  314.  
  315.     # create ascii-printer entry-dialog
  316.     ClassMaker::extend AsciiPrinterDlg MtoolAsciiPrinterDlg \
  317.     {M4_a_printer M4_a_printer_llen M4_a_printer_plen}
  318.     $this aPrinter [MtoolAsciiPrinterDlg new $this.aPrinter \
  319.     -M4_a_printer [m4_var get M4_a_printer] \
  320.     -M4_a_printer_llen [m4_var get M4_a_printer_llen] \
  321.     -M4_a_printer_plen [m4_var get M4_a_printer_plen] \
  322.     -cancelPressed {
  323.         [%this cmdField] text [%this M4_a_printer]
  324.         [%this llenField] intValue [%this M4_a_printer_llen]
  325.         [%this plenField] intValue [%this M4_a_printer_plen]
  326.     } \
  327.     -okPressed {
  328.         set dim ""
  329.         if {[%this length l] <= 0} {
  330.         set dim l
  331.         } elseif {[%this length p] <= 0} {
  332.         set dim p
  333.         }
  334.         if {"$dim" != ""} {
  335.         set fieldName [%this.top.printer.prView.${dim}lenLabel text]
  336.         wmtkerror "$fieldName must be a positive value"
  337.         return
  338.         }
  339.         set index 0
  340.         foreach triple {
  341.         {M4_a_printer cmdField text}
  342.         {M4_a_printer_llen llenField intValue}
  343.         {M4_a_printer_plen plenField intValue}
  344.         } {
  345.         set m4var [lindex $triple 0]
  346.         set field [%this [lindex $triple 1]]
  347.         set entry [lindex $triple 2]
  348.         if {"[%this $m4var]" != "[$field $entry]"} {
  349.             %this $m4var [$field $entry]
  350.             catch {m4_var set $m4var [%this $m4var]}
  351.         }
  352.         incr index 1
  353.         }
  354.         %this popDown
  355.     }]
  356.  
  357.     $this m4VarDes [M4VarDescription new $this.m4VarDes]
  358.  
  359.     send -async [$this dispatcher] \
  360.     ClDispatcher::mtoolStarted [list [get_comm_name]] $cmd [list $dir]
  361.     return $this
  362. }
  363.  
  364. method ClMtool::messageAreaPresent {this show} {
  365.     if {$show} {
  366.     $this addMessageArea
  367.     } else {
  368.     [$this messageArea] delete
  369.     }
  370. }
  371.  
  372. method ClMtool::toolBarPresent {this show} {
  373.     if {$show} {
  374.     $this addToolBar
  375.     } else {
  376.     [$this toolBar] delete
  377.     }
  378. }
  379.  
  380. method ClMtool::addToolBar {this} {
  381.     ToolBar new .main.bar -entrySet {
  382.     .main.menubar.file.menu.save
  383.     .main.menubar.file.menu.print
  384.     .main.menubar.file.menu.exit
  385.     SEPARATOR
  386.     .main.menubar.edit.menu.copy
  387.     SEPARATOR
  388.     .main.menubar.options.menu.clearscreen
  389.     .main.menubar.options.menu.reuse
  390.     .main.menubar.options.menu.suspendoutput
  391.     }
  392. }
  393.  
  394. method ClMtool::setToolBarPresence {this} {
  395.     if [m4_var get M4_toolbar -context mtool] {
  396.     $this addToolBar
  397.     } else {
  398.     [$this menuBar].view.menu.toolbar state 0
  399.     }
  400. }
  401.  
  402. method ClMtool::saveToolBarPresence {this} {
  403.     set toolBarPresent [expr {[$this toolBar] != ""}]
  404.     if {$toolBarPresent != [m4_var get M4_toolbar -context mtool]} {
  405.     m4_var set M4_toolbar $toolBarPresent -context mtool
  406.     }
  407. }
  408.  
  409. method ClMtool::addMessageArea {this} {
  410.     MessageArea new $this.msg
  411. }
  412.  
  413. method ClMtool::setMessageAreaPresence {this} {
  414.     if [m4_var get M4_messagearea -context mtool] {
  415.     $this addMessageArea
  416.     } else {
  417.     [$this menuBar].view.menu.messagearea state 0
  418.     }
  419. }
  420.  
  421. method ClMtool::saveMessageAreaPresence {this} {
  422.     set areaPresent [expr {[$this messageArea] != ""}]
  423.     if {$areaPresent != [m4_var get M4_messagearea -context mtool]} {
  424.     m4_var set M4_messagearea $areaPresent -context mtool
  425.     }
  426. }
  427.  
  428.  
  429. # Callback for when a command is started.
  430. #
  431. method ClMtool::cmdStarted {this msg} {
  432.     [$this menuBar].file.menu.exit sensitive no
  433.     [$this menuBar].process.menu.terminate sensitive yes
  434.     if {! $win95} {
  435.     [$this menuBar].process.menu.abort sensitive yes
  436.     [$this menuBar].process.menu.kill sensitive yes
  437.     }
  438.     wmtkmessage $msg
  439. }
  440.  
  441.  
  442. # Callback for when a command is finished.
  443. #
  444. method ClMtool::cmdFinished {this msg} {
  445.     wmtkmessage $msg
  446.     if {"[$this clientId]" == ""} {
  447.     return
  448.     }
  449.     [$this menuBar].file.menu.exit sensitive yes
  450.     [$this menuBar].process.menu.terminate sensitive no
  451.     if {! $win95} {
  452.     [$this menuBar].process.menu.abort sensitive no
  453.     [$this menuBar].process.menu.kill sensitive no
  454.     }
  455.     $this notifyFinished
  456. }
  457.  
  458.  
  459. # Update the title of the OutTermWindow.
  460. #
  461. method ClMtool::updateTitle {this} {
  462.     $this Exetool::updateTitle
  463.     $this popUp
  464. }
  465.  
  466.  
  467. # Start the execution of command(s) and show the output
  468. # in the OutTermWindow.
  469. #
  470. method ClMtool::execute {this} {
  471.     [$this suspendButton] state no
  472.     [$this win] commandLine [$this cmdLine]
  473.     [$this win] execute
  474. }
  475.  
  476.  
  477. # Stop the Mtool if it is not busy.
  478. #
  479. method ClMtool::stop {this} {
  480.     if {![[$this win] busy]} {
  481.     $this busy TRUE
  482.     wmtkmessage "Exiting..."
  483.     $this Exetool::stop
  484.     }
  485. }
  486.  
  487. method ClMtool::handleReusableChanged {this} {
  488.     $this reusable [[$this reuseButton] state]
  489.     m4_var set M4_reuse_tool [$this reusable] -context mtool
  490.     if {![[$this win] busy]} {
  491.     $this Exetool::handleReusableChanged
  492.     }
  493. }
  494.  
  495. method ClMtool::toolName {this} {
  496.     return mtool
  497. }
  498.  
  499. # Do not delete this line -- regeneration end marker
  500.  
  501.