'From Squeak5.3beta of 18 January 2020 [latest update: #19328] on 20 January 2020 at 9:11 pm'!
PluggableWidgetSpec subclass: #PluggableTextSpec
	instanceVariableNames: 'getText setText selection menu askBeforeDiscardingEdits editText indicateUnacceptedChanges stylerClass font readOnly softLineWrap hardLineWrap textColor forceString'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'ToolBuilder-Kernel'!

!FillInTheBlankMorph methodsFor: 'initialization' stamp: 'ct 1/20/2020 21:09'!
createTextPaneAcceptOnCR: acceptBoolean 

	textPane := PluggableTextMorph
				on: self
				text: #response
				accept: #response:
				readSelection: #selectionInterval
				menu: #codePaneMenu:shifted:.
	textPane 
		setProperty: #forceString toValue: true;
		showScrollBarsOnlyWhenNeeded;
		wantsFrameAdornments: false;
		hasUnacceptedEdits: true;
		acceptOnCR: acceptBoolean;
		setNameTo: 'textPane';
		layoutFrame: (LayoutFrame fractions: (0@0 corner: 1@1));
		hResizing: #spaceFill;
		vResizing: #spaceFill;
		scrollToTop.
	^ textPane! !


!MorphicToolBuilder methodsFor: 'widgets required' stamp: 'ct 1/20/2020 20:07'!
buildPluggableText: aSpec
	| widget |
	widget := self textPaneClass new.
	aSpec stylerClass ifNotNil: [:c | widget styler: (c new view: widget)].	
	widget
		on: aSpec model
		text: aSpec getText 
		accept: aSpec setText
		readSelection: aSpec selection 
		menu: aSpec menu.
	aSpec font ifNotNil: [:f | widget font: f].
	
	widget readOnly: aSpec readOnly.
	widget editTextSelector: aSpec editText.
	widget wantsFrameAdornments: aSpec indicateUnacceptedChanges.

	widget askBeforeDiscardingEdits: aSpec askBeforeDiscardingEdits.
	widget setProperty: #alwaysAccept toValue: aSpec askBeforeDiscardingEdits not.
	widget setProperty: #forceString toValue: aSpec forceString.

	widget wrapFlag: (aSpec softLineWrap ifNil: [true]).
	
	self register: widget id: aSpec name.
	widget getColorSelector: aSpec color.
	widget getTextColorSelector: aSpec textColor.
	self buildHelpFor: widget spec: aSpec.
	 
	self setFrame: aSpec frame in: widget.
	self setLayoutHintsFor: widget spec: aSpec.
	
	parent ifNotNil:[self add: widget to: parent].
	^widget! !


!PluggableTextMorph methodsFor: 'editor access' stamp: 'ct 1/20/2020 20:03'!
textEdited: someText
	"Tell the model about some edits in the text if interested. This is not #accept, which means that it will be send on every keystroke."
	
	| hadEdits |
	(self valueOfProperty: #forceString ifAbsent: [false]) ifTrue: [
		hadEdits := self hasUnacceptedEdits.
		self setText: someText asString.
		self hasUnacceptedEdits: hadEdits].
	self editTextSelector ifNotNil: [:selector |
		model perform: selector with: someText].! !


!PluggableTextSpec methodsFor: 'accessing' stamp: 'ct 1/20/2020 20:06'!
forceString

	^ forceString ifNil: [false]! !

!PluggableTextSpec methodsFor: 'accessing' stamp: 'ct 1/20/2020 20:06'!
forceString: aBoolean

	forceString := aBoolean! !


!SearchBar methodsFor: 'toolbuilder' stamp: 'ct 1/20/2020 20:07'!
buildWith: builder

	^ (builder build: (builder pluggableInputFieldSpec new
		model: self;
		getText: #searchTerm;
		setText: #smartSearch:in:;
		editText: #searchTermSilently:;
		menu: #menu:shifted:;
		selection: #selection;
		indicateUnacceptedChanges: false;
		forceString: true;
		help: 'Search or evaluate...' translated))
			name: #searchBar;
			wantsFrameAdornments: false;
			yourself! !

