DirectoryContentsBrowser.st
changeset 11058 ab216c9278c6
parent 10559 e36369957676
child 11177 4b83b53c4b1b
equal deleted inserted replaced
11057:a035d065549c 11058:ab216c9278c6
   900 
   900 
   901 directory:aDirectory
   901 directory:aDirectory
   902     "change the current directory and read the items
   902     "change the current directory and read the items
   903     "
   903     "
   904 
   904 
   905     directory notNil ifTrue:[
   905     aDirectory ~= directory ifTrue:[
   906         AbstractFileBrowser directoryHistory setPosition:(browser firstLineShown) for:(directory pathName).
   906         directory notNil ifTrue:[
   907     ].
   907             AbstractFileBrowser directoryHistory setPosition:(browser firstLineShown) for:(directory pathName).
   908     directory := aDirectory.
   908         ].
   909     self wakeUpForDirectoryChanged.
   909         directory := aDirectory.
       
   910         self wakeUpForDirectoryChanged.
       
   911     ]
       
   912 
       
   913     "Modified: / 07-01-2012 / 16:41:20 / cg"
   910 !
   914 !
   911 
   915 
   912 directoryChangeFlag
   916 directoryChangeFlag
   913     directoryChangeFlag isNil ifTrue:[
       
   914         directoryChangeFlag := false.
       
   915     ].
       
   916     ^ directoryChangeFlag
   917     ^ directoryChangeFlag
   917 
   918 
   918     "Modified: / 01-10-2007 / 19:22:31 / cg"
   919     "Modified: / 07-01-2012 / 16:34:39 / cg"
   919 !
   920 !
   920 
   921 
   921 directoryChangeFlag:something
   922 directoryChangeFlag:aBoolean
   922     directoryChangeFlag := something.
   923     directoryChangeFlag := aBoolean.
   923 
   924 
   924     "Modified: / 01-10-2007 / 19:22:35 / cg"
   925     "Modified: / 01-10-2007 / 19:22:35 / cg"
       
   926     "Modified (format): / 07-01-2012 / 16:34:46 / cg"
   925 !
   927 !
   926 
   928 
   927 directoryContentsChangeFlag
   929 directoryContentsChangeFlag
   928     "return the value of the instance variable 'directoryContentsChangeFlag' (automatically generated)"
   930     "return the value of the instance variable 'directoryContentsChangeFlag' (automatically generated)"
   929 
   931 
   930     directoryContentsChangeFlag isNil ifTrue:[
       
   931         directoryContentsChangeFlag := false.
       
   932     ].
       
   933     ^ directoryContentsChangeFlag
   932     ^ directoryContentsChangeFlag
   934 !
   933 
   935 
   934     "Modified: / 07-01-2012 / 16:34:51 / cg"
   936 directoryContentsChangeFlag:something
   935 !
       
   936 
       
   937 directoryContentsChangeFlag:aBoolean
   937     "set the value of the instance variable 'directoryContentsChangeFlag' (automatically generated)"
   938     "set the value of the instance variable 'directoryContentsChangeFlag' (automatically generated)"
   938 
   939 
   939     directoryContentsChangeFlag := something.
   940     directoryContentsChangeFlag := aBoolean.
       
   941 
       
   942     "Modified (format): / 07-01-2012 / 16:35:01 / cg"
   940 !
   943 !
   941 
   944 
   942 doubleClickAction
   945 doubleClickAction
   943 
   946 
   944     ^ doubleClickAction
   947     ^ doubleClickAction
   952 !
   955 !
   953 
   956 
   954 filterChangeFlag
   957 filterChangeFlag
   955     "return the value of the instance variable 'filterChangeFlag' (automatically generated)"
   958     "return the value of the instance variable 'filterChangeFlag' (automatically generated)"
   956 
   959 
   957     filterChangeFlag isNil ifTrue:[
       
   958         filterChangeFlag := false.
       
   959     ].
       
   960     ^ filterChangeFlag
   960     ^ filterChangeFlag
   961 !
   961 
   962 
   962     "Modified: / 07-01-2012 / 16:35:07 / cg"
   963 filterChangeFlag:something
   963 !
       
   964 
       
   965 filterChangeFlag:aBoolean
   964     "set the value of the instance variable 'filterChangeFlag' (automatically generated)"
   966     "set the value of the instance variable 'filterChangeFlag' (automatically generated)"
   965 
   967 
   966     filterChangeFlag := something.
   968     filterChangeFlag := aBoolean.
       
   969 
       
   970     "Modified (format): / 07-01-2012 / 16:35:12 / cg"
   967 !
   971 !
   968 
   972 
   969 isBusy
   973 isBusy
   970     "return the value of the instance variable 'isBusy' (automatically generated)"
   974     "return the value of the instance variable 'isBusy' (automatically generated)"
   971 
   975 
  1005 !
  1009 !
  1006 
  1010 
  1007 sortBlockChangeFlag
  1011 sortBlockChangeFlag
  1008     "return the value of the instance variable 'sortBlockChangeFlag' (automatically generated)"
  1012     "return the value of the instance variable 'sortBlockChangeFlag' (automatically generated)"
  1009 
  1013 
  1010     sortBlockChangeFlag isNil ifTrue:[
       
  1011         sortBlockChangeFlag := false.
       
  1012     ].
       
  1013     ^ sortBlockChangeFlag
  1014     ^ sortBlockChangeFlag
  1014 !
  1015 
  1015 
  1016     "Modified: / 07-01-2012 / 16:35:20 / cg"
  1016 sortBlockChangeFlag:something
  1017 !
       
  1018 
       
  1019 sortBlockChangeFlag:aBoolean
  1017     "set the value of the instance variable 'sortBlockChangeFlag' (automatically generated)"
  1020     "set the value of the instance variable 'sortBlockChangeFlag' (automatically generated)"
  1018 
  1021 
  1019     sortBlockChangeFlag := something.
  1022     sortBlockChangeFlag := aBoolean.
       
  1023 
       
  1024     "Modified (format): / 07-01-2012 / 16:35:25 / cg"
  1020 !
  1025 !
  1021 
  1026 
  1022 updateContentsSelection
  1027 updateContentsSelection
  1023     "return the value of the instance variable 'updateToExternFileHolder' (automatically generated)"
  1028     "return the value of the instance variable 'updateToExternFileHolder' (automatically generated)"
  1024 
  1029 
  1788 
  1793 
  1789 initialize
  1794 initialize
  1790     changeSema := Semaphore new. 
  1795     changeSema := Semaphore new. 
  1791     updateCycleSemaphore := Semaphore new.
  1796     updateCycleSemaphore := Semaphore new.
  1792     accessLock := RecursionLock new.
  1797     accessLock := RecursionLock new.
       
  1798 
       
  1799     filterChangeFlag := false.
       
  1800     sortBlockChangeFlag := false.
       
  1801     directoryChangeFlag := false.
       
  1802     directoryContentsChangeFlag := false.
       
  1803 
  1793     super initialize.
  1804     super initialize.
  1794 
  1805 
  1795     "Modified: / 12-12-2006 / 17:10:05 / cg"
  1806     "Modified: / 07-01-2012 / 16:34:25 / cg"
  1796 ! !
  1807 ! !
  1797 
  1808 
  1798 !DirectoryContentsBrowser methodsFor:'menu accessing'!
  1809 !DirectoryContentsBrowser methodsFor:'menu accessing'!
  1799 
  1810 
  1800 viewBrowserMenu
  1811 viewBrowserMenu
  2186         "/ update icon for visible items by suffix
  2197         "/ update icon for visible items by suffix
  2187         desc := self findNextVisibleItemFor:[:n| n iconOrNil isNil ].
  2198         desc := self findNextVisibleItemFor:[:n| n iconOrNil isNil ].
  2188         desc notNil ifTrue:[  
  2199         desc notNil ifTrue:[  
  2189             icon := self getIconFor:desc.
  2200             icon := self getIconFor:desc.
  2190             icon notNil ifTrue:[
  2201             icon notNil ifTrue:[
       
  2202                 icon ~= desc icon ifTrue:[
       
  2203                     desc icon:icon.
       
  2204                     (iconIndex ~~ 0) ifTrue:[
       
  2205                         browser invalidateVisibleRow:desc colAt:iconIndex
       
  2206                     ].
       
  2207                     self debugMessage:'icon for visible items ', desc baseName.
       
  2208                 ].
       
  2209             ].
       
  2210                     ^ true
       
  2211         ].
       
  2212         "/ update icon for visible items by contents
       
  2213         desc := self findNextVisibleItemFor:
       
  2214                     [:n| 
       
  2215                         (n iconKey == #file 
       
  2216                         and:[(mime := n mimeTypeForContents asSymbol) ~= #unknown])
       
  2217                     ].
       
  2218         desc notNil ifTrue:[
       
  2219             icon := self getIconForMimeType:mime for:desc.
       
  2220 "/            icon := self getIconForMimeTypeByContents:desc.
       
  2221             icon ~= desc icon ifTrue:[
  2191                 desc icon:icon.
  2222                 desc icon:icon.
  2192                 (icon notNil and:[iconIndex ~~ 0]) ifTrue:[
  2223                 (icon notNil and:[iconIndex ~~ 0]) ifTrue:[
  2193                     browser invalidateVisibleRow:desc colAt:iconIndex
  2224                     browser invalidateVisibleRow:desc colAt:iconIndex
  2194                 ].
  2225                 ].
  2195                 self debugMessage:'icon for visible items ', desc baseName.
       
  2196                 ^ true
       
  2197             ].
       
  2198         ].
       
  2199         "/ update icon for visible items by contents
       
  2200         desc := self findNextVisibleItemFor:[:n| 
       
  2201             (n iconKey == #file 
       
  2202             and:[(mime := n mimeTypeForContents asSymbol) ~= #unknown])
       
  2203         ].
       
  2204         desc notNil ifTrue:[
       
  2205             icon := self getIconForMimeType:mime for:desc.
       
  2206 "/            icon := self getIconForMimeTypeByContents:desc.
       
  2207             desc icon:icon.
       
  2208             (icon notNil and:[iconIndex ~~ 0]) ifTrue:[
       
  2209                 browser invalidateVisibleRow:desc colAt:iconIndex
       
  2210             ].
  2226             ].
  2211             ^ true
  2227             ^ true
  2212         ].
  2228         ].
  2213         "/ update file info for visible items if file info column is shown
  2229         "/ update file info for visible items if file info column is shown
  2214         fileDescriptionIndex ~~ 0 ifTrue:[
  2230         fileDescriptionIndex ~~ 0 ifTrue:[
  2283             self debugMessage:'update file info for invisible items if file info column is not shown: ', desc baseName.
  2299             self debugMessage:'update file info for invisible items if file info column is not shown: ', desc baseName.
  2284             ^ true
  2300             ^ true
  2285         ].
  2301         ].
  2286     ].
  2302     ].
  2287     ^ false
  2303     ^ false
       
  2304 
       
  2305     "Modified: / 07-01-2012 / 16:39:12 / cg"
  2288 ! !
  2306 ! !
  2289 
  2307 
  2290 !DirectoryContentsBrowser methodsFor:'update modification cycle'!
  2308 !DirectoryContentsBrowser methodsFor:'update modification cycle'!
  2291 
  2309 
  2292 modificationCycle
  2310 modificationCycle
  2293 
       
  2294     | oldModificationTime  desc|
  2311     | oldModificationTime  desc|
  2295 
  2312 
  2296     directory isNil ifTrue:[^ self].
  2313     directory isNil ifTrue:[^ self].
  2297 
  2314 
  2298     directory exists ifFalse:[
  2315     directory exists ifFalse:[
  2299         self directoryChangeFlag:true.
  2316         "/ directory vanished
       
  2317         directoryContentsChangeFlag := true.
  2300         ^ self
  2318         ^ self
  2301     ].
  2319     ].
  2302     directory isRootDirectory ifTrue:[
  2320     directory isRootDirectory ifTrue:[
  2303         ^ self
  2321         ^ self
  2304     ].
  2322     ].
  2305 
  2323 
  2306     oldModificationTime := modificationTime.
  2324     oldModificationTime := modificationTime.
  2307     modificationTime := directory modificationTime.
  2325     modificationTime := directory modificationTime.
  2308 
  2326 
  2309     oldModificationTime ~= modificationTime ifTrue:[
  2327     oldModificationTime ~= modificationTime ifTrue:[
  2310         self wakeUpForDirectoryContentsChanged.
  2328         directoryContentsChangeFlag := true.
       
  2329 "/        self wakeUpForDirectoryContentsChanged.
  2311         ^ self
  2330         ^ self
  2312     ].
  2331     ].
  2313 
  2332 
  2314     desc := self findNextItemFor:[:n| n hasBeenModified ].
  2333     desc := self findNextItemFor:[:n| n hasBeenModified ].
  2315 
  2334 
  2317         desc resetItem.
  2336         desc resetItem.
  2318         browser invalidateVisibleRow:desc.
  2337         browser invalidateVisibleRow:desc.
  2319         self debugMessage:'item is modified ', desc baseName.
  2338         self debugMessage:'item is modified ', desc baseName.
  2320         ^ self.
  2339         ^ self.
  2321     ].
  2340     ].
       
  2341 
       
  2342     "Modified: / 07-01-2012 / 16:42:40 / cg"
  2322 ! !
  2343 ! !
  2323 
  2344 
  2324 !DirectoryContentsBrowser methodsFor:'update task'!
  2345 !DirectoryContentsBrowser methodsFor:'update task'!
  2325 
  2346 
  2326 createItemList
  2347 createItemList
  2346         for:self
  2367         for:self
  2347         arguments:(Array with:filteredItems).
  2368         arguments:(Array with:filteredItems).
  2348 !
  2369 !
  2349 
  2370 
  2350 debugMessage:aString
  2371 debugMessage:aString
  2351 
       
  2352     Debug == true ifTrue:[
  2372     Debug == true ifTrue:[
  2353         Transcript showCR:aString
  2373         Transcript showCR:aString
  2354     ].
  2374     ].
       
  2375 
       
  2376     "
       
  2377      Debug := true
       
  2378      Debug := false
       
  2379     "
       
  2380 
       
  2381     "Modified (comment): / 07-01-2012 / 16:30:25 / cg"
  2355 !
  2382 !
  2356 
  2383 
  2357 directoryChanged
  2384 directoryChanged
  2358     "reread the whole list of items"
  2385     "reread the whole list of items"
  2359 
  2386 
  2521         updateTask terminate.
  2548         updateTask terminate.
  2522         updateTask := nil.
  2549         updateTask := nil.
  2523     ].
  2550     ].
  2524 !
  2551 !
  2525 
  2552 
       
  2553 updateAfterTimeout:timeOut
       
  2554 
       
  2555 "/    Transcript showCR:'START'.
       
  2556     self isBusy:true.
       
  2557     [
       
  2558         directoryChangeFlag ifTrue:[ 
       
  2559             directoryChangeFlag := false.
       
  2560             self debugMessage:'directoryChanged'.
       
  2561             self directoryChanged.
       
  2562         ].
       
  2563         directoryContentsChangeFlag ifTrue:[
       
  2564             directoryContentsChangeFlag := false.
       
  2565             self debugMessage:'directoryContentsChanged'.
       
  2566             self directoryContentsChanged.
       
  2567         ].
       
  2568         filterChangeFlag ifTrue:[
       
  2569             filterChangeFlag := false.
       
  2570             self debugMessage:'filterChanged'.
       
  2571             self filterChanged.
       
  2572         ].
       
  2573         sortBlockChangeFlag ifTrue:[
       
  2574             sortBlockChangeFlag := false.
       
  2575             self debugMessage:'sortBlockChanged'.
       
  2576             self sortBlockChanged.
       
  2577         ].
       
  2578         timeOut ifTrue:[
       
  2579             self debugMessage:'evaluate modification'.
       
  2580             self modificationCycle
       
  2581         ].
       
  2582         self updateColumnsCycle ifTrue:[
       
  2583             self debugMessage:'next time another columns update'.
       
  2584             changeSema signal
       
  2585         ] ifFalse:[
       
  2586             self debugMessage:'next time no column update'.
       
  2587         ].
       
  2588     ] ensure:[
       
  2589         self isBusy:false.
       
  2590         updateCycleSemaphore signalIf
       
  2591     ].
       
  2592 "/        Transcript showCR:'STOP'.
       
  2593 
       
  2594     "Created: / 07-01-2012 / 16:27:50 / cg"
       
  2595 !
       
  2596 
  2526 updateStep
  2597 updateStep
  2527     |timedOut sensor|
  2598     |timedOut sensor|
  2528 
  2599 
  2529     "/ Processor yield.
  2600     "/ Processor yield.
  2530 
  2601 
  2537         timedOut ifFalse:[changeSema signal].
  2608         timedOut ifFalse:[changeSema signal].
  2538         ^ self 
  2609         ^ self 
  2539     ].
  2610     ].
  2540 
  2611 
  2541     AbortOperationRequest handle:[
  2612     AbortOperationRequest handle:[
  2542         "if directory changed all running update flags must be reset"
  2613         "/ to get out of a debugger loop...
  2543 
       
  2544         self debugMessage:'got an abort signal'.
  2614         self debugMessage:'got an abort signal'.
  2545         self directoryContentsChangeFlag:false.
  2615         self directoryContentsChangeFlag:false.
  2546         self filterChangeFlag:false.
  2616         self filterChangeFlag:false.
  2547         self sortBlockChangeFlag:false.
  2617         self sortBlockChangeFlag:false.
  2548     ] do:[
  2618     ] do:[
  2549         self debugMessage:'sema wait'.
  2619         self debugMessage:'sema wait'.
  2550         timedOut := (changeSema waitWithTimeoutMs:(self class updateTaskCyleTime)) isNil.
  2620         timedOut := (changeSema waitWithTimeoutMs:(self class updateTaskCyleTime)) isNil.
  2551         self debugMessage:'timedOut:', timedOut asString.
  2621         self debugMessage:'timedOut:', timedOut asString.
  2552 
  2622 
  2553         (self filterChangeFlag 
  2623         (filterChangeFlag 
  2554         or:[self sortBlockChangeFlag 
  2624         or:[ sortBlockChangeFlag
  2555         or:[self directoryChangeFlag
  2625         or:[ directoryChangeFlag
  2556         or:[self directoryContentsChangeFlag]]]) ifTrue:[
  2626         or:[ directoryContentsChangeFlag ]]]) ifTrue:[
  2557             accessLock critical:[
  2627             accessLock critical:[
  2558                 self updateWithTimeout:timedOut.
  2628                 self updateAfterTimeout:timedOut.
  2559             ].
  2629             ].
  2560         ].
  2630         ].
  2561     ].
  2631     ].
  2562 
  2632 
  2563     "Modified: / 02-03-2011 / 23:00:02 / cg"
  2633     "Modified: / 07-01-2012 / 16:36:53 / cg"
  2564 !
       
  2565 
       
  2566 updateWithTimeout:timeOut
       
  2567 
       
  2568 "/    Transcript showCR:'START'.
       
  2569     self isBusy:true.
       
  2570     [
       
  2571         self directoryChangeFlag ifTrue:[ 
       
  2572             self directoryChangeFlag:false.
       
  2573             self debugMessage:'directoryChanged'.
       
  2574             self directoryChanged.
       
  2575         ].
       
  2576         self directoryContentsChangeFlag ifTrue:[
       
  2577             self directoryContentsChangeFlag:false.
       
  2578             self debugMessage:'directoryContentsChanged'.
       
  2579             self directoryContentsChanged.
       
  2580         ].
       
  2581         self filterChangeFlag ifTrue:[
       
  2582             self filterChangeFlag:false.
       
  2583             self debugMessage:'filterChanged'.
       
  2584             self filterChanged.
       
  2585         ].
       
  2586         self sortBlockChangeFlag ifTrue:[
       
  2587             self sortBlockChangeFlag:false.
       
  2588             self debugMessage:'sortBlockChanged'.
       
  2589             self sortBlockChanged.
       
  2590         ].
       
  2591         timeOut ifTrue:[
       
  2592             self debugMessage:'evaluate modification'.
       
  2593             self modificationCycle
       
  2594         ].
       
  2595         self updateColumnsCycle ifTrue:[
       
  2596             self debugMessage:'next time another columns update'.
       
  2597             changeSema signal
       
  2598         ] ifFalse:[
       
  2599             self debugMessage:'next time no column update'.
       
  2600         ].
       
  2601     ] ensure:[
       
  2602         self isBusy:false.
       
  2603         updateCycleSemaphore signalIf
       
  2604     ].
       
  2605 "/        Transcript showCR:'STOP'.
       
  2606 ! !
  2634 ! !
  2607 
  2635 
  2608 !DirectoryContentsBrowser methodsFor:'update task trigger'!
  2636 !DirectoryContentsBrowser methodsFor:'update task trigger'!
  2609 
  2637 
  2610 wakeUp
  2638 wakeUp
  2616 
  2644 
  2617     "Modified: / 10-08-2010 / 14:07:40 / sr"
  2645     "Modified: / 10-08-2010 / 14:07:40 / sr"
  2618 !
  2646 !
  2619 
  2647 
  2620 wakeUpForDirectoryChanged
  2648 wakeUpForDirectoryChanged
  2621 
       
  2622     self isBusy ifTrue:[
  2649     self isBusy ifTrue:[
  2623         self isBusy:false.
  2650         self isBusy:false.
  2624         updateTask interruptWith:[AbortSignal raise].
  2651         updateTask interruptWith:[AbortSignal raise].
  2625     ].
  2652     ].
  2626     self directoryChangeFlag:true.
  2653     directoryChangeFlag := true.
  2627     self wakeUp.
  2654     self wakeUp.
       
  2655 
       
  2656     "Modified: / 07-01-2012 / 16:43:12 / cg"
  2628 !
  2657 !
  2629 
  2658 
  2630 wakeUpForDirectoryContentsChanged
  2659 wakeUpForDirectoryContentsChanged
  2631 
  2660 
  2632     self directoryContentsChangeFlag:true.
  2661     self directoryContentsChangeFlag:true.
  3341 ! !
  3370 ! !
  3342 
  3371 
  3343 !DirectoryContentsBrowser class methodsFor:'documentation'!
  3372 !DirectoryContentsBrowser class methodsFor:'documentation'!
  3344 
  3373 
  3345 version
  3374 version
  3346     ^ '$Header: /cvs/stx/stx/libtool/DirectoryContentsBrowser.st,v 1.240 2011-08-09 16:21:14 vrany Exp $'
  3375     ^ '$Header: /cvs/stx/stx/libtool/DirectoryContentsBrowser.st,v 1.241 2012-01-07 17:09:40 cg Exp $'
  3347 !
  3376 !
  3348 
  3377 
  3349 version_CVS
  3378 version_CVS
  3350     ^ '$Header: /cvs/stx/stx/libtool/DirectoryContentsBrowser.st,v 1.240 2011-08-09 16:21:14 vrany Exp $'
  3379     ^ '$Header: /cvs/stx/stx/libtool/DirectoryContentsBrowser.st,v 1.241 2012-01-07 17:09:40 cg Exp $'
  3351 ! !
  3380 ! !