Skip to content

Commit

Permalink
Add font size + font weight + TU + Plugin + properties
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLEGOFF committed Jul 31, 2023
1 parent caf9a64 commit 17226c7
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 2 deletions.
62 changes: 62 additions & 0 deletions src/Pyramid-Bloc/PyramidBlocTextPlugin.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Class {
#name : #PyramidBlocTextPlugin,
#superclass : #Object,
#traits : 'TPyramidPlugin',
#classTraits : 'TPyramidPlugin classTrait',
#category : #'Pyramid-Bloc-plugin-bloc-text'
}

{ #category : #accessing }
PyramidBlocTextPlugin class >> changeText [

| property |
property := PyramidProperty new
name: 'Text';
command: PyramidChangeTextCommand new;
pyramidInputPresenterClass: PyramidTextInputPresenter;
yourself.
property pyramidInputPresenterModel help:
'Change the value of the text'.
^ property
]

{ #category : #accessing }
PyramidBlocTextPlugin class >> fontSize [

| property |
property := PyramidProperty new
name: 'Font size';
command: PyramidFontSizeCommand new;
pyramidInputPresenterClass: PyramidNumberInputPresenter;
yourself.
property pyramidInputPresenterModel help:
'Change the font size.'.
^ property
]

{ #category : #accessing }
PyramidBlocTextPlugin class >> fontWeight [

| property |
property := PyramidProperty new
name: 'Font weight';
command: PyramidFontWeightCommand new;
pyramidInputPresenterClass: PyramidNumberInputPresenter;
yourself.
property pyramidInputPresenterModel help: 'Change the font weight.'.
^ property
]

{ #category : #'class initialization' }
PyramidBlocTextPlugin class >> initialize [

PyramidPluginManager uniqueInstance addPlugin: self
]

{ #category : #'as yet unclassified' }
PyramidBlocTextPlugin >> connectOn: aPyramidEditor [

aPyramidEditor propertiesManager addProperty: self class changeText.
aPyramidEditor propertiesManager addProperty: self class fontSize.
aPyramidEditor propertiesManager addProperty: self class fontWeight
]
22 changes: 22 additions & 0 deletions src/Pyramid-Bloc/PyramidFontSizeCommand.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Class {
#name : #PyramidFontSizeCommand,
#superclass : #PyramidBlocTextCommand,
#category : #'Pyramid-Bloc-plugin-bloc-text'
}

{ #category : #'as yet unclassified' }
PyramidFontSizeCommand >> getValueFor: aBlTextElement [

aBlTextElement text attributesFinder
findAttributesSuchThat: [ :a | a class = BlFontSizeAttribute ]
indicesDo: [ :new :old :a | ^ a size ].
self flag: #TODO. "I put 10 as a default font size. I don't know where this information come from."
^ 10
]

{ #category : #'as yet unclassified' }
PyramidFontSizeCommand >> setValueFor: aBlTextElement with: aNumber [

aBlTextElement text attribute:
(BlFontSizeAttribute size: aNumber)
]
51 changes: 51 additions & 0 deletions src/Pyramid-Tests/PyramidFontSizeCommandTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Class {
#name : #PyramidFontSizeCommandTest,
#superclass : #TestCase,
#traits : 'TPyramidFontAttributeCommandTest',
#classTraits : 'TPyramidFontAttributeCommandTest classTrait',
#category : #'Pyramid-Tests-cases-plugin-bloc-text'
}

{ #category : #'as yet unclassified' }
PyramidFontSizeCommandTest >> attributeClass [

^ BlFontSizeAttribute
]

{ #category : #accessing }
PyramidFontSizeCommandTest >> command [

^ PyramidFontSizeCommand new
]

{ #category : #'as yet unclassified' }
PyramidFontSizeCommandTest >> targetContainers [

^ {
(PyramidCommandTestContainer
no: 'test1' asRopedText asElement
with: ('test1' asRopedText
fontSize: 20;
yourself) asElement
prop: 20).
(PyramidCommandTestContainer
no: ('test2' asRopedText
fontSize: 20;
yourself) asElement
with: ('test2' asRopedText
fontSize: 5;
yourself) asElement
prop: 5).
(PyramidCommandTestContainer
no: ('test3' asRopedText
bold;
attribute: (BlFontSizeAttribute size: 20);
attribute: (BlTextForegroundAttribute color: Color green);
yourself) asElement
with: ('test3' asRopedText
bold;
attribute: (BlFontSizeAttribute size: 30);
attribute: (BlTextForegroundAttribute color: Color green);
yourself) asElement
prop: 30) }
]
10 changes: 8 additions & 2 deletions src/Pyramid-Tests/PyramidFontWeightCommandTest.class.st
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
Class {
#name : #PyramidFontWeightCommandTest,
#superclass : #TestCase,
#traits : 'TPyramidCommandTest',
#classTraits : 'TPyramidCommandTest classTrait',
#traits : 'TPyramidFontAttributeCommandTest',
#classTraits : 'TPyramidFontAttributeCommandTest classTrait',
#category : #'Pyramid-Tests-cases-plugin-bloc-text'
}

{ #category : #'as yet unclassified' }
PyramidFontWeightCommandTest >> attributeClass [

^ BlFontWeightAttribute
]

{ #category : #accessing }
PyramidFontWeightCommandTest >> command [

Expand Down
32 changes: 32 additions & 0 deletions src/Pyramid-Tests/TPyramidFontAttributeCommandTest.trait.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Trait {
#name : #TPyramidFontAttributeCommandTest,
#traits : 'TPyramidCommandTest',
#classTraits : 'TPyramidCommandTest classTrait',
#category : #'Pyramid-Tests-cases-plugin-bloc-text'
}

{ #category : #'as yet unclassified' }
TPyramidFontAttributeCommandTest >> attributeClass [

^ self shouldBeImplemented
]

{ #category : #tests }
TPyramidFontAttributeCommandTest >> testSetValueForWith [

| attributes |
self targetsWithoutValuesAndValues do: [ :each |
attributes := (each key text attributesFinder
attributesAndIndicesSuchThat: [ :a |
self attributeClass ~= a class ]) collect: [ :a |
a key ].
self command setValueFor: each key with: each value.
self assert: (self command getValueFor: each key) equals: each value.
self
assert:
((each key text attributesFinder attributesAndIndicesSuchThat: [
:a | true ])
collect: [ :a | a key ]
thenSelect: [ :a | self attributeClass ~= a class ])
equals: attributes ]
]

0 comments on commit 17226c7

Please sign in to comment.