UnixDesktop.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 12 Aug 2009 14:49:00 +0100
branchjv
changeset 17723 0cd9ce703bab
child 17761 b0e5971141bc
permissions -rw-r--r--
- Support for better desktop integration - classes AbstractDesktop and friends. - Introduced class Language (and SmalltalkLanguage as default)

"{ Package: 'stx:libbasic' }"

AbstractDesktop subclass:#UnixDesktop
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'System-Desktop'
!


!UnixDesktop class methodsFor:'accessing'!

priority

    ^1

    "Modified: / 11-08-2009 / 16:40:06 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!UnixDesktop class methodsFor:'accessing - defaults'!

defaultEditorCommand
    ^ (OperatingSystem getEnvironment: 'VISUAL') 
        ifNil: [ (OperatingSystem getEnvironment: 'EDITOR') ]

    "Created: / 11-08-2009 / 16:53:52 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!UnixDesktop class methodsFor:'testing'!

isAvailable

    ^OperatingSystem isUNIXlike

    "Modified: / 11-08-2009 / 16:40:30 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!UnixDesktop methodsFor:'accessing - commands'!

editorCommand

    ^UserPreferences current editorCommand 
        ifNil:[self class defaultEditorCommand]

    "
        Desktop editorCommand
    "

    "Created: / 11-08-2009 / 17:32:42 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!UnixDesktop methodsFor:'operations'!

edit: filenames

    "
        Opens desktop's preferred editor on given filenames.

        filenames - a String or Filename or collection of those.
    "

    ^self execute: self editorCommand filenames: filenames

    "
        Desktop edit: '/home/janfrog/.emacs'
    "

    "Created: / 11-08-2009 / 17:35:57 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!UnixDesktop methodsFor:'operations - private'!

execute: command filenames: filenames

    | filenamesAsStrings placeholders |
    filenamesAsStrings := (self toArrayOfFilenames: filenames) collect:[:f|f asString].
    placeholders := Dictionary new.
    placeholders 
        at: 'f' put: (filenamesAsStrings asStringWith: Character space);
        at: 'F'  put: filenamesAsStrings first.

    ^self execute: command placeholders: placeholders.

    "Created: / 11-08-2009 / 17:40:10 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

execute: command placeholders: placeholders

    ^OperatingSystem 
        executeCommand:(command expandPlaceholdersWith: placeholders)

    "
        Desktop edit: '/home/janfrog/.emacs'
    "

    "Created: / 11-08-2009 / 17:41:45 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!UnixDesktop class methodsFor:'documentation'!

version
    ^'$Id: UnixDesktop.st 10461 2009-08-12 13:49:00Z vranyj1 $'
! !