FileBrowser.st
changeset 2166 e1b98bde42c4
parent 2158 edf13d7fd732
child 2170 e9078e7a7e40
equal deleted inserted replaced
2165:db340546f304 2166:e1b98bde42c4
  1914 
  1914 
  1915 fileFindFile
  1915 fileFindFile
  1916     |sel bindings
  1916     |sel bindings
  1917      namePatternHolder contentsPatternHolder
  1917      namePatternHolder contentsPatternHolder
  1918      ignoreCaseInName ignoreCaseInContents
  1918      ignoreCaseInName ignoreCaseInContents
  1919      namePattern contentsPattern 
  1919      namePattern namePatterns contentsPattern 
  1920      searchForSameContentsEnabled searchForSameContents|
  1920      searchForSameContentsEnabled searchForSameContents|
  1921 
  1921 
  1922     (self askIfModified:'contents has not been saved.\\Modifications will be lost when you proceed.'
  1922     (self askIfModified:'contents has not been saved.\\Modifications will be lost when you proceed.'
  1923 	      yesButton:'proceed') ifFalse:[^ self].
  1923               yesButton:'proceed') ifFalse:[^ self].
  1924 
  1924 
  1925     subView contents:nil; scrollToTop.
  1925     subView contents:nil; scrollToTop.
  1926 
  1926 
  1927     bindings := IdentityDictionary new.
  1927     bindings := IdentityDictionary new.
  1928     bindings at:#namePatternHolder put:(namePatternHolder := '' asValue).
  1928     bindings at:#namePatternHolder put:(namePatternHolder := '' asValue).
  1931     bindings at:#ignoreCaseInContents put:(ignoreCaseInContents := false asValue).
  1931     bindings at:#ignoreCaseInContents put:(ignoreCaseInContents := false asValue).
  1932 
  1932 
  1933     searchForSameContentsEnabled := false.
  1933     searchForSameContentsEnabled := false.
  1934     sel := fileListView selectionValue.
  1934     sel := fileListView selectionValue.
  1935     sel size == 1 ifTrue:[
  1935     sel size == 1 ifTrue:[
  1936 	searchForSameContentsEnabled := true.
  1936         searchForSameContentsEnabled := true.
  1937 	sel := sel first string withoutSeparators
  1937         sel := sel first string withoutSeparators
  1938     ].
  1938     ].
  1939     bindings at:#searchForSameContentsEnabled put:(searchForSameContentsEnabled := searchForSameContentsEnabled asValue).
  1939     bindings at:#searchForSameContentsEnabled put:(searchForSameContentsEnabled := searchForSameContentsEnabled asValue).
  1940     bindings at:#searchForSameContents put:(searchForSameContents := false asValue).
  1940     bindings at:#searchForSameContents put:(searchForSameContents := false asValue).
  1941     bindings at:#notSearchForSameContents put:(BlockValue forLogicalNot:searchForSameContents).
  1941     bindings at:#notSearchForSameContents put:(BlockValue forLogicalNot:searchForSameContents).
  1942 
  1942 
  1943 
  1943 
  1944     (SimpleDialog new 
  1944     (SimpleDialog new 
  1945 	openFor:self
  1945         openFor:self
  1946 	interfaceSpec:(self class fileSearchDialogSpec)
  1946         interfaceSpec:(self class fileSearchDialogSpec)
  1947 	withBindings:bindings) ifTrue:[
  1947         withBindings:bindings) ifTrue:[
  1948 
  1948 
  1949 	namePattern := namePatternHolder value.
  1949         namePattern := namePatternHolder value.
  1950 	namePattern size == 0 ifTrue:[
  1950         namePattern size == 0 ifTrue:[
  1951 	    namePattern := nil
  1951             namePatterns := nil
  1952 	] ifFalse:[
  1952         ] ifFalse:[
  1953 	    ignoreCaseInName value ifTrue:[
  1953             ignoreCaseInName value ifTrue:[
  1954 		namePattern := namePattern asLowercase
  1954                 namePattern := namePattern asLowercase
  1955 	    ]
  1955             ].
  1956 	].
  1956             namePatterns := namePattern asCollectionOfSubstringsSeparatedBy:$;
  1957 	contentsPattern := contentsPatternHolder value.
  1957         ].
  1958 	contentsPattern size == 0 ifTrue:[
  1958         contentsPattern := contentsPatternHolder value.
  1959 	    contentsPattern := nil
  1959         contentsPattern size == 0 ifTrue:[
  1960 	] ifFalse:[
  1960             contentsPattern := nil
  1961 	    ignoreCaseInContents value ifTrue:[
  1961         ] ifFalse:[
  1962 		contentsPattern := contentsPattern asLowercase
  1962             ignoreCaseInContents value ifTrue:[
  1963 	    ]
  1963                 contentsPattern := contentsPattern asLowercase
  1964 	].
  1964             ]
  1965 
  1965         ].
  1966 	self withWaitCursorDo:[
  1966 
  1967 	    |stopSignal access myProcess lowerFrameView|
  1967         self withWaitCursorDo:[
  1968 
  1968             |stopSignal access myProcess lowerFrameView|
  1969 	    myProcess := Processor activeProcess.
  1969 
  1970 
  1970             myProcess := Processor activeProcess.
  1971 	    access := Semaphore forMutualExclusion name:'accessLock'.
  1971 
  1972 	    stopSignal := Signal new.
  1972             access := Semaphore forMutualExclusion name:'accessLock'.
  1973 
  1973             stopSignal := Signal new.
  1974 	    "
  1974 
  1975 	     The following is tricky: 
  1975             "
  1976 	     the pauseToggle & killButton will
  1976              The following is tricky: 
  1977 	     be handled by their own windowGroup process.
  1977              the pauseToggle & killButton will
  1978 	     This means, that they respond to events even though
  1978              be handled by their own windowGroup process.
  1979 	     I myself am reading the commands output.
  1979              This means, that they respond to events even though
  1980 	    "
  1980              I myself am reading the commands output.
  1981 
  1981             "
  1982 	    commandView beInvisible.
  1982 
  1983 
  1983             commandView beInvisible.
  1984 	    "
  1984 
  1985 	     must take kill & pauseButtons out of my group
  1985             "
  1986 	    "
  1986              must take kill & pauseButtons out of my group
  1987 	    killButton windowGroup:nil.
  1987             "
  1988 
  1988             killButton windowGroup:nil.
  1989 	    "
  1989 
  1990 	     bring them to front, and turn hidden-mode off
  1990             "
  1991 	    "
  1991              bring them to front, and turn hidden-mode off
  1992 	    killButton label:(resources string:'stop').
  1992             "
  1993 	    killButton raise; beVisible.
  1993             killButton label:(resources string:'stop').
  1994 
  1994             killButton raise; beVisible.
  1995 	    "
  1995 
  1996 	     kill will make me raise the stopSignal when pressed
  1996             "
  1997 	    "
  1997              kill will make me raise the stopSignal when pressed
  1998 	    killButton 
  1998             "
  1999 		action:[
  1999             killButton 
  2000 		    access critical:[
  2000                 action:[
  2001 			myProcess interruptWith:[stopSignal raiseRequest].
  2001                     access critical:[
  2002 		    ]
  2002                         myProcess interruptWith:[stopSignal raiseRequest].
  2003 		].
  2003                     ]
  2004 
  2004                 ].
  2005 	    "
  2005 
  2006 	     start kill button under its own windowgroup
  2006             "
  2007 	    "
  2007              start kill button under its own windowgroup
  2008 	    killButton openAutonomous.
  2008             "
  2009 	    killButton windowGroup process processGroupId:(Processor activeProcess id).
  2009             killButton openAutonomous.
  2010 
  2010             killButton windowGroup process processGroupId:(Processor activeProcess id).
  2011 	    lowerFrameView := subView superView.
  2011 
  2012 
  2012             lowerFrameView := subView superView.
  2013 	    [
  2013 
  2014 		stopSignal catch:[
  2014             [
  2015 		    searchForSameContents value ifTrue:[
  2015                 stopSignal catch:[
  2016 			self 
  2016                     searchForSameContents value ifTrue:[
  2017 			    doFindFileNamed:namePattern
  2017                         self 
  2018 			    ignoreCase:ignoreCaseInName value
  2018                             doFindFileNamed:namePatterns
  2019 			    containingString:nil
  2019                             ignoreCase:ignoreCaseInName value
  2020 			    ignoreCaseInContents:ignoreCaseInContents value
  2020                             containingString:nil
  2021 			    sameContentsAsFile:(currentDirectory asFilename construct:sel) 
  2021                             ignoreCaseInContents:ignoreCaseInContents value
  2022 			    sameContentsAs:nil 
  2022                             sameContentsAsFile:(currentDirectory asFilename construct:sel) 
  2023 			    in:currentDirectory.
  2023                             sameContentsAs:nil 
  2024 		    ] ifFalse:[
  2024                             in:currentDirectory.
  2025 			(contentsPattern size > 0 or:[namePattern size > 0]) ifTrue:[
  2025                     ] ifFalse:[
  2026 			    self 
  2026                         (contentsPattern size > 0 or:[namePatterns size > 0]) ifTrue:[
  2027 				doFindFileNamed:namePattern
  2027                             self 
  2028 				ignoreCase:ignoreCaseInName value
  2028                                 doFindFileNamed:namePatterns
  2029 				containingString:contentsPattern
  2029                                 ignoreCase:ignoreCaseInName value
  2030 				ignoreCaseInContents:ignoreCaseInContents value
  2030                                 containingString:contentsPattern
  2031 				sameContentsAsFile:nil 
  2031                                 ignoreCaseInContents:ignoreCaseInContents value
  2032 				sameContentsAs:nil 
  2032                                 sameContentsAsFile:nil 
  2033 				in:currentDirectory.
  2033                                 sameContentsAs:nil 
  2034 			]
  2034                                 in:currentDirectory.
  2035 		    ]
  2035                         ]
  2036 		]
  2036                     ]
  2037 	    ] valueNowOrOnUnwindDo:[
  2037                 ]
  2038 		|wg|
  2038             ] valueNowOrOnUnwindDo:[
  2039 
  2039                 |wg|
  2040 		self label:myName; iconLabel:myName.
  2040 
  2041 
  2041                 self label:myName; iconLabel:myName.
  2042 		"
  2042 
  2043 		 hide the button, and make sure it will stay
  2043                 "
  2044 		 hidden when we are realized again
  2044                  hide the button, and make sure it will stay
  2045 		"
  2045                  hidden when we are realized again
  2046 		killButton beInvisible.
  2046                 "
  2047 
  2047                 killButton beInvisible.
  2048 		commandView beVisible.
  2048 
  2049 
  2049                 commandView beVisible.
  2050 		"
  2050 
  2051 		 remove the killButton from its group
  2051                 "
  2052 		 (otherwise, it will be destroyed when we shut down the group)
  2052                  remove the killButton from its group
  2053 		"
  2053                  (otherwise, it will be destroyed when we shut down the group)
  2054 		wg := killButton windowGroup.
  2054                 "
  2055 		killButton windowGroup:nil.
  2055                 wg := killButton windowGroup.
  2056 
  2056                 killButton windowGroup:nil.
  2057 		"
  2057 
  2058 		 shut down the kill buttons windowgroup
  2058                 "
  2059 		"
  2059                  shut down the kill buttons windowgroup
  2060 		wg notNil ifTrue:[
  2060                 "
  2061 		    wg process terminate.
  2061                 wg notNil ifTrue:[
  2062 		].
  2062                     wg process terminate.
  2063 		"
  2063                 ].
  2064 		 clear its action (actually not needed, but
  2064                 "
  2065 		 releases reference to thisContext earlier)
  2065                  clear its action (actually not needed, but
  2066 		"
  2066                  releases reference to thisContext earlier)
  2067 		killButton action:nil.
  2067                 "
  2068 		killButton label:(resources string:'kill').
  2068                 killButton action:nil.
  2069 
  2069                 killButton label:(resources string:'kill').
  2070 		"/    
  2070 
  2071 		"/ allow interaction with the codeView
  2071                 "/    
  2072 		"/ (bring it back into my group)
  2072                 "/ allow interaction with the codeView
  2073 		"/
  2073                 "/ (bring it back into my group)
  2074 		lowerFrameView windowGroup:(self windowGroup).
  2074                 "/
  2075 	    ].
  2075                 lowerFrameView windowGroup:(self windowGroup).
  2076 
  2076             ].
  2077 	].
  2077 
  2078 	self label:myName.
  2078         ].
  2079 	currentFileName isNil ifTrue:[
  2079         self label:myName.
  2080 	    subView modified:false.
  2080         currentFileName isNil ifTrue:[
  2081 	].
  2081             subView modified:false.
       
  2082         ].
  2082     ].
  2083     ].
  2083 
  2084 
  2084     "Created: / 15.10.1998 / 11:32:57 / cg"
  2085     "Created: / 15.10.1998 / 11:32:57 / cg"
  2085     "Modified: / 15.10.1998 / 12:41:09 / cg"
  2086     "Modified: / 15.10.1998 / 12:41:09 / cg"
  2086 !
  2087 !
  5152     "Created: / 19.6.1996 / 09:39:07 / cg"
  5153     "Created: / 19.6.1996 / 09:39:07 / cg"
  5153     "Modified: / 18.9.1997 / 17:35:31 / stefan"
  5154     "Modified: / 18.9.1997 / 17:35:31 / stefan"
  5154     "Modified: / 4.2.1999 / 17:43:51 / cg"
  5155     "Modified: / 4.2.1999 / 17:43:51 / cg"
  5155 !
  5156 !
  5156 
  5157 
  5157 doFindFileNamed:namePattern ignoreCase:ignCaseInName containingString:contentsString ignoreCaseInContents:ignCaseInString sameContentsAsFile:filenameToCompareContentsOrNil sameContentsAs:bytesToCompareContentsOrNil in:aDirectory
  5158 doFindFileNamed:namePatterns ignoreCase:ignCaseInName containingString:contentsString ignoreCaseInContents:ignCaseInString sameContentsAsFile:filenameToCompareContentsOrNil sameContentsAs:bytesToCompareContentsOrNil in:aDirectory
  5158     |dir subDirs nameMatches contentsMatches lines contentsToCompare|
  5159     |dir subDirs nameMatches contentsMatches lines contentsToCompare|
  5159 
  5160 
  5160     bytesToCompareContentsOrNil notNil ifTrue:[
  5161     bytesToCompareContentsOrNil notNil ifTrue:[
  5161 	contentsToCompare := bytesToCompareContentsOrNil
  5162         contentsToCompare := bytesToCompareContentsOrNil
  5162     ].
  5163     ].
  5163 
  5164 
  5164     subDirs := OrderedCollection new.
  5165     subDirs := OrderedCollection new.
  5165 
  5166 
  5166     dir := aDirectory asFilename.
  5167     dir := aDirectory asFilename.
  5167     self label:myName , '- searching ' , dir name.
  5168     self label:myName , '- searching ' , dir name.
  5168     (dir directoryContents ? #()) sort do:[:fn |
  5169     (dir directoryContents ? #()) sort do:[:fn |
  5169 	|f|
  5170         |f|
  5170 
  5171 
  5171 	f := dir construct:fn.
  5172         f := dir construct:fn.
  5172 	f isDirectory ifTrue:[
  5173         f isDirectory ifTrue:[
  5173 	    f isSymbolicLink ifFalse:[
  5174             f isSymbolicLink ifFalse:[
  5174 		subDirs add:f
  5175                 subDirs add:f
  5175 	    ]
  5176             ]
  5176 	] ifFalse:[
  5177         ] ifFalse:[
  5177 	    (nameMatches := namePattern isNil) ifFalse:[
  5178             (nameMatches := namePatterns isNil) ifFalse:[
  5178 		ignCaseInName ifTrue:[
  5179                 ignCaseInName ifTrue:[
  5179 		    nameMatches := namePattern match:(fn asLowercase)
  5180                     nameMatches := namePatterns contains:[:aPattern | aPattern match:(fn asLowercase)]
  5180 		] ifFalse:[
  5181                 ] ifFalse:[
  5181 		    nameMatches := namePattern match:fn
  5182                     nameMatches := namePatterns contains:[:aPattern | aPattern  match:fn]
  5182 		]
  5183                 ]
  5183 	    ].
  5184             ].
  5184 	    nameMatches ifTrue:[
  5185             nameMatches ifTrue:[
  5185 		filenameToCompareContentsOrNil notNil ifTrue:[
  5186                 filenameToCompareContentsOrNil notNil ifTrue:[
  5186 		    "/ contents compare ...
  5187                     "/ contents compare ...
  5187 		    contentsMatches := false.
  5188                     contentsMatches := false.
  5188 		    f pathName ~= filenameToCompareContentsOrNil pathName ifTrue:[
  5189                     f pathName ~= filenameToCompareContentsOrNil pathName ifTrue:[
  5189 			f fileSize == filenameToCompareContentsOrNil fileSize ifTrue:[
  5190                         f fileSize == filenameToCompareContentsOrNil fileSize ifTrue:[
  5190 			    contentsToCompare isNil ifTrue:[
  5191                             contentsToCompare isNil ifTrue:[
  5191 				filenameToCompareContentsOrNil fileSize < (512*1024) ifTrue:[
  5192                                 filenameToCompareContentsOrNil fileSize < (512*1024) ifTrue:[
  5192 				    contentsToCompare := filenameToCompareContentsOrNil binaryContentsOfEntireFile
  5193                                     contentsToCompare := filenameToCompareContentsOrNil binaryContentsOfEntireFile
  5193 				]
  5194                                 ]
  5194 			    ].
  5195                             ].
  5195 			    contentsToCompare isNil ifTrue:[
  5196                             contentsToCompare isNil ifTrue:[
  5196 				"/ too large - compare block-wise ...
  5197                                 "/ too large - compare block-wise ...
  5197 				contentsMatches := (filenameToCompareContentsOrNil sameContentsAs:f).
  5198                                 contentsMatches := (filenameToCompareContentsOrNil sameContentsAs:f).
  5198 			    ] ifFalse:[
  5199                             ] ifFalse:[
  5199 				contentsMatches := contentsToCompare = (f binaryContentsOfEntireFile).
  5200                                 contentsMatches := contentsToCompare = (f binaryContentsOfEntireFile).
  5200 			    ]
  5201                             ]
  5201 			].
  5202                         ].
  5202 		    ] ifFalse:[
  5203                     ] ifFalse:[
  5203 			f isSymbolicLink ifTrue:[
  5204                         f isSymbolicLink ifTrue:[
  5204 			    subView insertLine:(f name , ' is a symbolic link to ' , f pathName)  before:subView cursorLine.
  5205                             subView insertLine:(f name , ' is a symbolic link to ' , f pathName)  before:subView cursorLine.
  5205 			    subView cursorDown.
  5206                             subView cursorDown.
  5206 			]
  5207                         ]
  5207 		    ]
  5208                     ]
  5208 		] ifFalse:[
  5209                 ] ifFalse:[
  5209 		    "/ string search ...
  5210                     "/ string search ...
  5210 		    (contentsMatches := contentsString isNil) ifFalse:[
  5211                     (contentsMatches := contentsString isNil) ifFalse:[
  5211 			(f exists and:[f isReadable]) ifFalse:[
  5212                         (f exists and:[f isReadable]) ifFalse:[
  5212 			    subView insertLine:('*** ' , f pathName , ' skipped - unreadable or bad symbolic link ***') before:subView cursorLine.
  5213                             subView insertLine:('*** ' , f pathName , ' skipped - unreadable or bad symbolic link ***') before:subView cursorLine.
  5213 			    subView cursorDown.
  5214                             subView cursorDown.
  5214 			] ifTrue:[
  5215                         ] ifTrue:[
  5215 			    f fileSize > (4024*1024) ifTrue:[
  5216                             f fileSize > (4024*1024) ifTrue:[
  5216 				subView insertLine:('*** ' , f pathName , ' skipped - too large ***') before:subView cursorLine.
  5217                                 subView insertLine:('*** ' , f pathName , ' skipped - too large ***') before:subView cursorLine.
  5217 				subView cursorDown.
  5218                                 subView cursorDown.
  5218 			    ] ifFalse:[
  5219                             ] ifFalse:[
  5219 				Stream lineTooLongErrorSignal handle:[:ex |
  5220                                 Stream lineTooLongErrorSignal handle:[:ex |
  5220 				    |cont|
  5221                                     |cont|
  5221 
  5222 
  5222 				    "/ this typically happens, when a binary file is read linewise ...
  5223                                     "/ this typically happens, when a binary file is read linewise ...
  5223 				    cont := f readStream binary contentsOfEntireFile asString.
  5224                                     cont := f readStream binary contentsOfEntireFile asString.
  5224 				    ignCaseInString ifTrue:[
  5225                                     ignCaseInString ifTrue:[
  5225 					contentsMatches := cont asLowercase includesString:contentsString
  5226                                         contentsMatches := cont asLowercase includesString:contentsString
  5226 				    ] ifFalse:[
  5227                                     ] ifFalse:[
  5227 					contentsMatches := cont includesString:contentsString
  5228                                         contentsMatches := cont includesString:contentsString
  5228 				    ].
  5229                                     ].
  5229 				] do:[    
  5230                                 ] do:[    
  5230 				    lines := f contents ? #().
  5231                                     lines := f contents ? #().
  5231 				    ignCaseInString ifTrue:[
  5232                                     ignCaseInString ifTrue:[
  5232 					contentsMatches := (lines findFirst:[:l | l asLowercase includesString:contentsString]) ~~ 0
  5233                                         contentsMatches := (lines findFirst:[:l | l asLowercase includesString:contentsString]) ~~ 0
  5233 				    ] ifFalse:[
  5234                                     ] ifFalse:[
  5234 					contentsMatches := (lines findFirst:[:l | l includesString:contentsString]) ~~ 0
  5235                                         contentsMatches := (lines findFirst:[:l | l includesString:contentsString]) ~~ 0
  5235 				    ].
  5236                                     ].
  5236 				].
  5237                                 ].
  5237 			    ].
  5238                             ].
  5238 			].
  5239                         ].
  5239 		    ].
  5240                     ].
  5240 		].
  5241                 ].
  5241 		contentsMatches ifTrue:[
  5242                 contentsMatches ifTrue:[
  5242 		    subView insertLine:f pathName before:subView cursorLine.
  5243                     subView insertLine:f pathName before:subView cursorLine.
  5243 		    subView cursorDown.
  5244                     subView cursorDown.
  5244 		]
  5245                 ]
  5245 	    ]
  5246             ]
  5246 	]
  5247         ]
  5247     ].
  5248     ].
  5248 
  5249 
  5249     subDirs do:[:dir |
  5250     subDirs do:[:dir |
  5250 	self
  5251         self
  5251 	    doFindFileNamed:namePattern 
  5252             doFindFileNamed:namePatterns 
  5252 	    ignoreCase:ignCaseInName 
  5253             ignoreCase:ignCaseInName 
  5253 	    containingString:contentsString 
  5254             containingString:contentsString 
  5254 	    ignoreCaseInContents:ignCaseInString 
  5255             ignoreCaseInContents:ignCaseInString 
  5255 	    sameContentsAsFile:filenameToCompareContentsOrNil 
  5256             sameContentsAsFile:filenameToCompareContentsOrNil 
  5256 	    sameContentsAs:contentsToCompare
  5257             sameContentsAs:contentsToCompare
  5257 	    in:dir
  5258             in:dir
  5258     ].
  5259     ].
  5259 
  5260 
  5260     "Created: / 15.10.1998 / 11:37:15 / cg"
  5261     "Created: / 15.10.1998 / 11:37:15 / cg"
  5261     "Modified: / 15.10.1998 / 12:50:48 / cg"
  5262     "Modified: / 15.10.1998 / 12:50:48 / cg"
  5262 !
  5263 !
  6631 ! !
  6632 ! !
  6632 
  6633 
  6633 !FileBrowser class methodsFor:'documentation'!
  6634 !FileBrowser class methodsFor:'documentation'!
  6634 
  6635 
  6635 version
  6636 version
  6636     ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.322 1999-05-18 19:12:43 cg Exp $'
  6637     ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.323 1999-05-21 10:11:45 cg Exp $'
  6637 ! !
  6638 ! !