#REFACTORING by exept
class: DialogBox
added:
#addTextBoxOn:view:withHeight:hScrollable:vScrollable:
#addTextBoxOn:view:withNumberOfLines:hScrollable:vScrollable:
comment/format in: #addTextBoxOn:class:withNumberOfLines:hScrollable:vScrollable:
changed: #addListBoxOn:class:withNumberOfLines:hScrollable:vScrollable:
class: DialogBox class
added: #requestRegex:initialAnswer:
--- a/DialogBox.st Thu Nov 14 19:05:21 2019 +0100
+++ b/DialogBox.st Sat Nov 16 22:17:02 2019 +0100
@@ -5641,6 +5641,37 @@
"
!
+requestRegex:aTitleString initialAnswer:initialRegexString
+ "Prompt the user for a valid regex.
+ Return nil on cancel or a valid RxMatcher"
+
+ | regex |
+
+ regex := initialRegexString.
+ "loop until we get a valid regex string back"
+ [
+ regex := self
+ requestText:aTitleString lines:5 columns:40 initialAnswer:regex.
+"/ multiLineRequest: aTitleString
+"/ initialAnswer: regex
+"/ answerHeight: 200.
+ "cancelled dialog ==> nil"
+ regex isNil ifTrue: [ ^ nil ].
+
+ [
+ ^ regex asRegex
+ ] on: Error do: [:regexParsingError|
+ "/ self defer: [
+ self inform: 'Bad Regex: ', regexParsingError asString
+ "/ ]
+ ].
+ ] repeat
+
+ "
+ Dialog requestRegex:'enter a regex pattern:' initialAnswer:'a*'
+ "
+!
+
requestText:title
"open a dialog asking for multiline text.
Return a stringCollection or nil if canceled."
@@ -10118,13 +10149,10 @@
The list has numLines (if nonNil) number of lines shown.
If scrolled, the ScrollWrapper is returned - otherwise the listView."
- |l|
-
- l := self addTextBoxOn:aModel class:aListViewClass withNumberOfLines:numLines hScrollable:hs vScrollable:vs.
- (aListViewClass canUnderstand:#doubleClickAction:) ifTrue:[
- l doubleClickAction:[:name | self okPressed].
- ].
- ^ l
+ ^ self
+ addTextBoxOn:aModel
+ class:aListViewClass
+ withNumberOfLines:numLines hScrollable:hs vScrollable:vs.
"
|dialog listView|
@@ -10301,39 +10329,19 @@
The list has numLines (if nonNil) number of lines shown.
If scrolled, the ScrollWrapper is returned - otherwise the listView."
- |l scr h dH|
-
- l := aListViewClass new.
- l model:aModel.
-
- (vs or:[hs]) ifTrue:[
- hs ifTrue:[
- scr := HVScrollableView forView:l miniScrollerH:true .
- ] ifFalse:[
- scr := ScrollableView forView:l
- ].
- scr resize.
- "/ Transcript show:scr height; show:' '; showCR:l height.
- dH := scr height - l height.
- ] ifFalse:[
- l level:-1.
- scr := l.
- dH := 0.
- ].
-
- numLines notNil ifTrue:[
- h := l heightForLines:numLines.
- ] ifFalse:[
- h := l preferredHeight
- ].
- self addComponent:scr withHeight:(h + dH).
- ^ scr
+ |listView|
+
+ listView := aListViewClass new.
+ ^ self
+ addTextBoxOn:aModel view:listView
+ withNumberOfLines:numLines
+ hScrollable:hs vScrollable:vs
"
|dialog listView|
dialog := DialogBox new.
- (dialog addTextLabel:'select any') adjust:#left.
+ (dialog addTextLabel:'Enter Text:') adjust:#left.
listView := dialog
addTextBoxOn:nil
@@ -10346,7 +10354,155 @@
dialog addAbortButton; addOkButton.
dialog open.
- dialog accepted ifTrue:[Transcript show:'selection is:'; showCR:listView contents].
+ dialog accepted ifTrue:[
+ Transcript show:'text is:'; showCR:listView contents
+ ].
+ "
+
+ "Created: 14.6.1996 / 23:33:47 / stefan"
+ "Modified: 8.11.1996 / 15:31:15 / cg"
+!
+
+addTextBoxOn:aModel view:aListView withHeight:heightInPixels hScrollable:hs vScrollable:vs
+ "add a ListView instance to the box.
+ The list has heightInPixels (if nonNil) height shown.
+ If scrolled, the ScrollWrapper is returned - otherwise the listView."
+
+ |scr h dH|
+
+ aListView model:aModel.
+ "/ aListView perform:#doubleClickAction: with:[:sel | self okPressed.] ifNotUnderstood:[].
+ (aListView class canUnderstand:#doubleClickAction:) ifTrue:[
+ aListView doubleClickAction:[:name | self okPressed].
+ ].
+
+ (vs or:[hs]) ifTrue:[
+ hs ifTrue:[
+ scr := HVScrollableView forView:aListView miniScrollerH:true .
+ ] ifFalse:[
+ scr := ScrollableView forView:aListView
+ ].
+ scr resize.
+ "/ Transcript show:scr height; show:' '; showCR:l height.
+ dH := scr height - aListView height.
+ ] ifFalse:[
+ aListView level:-1.
+ scr := aListView.
+ dH := 0.
+ ].
+
+ (h := heightInPixels) isNil ifTrue:[
+ h := aListView preferredHeight
+ ].
+ self addComponent:scr withHeight:(h + dH).
+ ^ scr
+
+ "
+ |dialog listView|
+
+ dialog := DialogBox new.
+ (dialog addTextLabel:'enter text') adjust:#left.
+
+ listView := dialog
+ addTextBoxOn:nil
+ view:EditTextView new
+ withHeight:50
+ hScrollable:true
+ vScrollable:true.
+
+
+ dialog addAbortButton; addOkButton.
+ dialog open.
+
+ dialog accepted ifTrue:[
+ Transcript show:'entered text is:'; showCR:listView contents
+ ].
+ "
+ "
+ |model dialog listView|
+
+ model := SelectionInList with:#('a' 'b' 'c' 'd' 'e').
+ dialog := DialogBox new.
+ (dialog addTextLabel:'enter text') adjust:#left.
+
+ listView := dialog
+ addTextBoxOn:model
+ view:SelectionInListView new
+ withHeight:50
+ hScrollable:true
+ vScrollable:true.
+
+
+ dialog addAbortButton; addOkButton.
+ dialog open.
+
+ dialog accepted ifTrue:[
+ Transcript show:'you selected:'; showCR:listView selection
+ ].
+ "
+
+ "Created: 14.6.1996 / 23:33:47 / stefan"
+ "Modified: 8.11.1996 / 15:31:15 / cg"
+!
+
+addTextBoxOn:aModel view:aListView withNumberOfLines:numLines hScrollable:hs vScrollable:vs
+ "add a ListView instance to the box.
+ The list has numLines (if nonNil) number of lines shown.
+ If scrolled, the ScrollWrapper is returned - otherwise the listView."
+
+ |h|
+
+ numLines notNil ifTrue:[
+ h := aListView heightForLines:numLines.
+ ].
+ ^ self
+ addTextBoxOn:aModel view:aListView
+ withHeight:h
+ hScrollable:hs vScrollable:vs
+
+
+ "
+ |dialog listView|
+
+ dialog := DialogBox new.
+ (dialog addTextLabel:'enter text') adjust:#left.
+
+ listView := dialog
+ addTextBoxOn:nil
+ class:EditTextView
+ withNumberOfLines:10
+ hScrollable:true
+ vScrollable:true.
+
+
+ dialog addAbortButton; addOkButton.
+ dialog open.
+
+ dialog accepted ifTrue:[
+ Transcript show:'you entered:'; showCR:listView contents
+ ].
+ "
+ "
+ |model dialog listView|
+
+ model := SelectionInList with:#('a' 'b' 'c' 'd' 'e').
+ dialog := DialogBox new.
+ (dialog addTextLabel:'enter text') adjust:#left.
+
+ listView := dialog
+ addTextBoxOn:model
+ class:SelectionInListView
+ withNumberOfLines:10
+ hScrollable:true
+ vScrollable:true.
+
+
+ dialog addAbortButton; addOkButton.
+ dialog open.
+
+ dialog accepted ifTrue:[
+ Transcript show:'you selected:'; showCR:listView selection
+ ].
"
"Created: 14.6.1996 / 23:33:47 / stefan"