TerminalApplication.st
author vrany
Wed, 30 Nov 2011 11:06:32 +0100
changeset 10937 9e0d1a54404a
parent 10253 b2a15ece506c
child 12123 4bde08cebd48
child 13135 6da72f8dbefa
permissions -rw-r--r--
changed: #createWorkspace

"
 COPYRIGHT (c) 2001 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libtool' }"

MultiViewToolApplication subclass:#TerminalApplication
	instanceVariableNames:'initialDirectory'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Smalltalk'
!

!TerminalApplication class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2001 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    A simple wrapper around a Terminal-View, adding a pullDown menu.

    [author:]
        Claus Gittinger
"
! !

!TerminalApplication class methodsFor:'interface specs'!

windowSpec
    "This resource specification was automatically generated
     by the UIPainter of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the UIPainter may not be able to read the specification."

    "
     UIPainter new openOnClass:TerminalApplication andSelector:#windowSpec
     TerminalApplication new openInterface:#windowSpec
     TerminalApplication open
    "

    <resource: #canvas>

    ^ 
     #(#FullSpec
        #name: #windowSpec
        #window: 
       #(#WindowSpec
          #label: 'Terminal'
          #name: 'Terminal'
          #min: #(#Point 10 10)
          #bounds: #(#Rectangle 13 23 445 264)
          #menu: #mainMenu
        )
        #component: 
       #(#SpecCollection
          #collection: #(
           #(#NoteBookViewSpec
              #name: 'NoteBook1'
              #layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
              #model: #selectedWorkspaceIndexHolder
              #menu: #tabList
              #useIndex: true
              #accessTabMenuAction: #tabMenuAt:
              #canvas: #workspaceHolder
              #canvasInset: 0
              #canvasFrameLevel: 0
              #keepCanvasAlive: true
              #tabLevel: 1
            )
           )
         
        )
      )
! !

!TerminalApplication class methodsFor:'menu specs'!

mainMenu
    "This resource specification was automatically generated
     by the MenuEditor of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the MenuEditor may not be able to read the specification."

    "
     MenuEditor new openOnClass:WorkspaceApplication andSelector:#mainMenu
     (Menu new fromLiteralArrayEncoding:(WorkspaceApplication mainMenu)) startUp
    "

    <resource: #menu>

    ^ 
     #(#Menu
        #(
         #(#MenuItem
            #label: 'File'
            #translateLabel: true
            #submenu: 
           #(#Menu
              #(
               #(#MenuItem
                  #label: 'New Shell'
                  #itemValue: #newWorkspace
                  #translateLabel: true
                )
               #(#MenuItem
                  #label: '-'
                )
               #(#MenuItem
                  #label: 'Playback File...'
                  #itemValue: #menuPlayback
                  #translateLabel: true
                )
               #(#MenuItem
                  #label: '-'
                )
               #(#MenuItem
                  #label: 'Save As...'
                  #itemValue: #menuSaveAs
                  #translateLabel: true
                )
               #(#MenuItem
                  #enabled: #hasMultipleBuffersHolder
                  #label: 'Save all As...'
                  #itemValue: #menuSaveAllAs
                  #translateLabel: true
                )
               #(#MenuItem
                  #label: '-'
                )
               #(#MenuItem
                  #label: 'Exit'
                  #itemValue: #closeRequest
                  #translateLabel: true
                )
               )
              nil
              nil
            )
          )
         #(#MenuItem
            #label: 'Buffers'
            #nameKey: #Buffer
            #translateLabel: true
            #submenu: 
           #(#Menu
              #(
               #(#MenuItem
                  #label: 'Add Buffer'
                  #itemValue: #addWorkspace
                  #translateLabel: true
                )
               #(#MenuItem
                  #label: 'Rename...'
                  #itemValue: #renameWorkspace
                  #translateLabel: true
                )
               #(#MenuItem
                  #label: '-'
                )
               #(#MenuItem
                  #enabled: #canRemoveWorkspace
                  #label: 'Remove Buffer'
                  #itemValue: #removeWorkspace
                  #translateLabel: true
                )
               )
              nil
              nil
            )
          )
         #(#MenuItem
            #label: 'Edit'
            #translateLabel: true
            #submenu: 
           #(#Menu
              #(
               #(#MenuItem
                  #enabled: #hasSelectionInActiveWorkspace
                  #label: 'Copy'
                  #itemValue: #copySelection
                  #translateLabel: true
                )
               #(#MenuItem
                  #label: 'Paste'
                  #itemValue: #paste
                  #translateLabel: true
                )
               #(#MenuItem
                  #label: '-'
                )
               #(#MenuItem
                  #label: 'Select All'
                  #itemValue: #selectAll
                  #translateLabel: true
                )
               )
              nil
              nil
            )
          )
         #(#MenuItem
            #label: 'Shell'
            #translateLabel: true
            #submenu: 
           #(#Menu
              #(
               #(#MenuItem
                  #label: 'Interrupt'
                  #itemValue: #doSendInterrupt
                  #translateLabel: true
                )
               #(#MenuItem
                  #label: 'Kill'
                  #itemValue: #doSendKillSignal
                  #translateLabel: true
                )
               #(#MenuItem
                  #label: '-'
                )
               #(#MenuItem
                  #label: 'Reset Terminal'
                  #itemValue: #doReset
                  #translateLabel: true
                )
               )
              nil
              nil
            )
          )
         #(#MenuItem
            #label: 'Help'
            #translateLabel: true
            #startGroup: #right
            #submenu: 
           #(#Menu
              #(
               #(#MenuItem
                  #label: 'Documentation'
                  #itemValue: #openDocumentation
                  #translateLabel: true
                )
               #(#MenuItem
                  #label: '-'
                )
               #(#MenuItem
                  #label: 'About this Application...'
                  #itemValue: #openAboutThisApplication
                  #translateLabel: true
                )
               )
              nil
              nil
            )
          )
         )
        nil
        nil
      )
