AbstractFileBrowser.st
changeset 6284 cf7d9fccade1
parent 6281 e8e47b1b290f
child 6286 fac153824f35
equal deleted inserted replaced
6283:7fa17d36a91c 6284:cf7d9fccade1
  2080 ! !
  2080 ! !
  2081 
  2081 
  2082 !AbstractFileBrowser methodsFor:'actions'!
  2082 !AbstractFileBrowser methodsFor:'actions'!
  2083 
  2083 
  2084 askForCommandFor:fileName thenDo:aBlock
  2084 askForCommandFor:fileName thenDo:aBlock
  2085     "setup and launch a querybox to ask for unix command.
  2085     "setup and launch a querybox to ask for a unix command.
  2086      Then evaluate aBlock passing the command-string as argument."
  2086      Then evaluate aBlock passing the command-string as argument."
  2087 
  2087 
  2088     |box osName commandString|
  2088     |box osName commandString|
  2089 
  2089 
  2090     osName := OperatingSystem platformName.
  2090     osName := OperatingSystem platformName.
  2457 ! !
  2457 ! !
  2458 
  2458 
  2459 !AbstractFileBrowser methodsFor:'aspects'!
  2459 !AbstractFileBrowser methodsFor:'aspects'!
  2460 
  2460 
  2461 applications
  2461 applications
  2462     "returns the list of registered applications
       
  2463     "
       
  2464     ^ aspects at:#applications
  2462     ^ aspects at:#applications
  2465 !
  2463 !
  2466 
  2464 
  2467 backgroundProcesses
  2465 backgroundProcesses
  2468 
  2466 
  2658 ! !
  2656 ! !
  2659 
  2657 
  2660 !AbstractFileBrowser methodsFor:'aspects handling'!
  2658 !AbstractFileBrowser methodsFor:'aspects handling'!
  2661 
  2659 
  2662 aspectFor:something ifAbsent:aBlock
  2660 aspectFor:something ifAbsent:aBlock
  2663     "returns the model for an aspect
  2661     "returns the model for an aspect; these are stored in a common dictionary"
  2664     "
  2662 
  2665     ^ self aspectFor:something ifAbsent:aBlock notPresentDo:nil
  2663     ^ self aspectFor:something ifAbsent:aBlock notPresentDo:nil
  2666 !
  2664 !
  2667 
  2665 
  2668 aspectFor:aKey ifAbsent:aBlock notPresentDo:notPresentBlock
  2666 aspectFor:aKey ifAbsent:aBlock notPresentDo:notPresentBlock
  2669     "return the model for an aspect"
  2667     "returns the model for an aspect; these are stored in a common dictionary"
  2670 
  2668 
  2671     |holder saveAspectItem aspect|
  2669     |holder saveAspectItem aspect|
  2672 
  2670 
  2673     holder := aspects at:aKey ifAbsent:[
  2671     holder := aspects at:aKey ifAbsent:[
  2674         masterApplication notNil ifTrue:[
  2672         masterApplication notNil ifTrue:[
  2701     ].
  2699     ].
  2702     ^ holder
  2700     ^ holder
  2703 !
  2701 !
  2704 
  2702 
  2705 aspectFor:something put:aValueHolder
  2703 aspectFor:something put:aValueHolder
       
  2704     "stores the model for an aspect; these are stored in a common dictionary"
       
  2705 
  2706     aspects at:something put:aValueHolder
  2706     aspects at:something put:aValueHolder
  2707 !
  2707 !
  2708 
  2708 
  2709 aspects
  2709 aspects
       
  2710     "returns the common aspect dictionary"
       
  2711 
  2710     ^ aspects
  2712     ^ aspects
  2711 !
  2713 !
  2712 
  2714 
  2713 runtimeAspectValueFor:something
  2715 runtimeAspectValueFor:something
  2714     "returns the default aspect item from the class variable RuntimeAspects
  2716     "returns the default aspect item from the class variable RuntimeAspects
  2853 ! !
  2855 ! !
  2854 
  2856 
  2855 !AbstractFileBrowser methodsFor:'aspects-visibility'!
  2857 !AbstractFileBrowser methodsFor:'aspects-visibility'!
  2856 
  2858 
  2857 activityVisibilityChannel
  2859 activityVisibilityChannel
  2858     " activityVisibilityChannel switches the activity indicator on/off
  2860     " activityVisibilityChannel switches the activity indicator on/off"
  2859     "
       
  2860 
  2861 
  2861     ^ self aspectFor:#activityVisibilityChannel ifAbsent:[ false asValue ].
  2862     ^ self aspectFor:#activityVisibilityChannel ifAbsent:[ false asValue ].
  2862 !
  2863 !
  2863 
  2864 
  2864 openAlwaysInTextEditor
  2865 openAlwaysInTextEditor
  3194 
  3195 
  3195     ^ self aspectFor:#clipboard ifAbsent:[Clipboard new]
  3196     ^ self aspectFor:#clipboard ifAbsent:[Clipboard new]
  3196 !
  3197 !
  3197 
  3198 
  3198 copyFilesToClipBoard:colOfFiles
  3199 copyFilesToClipBoard:colOfFiles
  3199     "defete current selected files/directories
       
  3200     "
       
  3201     self putInClipBoard:colOfFiles as:#copy.
  3200     self putInClipBoard:colOfFiles as:#copy.
  3202 !
  3201 !
  3203 
  3202 
  3204 cutFilesToClipBoard:colOfFiles
  3203 cutFilesToClipBoard:colOfFiles
  3205     "defete current selected files/directories
  3204     "defete current selected files/directories
  3237 ! !
  3236 ! !
  3238 
  3237 
  3239 !AbstractFileBrowser methodsFor:'drag & drop'!
  3238 !AbstractFileBrowser methodsFor:'drag & drop'!
  3240 
  3239 
  3241 canDropFiles:dropedObjects for:filename 
  3240 canDropFiles:dropedObjects for:filename 
  3242     | filenameDirString filenameDir|
  3241     |filenameDirString filenameDir|
  3243 
  3242 
  3244     dropedObjects isEmpty ifTrue:[^ false].
  3243     dropedObjects isEmpty ifTrue:[^ false].
       
  3244 
  3245     filenameDir := self getDirWithoutFileName:filename.
  3245     filenameDir := self getDirWithoutFileName:filename.
  3246     filenameDir isWritable ifFalse:[^ false].
  3246     filenameDir isWritable ifFalse:[^ false].
       
  3247 
  3247     filenameDirString := filenameDir asString.
  3248     filenameDirString := filenameDir asString.
  3248 
  3249 
  3249     dropedObjects do:[:aDropObject | 
  3250     dropedObjects do:[:aDropObject | 
  3250         |dropFileName dropFileNameString|
  3251         (self canDropObject:aDropObject into:filenameDir) ifFalse:[^ false].
  3251         dropFileName := aDropObject theObject.
  3252 "/        |dropFileName dropFileNameString physicalPathName|
  3252         dropFileNameString := dropFileName asString.
  3253 "/
  3253         dropFileName isDirectory ifTrue:[
  3254 "/        dropFileName := aDropObject theObject.
  3254             (self fileName:filenameDirString startsWith:dropFileNameString) ifTrue:[
  3255 "/        dropFileNameString := dropFileName asString.
  3255                 self notify:'Cannot drop a directory into one of its parent directories'.
  3256 "/        dropFileName isDirectory ifTrue:[
  3256                 ^ false
  3257 "/            (self fileName:filenameDirString startsWith:dropFileNameString) ifTrue:[
  3257             ]
  3258 "/                self notify:'Cannot drop a directory into one of its parent directories'.
  3258         ] ifFalse:[
  3259 "/                ^ false
  3259             | physicalPathName |
  3260 "/            ]
  3260             physicalPathName := dropFileName physicalPathName.
  3261 "/        ] ifFalse:[
  3261             (filenameDirString = dropFileName directory asString 
  3262 "/            physicalPathName := dropFileName physicalPathName.
  3262             or:[ aDropObject isFileInArchive not and:[physicalPathName notNil
  3263 "/            (filenameDirString = dropFileName directory asString 
  3263                  and:[ filenameDirString = physicalPathName asFilename directory asString]]]) ifTrue:[
  3264 "/            or:[ aDropObject isFileInArchive not and:[physicalPathName notNil
  3264                 self notify:'Cannot drop a file into same directory'.
  3265 "/                 and:[ filenameDirString = physicalPathName asFilename directory asString]]]) ifTrue:[
  3265                 ^ false
  3266 "/                self notify:'Cannot drop a file into same directory'.
  3266             ]
  3267 "/                ^ false
       
  3268 "/            ]
       
  3269 "/        ]
       
  3270     ].
       
  3271     self notify:nil.
       
  3272     ^ true
       
  3273 !
       
  3274 
       
  3275 canDropObject:aDropObject into:aDirectory
       
  3276     |filenameDirString dropFileName dropFileNameString physicalPathName|
       
  3277 
       
  3278     dropFileName := aDropObject theObject.
       
  3279     dropFileNameString := dropFileName asString.
       
  3280     dropFileName isDirectory ifTrue:[
       
  3281         filenameDirString := aDirectory asString.
       
  3282         (self fileName:filenameDirString startsWith:dropFileNameString) ifTrue:[
       
  3283             self notify:'Cannot drop a directory into one of its parent directories'.
       
  3284             ^ false
  3267         ]
  3285         ]
  3268     ].
  3286     ] ifFalse:[
  3269     ^ true
  3287         physicalPathName := dropFileName physicalPathName.
       
  3288         (aDirectory = dropFileName directory 
       
  3289         or:[ aDropObject isFileInArchive not 
       
  3290              and:[physicalPathName notNil
       
  3291              and:[ aDirectory = physicalPathName asFilename directory]]]) ifTrue:[
       
  3292             self notify:'Cannot drop a file into same directory'.
       
  3293             ^ false
       
  3294         ]
       
  3295     ].
       
  3296     ^ true.
  3270 !
  3297 !
  3271 
  3298 
  3272 doStartDrag:aDropSource in:aView
  3299 doStartDrag:aDropSource in:aView
  3273     "set the cursors before starting the drag & drop operation
  3300     "set the cursors before starting the drag & drop operation
  3274     "
  3301     "
  3300     self notify:msg.
  3327     self notify:msg.
  3301     ^ copy result
  3328     ^ copy result
  3302 !
  3329 !
  3303 
  3330 
  3304 copyFiles:aColOfSourceFiles to:aDirectory 
  3331 copyFiles:aColOfSourceFiles to:aDirectory 
  3305    "copy aColOfSourceFiles to aDirectory
       
  3306    "
       
  3307     |copy|
  3332     |copy|
  3308 
  3333 
  3309     self withWaitCursorDo:[
  3334     self withWaitCursorDo:[
  3310         copy := FileOperation copyFiles:aColOfSourceFiles to:aDirectory.
  3335         copy := FileOperation copyFiles:aColOfSourceFiles to:aDirectory.
  3311         copy result ifFalse:[
  3336         copy result ifFalse:[
  5727 ! !
  5752 ! !
  5728 
  5753 
  5729 !AbstractFileBrowser methodsFor:'menu queries-tools'!
  5754 !AbstractFileBrowser methodsFor:'menu queries-tools'!
  5730 
  5755 
  5731 anySTFilesPresent
  5756 anySTFilesPresent
  5732 
       
  5733     ^ self anyFilesPresentWithSuffix:'st'
  5757     ^ self anyFilesPresentWithSuffix:'st'
  5734 !
  5758 !
  5735 
  5759 
  5736 canCreateNewProject
  5760 canCreateNewProject
  5737 
  5761 
  6042 
  6066 
  6043     ^ nil
  6067     ^ nil
  6044 !
  6068 !
  6045 
  6069 
  6046 anyFilesPresentWithSuffix:suffix
  6070 anyFilesPresentWithSuffix:suffix
  6047 
       
  6048     |directories|
  6071     |directories|
  6049 
  6072 
  6050     directories := self currentDirectories value.
  6073     directories := self currentDirectories value.
  6051     directories do:[:dir|
  6074     directories do:[:dir|
  6052         [
  6075         [
  6097 
  6120 
  6098     ^ self fileListIsEmpty not.   
  6121     ^ self fileListIsEmpty not.   
  6099 !
  6122 !
  6100 
  6123 
  6101 fileName:aFilename1 startsWith:aFilename2
  6124 fileName:aFilename1 startsWith:aFilename2
  6102 
  6125     " check if aFilename2 is a prefix of aFilename1"
  6103 " check if aFilename2 starts with the same directories like aFilename1 "
       
  6104 
  6126 
  6105     | file1 file2 |
  6127     | file1 file2 |
  6106 
  6128 
  6107     aFilename2 isNil ifTrue:[ ^ false].
  6129     (aFilename2 isNil or:[aFilename1 isNil]) ifTrue:[ ^ false].
  6108     aFilename1 isNil ifTrue:[ ^ false].
       
  6109     file1 := aFilename1 asFilename.
  6130     file1 := aFilename1 asFilename.
  6110     file2 := aFilename2 asFilename.
  6131     file2 := aFilename2 asFilename.
       
  6132 
  6111     file2 isRootDirectory ifTrue:[ ^ true].
  6133     file2 isRootDirectory ifTrue:[ ^ true].
       
  6134 
  6112     ((file1 isDirectory) 
  6135     ((file1 isDirectory) 
  6113     and:[(file2 isDirectory)
  6136     and:[(file2 isDirectory)
  6114     and:[file1 directory = file2 directory]]) ifTrue:[
  6137     and:[file1 directory = file2 directory]]) ifTrue:[
  6115         ^ file1 baseName = file2 baseName
  6138         ^ file1 baseName = file2 baseName
  6116     ].
  6139     ].
  6691 ! !
  6714 ! !
  6692 
  6715 
  6693 !AbstractFileBrowser class methodsFor:'documentation'!
  6716 !AbstractFileBrowser class methodsFor:'documentation'!
  6694 
  6717 
  6695 version
  6718 version
  6696     ^ '$Header: /cvs/stx/stx/libtool/AbstractFileBrowser.st,v 1.289 2005-04-25 14:33:08 stefan Exp $'
  6719     ^ '$Header: /cvs/stx/stx/libtool/AbstractFileBrowser.st,v 1.290 2005-04-26 12:16:00 cg Exp $'
  6697 ! !
  6720 ! !