Skip to content

Commit

Permalink
Merge pull request pharo-project#7002 from estebanlm/merge-spec2-0.7.2
Browse files Browse the repository at this point in the history
merge-spec2-0.7.2
  • Loading branch information
MarcusDenker committed Jul 29, 2020
2 parents 9466150 + f72fa4b commit 3c6824c
Show file tree
Hide file tree
Showing 26 changed files with 310 additions and 37 deletions.
4 changes: 1 addition & 3 deletions src/Spec2-Adapters-Morphic/SpDialogWindow.class.st
Expand Up @@ -78,9 +78,7 @@ SpDialogWindow >> setToolbarFrom: aBlock [
| newToolbar |

newToolbar := aBlock value.
self toolbar: newToolbar.
self model presenter focusOrder addLast: toolbar.
toolbar focusOrder addLast: self model
self toolbar: newToolbar
]

{ #category : #accessing }
Expand Down
28 changes: 28 additions & 0 deletions src/Spec2-Adapters-Morphic/SpMorphicBoxAdapter.class.st
Expand Up @@ -243,3 +243,31 @@ SpMorphicBoxAdapter >> removeSubWidgets [
startPanel removeAllMorphs.
endPanel removeAllMorphs
]

{ #category : #accessing }
SpMorphicBoxAdapter >> replace: aPresenter with: otherPresenter [
| panel oldMorph newMorph |

oldMorph := aPresenter adapter widget.
panel := (startPanel submorphs includes: oldMorph)
ifTrue: [ startPanel ]
ifFalse: [ endPanel ].

newMorph := self
buildMorph: otherPresenter
constraints: (layout constraintsFor: otherPresenter).
panel replaceSubmorph: oldMorph by: newMorph
]

{ #category : #accessing }
SpMorphicBoxAdapter >> replace: aPresenter with: otherPresenter withConstraints: constraints [
| panel oldMorph newMorph |

oldMorph := aPresenter adapter widget.
panel := (startPanel submorphs includes: oldMorph)
ifTrue: [ startPanel ]
ifFalse: [ endPanel ].

newMorph := self buildMorph: otherPresenter constraints: constraints.
panel replaceSubmorph: oldMorph by: newMorph
]
Expand Up @@ -30,7 +30,9 @@ SpMorphicDialogWindowAdapter >> buildButtonBar [

{ #category : #factory }
SpMorphicDialogWindowAdapter >> buildWidget [

^ SpDialogWindow new
model: self model;
in: [ :this | self subscribeToAnnouncements: this ];
yourself
]
1 change: 1 addition & 0 deletions src/Spec2-Adapters-Morphic/SpMorphicLayoutAdapter.class.st
Expand Up @@ -16,6 +16,7 @@ SpMorphicLayoutAdapter >> adapter [
{ #category : #factory }
SpMorphicLayoutAdapter >> add: aPresenter constraints: constraints [

aPresenter owner: self model.
self widgetDo: [ :aPanel |
self
basicAdd: aPresenter
Expand Down
1 change: 1 addition & 0 deletions src/Spec2-Adapters-Morphic/SpMorphicMillerAdapter.class.st
Expand Up @@ -27,6 +27,7 @@ SpMorphicMillerAdapter >> add: aPresenter constraints: constraints [

self widget ifNil: [ ^ self ].

aPresenter owner: self model.
needRecalculatePages := true.
self
basicAdd: aPresenter
Expand Down
16 changes: 13 additions & 3 deletions src/Spec2-Adapters-Morphic/SpMorphicTableCellBuilder.class.st
Expand Up @@ -42,10 +42,16 @@ SpMorphicTableCellBuilder >> addCellColumn: aTableColumn [
SpMorphicTableCellBuilder >> addCellMorph: morph column: aTableColumn [

aTableColumn isExpandable ifFalse: [
aTableColumn width: (aTableColumn width
ifNotNil: [ :width | width max: morph width ]
ifNil: [ morph width ]).
cell hResizing: #shrinkWrap.
morph
hResizing: #rigid;
width: (aTableColumn width ifNil: [ morph width ]) ].
width: aTableColumn width ].

cell addMorphBack: morph

]

{ #category : #accessing }
Expand Down Expand Up @@ -86,9 +92,10 @@ SpMorphicTableCellBuilder >> rowIndex: anObject [

{ #category : #visiting }
SpMorphicTableCellBuilder >> visitCheckboxColumn: aTableColumn [
| presenter |
| presenter morph |

presenter := SpCheckBoxPresenter new
addStyle: 'compact';
state: (aTableColumn readObject: self item);
yourself.

Expand All @@ -97,8 +104,11 @@ SpMorphicTableCellBuilder >> visitCheckboxColumn: aTableColumn [
aTableColumn onDeactivation ifNotNil: [ :valuable |
presenter whenDeactivatedDo: [ valuable cull: self item ] ].

morph := presenter buildWithSpec.
presenter adapter applyStyle: morph.

self
addCellMorph: presenter buildWithSpec
addCellMorph: morph
column: aTableColumn
]

Expand Down
6 changes: 6 additions & 0 deletions src/Spec2-Adapters-Morphic/SpMorphicTableColumn.class.st
Expand Up @@ -29,6 +29,12 @@ SpMorphicTableColumn >> id [
^ self model title
]

{ #category : #testing }
SpMorphicTableColumn >> isExpandable [

^ self model isExpandable
]

{ #category : #testing }
SpMorphicTableColumn >> isSortable [

Expand Down
Expand Up @@ -21,6 +21,7 @@ SpMorphicTableDataSource >> cellColumn: column row: rowIndex [
cell: cell;
rowIndex: rowIndex;
visit: column model.
self setHeaderColumnLazyProperties: column.

^ cell
]
Expand Down
19 changes: 18 additions & 1 deletion src/Spec2-Adapters-Morphic/SpMorphicTextAdapter.class.st
Expand Up @@ -48,7 +48,8 @@ SpMorphicTextAdapter >> buildWidget [
self setEditable: self presenter isEditable to: newWidget.
self setEditingModeFor: newWidget.
self setText: self presenter text to: newWidget.


self setWrapWord: self presenter isWrapWord to: newWidget.
self presenter whenTextChangedDo: [ :text |
self setText: text to: newWidget ].
self presenter whenSelectionChangedDo: [ :selectionInterval |
Expand All @@ -57,6 +58,8 @@ SpMorphicTextAdapter >> buildWidget [
self setGhostText: text to: newWidget ].
self presenter whenEditableChangedDo: [ :value |
self setEditable: value to: newWidget ].
self presenter whenWrapWordChangedDo: [ :value |
self setWrapWord: value to: newWidget ].

^ newWidget
]
Expand Down Expand Up @@ -84,6 +87,12 @@ SpMorphicTextAdapter >> cursorPosition [
ifNotNil: [ :sel | self linePositionOf: sel ] ]
]

{ #category : #'widget API' }
SpMorphicTextAdapter >> cursorPositionIndex: index [

self widgetDo: [ :w | ^ w textArea editor pointIndex: index ]
]

{ #category : #private }
SpMorphicTextAdapter >> eventHandlerReceiver: aWidget [

Expand Down Expand Up @@ -126,6 +135,14 @@ SpMorphicTextAdapter >> setText: text to: aWidget [

]

{ #category : #private }
SpMorphicTextAdapter >> setWrapWord: aBoolean to: aWidget [

aBoolean
ifTrue: [ aWidget beWrapped ]
ifFalse: [ aWidget beNotWrapped ]
]

{ #category : #private }
SpMorphicTextAdapter >> updateExtentPropagationOf: string on: aWidget [
| stringMorph width height |
Expand Down
12 changes: 10 additions & 2 deletions src/Spec2-Adapters-Morphic/SpMorphicWindowAdapter.class.st
Expand Up @@ -206,7 +206,8 @@ SpMorphicWindowAdapter >> subscribeToAnnouncements: aWindow [

aWindow announcer
when: SpWindowWillClose send: #announce: to: self presenter announcer;
when: SpWindowResizing send: #announce: to: self presenter announcer
when: SpWindowResizing send: #announce: to: self presenter announcer;
when: WindowClosed send: #windowClosed to: self
]

{ #category : #icons }
Expand All @@ -226,6 +227,13 @@ SpMorphicWindowAdapter >> title: aString [
self widgetDo: [ :w | w setLabel: (aString ifNotNil: [ :theString | theString localizedForPresenter: self presenter]) ]
]

{ #category : #updating }
SpMorphicWindowAdapter >> windowClosed [

self windowIsClosing.
self presenter windowClosed
]

{ #category : #updating }
SpMorphicWindowAdapter >> windowIsClosing [

Expand All @@ -235,5 +243,5 @@ SpMorphicWindowAdapter >> windowIsClosing [
{ #category : #updating }
SpMorphicWindowAdapter >> windowIsOpening [

self model windowIsOpening
self presenter windowIsOpening
]
@@ -1,32 +1,31 @@
Trait {
#name : #SpTMorphicTableDataSourceCommons,
#instVars : [
'model'
'model',
'headersByColumn'
],
#category : #'Spec2-Adapters-Morphic-Table'
}

{ #category : #accessing }
SpTMorphicTableDataSourceCommons >> headerColumn: column [
| headerMorph |

column id ifNil: [ ^ nil ].
headerMorph := SpHeaderCellMorph new
addMorph: column id asMorph asReadOnlyMorph;
yourself.

column isSortable ifTrue: [
headerMorph eventHandler: (MorphicEventHandler new
on: #click
send: #sortByColumn:event:morph:
to: self
withValue: column).
column sortingIcon ifNotNil: [ :icon | headerMorph addMorph: icon ] ].
^ self headerForColumn: column
]

"column isExpandable ifFalse: [
headerMorph hResizing: #shrinkWrap ]."
{ #category : #accessing }
SpTMorphicTableDataSourceCommons >> headerForColumn: aColumn [

^ headerMorph
^ self headersByColumn
at: aColumn
ifAbsentPut: [ self newHeaderColumn: aColumn ]
]

{ #category : #accessing }
SpTMorphicTableDataSourceCommons >> headersByColumn [

^ headersByColumn ifNil: [ headersByColumn := SmallDictionary new ]
]

{ #category : #accessing }
Expand All @@ -52,6 +51,40 @@ SpTMorphicTableDataSourceCommons >> model: aTablePresenter [
model := aTablePresenter
]

{ #category : #'private factory' }
SpTMorphicTableDataSourceCommons >> newHeaderColumn: column [
| headerMorph |

headerMorph := SpHeaderCellMorph new
addMorph: column id asMorph asReadOnlyMorph;
yourself.

column isSortable ifTrue: [
headerMorph eventHandler: (MorphicEventHandler new
on: #click
send: #sortByColumn:event:morph:
to: self
withValue: column).
column sortingIcon ifNotNil: [ :icon | headerMorph addMorph: icon ] ].

^ headerMorph
]

{ #category : #private }
SpTMorphicTableDataSourceCommons >> setHeaderColumnLazyProperties: column [
"Some properties of a header just acquire value after rendering cells. This method makes sure
properties are set, but is responsibility of the user to actually call it (usually after create
a cell). See senders of this method too see where it goes."
| headerMorph |

column isExpandable ifTrue: [ ^ self ].
headerMorph := self headerForColumn: column.
headerMorph hResizing = #rigid
ifFalse: [ headerMorph hResizing: #rigid ].
headerMorph width = column width
ifFalse: [ headerMorph width: (column width ifNil: [ 0 ]) ]
]

{ #category : #sorting }
SpTMorphicTableDataSourceCommons >> sortByColumn: aColumn event: anEvent morph: aMorph [

Expand Down
21 changes: 21 additions & 0 deletions src/Spec2-Backend-Tests/SpBoxLayoutAdapterTest.class.st
Expand Up @@ -66,3 +66,24 @@ SpBoxLayoutAdapterTest >> testRemoveElementRemovesFromAdapter [
layout remove: element.
self assert: self adapter isEmpty
]

{ #category : #tests }
SpBoxLayoutAdapterTest >> testReplaceElementAfterOpen [
| p1 toReplace p2 replacement |

layout add: (p1 := SpLabelPresenter new).
layout add: (toReplace := SpLabelPresenter new).
layout add: (p2 := SpLabelPresenter new).
self openInstance.

replacement := SpButtonPresenter new.
layout replace: toReplace with: replacement.

self assert: self adapter children size equals: 3.
self
assert: self adapter children
equals: {
p1 adapter widget.
replacement adapter widget.
p2 adapter widget }
]
1 change: 1 addition & 0 deletions src/Spec2-Code/SpCodePopoverErrorPresenter.class.st
Expand Up @@ -70,6 +70,7 @@ SpCodePopoverErrorPresenter >> initializePresenters [
SpCodePopoverErrorPresenter >> initializeText [

text := self newText
beNotWrapWord;
propagateNaturalWidth: true;
propagateNaturalHeight: false;
editable: false;
Expand Down
1 change: 1 addition & 0 deletions src/Spec2-Code/SpCodePopoverPrintPresenter.class.st
Expand Up @@ -123,6 +123,7 @@ SpCodePopoverPrintPresenter >> newTextMultiLine: aString withScrollBars: withScr
| newText |

newText := self newText
beNotWrapWord;
propagateNaturalWidth: true;
propagateNaturalHeight: withScrollBars not;
editable: false;
Expand Down
13 changes: 13 additions & 0 deletions src/Spec2-Core/OrderedDictionary.extension.st
@@ -0,0 +1,13 @@
Extension { #name : #OrderedDictionary }

{ #category : #'*Spec2-Core' }
OrderedDictionary >> replaceKey: aKey with: otherKey [
| value index |

value := self at: aKey.
index := orderedKeys indexOf: aKey.
dictionary removeKey: aKey.
dictionary at: otherKey put: value.
orderedKeys at: index put: otherKey

]
3 changes: 2 additions & 1 deletion src/Spec2-Core/SpApplication.class.st
Expand Up @@ -327,7 +327,8 @@ SpApplication >> propertyAt: aKey put: aValue [
SpApplication >> reset [

self closeAllWindows.
windows removeAll
windows removeAll.
self backend resetAdapterBindings
]

{ #category : #running }
Expand Down
8 changes: 7 additions & 1 deletion src/Spec2-Core/SpApplicationBackend.class.st
Expand Up @@ -45,7 +45,7 @@ SpApplicationBackend >> adapterBindingsClass [
SpApplicationBackend >> initialize [

super initialize.
adapterBindings := self adapterBindingsClass new
self resetAdapterBindings
]

{ #category : #accessing }
Expand Down Expand Up @@ -74,6 +74,12 @@ SpApplicationBackend >> notifyInfo: aSpecNotification [
self subclassResponsibility
]

{ #category : #initialization }
SpApplicationBackend >> resetAdapterBindings [

adapterBindings := self adapterBindingsClass new
]

{ #category : #'ui dialogs' }
SpApplicationBackend >> selectFileTitle: aString [

Expand Down

0 comments on commit 3c6824c

Please sign in to comment.