Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving the behavior in all the dialogs #1536

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Class {
#name : 'SpDialogTest',
#name : 'SpInformUserDialogTest',
#superclass : 'TestCase',
#category : 'Spec2-Dialogs-Tests',
#package : 'Spec2-Dialogs-Tests'
}

{ #category : 'tests - informUserDuring' }
SpDialogTest >> testInformUserDuring [
SpInformUserDialogTest >> testInformUserDuring [

self shouldnt: [ SpInformUserDialog new informUser: 'hello' during: [ (Delay forMilliseconds: 100) wait] ] raise: Error
]

{ #category : 'tests - progress bar' }
SpDialogTest >> testInformUserDuringExecutesItsBlock [
SpInformUserDialogTest >> testInformUserDuringExecutesItsBlock [

| executed |
executed := false.
Expand All @@ -21,7 +21,7 @@ SpDialogTest >> testInformUserDuringExecutesItsBlock [
]

{ #category : 'tests - progress bar' }
SpDialogTest >> testInformUserDuringExecutesTheBlockOnlyOnce [
SpInformUserDialogTest >> testInformUserDuringExecutesTheBlockOnlyOnce [

| count |
count := 0.
Expand All @@ -32,7 +32,7 @@ SpDialogTest >> testInformUserDuringExecutesTheBlockOnlyOnce [
]

{ #category : 'tests - progress bar' }
SpDialogTest >> testInformUserDuringInSpApplicationExecutesTheBlockOnlyOnce [
SpInformUserDialogTest >> testInformUserDuringInSpApplicationExecutesTheBlockOnlyOnce [

| count |
count := 0.
Expand All @@ -43,29 +43,29 @@ SpDialogTest >> testInformUserDuringInSpApplicationExecutesTheBlockOnlyOnce [
]

{ #category : 'tests - informUserDuring' }
SpDialogTest >> testInformUserDuringViaApplication [
SpInformUserDialogTest >> testInformUserDuringViaApplication [

self shouldnt: [ SpPresenter new application informUser: 'hello' during: [ (Delay forMilliseconds: 100) wait] ] raise: Error.

]

{ #category : 'tests - informUserDuring' }
SpDialogTest >> testInformUserDuringViaPresenter [
SpInformUserDialogTest >> testInformUserDuringViaPresenter [

self shouldnt: [ SpPresenter new informUser: 'hello' during: [ (Delay forMilliseconds: 100) wait] ] raise: Error.
self shouldnt: [ SpPresenter new informUser: 'hello' during: [ (Delay forMilliseconds: 100) wait] ] raise: Error
]

{ #category : 'tests - progress bar' }
SpDialogTest >> testInformUserReturnsValueOfTheBlock [
SpInformUserDialogTest >> testInformUserReturnsValueOfTheBlock [

| returned |
returned := SpInformUserDialog new informUser: 'hello' during: [ 42 ].
self assert: returned equals: 42.
]

{ #category : 'tests - progress bar' }
SpDialogTest >> testProgressInformUserDuringExecutesItsBlock [
SpInformUserDialogTest >> testProgressInformUserDuringExecutesItsBlock [

| executed |
executed := false.
Expand Down
33 changes: 33 additions & 0 deletions src/Spec2-Dialogs/SpAbstractCancelableMessageDialog.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"
I am the abstract class that holds the common state and behavior of all the MessageDialogs that can have cancel button.
"
Class {
#name : 'SpAbstractCancelableMessageDialog',
#superclass : 'SpAbstractMessageDialog',
#instVars : [
'cancelLabel'
],
#category : 'Spec2-Dialogs',
#package : 'Spec2-Dialogs'
}

{ #category : 'initialization' }
SpAbstractCancelableMessageDialog >> addButtonsTo: aDialogWindowPresenter [

aDialogWindowPresenter
addButton: self cancelLabel do: [ :presenter | self cancel ].

super addButtonsTo: aDialogWindowPresenter
]

{ #category : 'api' }
SpAbstractCancelableMessageDialog >> cancelLabel [

^ cancelLabel ifNil: [ self class defaultCancelLabel ]
]

{ #category : 'api' }
SpAbstractCancelableMessageDialog >> cancelLabel: aString [

cancelLabel := aString
]
167 changes: 167 additions & 0 deletions src/Spec2-Dialogs/SpAbstractMessageDialog.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
"
I am the abstract class that holds the common state and behavior of all the MessageDialogs.
"
Class {
#name : 'SpAbstractMessageDialog',
#superclass : 'SpDialogPresenter',
#instVars : [
'label',
'title',
'initialExtent',
'acceptLabel'
],
#category : 'Spec2-Dialogs',
#package : 'Spec2-Dialogs'
}

{ #category : 'api' }
SpAbstractMessageDialog >> acceptLabel [

^ acceptLabel ifNil: [ self class defaultAcceptLabel ]
]

{ #category : 'api' }
SpAbstractMessageDialog >> acceptLabel: aString [

acceptLabel := aString
]

{ #category : 'initialization' }
SpAbstractMessageDialog >> addButtonsTo: aDialogWindowPresenter [

aDialogWindowPresenter
addDefaultButton: self acceptLabel
do: [ :presenter | self accept ]
]

{ #category : 'private' }
SpAbstractMessageDialog >> adjustExtentToLabelHeight: anExtent [

^ anExtent x @ (anExtent y - self singleLineDefaultHeight + (self calculateLabelHeightForTextWithoutMargin: label text forExtent: anExtent ))
]

{ #category : 'private' }
SpAbstractMessageDialog >> calculateLabelHeight [

^ (self calculateLabelHeightForTextWithoutMargin: label text forExtent: self extent) + self labelMargin
]

{ #category : 'private' }
SpAbstractMessageDialog >> calculateLabelHeightForTextWithoutMargin: aText forExtent: anExtent [

"We have a minimal height "
aText ifEmpty: [ ^ self singleLineDefaultHeight ].

^ (aText lineHeightsWrappingAtWidth: anExtent x - 20) sum

]

{ #category : 'layout' }
SpAbstractMessageDialog >> defaultLayout [

^ SpBoxLayout newTopToBottom
spacing: 0;
add: (SpBoxLayout newLeftToRight
add: (SpBoxLayout newTopToBottom
vAlignStart;
add: #image;
yourself)
expand: false;
add: #label withConstraints: [ :c |
c
expand: true;
fill: true ];
yourself);
yourself
]

{ #category : 'accessing' }
SpAbstractMessageDialog >> defaultTitle [

self subclassResponsibility
]

{ #category : 'TOREMOVE' }
SpAbstractMessageDialog >> extent [

^ initialExtent ifNil: [ self class defaultExtent ]
]

{ #category : 'TOREMOVE' }
SpAbstractMessageDialog >> extent: aPoint [

initialExtent := aPoint
]

{ #category : 'initialization' }
SpAbstractMessageDialog >> initialize [

super initialize.
self title: self defaultTitle
]

{ #category : 'initialization' }
SpAbstractMessageDialog >> initializeDialogWindow: aDialogWindowPresenter [

super initializeDialogWindow: aDialogWindowPresenter.

aDialogWindowPresenter initialExtent:
(self adjustExtentToLabelHeight: self class defaultExtent).
self addButtonsTo: aDialogWindowPresenter
]

{ #category : 'initialization' }
SpAbstractMessageDialog >> initializePresenters [

image := self newImage image: self defaultIcon.
label := self newDialogLabel.
]

{ #category : 'initialization' }
SpAbstractMessageDialog >> initializeWindow: aWindowPresenter [

aWindowPresenter
title: self title;
initialExtent: self extent
]

{ #category : 'api' }
SpAbstractMessageDialog >> label: aString [

label text: aString asText trim
]

{ #category : 'private' }
SpAbstractMessageDialog >> labelMargin [

^ 20
]

{ #category : 'private' }
SpAbstractMessageDialog >> newDialogLabel [

^ self newText
beNotEditable;
withoutScrollBars;
addStyle: 'textDisabled';
propagateNaturalHeight: true;
yourself.
]

{ #category : 'private' }
SpAbstractMessageDialog >> singleLineDefaultHeight [

^ TextStyle defaultFont height
]

{ #category : 'TOREMOVE' }
SpAbstractMessageDialog >> title [

^ title
]

{ #category : 'api' }
SpAbstractMessageDialog >> title: aString [

title := aString
]
Loading
Loading