AbstractFileBrowser.st
changeset 10304 ef51c640ee76
parent 10258 7d2454c716de
child 10305 58cfe23bd6cd
equal deleted inserted replaced
10303:8d251b3d7721 10304:ef51c640ee76
  2073                   label: 'Web Browser'
  2073                   label: 'Web Browser'
  2074                   itemValue: openWebBrowser
  2074                   itemValue: openWebBrowser
  2075                   translateLabel: true
  2075                   translateLabel: true
  2076                 )
  2076                 )
  2077                (MenuItem
  2077                (MenuItem
  2078                   "/ enabled: hasXmlFileSelected
       
  2079                   label: 'XML Inspector'
  2078                   label: 'XML Inspector'
  2080                   itemValue: inspectXmlFile
  2079                   itemValue: inspectXmlFile
  2081                   translateLabel: true
  2080                   translateLabel: true
  2082                   isVisible: hasXml
  2081                   isVisible: hasXml
  2083                   showBusyCursorWhilePerforming: true
  2082                   showBusyCursorWhilePerforming: true
  2268                   enabled: hasFileSelection
  2267                   enabled: hasFileSelection
  2269                   label: 'Hex Dump'
  2268                   label: 'Hex Dump'
  2270                   itemValue: fileHexDump
  2269                   itemValue: fileHexDump
  2271                   translateLabel: true
  2270                   translateLabel: true
  2272                 )
  2271                 )
  2273 "/ something I would like to have...
       
  2274 "/               (MenuItem
       
  2275 "/                  enabled: hasFileSelection
       
  2276 "/                  label: 'Hex Dump of First n Bytes...'
       
  2277 "/                  itemValue: fileHexDumpOfFirstNBytes
       
  2278 "/                  translateLabel: true
       
  2279 "/                )
       
  2280 "/               (MenuItem
       
  2281 "/                  enabled: hasFileSelection
       
  2282 "/                  label: 'Hex Dump of Last n Bytes...'
       
  2283 "/                  itemValue: fileHexDumpOfLastNBytes
       
  2284 "/                  translateLabel: true
       
  2285 "/                )
       
  2286                )
  2272                )
  2287               nil
  2273               nil
  2288               nil
  2274               nil
  2289             )
  2275             )
  2290           )
  2276           )
  2295            (Menu
  2281            (Menu
  2296               (
  2282               (
  2297                (MenuItem
  2283                (MenuItem
  2298                   label: 'File...'
  2284                   label: 'File...'
  2299                   itemValue: fileFindFile
  2285                   itemValue: fileFindFile
       
  2286                   translateLabel: true
       
  2287                 )
       
  2288                (MenuItem
       
  2289                   label: 'Duplicate File'
       
  2290                   itemValue: fileFindDuplicateFile
  2300                   translateLabel: true
  2291                   translateLabel: true
  2301                 )
  2292                 )
  2302                (MenuItem
  2293                (MenuItem
  2303                   label: 'Duplicate Files'
  2294                   label: 'Duplicate Files'
  2304                   itemValue: fileFindDuplicates
  2295                   itemValue: fileFindDuplicates
  2323           )
  2314           )
  2324          )
  2315          )
  2325         nil
  2316         nil
  2326         nil
  2317         nil
  2327       )
  2318       )
  2328 
       
  2329     "Modified: / 17-02-2011 / 13:55:43 / cg"
       
  2330 !
  2319 !
  2331 
  2320 
  2332 viewDetailsMenuSpec
  2321 viewDetailsMenuSpec
  2333     "This resource specification was automatically generated
  2322     "This resource specification was automatically generated
  2334      by the MenuEditor of ST/X."
  2323      by the MenuEditor of ST/X."
  5797     textBox extent:((maxLength * 5)@(info size * 20)); sizeFixed:false.
  5786     textBox extent:((maxLength * 5)@(info size * 20)); sizeFixed:false.
  5798     textBox maxExtent:Screen current extent.
  5787     textBox maxExtent:Screen current extent.
  5799     textBox openModeless.
  5788     textBox openModeless.
  5800 
  5789 
  5801     "Modified: / 25-07-2006 / 09:07:22 / cg"
  5790     "Modified: / 25-07-2006 / 09:07:22 / cg"
       
  5791 !
       
  5792 
       
  5793 fileFindDuplicateFile
       
  5794     "scan directory for duplicates of the selected files"
       
  5795 
       
  5796     |files filesBySize samePerFile stream textBox|
       
  5797 
       
  5798     files := self currentSelectedFiles.
       
  5799     files isEmpty ifTrue:[^ self].
       
  5800 
       
  5801     filesBySize := Dictionary new.
       
  5802     files do:[:fn |
       
  5803         |sz entry|
       
  5804 
       
  5805         sz := fn asFilename fileSize.
       
  5806         (filesBySize at:sz ifAbsentPut:[Set new]) add:fn.
       
  5807     ].
       
  5808 
       
  5809     samePerFile := Dictionary new.
       
  5810 
       
  5811     self currentSelectedDirectories do:[:eachDir |
       
  5812         eachDir recursiveDirectoryContentsAsFilenamesDo:[:eachFile |
       
  5813             eachFile isDirectory ifFalse:[
       
  5814                 |sz possibleMatches|
       
  5815 
       
  5816                 sz := eachFile fileSize.
       
  5817                 possibleMatches := filesBySize at:sz ifAbsent:nil.
       
  5818                 possibleMatches notNil ifTrue:[
       
  5819                     possibleMatches do:[:eachFileWithSameSize |
       
  5820                         (eachFileWithSameSize sameContentsAs:eachFile) ifTrue:[
       
  5821                             (samePerFile at:eachFileWithSameSize ifAbsentPut:[Set new]) add:eachFile
       
  5822                         ]
       
  5823                     ]
       
  5824                 ]
       
  5825             ]
       
  5826         ]
       
  5827     ].
       
  5828 
       
  5829     stream := WriteStream on:''.
       
  5830     samePerFile keysAndValuesDo:[:origFile :sameFiles|
       
  5831         stream nextPutLine:origFile baseName.
       
  5832         (sameFiles asOrderedCollection collect:[:each | each baseName]) sort do:[:eachSameName |
       
  5833             stream nextPutAll:'    '; nextPutLine:eachSameName.
       
  5834         ]
       
  5835     ].
       
  5836 
       
  5837     textBox := TextBox new.
       
  5838     textBox initialText:(stream contents).
       
  5839     textBox title:'Files with same contents'.
       
  5840     textBox readOnly:true.
       
  5841     textBox noCancel.
       
  5842     textBox extent:(350@400).
       
  5843     textBox maxExtent:Screen current extent.
       
  5844     textBox openModeless. "/ showAtPointer.
       
  5845 
       
  5846 "/
       
  5847 "/    self withActivityIndicationDo:[
       
  5848 "/        result := Dictionary new.
       
  5849 "/
       
  5850 "/        infoDir := Dictionary new.
       
  5851 "/        allFiles do:[:fn |
       
  5852 "/            infoDir at:fn put:(fn info)
       
  5853 "/        ].
       
  5854 "/
       
  5855 "/        "/ for each, get the files size.
       
  5856 "/        "/ in a first pass, look for files of the same size and
       
  5857 "/        "/ compare them ...
       
  5858 "/
       
  5859 "/        filesBySize := Dictionary new.
       
  5860 "/        infoDir keysAndValuesDo:[:fn :info |
       
  5861 "/            |sz entry|
       
  5862 "/
       
  5863 "/            sz := info size.
       
  5864 "/            entry := filesBySize at:sz ifAbsentPut:[Set new].
       
  5865 "/            entry add:fn.
       
  5866 "/        ].
       
  5867 "/
       
  5868 "/        "/ any of same size ?
       
  5869 "/
       
  5870 "/        filesBySize do:[:entry |
       
  5871 "/            |files|
       
  5872 "/
       
  5873 "/            entry size > 1 ifTrue:[
       
  5874 "/                files := entry asArray.
       
  5875 "/                1 to:files size-1 do:[:idx1 |
       
  5876 "/                    idx1+1 to:files size do:[:idx2 |
       
  5877 "/                        |fn1 fn2|
       
  5878 "/
       
  5879 "/                        fn1 := files at:idx1.
       
  5880 "/                        fn2 := files at:idx2.
       
  5881 "/
       
  5882 "/                        (result at:fn2 ifAbsent:nil) ~= fn1 ifTrue:[
       
  5883 "/                            "/ compare the files
       
  5884 "/                            (fn1 sameContentsAs:fn2) ifTrue:[
       
  5885 "/"/                                Transcript show:'Same: '; show:fn1 baseName; show:' and '; showCR:fn2 baseName.
       
  5886 "/                                result at:fn1 put:fn2.
       
  5887 "/                            ]
       
  5888 "/                        ]
       
  5889 "/                    ]
       
  5890 "/                ]
       
  5891 "/            ]
       
  5892 "/        ].
       
  5893 "/
       
  5894 "/        result := result associations.
       
  5895 "/        result := result collect:[:assoc |
       
  5896 "/                                        |f1 f2|
       
  5897 "/
       
  5898 "/                                        f1 := assoc key asString.
       
  5899 "/                                        f2 := assoc value asString.
       
  5900 "/                                        f1 < f2 ifTrue:[
       
  5901 "/                                            f2 -> f1
       
  5902 "/                                        ] ifFalse:[
       
  5903 "/                                            f1 -> f2
       
  5904 "/                                        ]
       
  5905 "/                                ].
       
  5906 "/        "/ result sort:[:f1 :f2 | f1 key > f2 key "f2 value < f1 key value"].
       
  5907 "/        result sort:[:f1 :f2 | " f1 key > f2 key" f2 value < f1 key value].
       
  5908 "/
       
  5909 "/        info := OrderedCollection new.
       
  5910 "/        size := self getBestDirectory asString size.
       
  5911 "/        result do:[:assoc |
       
  5912 "/            |fn1 fn2|
       
  5913 "/
       
  5914 "/            fn1 := assoc key.
       
  5915 "/            fn2 := assoc value.
       
  5916 "/            size > 1 ifTrue:[
       
  5917 "/                fn1 := ('..', (fn1 copyFrom:(size + 1))).
       
  5918 "/                fn2 := ('..', (fn2 copyFrom:(size + 1))).
       
  5919 "/            ].
       
  5920 "/            (fn1 includes:Character space) ifTrue:[
       
  5921 "/                fn1 := '"' , fn1 , '"'
       
  5922 "/            ].
       
  5923 "/            (fn2 includes:Character space) ifTrue:[
       
  5924 "/                fn2 := '"' , fn2 , '"'
       
  5925 "/            ].
       
  5926 "/            info add:(fn1 , ' same as ' , fn2)
       
  5927 "/        ].
       
  5928 "/        info isEmpty ifTrue:[
       
  5929 "/            Dialog information:'No duplicate files found.'.
       
  5930 "/            ^ self.
       
  5931 "/        ].
       
  5932 "/    ].
       
  5933 "/    stream := WriteStream on:''.
       
  5934 "/    info do:[:el|
       
  5935 "/        stream nextPutLine:el.
       
  5936 "/    ].
       
  5937 "/    titleStream := WriteStream on:''.
       
  5938 "/    titleStream nextPutAll:'File duplicates in director'.
       
  5939 "/    directories size == 1 ifTrue:[
       
  5940 "/        titleStream nextPutAll:'y: ', directories first asString.
       
  5941 "/    ] ifFalse:[
       
  5942 "/        titleStream nextPutLine:'ies: '.
       
  5943 "/        directories do:[:dir|
       
  5944 "/            size > 1 ifTrue:[
       
  5945 "/                titleStream nextPutAll:'..'.
       
  5946 "/                titleStream nextPutLine:((dir asString) copyFrom:(size + 1)).
       
  5947 "/            ] ifFalse:[
       
  5948 "/                titleStream nextPutLine:(dir asString).
       
  5949 "/            ].
       
  5950 "/        ]
       
  5951 "/    ].
       
  5952 "/
       
  5953 "/    textBox := TextBox new.
       
  5954 "/    textBox initialText:(stream contents).
       
  5955 "/    textBox title:(titleStream contents).
       
  5956 "/    textBox readOnly:true.
       
  5957 "/    textBox noCancel.
       
  5958 "/    stream := WriteStream on:'Duplicates in '.
       
  5959 "/    directories do:[ :aDirectory |
       
  5960 "/        stream nextPutAll:aDirectory baseName.
       
  5961 "/        stream space.
       
  5962 "/    ].
       
  5963 "/    textBox label:stream contents.
       
  5964 "/    maxLength := 10.
       
  5965 "/    info do:[: el |
       
  5966 "/        maxLength := maxLength max:(el size).
       
  5967 "/    ].
       
  5968 "/    textBox extent:((maxLength * 5)@((info size max:40)* 10)).
       
  5969 "/    textBox maxExtent:Screen current extent.
       
  5970 "/    textBox openModeless. "/ showAtPointer.
       
  5971 
       
  5972     "Created: / 11-07-2011 / 12:39:44 / cg"
  5802 !
  5973 !
  5803 
  5974 
  5804 fileFindDuplicates
  5975 fileFindDuplicates
  5805     "scan directory for duplicate files"
  5976     "scan directory for duplicate files"
  5806 
  5977 
  7415 javaSupportLoaded
  7586 javaSupportLoaded
  7416 
  7587 
  7417     ^ false
  7588     ^ false
  7418 ! !
  7589 ! !
  7419 
  7590 
  7420 
       
  7421 !AbstractFileBrowser methodsFor:'presentation'!
  7591 !AbstractFileBrowser methodsFor:'presentation'!
  7422 
  7592 
  7423 getModeString:modeBits
  7593 getModeString:modeBits
  7424     "convert file-mode bits into a more user-friendly string.
  7594     "convert file-mode bits into a more user-friendly string.
  7425      This is wrong here - should be moved into OperatingSystem."
  7595      This is wrong here - should be moved into OperatingSystem."
  8332 ! !
  8502 ! !
  8333 
  8503 
  8334 !AbstractFileBrowser class methodsFor:'documentation'!
  8504 !AbstractFileBrowser class methodsFor:'documentation'!
  8335 
  8505 
  8336 version_CVS
  8506 version_CVS
  8337     ^ '$Header: /cvs/stx/stx/libtool/AbstractFileBrowser.st,v 1.461 2011-07-07 14:14:30 vrany Exp $'
  8507     ^ '$Header: /cvs/stx/stx/libtool/AbstractFileBrowser.st,v 1.462 2011-07-11 10:56:34 cg Exp $'
  8338 ! !
  8508 ! !