FileBrowser.st
changeset 132 9bf0c15113f2
parent 126 fca75dda31db
child 133 fa9a37e36a07
equal deleted inserted replaced
131:48cd793d8eb4 132:9bf0c15113f2
    15 StandardSystemView subclass:#FileBrowser
    15 StandardSystemView subclass:#FileBrowser
    16 	 instanceVariableNames:'labelView filterField fileListView subView currentDirectory
    16 	 instanceVariableNames:'labelView filterField fileListView subView currentDirectory
    17 		fileList checkBlock checkDelta timeOfLastCheck showLongList
    17 		fileList checkBlock checkDelta timeOfLastCheck showLongList
    18 		showVeryLongList showDotFiles myName killButton compressTabs
    18 		showVeryLongList showDotFiles myName killButton compressTabs
    19 		lockUpdate previousDirectory currentFileName timeOfFileRead
    19 		lockUpdate previousDirectory currentFileName timeOfFileRead
    20 		tabSpec'
    20 		tabSpec commandView commandIndex'
    21 	 classVariableNames:'DirectoryHistory DirectoryHistoryWhere HistorySize DefaultIcon'
    21 	 classVariableNames:'DirectoryHistory DirectoryHistoryWhere HistorySize DefaultIcon
       
    22 			     CommandHistory CommandHistorySize'
    22 	 poolDictionaries:''
    23 	 poolDictionaries:''
    23 	 category:'Interface-Browsers'
    24 	 category:'Interface-Browsers'
    24 !
    25 !
    25 
    26 
    26 FileBrowser comment:'
    27 FileBrowser comment:'
    27 COPYRIGHT (c) 1991 by Claus Gittinger
    28 COPYRIGHT (c) 1991 by Claus Gittinger
    28 	      All Rights Reserved
    29 	      All Rights Reserved
    29 
    30 
    30 $Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.47 1995-08-29 23:46:46 claus Exp $
    31 $Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.48 1995-09-07 12:53:25 claus Exp $
    31 '!
    32 '!
    32 
    33 
    33 !FileBrowser class methodsFor:'documentation'!
    34 !FileBrowser class methodsFor:'documentation'!
    34 
    35 
    35 copyright
    36 copyright
    46 "
    47 "
    47 !
    48 !
    48 
    49 
    49 version
    50 version
    50 "
    51 "
    51 $Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.47 1995-08-29 23:46:46 claus Exp $
    52 $Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.48 1995-09-07 12:53:25 claus Exp $
    52 "
    53 "
    53 !
    54 !
    54 
    55 
    55 documentation
    56 documentation
    56 "
    57 "
   159     showDotFiles := resources at:'SHOW_DOT_FILES' default:false.
   160     showDotFiles := resources at:'SHOW_DOT_FILES' default:false.
   160 
   161 
   161 
   162 
   162     lockUpdate := false.
   163     lockUpdate := false.
   163 
   164 
       
   165     CommandHistory isNil ifTrue:[
       
   166 	CommandHistory := OrderedCollection new.
       
   167 	CommandHistorySize := 50
       
   168     ].
   164     DirectoryHistory isNil ifTrue:[
   169     DirectoryHistory isNil ifTrue:[
   165 	DirectoryHistory := OrderedCollection new.
   170 	DirectoryHistory := OrderedCollection new.
   166 	DirectoryHistoryWhere := OrderedCollection new.
   171 	DirectoryHistoryWhere := OrderedCollection new.
   167 	HistorySize := 15.
   172 	HistorySize := 15.
   168     ].
   173     ].
       
   174     commandIndex := 0.
   169 
   175 
   170     myName := (resources string:self class name).
   176     myName := (resources string:self class name).
   171     self label:myName.
   177     self label:myName.
   172 
   178 
   173     labelFrame := View 
   179     labelFrame := View 
   210     killButton := Button label:(resources string:'kill') in:self.
   216     killButton := Button label:(resources string:'kill') in:self.
   211     killButton origin:(halfSpacing @ halfSpacing)
   217     killButton origin:(halfSpacing @ halfSpacing)
   212 	       extent:(killButton width @ filterField height).
   218 	       extent:(killButton width @ filterField height).
   213     killButton hiddenOnRealize:true.
   219     killButton hiddenOnRealize:true.
   214 
   220 
   215     frame := VariableVerticalPanel
   221     self initializeCommandViewIn:self.
   216 		 origin:[frame borderWidth negated 
   222 
   217 			 @ 
   223 "/    frame := VariableVerticalPanel
   218 			 labelFrame height
   224 "/                 origin:[frame borderWidth negated 
   219 			 "/ (labelView height + labelView origin y + spacing)
   225 "/                         @ 
   220 			]
   226 "/                         labelFrame height
   221 		 corner:(1.0 @ 1.0)
   227 "/                         "/ (labelView height + labelView origin y + spacing)
   222 		     in:self.
   228 "/                        ]
       
   229 "/                 corner:(1.0 @ 1.0)
       
   230 "/                     in:self.
       
   231 
       
   232     frame := VariableVerticalPanel origin:0.0@0.0 corner:1.0@1.0 in:self.
       
   233     frame topInset:labelFrame height.
       
   234     commandView notNil ifTrue:[
       
   235 	frame bottomInset:(commandView height + spacing)
       
   236     ].
   223 
   237 
   224     topFrame := ScrollableView for:SelectionInListView in:frame.
   238     topFrame := ScrollableView for:SelectionInListView in:frame.
   225     topFrame origin:(0.0 @ 0.0) corner:(1.0 @ 0.3).
   239     topFrame origin:(0.0 @ 0.0) corner:(1.0 @ 0.3).
   226 
   240 
   227     fileListView := topFrame scrolledView.
   241     fileListView := topFrame scrolledView.
   230 					      self fileGet].
   244 					      self fileGet].
   231     fileListView multipleSelectOk:true.
   245     fileListView multipleSelectOk:true.
   232     fileListView menuHolder:self; menuPerformer:self; menuMessage:#fileListMenu.
   246     fileListView menuHolder:self; menuPerformer:self; menuMessage:#fileListMenu.
   233 
   247 
   234     v := self initializeSubViewIn:frame.
   248     v := self initializeSubViewIn:frame.
       
   249 
   235     v origin:(0.0 @ 0.3) corner:(1.0 @ 1.0).
   250     v origin:(0.0 @ 0.3) corner:(1.0 @ 1.0).
   236     subView := v scrolledView.
   251     subView := v scrolledView.
   237     (subView respondsTo:#directoryForFileDialog:) ifTrue:[
   252     (subView respondsTo:#directoryForFileDialog:) ifTrue:[
   238 	subView directoryForFileDialog:currentDirectory
   253 	subView directoryForFileDialog:currentDirectory
   239     ].
   254     ].
   240 
   255 
   241     ObjectMemory addDependent:self.
   256     ObjectMemory addDependent:self.
       
   257 
       
   258     "Modified: 6.9.1995 / 20:26:06 / claus"
   242 !
   259 !
   243 
   260 
   244 initializeFilterPattern
   261 initializeFilterPattern
   245     "set an initial matchpattern - can be redefined in subclasses"
   262     "set an initial matchpattern - can be redefined in subclasses"
   246 
   263 
   257      different view types (SoundFileBrowser/ImageBrowsers etc.)"
   274      different view types (SoundFileBrowser/ImageBrowsers etc.)"
   258 
   275 
   259     ^ HVScrollableView for:CodeView miniScrollerH:true miniScrollerV:false in:frame.
   276     ^ HVScrollableView for:CodeView miniScrollerH:true miniScrollerV:false in:frame.
   260 !
   277 !
   261 
   278 
       
   279 initializeCommandViewIn:frame
       
   280     "set up the command view - can be redefined in subclasses as empty,
       
   281      if no commandView is wanted"
       
   282 
       
   283 
       
   284     commandView := EditField origin:0.0@1.0 corner:1.0@1.0 in:frame.
       
   285     commandView topInset:(commandView preferredExtent y negated - ViewSpacing).
       
   286     commandView bottomInset:ViewSpacing.
       
   287     commandView horizontalInset:ViewSpacing.
       
   288 
       
   289     commandView contents:'** no commands which require input here **'.
       
   290 
       
   291     commandView entryCompletionBlock:[
       
   292 	FilenameEditField filenameCompletionBlock 
       
   293 		value:commandView
       
   294 		value:currentDirectory pathName asFilename
       
   295 		value:false
       
   296 		value:false
       
   297     ].
       
   298     commandView leaveAction:[:key | 
       
   299 	|cmd nCmd empty|
       
   300 
       
   301 	(key == #CursorDown 
       
   302 	or:[key == #CursorUp]) ifTrue:[
       
   303             nCmd := CommandHistory size.
       
   304             nCmd == 0 ifTrue:[
       
   305                 empty := true
       
   306             ] ifFalse:[
       
   307                 key == #CursorUp ifTrue:[
       
   308                     commandIndex == nCmd ifTrue:[
       
   309                         commandView flash.
       
   310                     ].
       
   311                     commandIndex := (commandIndex + 1) min:nCmd
       
   312                 ] ifFalse:[
       
   313                     commandIndex == 1 ifTrue:[
       
   314                         commandView flash.
       
   315                         empty := true.
       
   316                     ].
       
   317                     commandIndex := (commandIndex - 1) max:1.
       
   318                 ].
       
   319             ].
       
   320             empty == true ifTrue:[
       
   321                 commandView contents:nil
       
   322             ] ifFalse:[
       
   323                 commandView contents:(CommandHistory at:commandIndex).
       
   324             ]        
       
   325 	].
       
   326 	key == #Return ifTrue:[
       
   327 	    cmd := commandView contents.
       
   328 
       
   329 	    subView insertStringAtCursor:'>> '.
       
   330 	    subView insertStringAtCursor:cmd.
       
   331 	    subView insertCharAtCursor:(Character cr).
       
   332 
       
   333 	    (cmd notNil and:[cmd notEmpty]) ifTrue:[
       
   334 		CommandHistory notNil ifTrue:[
       
   335 		    CommandHistory addFirst:cmd.
       
   336 		    CommandHistory size > CommandHistorySize ifTrue:[
       
   337 			CommandHistory removeLast
       
   338 		    ]
       
   339 		].
       
   340 		self doExecuteCommand:cmd replace:false.
       
   341 		commandView contents:nil.
       
   342 		commandIndex := 0
       
   343 	    ]
       
   344 	]
       
   345     ].
       
   346 
       
   347     "Modified: 7.9.1995 / 11:43:55 / claus"
       
   348 !
       
   349 
   262 currentDirectory:aDirectoryPath
   350 currentDirectory:aDirectoryPath
   263     "set the directory to be browsed"
   351     "set the directory to be browsed"
   264 
   352 
   265     currentDirectory := FileDirectory directoryNamed:aDirectoryPath.
   353     currentDirectory := FileDirectory directoryNamed:aDirectoryPath.
   266     self changed:#path.
   354     self changed:#path.
   274 !
   362 !
   275 
   363 
   276 focusSequence
   364 focusSequence
   277     "return the sequence in which ALT-CursorRight steps focus"
   365     "return the sequence in which ALT-CursorRight steps focus"
   278 
   366 
   279     ^ Array with:filterField with:fileListView with:subView
   367     |fs|
       
   368 
       
   369     fs := Array 
       
   370 	with:filterField 
       
   371 	with:fileListView 
       
   372 	with:subView.
       
   373 
       
   374     commandView notNil ifTrue:[
       
   375 	fs := fs copyWith:commandView
       
   376     ].
       
   377     ^fs
   280 ! !
   378 ! !
   281 
   379 
   282 !FileBrowser methodsFor:'events'!
   380 !FileBrowser methodsFor:'events'!
   283 
   381 
   284 visibilityChange:how
   382 visibilityChange:how
   317     aComponent == filterField ifTrue:[
   415     aComponent == filterField ifTrue:[
   318 	s := 'HELP_FILTER'
   416 	s := 'HELP_FILTER'
   319     ].
   417     ].
   320     aComponent == labelView ifTrue:[
   418     aComponent == labelView ifTrue:[
   321 	s := 'HELP_PATHFIELD'
   419 	s := 'HELP_PATHFIELD'
       
   420     ].
       
   421     aComponent == commandView ifTrue:[
       
   422 	s := 'HELP_COMMANDVIEW'
   322     ].
   423     ].
   323     s notNil ifTrue:[
   424     s notNil ifTrue:[
   324 	^ resources string:s
   425 	^ resources string:s
   325     ].
   426     ].
   326     ^ nil
   427     ^ nil
  1299 		myProcess := Processor activeProcess.
  1400 		myProcess := Processor activeProcess.
  1300 		myPriority := myProcess priority.
  1401 		myPriority := myProcess priority.
  1301 		myProcess priority:(Processor userBackgroundPriority).
  1402 		myProcess priority:(Processor userBackgroundPriority).
  1302 
  1403 
  1303 		[
  1404 		[
  1304 		    |codeView|
  1405 		    |codeView lines|
  1305 
  1406 
  1306 		    codeView := subView.
  1407 		    codeView := subView.
  1307 
  1408 
  1308 		    replace ifTrue:[
  1409 		    replace ifTrue:[
  1309 			codeView list:nil.
  1410 			codeView list:nil.
  1313 		    [stream atEnd] whileFalse:[
  1414 		    [stream atEnd] whileFalse:[
  1314 			(stream readWaitWithTimeoutMs:250) ifFalse:[
  1415 			(stream readWaitWithTimeoutMs:250) ifFalse:[
  1315 			    "
  1416 			    "
  1316 			     data available
  1417 			     data available
  1317 			    "
  1418 			    "
       
  1419 			    lines := OrderedCollection new:50.
  1318 			    line := stream nextLine.
  1420 			    line := stream nextLine.
       
  1421 			    line notNil ifTrue:[lines add:line].
       
  1422 
       
  1423 			    [stream atEnd not
       
  1424 			    and:[stream canReadWithoutBlocking
       
  1425 			    and:[lines size < 50]]] whileTrue:[
       
  1426 				line := stream nextLine.
       
  1427 				line notNil ifTrue:[lines add:line].
       
  1428 			    ].
  1319 
  1429 
  1320 			    "
  1430 			    "
  1321 			     need this critical section; otherwise,
  1431 			     need this critical section; otherwise,
  1322 			     we could get the signal while waiting for
  1432 			     we could get the signal while waiting for
  1323 			     an expose event ...
  1433 			     an expose event ...
  1324 			    "
  1434 			    "
  1325 			    access critical:[                        
  1435 			    access critical:[                        
  1326 				line notNil ifTrue:[
  1436 				lines size > 0 ifTrue:[
  1327 				    line := line withTabsExpanded.
       
  1328 				    replace ifTrue:[
  1437 				    replace ifTrue:[
  1329 					codeView at:lnr put:line.
  1438 					lines do:[:line |
  1330 					codeView cursorToBottom; cursorDown.
  1439 					    codeView at:lnr put:line withTabsExpanded.
  1331 					lnr := lnr + 1.
  1440 					    codeView cursorToBottom; cursorDown.
       
  1441 					    lnr := lnr + 1.
       
  1442 					].
  1332 				    ] ifFalse:[
  1443 				    ] ifFalse:[
  1333 					codeView insertStringAtCursor:line.
  1444 codeView insertLines:lines before:codeView cursorLine.
  1334 					codeView insertCharAtCursor:(Character cr).
  1445 codeView cursorDown:lines size.
       
  1446 "/ lines do:[:line |
       
  1447 "/     codeView insertLine:line withTabsExpanded before:codeView cursorLine.
       
  1448 "/     codeView cursorDown.
       
  1449 "/ ]
       
  1450 "/                                        codeView insertStringAtCursor:line.
       
  1451 "/                                        codeView insertCharAtCursor:(Character cr).
  1335 				    ]
  1452 				    ]
  1336 				].
  1453 				].
  1337 			    ].
  1454 			    ].
  1338 			].
  1455 			].
  1339 
  1456 
  1381 	"
  1498 	"
  1382 	 clear its action (actually not needed, but
  1499 	 clear its action (actually not needed, but
  1383 	 releases reference to thisContext earlier)
  1500 	 releases reference to thisContext earlier)
  1384 	"
  1501 	"
  1385 	killButton action:nil.
  1502 	killButton action:nil.
  1386     ]
  1503     ].
       
  1504 
       
  1505     subView size > 10000 ifTrue:[
       
  1506 	self warn:'text quite large now - please cut off some lines'
       
  1507     ]
       
  1508 
       
  1509     "Modified: 6.9.1995 / 20:56:15 / claus"
  1387 !
  1510 !
  1388 
  1511 
  1389 initialCommandFor:fileName into:aBox
  1512 initialCommandFor:fileName into:aBox
  1390     "set a useful initial command for execute box.
  1513     "set a useful initial command for execute box.
  1391 
  1514 
  1491 	fileName := fileList at:sel first
  1614 	fileName := fileList at:sel first
  1492     ].
  1615     ].
  1493     fileName notNil ifTrue:[
  1616     fileName notNil ifTrue:[
  1494 	self initialCommandFor:fileName into:box.
  1617 	self initialCommandFor:fileName into:box.
  1495     ].
  1618     ].
       
  1619     box directory:currentDirectory pathName asFilename.
  1496     box showAtPointer
  1620     box showAtPointer
       
  1621 
       
  1622     "Modified: 7.9.1995 / 10:31:54 / claus"
  1497 !
  1623 !
  1498 
  1624 
  1499 selectedFilesDo:aBlock
  1625 selectedFilesDo:aBlock
  1500     "evaluate aBlock on all selected files;
  1626     "evaluate aBlock on all selected files;
  1501      show a wait cursor while doing this"
  1627      show a wait cursor while doing this"
  1962 !
  2088 !
  1963 
  2089 
  1964 fileFileInLazy:lazy
  2090 fileFileInLazy:lazy
  1965     "fileIn the selected file(s)"
  2091     "fileIn the selected file(s)"
  1966 
  2092 
  1967     |aStream upd here oldPath wasLazy|
  2093     |aStream here oldPath wasLazy|
  1968 
  2094 
  1969     self selectedFilesDo:[:fileName |
  2095     self selectedFilesDo:[:fileName |
  1970 	((currentDirectory typeOf:fileName) == #regular) ifTrue:[
  2096 	((currentDirectory typeOf:fileName) == #regular) ifTrue:[
  1971 	    here := currentDirectory pathName.
  2097 	    here := currentDirectory pathName.
  1972 
  2098 
  1977 		    ObjectFileLoader loadObjectFile:(here , '/' ,fileName)
  2103 		    ObjectFileLoader loadObjectFile:(here , '/' ,fileName)
  1978 		]
  2104 		]
  1979 	    ] ifFalse:[
  2105 	    ] ifFalse:[
  1980 		aStream := FileStream readonlyFileNamed:fileName in:currentDirectory.
  2106 		aStream := FileStream readonlyFileNamed:fileName in:currentDirectory.
  1981 		aStream isNil ifFalse:[
  2107 		aStream isNil ifFalse:[
  1982 		    upd := Class updateChanges:false.
       
  1983 		    [
  2108 		    [
  1984 			oldPath := Smalltalk systemPath.
  2109 			Class withoutUpdatingChangesDo:[
  1985 			Smalltalk systemPath:(oldPath copy addFirst:here; yourself).
  2110 			    oldPath := Smalltalk systemPath.
  1986 			wasLazy := Compiler compileLazy:lazy.
  2111 			    Smalltalk systemPath:(oldPath copy addFirst:here; yourself).
  1987 			aStream fileIn.
  2112 			    wasLazy := Compiler compileLazy:lazy.
       
  2113 			    aStream fileIn.
       
  2114 			]
  1988 		    ] valueNowOrOnUnwindDo:[
  2115 		    ] valueNowOrOnUnwindDo:[
  1989 			Compiler compileLazy:wasLazy.
  2116 			Compiler compileLazy:wasLazy.
  1990 			Smalltalk systemPath:oldPath.
  2117 			Smalltalk systemPath:oldPath.
  1991 			Class updateChanges:upd.
       
  1992 			aStream close
  2118 			aStream close
  1993 		    ]
  2119 		    ]
  1994 		]
  2120 		]
  1995 	    ]
  2121 	    ]
  1996 	]
  2122 	]