'From Squeak6.0alpha of 15 September 2020 [latest update: #19851] on 25 September 2020 at 7:32 pm'!

!ChangeSet class methodsFor: 'file list services' stamp: 'ct 9/25/2020 19:24'!
serviceFileIntoNewChangeSet
	"Answer a service for installing a file into a new change set"

	^ SimpleServiceEntry 
		provider: self 
		label: 'install into new change set' translated
		selector: #fileIntoNewChangeSet:
		description: 'install the file as a body of code in the image: create a new change set and file-in the selected file into it' translated
		buttonLabel: 'install'! !

!ChangeSet class methodsFor: 'file list services' stamp: 'ct 9/25/2020 19:26'!
serviceFileIntoNewChangeSetWithoutUpdatingUI
	"Answer a service for installing a file into a new change set without updating the UI."

	^ SimpleServiceEntry 
		provider: self 
		label: 'install into new change set - without updating UI' translated
		selector: #fileIntoNewChangeSetWithoutUpdatingUI:
		description: 'Install the file as a body of code in the image: create a new change set and file-in the selected file into it. Don''t update the UI in the meantime. Recommended when loading change sets that touch critical UI services.' translated
		buttonLabel: 'install without updating UI' translated! !

!ChangeSet class methodsFor: 'file list services' stamp: 'ct 9/25/2020 19:25'!
services

	^ {
		self serviceFileIntoNewChangeSet.
		self serviceFileIntoNewChangeSetWithoutUpdatingUI
	}! !

!ChangeSet class methodsFor: 'services' stamp: 'ct 9/25/2020 19:27'!
fileIntoNewChangeSet: fullName
	"File in all of the contents of the currently selected file, if any, into a new change set." 

	^ self fileIntoNewChangeSet: fullName updateUI: true! !

!ChangeSet class methodsFor: 'services' stamp: 'ct 9/25/2020 19:27'!
fileIntoNewChangeSet: fullName updateUI: updateUI
	"File in all of the contents of the currently selected file, if any, into a new change set." 

	| fn ff |
	fullName ifNil: [^ Beeper beep].
	ff := FileStream readOnlyFileNamed: (fn := GZipReadStream uncompressedFileName: fullName).
	^ ChangeSet
		newChangesFromStream: ff
		named: (FileDirectory localNameFor: fn)
		updateUI: updateUI! !

!ChangeSet class methodsFor: 'services' stamp: 'ct 9/25/2020 19:28'!
fileIntoNewChangeSetWithoutUpdatingUI: fullName
	"File in all of the contents of the currently selected file, if any, into a new change set. Don't update the UI during filein. Useful when loading change sets that touch critical UI services."

	^ self fileIntoNewChangeSet: fullName updateUI: false! !

!ChangeSet class methodsFor: 'services' stamp: 'ct 9/25/2020 19:21'!
newChangesFromStream: aStream named: aName

	^ self newChangesFromStream: aStream named: aName updateUI: true! !

!ChangeSet class methodsFor: 'services' stamp: 'ct 9/25/2020 19:16'!
newChangesFromStream: aStream named: aName updateUI: updateUI
	"File in the code from the stream into a new change set whose name is derived from aName. Leave the current change set unchanged. Return the new change set or nil on failure."

	| oldChanges newName newSet |
	oldChanges := ChangeSet current.
	PreviousSet := oldChanges name. 		"so a Bumper update can find it"
	newName := aName sansPeriodSuffix.
	newSet := self basicNewChangeSet: newName.
	[
		| newStream |
		newSet ifNotNil: [
			newStream := (aStream respondsTo: #converter:)
				ifTrue: [aStream]
				ifFalse: [(MultiByteBinaryOrTextStream with: (aStream contentsOfEntireFile))
					reset].
			
			self newChanges: newSet.
			newStream
				setConverterForCode;
				fileInAnnouncing: ('Loading {1}...' translated format: {newName})
					silently: false
					updateUI: updateUI.
			RemarkNotification signal: ('File {1} successfully filed in to change set {2}' translated format: {aName. newName})].
		aStream close
	] ensure: [
		self newChanges: oldChanges
	].
	PreviousSet := nil.
	^ newSet! !


!PositionableStream methodsFor: '*System-Changes-fileIn/Out' stamp: 'ct 9/25/2020 19:17'!
fileInAnnouncing: announcement 

	^ self
		fileInAnnouncing: announcement
		silently: false
		updateUI: true! !

!PositionableStream methodsFor: '*System-Changes-fileIn/Out' stamp: 'ct 9/25/2020 19:19'!
fileInAnnouncing: announcement silently: silently updateUI: updateUI

	^ self
		fileInFor: nil
		announcing: announcement
		silently: silently
		updateUI: updateUI! !

!PositionableStream methodsFor: '*System-Changes-fileIn/Out' stamp: 'ct 9/25/2020 19:19'!
fileInFor: client announcing: announcement

	^ self
		fileInFor: client
		announcing: announcement
		silently: true
		updateUI: true! !

!PositionableStream methodsFor: '*System-Changes-fileIn/Out' stamp: 'ct 9/25/2020 19:18'!
fileInFor: client announcing: announcement silently: silently updateUI: updateUI
	"This is special for reading expressions from text that has been formatted with exclamation delimitors. The expressions are read and passed to the Compiler. Answer the result of compilation. Put up a progress report with the given announcement as the title. If not silently, every change record will be logged to the changes file. If updateUI is true, the progress report will be updated after each processed change record."

	| fileInBlock val chunk |
	fileInBlock := [
		self skipSeparators.
		[val := (self peekFor: $!!) 
			ifTrue: [(Compiler evaluate: self nextChunk for: client logged: false)
				scanFrom: self]
			ifFalse: [
				chunk := self nextChunk.
				self checkForPreamble: chunk.
				Compiler evaluate: chunk for: client logged: silently not]
		]
			on: InMidstOfFileinNotification
			do: [:ex | ex resume: true].
		self skipStyleChunk].
	
	[updateUI
		ifTrue: [ announcement 
			displayProgressFrom: 0
			to: self size
			during: [:bar |
				[self atEnd] whileFalse: [
					bar value: self position.
					fileInBlock value]] ]
		ifFalse: [ Project uiManager
			informUser: announcement
			during: [
				[self atEnd] whileFalse: fileInBlock] ].
	] ensure: [self close].
	
	"Note:  The main purpose of this banner is to flush the changes file."
	Smalltalk logChange: '----End fileIn of ' , self name , '----'.
	
	^ val! !

!PositionableStream methodsFor: '*System-Changes-fileIn/Out' stamp: 'ct 9/25/2020 19:20'!
fileInSilentlyAnnouncing: announcement 

	^ self
		fileInAnnouncing: announcement
		silently: false
		updateUI: false! !

PositionableStream removeSelector: #fileInAnnouncing:silently:!
ChangeSet class removeSelector: #fileIntoNewChangeSet:silently:!
