XTermView.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 30 Jan 2012 17:49:41 +0000
branchjv
changeset 12128 a7ff7d66ee85
parent 12125 0c49a3b13e43
child 12216 5698c277f043
permissions -rw-r--r--
Improvements in LintHighlighter, few fixes

"
 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.

    (XTermExecutable := OperatingSystem pathOfCommand:'urxvt') ifNotNil:[
        XTermType := #rxvt.
        ^self
    ].

    (XTermExecutable := OperatingSystem pathOfCommand:'rxvt') ifNotNil:[
        XTermType := #rxvt.
        ^self
    ].

    (XTermExecutable := OperatingSystem pathOfCommand:'xterm') ifNotNil:[
        XTermType := #xterm.
        ^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.2 2011/09/13 10:24:04 vrany Exp §'
!

version_SVN
    ^ '$Id: XTermView.st 7854 2012-01-30 17:49:41Z vranyj1 $'
! !

XTermView initialize!