XTermView.st
author Claus Gittinger <cg@exept.de>
Fri, 21 Jun 2013 01:00:24 +0200
changeset 12947 46051d026ba5
parent 11831 f2e23f8433f1
child 12401 4714b9640528
child 13790 743e45769350
permissions -rw-r--r--
class: DebugView changed: #findHandlerFor #ignoreHaltOrBreakpoint:method:line:parameter:forCount:orTimeDuration:orUntilShiftKey:orReceiverClass:orProcess:

"
 COPYRIGHT (c) 2006 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' }"

XEmbedContainerView subclass:#XTermView
	instanceVariableNames:'pid wid wd'
	classVariableNames:'XTermType XTermExecutable'
	poolDictionaries:''
	category:'Interface-Tools-Terminal'
!

!XTermView class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2006 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.
"
! !

!XTermView class methodsFor:'class initialization'!

initialize

    XTermType := #unavailable.
    #(urxvt rxvt xterm) do:[:eachXtermCommandSymbol|	
    	(XTermExecutable := OperatingSystem pathOfCommand:eachXtermCommandSymbol) notNil ifTrue:[
       	    XTermType := eachXtermCommandSymbol.
            ^ self
	].
    ].

    "
        XTermView initialize 
    "

    "Created: / 09-12-2010 / 23:15:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!XTermView class methodsFor:'defaults'!

defaultFont

    DefaultFont ifNotNil:[^CodeView defaultFont].
    ^super defaultFont.

    "Created: / 25-11-2010 / 12:50:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

updateStyleCache

    super updateStyleCache.
    "/DefaultViewBackgroundColor := Color black.

    "Created: / 25-11-2010 / 12:21:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!XTermView class methodsFor:'queries'!

isAvailable

    ^XTermType ~= #unavailable

    "Created: / 09-12-2010 / 23:21:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!XTermView methodsFor:'accessing'!

workingDirectory: aStringOrFilename

    aStringOrFilename ifNotNil:
        [wd := aStringOrFilename asString].

    "Created: / 25-11-2010 / 12:32:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!XTermView methodsFor:'event handling'!

clientUnplugged: clientInitiated

    | app |

    super clientUnplugged: clientInitiated.

    clientInitiated ifFalse:[^self].
    
    "But hackish..."
    app := self application.
    app ifNil:[^self].
    #(removeWorkspace "WorkspaceApplication"
      doCloseApplication "FileBrowserNotebook"
      bufferMenuRemoveCurrentBuffer "NewSystemBrowser"
    ) do:[:closeSelector|
        (app topApplication respondsTo: closeSelector) ifTrue:
            [app topApplication perform: closeSelector]].

    "Created: / 06-06-2011 / 10:04:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!XTermView methodsFor:'initialization & release'!

destroy

    super destroy.
    pid ifNotNil:
        [OperatingSystem terminateProcess: pid].

    "Created: / 25-11-2010 / 10:48:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 01-06-2011 / 13:13:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

initStyle

    "Created: / 25-11-2010 / 12:14:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

initialize

    super initialize.
    wd := Filename defaultDirectory asString

    "Created: / 25-11-2010 / 12:34:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!XTermView methodsFor:'mimicry'!

shellTerminateAction: aBlock

    "Nothing to do"

    "Created: / 25-11-2010 / 12:37:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

startShellIn:aUnixFilename

    "Nothing to do. just to be compatible with TerminalView"

    "Created: / 25-11-2010 / 12:38:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!XTermView methodsFor:'private'!

xcolorNameFor: aColor

    ^'rgb:%1/%2/%3' 
            bindWith: (aColor redByte   printStringRadix: 16)
                with: (aColor greenByte printStringRadix: 16)
                with: (aColor blueByte  printStringRadix: 16)

    "Created: / 25-11-2010 / 12:25:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

xtermArgs

    | args |

    args := OrderedCollection new.
    args
        add: self xtermExecutable;
        add: (XTermType == #rxvt ifTrue:['-embed'] ifFalse:['-into']); add: drawableId address printString;        
        add: '-j';
        add: '-font'; add: (device fullFontNameOf: (font fontId));
        add: '-fg'; add: 'white'"(self xcolorNameFor: foreground)";
        add: '-bg'; add: 'black'"(self xcolorNameFor: viewBackground)".

    XTermType == #rxvt ifTrue:[
    args
        add: '-tn'; add: 'xterm'
    ].

    ^args asArray

    "Modified: / 10-06-2011 / 19:51:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

xtermExecutable

    ^ XTermExecutable

    "Modified: / 09-12-2010 / 23:16:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!XTermView methodsFor:'queries'!

preferredExtent
    "return my preferred extent - this is the minimum size I would like to have.
     If the preferredExtent has been set, that one is returned.
     Otherwise, if there are any components, a rectangle enclosing them
     is returned. Otherwise, the actual extent is returned."

    "/ If I have an explicit preferredExtent..
    explicitExtent notNil ifTrue:[
        ^ explicitExtent
    ].

    "/ If I have a cached preferredExtent value..
    preferredExtent notNil ifTrue:[
        ^ preferredExtent
    ].

    ^(font width * 80) @ (font height * 25)

    "Modified: / 19-07-1996 / 20:43:32 / cg"
    "Created: / 25-11-2010 / 12:51:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!XTermView methodsFor:'realization'!

postRealize

    super postRealize.
    XTermType ~= #rxvt ifTrue:[self sizeChanged: nil]

    "Created: / 25-11-2010 / 11:08:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-12-2010 / 22:08:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

preRealize
    super preRealize.
    clientViewId isNil ifTrue:[
    pid := OperatingSystem 
                exec:self xtermExecutable
                withArguments:self xtermArgs
                fork:true
                inDirectory: wd.
    ]

    "Created: / 25-11-2010 / 10:51:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 02-06-2011 / 23:27:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!XTermView methodsFor:'testing'!

isTextView

    ^false

    "Created: / 13-09-2011 / 11:22:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!XTermView class methodsFor:'documentation'!

version_CVS
    ^ '$Header: /cvs/stx/stx/libtool/XTermView.st,v 1.3 2012-10-01 10:46:37 stefan Exp $'
!

version_SVN
    ^ '§Id: XTermView.st 7802 2011-07-05 18:33:36Z vranyj1 §'
! !

XTermView initialize!