!

tabMenu
    "This resource specification was automatically generated
     by the MenuEditor of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the MenuEditor may not be able to read the specification."

    "
     MenuEditor new openOnClass:WorkspaceApplication andSelector:#tabMenu
     (Menu new fromLiteralArrayEncoding:(WorkspaceApplication tabMenu)) startUp
    "

    <resource: #menu>

    ^ 
     #(#Menu
        #(
         #(#MenuItem
            #label: 'Add Buffer'
            #translateLabel: true
            "/ #triggerOnDown: true
            #value: #addWorkspace
          )
         #(#MenuItem
            #label: 'Rename...'
            #translateLabel: true
            "/ #triggerOnDown: true
            #value: #renameWorkspace:
          )
         #(#MenuItem
            #label: '-'
          )
         #(#MenuItem
            #label: 'Remove Buffer'
            #translateLabel: true
            "/ #triggerOnDown: true
            #value: #removeWorkspace:
            #enabled: #canRemoveWorkspace:
          )
         )
        nil
        nil
      )
! !

!TerminalApplication class methodsFor:'special startup'!

openIn:aDirectory
    "launch a new terminal in some directory"

    |terminal|

    terminal := self new.
    terminal initialDirectory:aDirectory.
    terminal open.
    ^ terminal

    "
     TerminalApplication open
     TerminalApplication openIn:'/etc'
    "
! !

!TerminalApplication methodsFor:'menu-actions'!

addWorkspace
    self addWindow:(self createWorkspace) named:'Terminal%1'
!

createWorkspace
    |scr|

"/    JV@2011-11-30: XTermView disabled as recent changes in
"/    #startShellInSelectedWindow leads to infinite loop.
"/    further investigation needed.        

"/    (OperatingSystem isUNIXlike and:[XTermView notNil]) ifTrue:[
"/        scr := XTermView new.
"/        scr workingDirectory: initialDirectory.
"/    ] ifFalse:[
        VT100TerminalView isNil ifTrue:[
            self error:'missing: VT100TerminalView'
        ].
        scr := (HVScrollableView for:VT100TerminalView).
        scr autoHideScrollBars:false.
        scr horizontalMini:true.
"/    ].

    self window realized ifTrue:[
        self window sensor pushUserEvent:#startShellInSelectedWindow for:self.
    ].
    ^ scr

    "Modified: / 08-04-2011 / 14:56:57 / cg"
    "Modified (format): / 30-11-2011 / 11:06:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

doKill
    self selectedWorkspacesTextView doKill.
!

doReset
    self selectedWorkspacesTextView doReset.
!

doSendInterrupt
    self selectedWorkspacesTextView doSendInterrupt.
!

doSendKillSignal
    self selectedWorkspacesTextView doSendKillSignal.
!

menuPlayback
    |file suff|

    suff := 'sh'.

    OperatingSystem isMSDOSlike ifTrue:[ suff := 'bat' ].
    file := Dialog requestFileName:'Playback file' default:('file.',suff) pattern:('*.',suff).
    file size > 0 ifTrue:[
        self playbackFile:file
    ]
!

openDocumentation
    "opens the documentation file"

    self openHTMLDocument: 'tools/misc/TOP.html#TERMINAL'
!

playbackFile:aFileName 
    |file ws|

    file := aFileName asFilename.
    file exists ifFalse:[
        Dialog warn:(resources string:'File %1 does not exist.' with:file asString).
        ^ self
    ].

    ws := self selectedWorkspacesTextView.
    file readingLinesDo:[:eachLine | ws sendLine:eachLine]
    .
! !

!TerminalApplication methodsFor:'private'!

isModifiedWorkspace:aView
    ^ false
! !

!TerminalApplication methodsFor:'startup'!

initialDirectory:aDirectory
    initialDirectory := aDirectory
!

postBuildWith:aBuilder
    |w h|

    super postBuildWith:aBuilder.

    w := self window width max:(workspaces first preferredExtent x).
    h := builder menuBar height + (workspaces first preferredExtent y).
    self window extent:(w@h).
!

postOpenWith:aBuilder
    self startShellInSelectedWindow.
    super postOpenWith:aBuilder
!

shellFinishedInWorkspace:aView
    "/ vt backgroundColor:(Color red).
    aView 
        cr; 
        nextPutLine:('>> shell terminated.' asText allBold colorizeAllWith:Color red).
!

startShellInSelectedWindow
    |vt|

    vt := self selectedWorkspacesTextView.
    (vt notNil and:[vt superView realized]) ifFalse:[
        self window sensor pushUserEvent:#startShellInSelectedWindow for:self.
        ^ self.
    ].

    vt startShellIn:initialDirectory.
    vt shellTerminateAction:[self shellFinishedInWorkspace:vt].

    "Modified: / 07-04-2011 / 09:03:55 / cg"
! !

!TerminalApplication class methodsFor:'documentation'!

version_CVS
    ^ '$Header: /cvs/stx/stx/libtool/TerminalApplication.st,v 1.11 2011-11-30 10:06:32 vrany Exp $'
! !