FBrowser.st
changeset 380 ec0cfd2b3200
parent 355 55f1bac567eb
child 381 0b715d777c48
equal deleted inserted replaced
379:b7adadee426a 380:ec0cfd2b3200
   941 
   941 
   942 update:what with:someArgument from:changedObject
   942 update:what with:someArgument from:changedObject
   943     realized ifFalse:[^ self].
   943     realized ifFalse:[^ self].
   944 
   944 
   945     (what == #aboutToExit) ifTrue:[
   945     (what == #aboutToExit) ifTrue:[
   946 	"system wants to shut down this
   946         "system wants to shut down this
   947 	 - if text was modified, pop up, and ask user and save if requested."
   947          - if text was modified, pop up, and ask user and save if requested."
   948 
   948 
   949 	(subView modified and:[subView contentsWasSaved not]) ifTrue:[
   949         (subView modified and:[subView contentsWasSaved not]) ifTrue:[
   950 	    self raiseDeiconified.
   950             self raiseDeiconified.
   951 
   951 
   952 	    self ask:(resources at:'FileBrowser:\\contents has not been saved.\\Save before exiting ?') withCRs
   952             (self 
   953 		 yesButton:'save'
   953                 ask:(resources at:'FileBrowser:\\contents has not been saved.\\Save before exiting ?')
   954 		 noButton:'don''t save'
   954                 yesButton:'save'
   955 		 action:[
   955                 noButton:'don''t save')
   956 			subView acceptAction notNil ifTrue:[
   956             ifTrue:[
   957 			    subView accept
   957                 subView acceptAction notNil ifTrue:[
   958 			] ifFalse:[
   958                     subView accept
   959 			    subView save
   959                 ] ifFalse:[
   960 			]
   960                     subView save
   961 		    ]
   961                 ]
   962 	].
   962             ]
   963 	^ self
   963         ].
       
   964         ^ self
   964     ].
   965     ].
   965     changedObject == tabSpec ifTrue:[
   966     changedObject == tabSpec ifTrue:[
   966 	fileListView redraw
   967         fileListView redraw
   967     ].
   968     ].
       
   969 
       
   970     "Modified: 21.2.1996 / 01:17:53 / cg"
   968 ! !
   971 ! !
   969 
   972 
   970 !FileBrowser methodsFor:'pathField user interaction'!
   973 !FileBrowser methodsFor:'pathField user interaction'!
   971 
   974 
   972 changeCurrentDirectory
   975 changeCurrentDirectory
  1078 
  1081 
  1079     ^ self ask:question yesButton:yesButtonText noButton:'cancel' 
  1082     ^ self ask:question yesButton:yesButtonText noButton:'cancel' 
  1080 !
  1083 !
  1081 
  1084 
  1082 ask:question yesButton:yesButtonText noButton:noButtonText
  1085 ask:question yesButton:yesButtonText noButton:noButtonText
  1083     "common method to ask a yes/no question; return true or false"
       
  1084 
       
  1085     self 
       
  1086 	ask:question 
       
  1087 	yesButton:yesButtonText 
       
  1088 	noButton:noButtonText 
       
  1089 	action:[^ true].
       
  1090     ^ false
       
  1091 !
       
  1092 
       
  1093 ask:question yesButton:yesButtonText noButton:noButtonText action:aBlock
       
  1094     "common method to ask a yes/no question"
  1086     "common method to ask a yes/no question"
  1095 
  1087 
  1096     |yesNoBox|
  1088     ^ Dialog 
  1097 
  1089         confirm:question withCRs
  1098     yesNoBox := YesNoBox 
  1090         yesLabel:(resources at:yesButtonText)
  1099 		    title:question withCRs
  1091         noLabel:(resources at:noButtonText)
  1100 		  yesText:(resources at:yesButtonText)
  1092 
  1101 		   noText:(resources at:noButtonText).
  1093     "Modified: 21.2.1996 / 01:19:21 / cg"
  1102     yesNoBox okAction:aBlock.
       
  1103     yesNoBox showAtPointer
       
  1104 !
  1094 !
  1105 
  1095 
  1106 askForCommandThenDo:aBlock
  1096 askForCommandThenDo:aBlock
  1107     "setup and launch a querybox to ask for unix command.
  1097     "setup and launch a querybox to ask for unix command.
  1108      Then evaluate aBlock passing the command-string as argument."
  1098      Then evaluate aBlock passing the command-string as argument."
  1378 
  1368 
  1379 doCreateFile:newName
  1369 doCreateFile:newName
  1380     |aStream|
  1370     |aStream|
  1381 
  1371 
  1382     (currentDirectory includes:newName) ifTrue:[
  1372     (currentDirectory includes:newName) ifTrue:[
  1383 	(self
  1373         (self
  1384 	    ask:(resources string:'%1 already exists\\truncate ?' with:newName)
  1374             ask:(resources string:'%1 already exists\\truncate ?' with:newName)
  1385 	    yesButton:'truncate'
  1375             yesButton:'truncate'
  1386 	    noButton:'cancel'
  1376         ) ifFalse:[^ self].
  1387 	) ifFalse:[^ self].
       
  1388     ].
  1377     ].
  1389 
  1378 
  1390     aStream := FileStream newFileNamed:newName in:currentDirectory.
  1379     aStream := FileStream newFileNamed:newName in:currentDirectory.
  1391     aStream notNil ifTrue:[
  1380     aStream notNil ifTrue:[
  1392 	aStream close.
  1381         aStream close.
  1393 	self updateCurrentDirectory
  1382         self updateCurrentDirectory
  1394     ] ifFalse:[
  1383     ] ifFalse:[
  1395 	self showAlert:(resources string:'cannot create file ''%1'' !!' with:newName)
  1384         self showAlert:(resources string:'cannot create file ''%1'' !!' with:newName)
  1396 		  with:(FileStream lastErrorString)
  1385                   with:(FileStream lastErrorString)
  1397     ]
  1386     ]
       
  1387 
       
  1388     "Modified: 21.2.1996 / 01:24:16 / cg"
  1398 !
  1389 !
  1399 
  1390 
  1400 doExecuteCommand:command replace:replace
  1391 doExecuteCommand:command replace:replace
  1401     "execute a unix command inserting the output of the command.
  1392     "execute a unix command inserting the output of the command.
  1402      If replace is true, all text is replaced by the commands output;
  1393      If replace is true, all text is replaced by the commands output;
  1569 !
  1560 !
  1570 
  1561 
  1571 doFileGet
  1562 doFileGet
  1572     "get selected file - show contents in subView"
  1563     "get selected file - show contents in subView"
  1573 
  1564 
  1574     |fileName|
  1565     |fileName iconLbl winLbl|
  1575 
  1566 
  1576     self withReadCursorDo:[
  1567     self withReadCursorDo:[
  1577 	fileName := self getSelectedFileName.
  1568         fileName := self getSelectedFileName.
  1578 	fileName notNil ifTrue:[
  1569         fileName notNil ifTrue:[
  1579 	    (currentDirectory isDirectory:fileName) ifTrue:[
  1570             (currentDirectory isDirectory:fileName) ifTrue:[
  1580 		self doChangeCurrentDirectoryTo:fileName updateHistory:true.
  1571                 self doChangeCurrentDirectoryTo:fileName updateHistory:true.
  1581 		self label:myName.
  1572                 winLbl := myName.
  1582 		self iconLabel:myName
  1573                 iconLbl := myName
  1583 	    ] ifFalse:[
  1574             ] ifFalse:[
  1584 		(currentDirectory exists:fileName) ifFalse:[
  1575                 (currentDirectory exists:fileName) ifFalse:[
  1585 		    self warn:(resources string:'oops, ''%1'' is gone' with:fileName).
  1576                     self warn:(resources string:'oops, ''%1'' is gone' with:fileName).
  1586 		    ^ self
  1577                     ^ self
  1587 		].
  1578                 ].
  1588 		timeOfFileRead := currentDirectory timeOfLastChange:fileName.
  1579                 timeOfFileRead := currentDirectory timeOfLastChange:fileName.
  1589 		self showFile:fileName insert:false.
  1580                 self showFile:fileName insert:false.
  1590 		currentFileName := fileName.
  1581                 currentFileName := fileName.
  1591 
  1582 
  1592 		subView acceptAction:[:theCode |
  1583                 subView acceptAction:[:theCode |
  1593 		    self withCursor:(Cursor write) do:[
  1584                     self withCursor:(Cursor write) do:[
  1594 			self writeFile:fileName text:theCode.
  1585                         self writeFile:fileName text:theCode.
  1595 			timeOfFileRead := currentDirectory timeOfLastChange:fileName.
  1586                         timeOfFileRead := currentDirectory timeOfLastChange:fileName.
  1596 			self label:myName , ': ' , currentFileName
  1587                         self label:myName , ': ' , currentFileName
  1597 		    ]
  1588                     ]
  1598 		].
  1589                 ].
  1599 
  1590 
  1600 		(currentDirectory isWritable:fileName) ifFalse:[
  1591                 winLbl := myName , ': ' , fileName.
  1601 		    self label:(myName , ': ' , fileName , ' (readonly)')
  1592                 (currentDirectory isWritable:fileName) ifFalse:[
  1602 		] ifTrue:[
  1593                     winLbl := winLbl , ' (readonly)'
  1603 		    self label:(myName , ': ' , fileName)
  1594                 ].
  1604 		].
  1595                 iconLbl := fileName
  1605 		self iconLabel:fileName
  1596             ].
  1606 	    ]
  1597             self label:winLbl.
  1607 	]
  1598             self iconLabel:iconLbl.
  1608     ]
  1599         ]
  1609 
  1600     ]
  1610     "Modified: 17.12.1995 / 15:42:16 / cg"
  1601 
       
  1602     "Modified: 21.2.1996 / 01:28:35 / cg"
  1611 !
  1603 !
  1612 
  1604 
  1613 doRemove
  1605 doRemove
  1614     "remove the selected file(s) - no questions asked"
  1606     "remove the selected file(s) - no questions asked"
  1615 
  1607 
  1616     |ok msg dir|
  1608     |ok msg dir|
  1617 
  1609 
  1618     lockUpdate := true.
  1610     lockUpdate := true.
  1619     [
  1611     [
  1620 	self selectedFilesDo:[:fileName |
  1612         self selectedFilesDo:[:fileName |
  1621 	    ok := false.
  1613             ok := false.
  1622 	    (currentDirectory isDirectory:fileName) ifTrue:[
  1614             (currentDirectory isDirectory:fileName) ifTrue:[
  1623 		dir := FileDirectory directoryNamed:fileName in:currentDirectory.
  1615                 dir := FileDirectory directoryNamed:fileName in:currentDirectory.
  1624 		dir isEmpty ifFalse:[
  1616                 (dir isEmpty 
  1625 		    (self ask:(resources string:'directory ''%1'' is not empty\remove anyway ?' with:fileName)
  1617                 or:[
  1626 			  yesButton:'remove') ifTrue:[
  1618                     (self 
  1627 			 ok := currentDirectory removeDirectory:fileName
  1619                         ask:(resources string:'directory ''%1'' is not empty\remove anyway ?' with:fileName)
  1628 		    ]
  1620                         yesButton:'remove')])
  1629 		] ifTrue:[
  1621                 ifTrue:[
  1630 		    ok := currentDirectory removeDirectory:fileName
  1622                     ok := currentDirectory removeDirectory:fileName
  1631 		].
  1623                 ].
  1632 	    ] ifFalse:[
  1624             ] ifFalse:[
  1633 		ok := currentDirectory remove:fileName.
  1625                 ok := currentDirectory remove:fileName.
  1634 	    ].
  1626             ].
  1635 	    ok ifFalse:[
  1627             ok ifFalse:[
  1636 		"was not able to remove it"
  1628                 "was not able to remove it"
  1637 		msg := (resources string:'cannot remove ''%1'' !!' with:fileName).
  1629                 msg := (resources string:'cannot remove ''%1'' !!' with:fileName).
  1638 		self showAlert:msg with:(OperatingSystem lastErrorString)
  1630                 self showAlert:msg with:(OperatingSystem lastErrorString)
  1639 	    ] ifTrue:[
  1631             ] ifTrue:[
  1640 "
  1632 "
  1641 		self show:nil
  1633                 self show:nil
  1642 "
  1634 "
  1643 	    ]
  1635             ]
  1644 	].
  1636         ].
  1645     ] valueNowOrOnUnwindDo:[
  1637     ] valueNowOrOnUnwindDo:[
  1646 	lockUpdate := false.
  1638         lockUpdate := false.
  1647 	fileListView deselect.
  1639         fileListView deselect.
  1648 	self updateCurrentDirectory.
  1640         self updateCurrentDirectory.
  1649     ]                
  1641     ]
       
  1642 
       
  1643     "Modified: 21.2.1996 / 01:21:35 / cg"
  1650 !
  1644 !
  1651 
  1645 
  1652 doRename:oldName to:newName
  1646 doRename:oldName to:newName
  1653     (oldName notNil and:[newName notNil]) ifTrue:[
  1647     (oldName notNil and:[newName notNil]) ifTrue:[
  1654 	(oldName isBlank or:[newName isBlank]) ifFalse:[
  1648 	(oldName isBlank or:[newName isBlank]) ifFalse:[
  2324 
  2318 
  2325     |newCollection|
  2319     |newCollection|
  2326 
  2320 
  2327     newCollection := aCollection species new.
  2321     newCollection := aCollection species new.
  2328     aCollection do:[:fname |
  2322     aCollection do:[:fname |
  2329 	((fname startsWith:'.') and:[(fname = '..') not]) ifTrue:[
  2323         |ignore|
  2330 	    showDotFiles ifTrue:[
  2324 
  2331 		newCollection add:fname
  2325         ignore := false.
  2332 	    ]
  2326 
  2333 	] ifFalse:[
  2327         ((fname startsWith:'.') and:[fname ~= '..']) ifTrue:[
  2334 	    newCollection add:fname
  2328             showDotFiles ifFalse:[
  2335 	]
  2329                 ignore := true
       
  2330             ]
       
  2331         ].
       
  2332         ignore ifFalse:[
       
  2333             newCollection add:fname
       
  2334         ]
  2336     ].
  2335     ].
  2337     ^ newCollection
  2336     ^ newCollection
       
  2337 
       
  2338     "Modified: 21.2.1996 / 01:33:18 / cg"
  2338 !
  2339 !
  2339 
  2340 
  2340 writeFile:fileName text:someText 
  2341 writeFile:fileName text:someText 
  2341     |stream msg startNr nLines string|
  2342     |stream msg startNr nLines string|
  2342 
  2343 
  2386 ! !
  2387 ! !
  2387 
  2388 
  2388 !FileBrowser class methodsFor:'documentation'!
  2389 !FileBrowser class methodsFor:'documentation'!
  2389 
  2390 
  2390 version
  2391 version
  2391 ^ '$Header: /cvs/stx/stx/libtool/Attic/FBrowser.st,v 1.70 1996-02-08 23:26:59 cg Exp $'! !
  2392 ^ '$Header: /cvs/stx/stx/libtool/Attic/FBrowser.st,v 1.71 1996-02-21 00:37:46 cg Exp $'! !