FileBrowser.st
changeset 3025 a1d9d7b0d0b3
parent 3022 1063cadd13f7
child 3026 3fb47b4a366c
equal deleted inserted replaced
3024:51e109cb8ae0 3025:a1d9d7b0d0b3
    85 "
    85 "
    86 ! !
    86 ! !
    87 
    87 
    88 !FileBrowser class methodsFor:'instance creation'!
    88 !FileBrowser class methodsFor:'instance creation'!
    89 
    89 
       
    90 on:aDirectoryPath
       
    91     "return a new FileBrowser in a pathname"
       
    92 
       
    93     ^ (self new currentDirectory:aDirectoryPath)
       
    94 
       
    95     "
       
    96      (FileBrowser on:'/usr/local/bin') open
       
    97      (FileBrowser on:'/etc'          ) open
       
    98      (FileBrowser on:'..'            ) open
       
    99      (FileBrowser on:'.'             ) open
       
   100     "
       
   101 !
       
   102 
    90 openOn:aDirectoryPath
   103 openOn:aDirectoryPath
    91     "start a new FileBrowser in a pathname"
   104     "start a new FileBrowser in a pathname"
    92 
   105 
    93     ^ (self new currentDirectory:aDirectoryPath) open
   106     ^ (self on:aDirectoryPath) open
    94 
   107 
    95     "
   108     "
    96      FileBrowser openOn:'aDirectoryPath'
       
    97      FileBrowser openOn:'/etc'
   109      FileBrowser openOn:'/etc'
    98      FileBrowser openOn:'..'
   110      FileBrowser openOn:'..'
    99      FileBrowser openOn:'.'
   111      FileBrowser openOn:'.'
   100     "
   112     "
   101 !
   113 !
   102 
   114 
       
   115 openOn:aDirectoryPath withExtent:extent
       
   116     "start a new FileBrowser in a pathname"
       
   117 
       
   118     ^ (self on:aDirectoryPath) openWithExtent:extent
       
   119 
       
   120     "
       
   121      FileBrowser openOn:'/etc'           withExtent:200@300
       
   122      FileBrowser openOn:'..'             withExtent:200@300
       
   123      FileBrowser openOn:'.'              withExtent:200@300
       
   124     "
       
   125 !
       
   126 
   103 openOnFileNamed:aFilename
   127 openOnFileNamed:aFilename
   104     "start a new FileBrowser on a file"
   128     "start a new FileBrowser on a file"
   105 
   129 
   106     |f browser|
   130     |f browser|
   107 
   131 
   108     f := aFilename asFilename.
   132     f := aFilename asFilename.
   109     f isDirectory ifTrue:[
   133     f isDirectory ifTrue:[
   110 	^ self openOn:aFilename
   134         ^ self openOn:aFilename
   111     ].
   135     ].
   112 
   136 
   113     browser := self new.
   137     browser := self on:f directoryName.
   114     browser currentDirectory:f directoryName.
       
   115     browser updateCurrentDirectory.
   138     browser updateCurrentDirectory.
   116     browser showFile:f baseName.
   139     browser showFile:f baseName.
   117 
   140 
   118     ^ browser open.
   141     ^ browser open.
   119 
   142 
  2730 
  2753 
  2731     |any path|
  2754     |any path|
  2732 
  2755 
  2733     any := false.
  2756     any := false.
  2734     self selectedFilesDo:[:fileName |
  2757     self selectedFilesDo:[:fileName |
  2735 	path := currentDirectory filenameFor:fileName.
  2758         path := currentDirectory filenameFor:fileName.
  2736 	path isDirectory ifTrue:[
  2759         path isDirectory ifTrue:[
  2737 	    self class openOn:(path pathName).
  2760             self class openOn:(path pathName).
  2738 	    any := true
  2761             any := true
  2739 	]
  2762         ]
  2740     ].
  2763     ].
  2741     any ifFalse:[
  2764     any ifFalse:[
  2742 	self class openOn:currentDirectory pathName
  2765         self class openOn:currentDirectory pathName withExtent:self topView extent
  2743     ]
  2766     ]
  2744 
  2767 
  2745     "Modified: 18.9.1997 / 16:32:39 / stefan"
  2768     "Modified: 18.9.1997 / 16:32:39 / stefan"
  2746 !
  2769 !
  2747 
  2770 
  4848 
  4871 
  4849     "
  4872     "
  4850      kill will make me raise the stopSignal when pressed
  4873      kill will make me raise the stopSignal when pressed
  4851     "
  4874     "
  4852     killButton 
  4875     killButton 
  4853 	action:[
  4876         action:[
  4854 	    stream notNil ifTrue:[
  4877             stream notNil ifTrue:[
  4855 		access critical:[
  4878                 access critical:[
  4856 		    myProcess interruptWith:[stopSignal raiseRequest].
  4879                     myProcess interruptWith:[stopSignal raiseRequest].
  4857 		]
  4880                 ]
  4858 	    ]
  4881             ]
  4859 	].
  4882         ].
  4860 
  4883 
  4861     "
  4884     "
  4862      pause makes me stop reading the commands output
  4885      pause makes me stop reading the commands output
  4863     "
  4886     "
  4864     pauseHolder := false asValue.
  4887     pauseHolder := false asValue.
  4865     pauseToggle model:pauseHolder.
  4888     pauseToggle model:pauseHolder.
  4866     pauseToggle pressAction:[
  4889     pauseToggle pressAction:[
  4867 	stream notNil ifTrue:[
  4890         stream notNil ifTrue:[
  4868 	    access critical:[
  4891             access critical:[
  4869 		myProcess interruptWith:[pauseSignal raiseRequest].
  4892                 myProcess interruptWith:[pauseSignal raiseRequest].
  4870 	    ]
  4893             ]
  4871 	]
  4894         ]
  4872     ].
  4895     ].
  4873 
  4896 
  4874 
  4897 
  4875     "
  4898     "
  4876      start kill button under its own windowgroup
  4899      start kill button under its own windowgroup
  4892      go fork a pipe and read it
  4915      go fork a pipe and read it
  4893     "
  4916     "
  4894     self label:(myName , ': executing ' , (command copyTo:(20 min:command size)) , ' ...').
  4917     self label:(myName , ': executing ' , (command copyTo:(20 min:command size)) , ' ...').
  4895     [
  4918     [
  4896       self withWaitCursorDo:[
  4919       self withWaitCursorDo:[
  4897 	stopSignal catch:[
  4920         stopSignal catch:[
  4898 	    pauseSignal handle:[:ex|
  4921             pauseSignal handle:[:ex|
  4899 		|noPauseSema|
  4922                 |noPauseSema|
  4900 
  4923 
  4901 		"/    
  4924                 "/    
  4902 		"/ allow interaction with
  4925                 "/ allow interaction with
  4903 		"/ the codeView via the other windowGroup
  4926                 "/ the codeView via the other windowGroup
  4904 		"/
  4927                 "/
  4905 		lowerFrameView windowGroup:buttonWindowGroup.
  4928                 lowerFrameView windowGroup:buttonWindowGroup.
  4906 
  4929 
  4907 		"/
  4930                 "/
  4908 		"/ wait for pause to be turned off
  4931                 "/ wait for pause to be turned off
  4909 		"/
  4932                 "/
  4910 		noPauseSema := Semaphore new.
  4933                 noPauseSema := Semaphore new.
  4911 		pauseHolder onChangeSend:#signal to:noPauseSema.
  4934                 pauseHolder onChangeSend:#signal to:noPauseSema.
  4912 		noPauseSema wait.
  4935                 noPauseSema wait.
  4913 
  4936 
  4914 		"/    
  4937                 "/    
  4915 		"/ no interaction with the codeView ...
  4938                 "/ no interaction with the codeView ...
  4916 		"/
  4939                 "/
  4917 		lowerFrameView windowGroup:(self windowGroup).
  4940                 lowerFrameView windowGroup:(self windowGroup).
  4918 		ex proceed.
  4941                 ex proceed.
  4919 	    ] do:[
  4942             ] do:[
  4920 		startLine := subView cursorLine.
  4943                 startLine := subView cursorLine.
  4921 		startCol := subView cursorCol.
  4944                 startCol := subView cursorCol.
  4922 
  4945 
  4923 		"
  4946                 "
  4924 		 this can be a time consuming operation; therefore lower my priority
  4947                  this can be a time consuming operation; therefore lower my priority
  4925 		"
  4948                 "
  4926 		myProcess := Processor activeProcess.
  4949                 myProcess := Processor activeProcess.
  4927 "/                myPriority := myProcess priority.
  4950 "/                myPriority := myProcess priority.
  4928 "/                myProcess priority:(Processor userBackgroundPriority).
  4951 "/                myProcess priority:(Processor userBackgroundPriority).
  4929 
  4952 
  4930 		stream := PipeStream 
  4953                 stream := PipeStream 
  4931 			    readingFrom:command
  4954                             readingFrom:command
  4932 			    errorDisposition:#inline
  4955                             errorDisposition:#inline
  4933 			    inDirectory:currentDirectory.
  4956                             inDirectory:currentDirectory.
  4934 		stream notNil ifTrue:[
  4957                 stream notNil ifTrue:[
  4935 		    [
  4958                     [
  4936 			|codeView lines noPauseSema enc|
  4959                         |codeView lines noPauseSema enc|
  4937 
  4960 
  4938 			enc := fileEncoding.
  4961                         enc := fileEncoding.
  4939 			enc == #iso8859 ifTrue:[
  4962                         enc == #iso8859 ifTrue:[
  4940 			    enc := nil
  4963                             enc := nil
  4941 			].
  4964                         ].
  4942 
  4965 
  4943 			stream buffered:true.
  4966                         stream buffered:true.
  4944 			codeView := subView.
  4967                         codeView := subView.
  4945 			codeView unselect.
  4968                         codeView unselect.
  4946 
  4969 
  4947 			replace ifTrue:[
  4970                         replace ifTrue:[
  4948 			    codeView list:nil.
  4971                             codeView list:nil.
  4949 			    lnr := 1.
  4972                             lnr := 1.
  4950 			].
  4973                         ].
  4951 
  4974 
  4952 			stillReplacing := replace.
  4975                         stillReplacing := replace.
  4953 
  4976 
  4954 			[stream readWait. stream atEnd] whileFalse:[
  4977                         [stream atEnd or:[stream readWait. stream atEnd]] whileFalse:[
  4955 			    "
  4978                             "
  4956 			     data available; read up to 100 lines
  4979                              data available; read up to 100 lines
  4957 			     and insert as a single junk. This speeds up
  4980                              and insert as a single junk. This speeds up
  4958 			     display of long output (less line-scrolling).
  4981                              display of long output (less line-scrolling).
  4959 			    "
  4982                             "
  4960 			    lines := OrderedCollection new:100.
  4983                             lines := OrderedCollection new:100.
  4961 
  4984 
  4962 			    [
  4985                             [
  4963 				line := stream nextLine.
  4986                                 line := stream nextLine.
  4964 				line notNil ifTrue:[
  4987                                 line notNil ifTrue:[
  4965 				    enc notNil ifTrue:[
  4988                                     enc notNil ifTrue:[
  4966 					line := line decodeFrom:enc
  4989                                         line := line decodeFrom:enc
  4967 				    ].
  4990                                     ].
  4968 				    lines add:line
  4991                                     lines add:line
  4969 				].
  4992                                 ].
  4970 			    ] doWhile:[
  4993                             ] doWhile:[
  4971 				stream canReadWithoutBlocking
  4994                                 stream canReadWithoutBlocking
  4972 				and:[stream atEnd not
  4995                                 and:[stream atEnd not
  4973 				and:[lines size < 100]]
  4996                                 and:[lines size < 100]]
  4974 			    ]. 
  4997                             ]. 
  4975 
  4998 
  4976 			    "
  4999                             "
  4977 			     need this critical section; otherwise,
  5000                              need this critical section; otherwise,
  4978 			     we could get the signal while waiting for
  5001                              we could get the signal while waiting for
  4979 			     an expose event ...
  5002                              an expose event ...
  4980 			    "
  5003                             "
  4981 			    access critical:[                        
  5004                             access critical:[                        
  4982 				lines size > 0 ifTrue:[
  5005                                 lines size > 0 ifTrue:[
  4983 				    stillReplacing ifTrue:[
  5006                                     stillReplacing ifTrue:[
  4984 					lines do:[:line |
  5007                                         lines do:[:line |
  4985 					    codeView at:lnr put:line withTabsExpanded.
  5008                                             codeView at:lnr put:line withTabsExpanded.
  4986 					    codeView cursorToBottom; cursorDown:1.
  5009                                             codeView cursorToBottom; cursorDown:1.
  4987 					    lnr := lnr + 1.
  5010                                             lnr := lnr + 1.
  4988 					    lnr > codeView list size ifTrue:[
  5011                                             lnr > codeView list size ifTrue:[
  4989 						stillReplacing := false
  5012                                                 stillReplacing := false
  4990 					    ]
  5013                                             ]
  4991 					].
  5014                                         ].
  4992 				    ] ifFalse:[
  5015                                     ] ifFalse:[
  4993 					codeView insertLines:lines before:codeView cursorLine.
  5016                                         codeView insertLines:lines before:codeView cursorLine.
  4994 					codeView cursorDown:lines size.
  5017                                         codeView cursorDown:lines size.
  4995 				    ]
  5018                                     ]
  4996 				].
  5019                                 ].
  4997 			    ].
  5020                             ].
  4998 
  5021 
  4999 			    "
  5022                             "
  5000 			     give others running at same prio a chance too
  5023                              give others running at same prio a chance too
  5001 			     (especially other FileBrowsers doing the same)
  5024                              (especially other FileBrowsers doing the same)
  5002 			    "
  5025                             "
  5003 			    Processor yield
  5026                             Processor yield
  5004 			].
  5027                         ].
  5005 		    ] valueNowOrOnUnwindDo:[
  5028                     ] valueNowOrOnUnwindDo:[
  5006 			stream shutDown "close". stream := nil.
  5029                         stream shutDown "close". stream := nil.
  5007 		    ].
  5030                     ].
  5008 
  5031 
  5009 		    "/
  5032                     "/
  5010 		    "/ the command could have changed the directory
  5033                     "/ the command could have changed the directory
  5011 		    "/
  5034                     "/
  5012 		    self updateCurrentDirectoryIfChanged
  5035                     self updateCurrentDirectoryIfChanged
  5013 		].
  5036                 ].
  5014 		replace ifTrue:[
  5037                 replace ifTrue:[
  5015 		    subView modified:false.
  5038                     subView modified:false.
  5016 		].
  5039                 ].
  5017 	    ]
  5040             ]
  5018 	]
  5041         ]
  5019       ]
  5042       ]
  5020     ] valueNowOrOnUnwindDo:[
  5043     ] valueNowOrOnUnwindDo:[
  5021 	|wg|
  5044         |wg|
  5022 
  5045 
  5023 	self label:myName; iconLabel:myName.
  5046         self label:myName; iconLabel:myName.
  5024 "/        myProcess notNil ifTrue:[myProcess priority:myPriority].
  5047 "/        myProcess notNil ifTrue:[myProcess priority:myPriority].
  5025 
  5048 
  5026 	"
  5049         "
  5027 	 hide the button, and make sure it will stay
  5050          hide the button, and make sure it will stay
  5028 	 hidden when we are realized again
  5051          hidden when we are realized again
  5029 	"
  5052         "
  5030 	killButton beInvisible.
  5053         killButton beInvisible.
  5031 	pauseToggle beInvisible.
  5054         pauseToggle beInvisible.
  5032 
  5055 
  5033 	commandView beVisible.
  5056         commandView beVisible.
  5034 
  5057 
  5035 	"
  5058         "
  5036 	 remove the killButton from its group
  5059          remove the killButton from its group
  5037 	 (otherwise, it will be destroyed when we shut down the group)
  5060          (otherwise, it will be destroyed when we shut down the group)
  5038 	"
  5061         "
  5039 	wg := killButton windowGroup.
  5062         wg := killButton windowGroup.
  5040 	killButton windowGroup:nil.
  5063         killButton windowGroup:nil.
  5041 	pauseToggle windowGroup:nil.
  5064         pauseToggle windowGroup:nil.
  5042 
  5065 
  5043 	"
  5066         "
  5044 	 shut down the kill buttons windowgroup
  5067          shut down the kill buttons windowgroup
  5045 	"
  5068         "
  5046 	wg notNil ifTrue:[
  5069         wg notNil ifTrue:[
  5047 	    wg process terminate.
  5070             wg process terminate.
  5048 	].
  5071         ].
  5049 	"
  5072         "
  5050 	 clear its action (actually not needed, but
  5073          clear its action (actually not needed, but
  5051 	 releases reference to thisContext earlier)
  5074          releases reference to thisContext earlier)
  5052 	"
  5075         "
  5053 	killButton action:nil.
  5076         killButton action:nil.
  5054 	pauseToggle pressAction:nil.
  5077         pauseToggle pressAction:nil.
  5055 	"/    
  5078         "/    
  5056 	"/ allow interaction with the codeView
  5079         "/ allow interaction with the codeView
  5057 	"/ (bring it back into my group)
  5080         "/ (bring it back into my group)
  5058 	"/
  5081         "/
  5059 	lowerFrameView windowGroup:(self windowGroup).
  5082         lowerFrameView windowGroup:(self windowGroup).
  5060     ].
  5083     ].
  5061 
  5084 
  5062     currentFileName isNil ifTrue:[
  5085     currentFileName isNil ifTrue:[
  5063 	subView modified:false.
  5086         subView modified:false.
  5064     ].
  5087     ].
  5065 
  5088 
  5066     subView size > 10000 ifTrue:[
  5089     subView size > 10000 ifTrue:[
  5067 	self warn:'text quite large now - please cut off some lines'
  5090         self warn:'text quite large now - please cut off some lines'
  5068     ]
  5091     ]
  5069 
  5092 
  5070     "Modified: / 21.9.1995 / 11:18:46 / claus"
  5093     "Modified: / 21.9.1995 / 11:18:46 / claus"
  5071     "Modified: / 6.3.1998 / 17:32:03 / stefan"
  5094     "Modified: / 6.3.1998 / 17:32:03 / stefan"
  5072     "Modified: / 15.10.1998 / 12:37:52 / cg"
  5095     "Modified: / 15.10.1998 / 12:37:52 / cg"
  7251 ! !
  7274 ! !
  7252 
  7275 
  7253 !FileBrowser class methodsFor:'documentation'!
  7276 !FileBrowser class methodsFor:'documentation'!
  7254 
  7277 
  7255 version
  7278 version
  7256     ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.406 2001-05-24 14:50:39 cg Exp $'
  7279     ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.407 2001-06-12 12:19:54 cg Exp $'
  7257 ! !
  7280 ! !