Grafoscopio/src/Grafoscopio/GrafoscopioReplace.class.st

123 lines
2.4 KiB
Smalltalk

"
I'm a tool for finding and replacing text ocurrences in notebook
nodes.
"
Class {
#name : #GrafoscopioReplace,
#superclass : #ComposablePresenter,
#instVars : [
'find',
'replace',
'ok',
'cancel'
],
#category : #'Grafoscopio-UI'
}
{ #category : #specs }
GrafoscopioReplace class >> defaultSpec [
^ SpecLayout composed
newColumn: [ :column |
column
add: #find;
add: #replace;
newRow: [ :row | row add: #ok; add: #cancel ] height: self toolbarHeight ];
yourself
]
{ #category : #accessing }
GrafoscopioReplace >> cancel [
^ cancel
]
{ #category : #accessing }
GrafoscopioReplace >> cancel: anObject [
cancel := anObject
]
{ #category : #accessing }
GrafoscopioReplace >> find [
^ find
]
{ #category : #accessing }
GrafoscopioReplace >> find: anObject [
find := anObject
]
{ #category : #initialization }
GrafoscopioReplace >> initializePresenter [
"Here we need to deal with changes in the OK button to send messages about the
state of the 'find' and 'replace' variables or do nothing if 'Cancel' is pressed."
ok whenStateChangedDo: [
Transcript show: 'OK Clicked!' ]
]
{ #category : #initialization }
GrafoscopioReplace >> initializeWidgets [
find := self newTextInput
ghostText: 'Text to find...';
autoAccept: true.
replace := self newTextInput
ghostText: 'Text to replace...';
autoAccept: true.
ok := self newButton
label: 'OK';
state: false;
action: [
ok state: true.
self window close. ] .
cancel := self newButton
label: 'Cancel';
action: [
cancel state: true.
self window close ].
self focusOrder
add: find;
add: replace;
add: ok;
add: cancel.
self askOkToClose: true
]
{ #category : #accessing }
GrafoscopioReplace >> ok [
^ ok
]
{ #category : #accessing }
GrafoscopioReplace >> ok: anObject [
ok := anObject
]
{ #category : #private }
GrafoscopioReplace >> okToChange [
^ true
]
{ #category : #accessing }
GrafoscopioReplace >> replace [
^ replace
]
{ #category : #accessing }
GrafoscopioReplace >> replace: anObject [
replace := anObject
]
{ #category : #initialization }
GrafoscopioReplace >> returnValues [
self ok state
ifFalse: [ ^ self ]
ifTrue: [^ Dictionary new
at: 'find' put: find getText;
at: 'replace' put: replace getText;
yourself]
]
{ #category : #api }
GrafoscopioReplace >> title [
^ 'Find & Replace'
]