Skip to content

Commit

Permalink
GtPharoNewMethodCoderElement initialize selfObject if defined [fe…
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajKubelka committed Dec 27, 2024
1 parent d480e3a commit 582756c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
Class {
#name : #GtPharoNewMethodCoderElement,
#superclass : #BrFrame,
#traits : 'TGtWithPharoMethodCoderViewModel',
#classTraits : 'TGtWithPharoMethodCoderViewModel classTrait',
#traits : 'TGtWithPharoMethodCoderViewModel + TGtCoderWithSelfObjectHolder + TGtCoderWithBehaviorHolder',
#classTraits : 'TGtWithPharoMethodCoderViewModel classTrait + TGtCoderWithSelfObjectHolder classTrait + TGtCoderWithBehaviorHolder classTrait',
#instVars : [
'sourceCoderElement',
'tagsElement',
'behavior',
'methodCoderViewModelValueHolder',
'onMethodCoderSaved'
],
Expand All @@ -18,38 +17,32 @@ GtPharoNewMethodCoderElement class >> preferredExtent [
^ 400 @ 150
]

{ #category : #'api - initialization' }
GtPharoNewMethodCoderElement >> behavior: aBehavior [
"Behavior is a class (or Trait) for which a new method will be created."

behavior := aBehavior
]

{ #category : #'private - updating' }
GtPharoNewMethodCoderElement >> ensureMethodCoderViewModel [
| aNewMethodCoderViewModel aNewMethodCoder newMethodText |
aNewMethodCoderViewModel := methodCoderViewModelValueHolder
ifNotNil: #contents.
aNewMethodCoderViewModel
ifNotNil:
[self pharoMethodCoderViewModel: aNewMethodCoderViewModel.
^self].
aNewMethodCoderViewModel ifNotNil: [
self pharoMethodCoderViewModel: aNewMethodCoderViewModel.
^ self ].

newMethodText := ('' asRopedText)
glamorousCodeFontAndSize;
attribute: (BrGhostTextAttribute
for: ('newMethod' asRopedText glamorousCodeFontAndSize
foreground: Color lightGray))
beNotOverwritableByStyler.
glamorousCodeFontAndSize;
attribute: (BrGhostTextAttribute
for: ('newMethod' asRopedText glamorousCodeFontAndSize
foreground: Color lightGray))
beNotOverwritableByStyler.
aNewMethodCoder := (GtPharoMethodCoder
forNewMethod: (behavior ifNil: [Object]))
currentSourceText: newMethodText;
protocol: AbstractProtocol unclassified;
yourself.
aNewMethodCoderViewModel := (aNewMethodCoder asCoderViewModel)
withoutHeader;
expanded: true;
focused: true;
moveCursorAtEnd.
forNewMethod: (self behaviorIfNone: [ Object ]))
currentSourceText: newMethodText;
protocol: AbstractProtocol unclassified;
yourself.
aNewMethodCoderViewModel := aNewMethodCoder asCoderViewModel
selfObjectHolder: self selfObjectHolder;
withoutHeader;
expanded: true;
focused: true;
moveCursorAtEnd.
self pharoMethodCoderViewModel: aNewMethodCoderViewModel.
methodCoderViewModelValueHolder
ifNotNil: [:aValueHolder | aValueHolder contents: aNewMethodCoderViewModel]
Expand Down Expand Up @@ -114,7 +107,7 @@ GtPharoNewMethodCoderElement >> onAddedToSceneGraph [
super onAddedToSceneGraph.

self hasPharoMethodCoderViewModel ifTrue: [ ^ self ].
behavior ifNil: [ ^ self ].
self behaviorIfNone: [ ^ self ].
self ensureMethodCoderViewModel
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ GtPharoNewMethodCoderMenu >> coderViewModel [
^ valueHolder contents
]

{ #category : #accessing }
GtPharoNewMethodCoderMenu >> coderViewModel: aCoderViewModel [
coder := aCoderViewModel coderModel.
valueHolder contents: aCoderViewModel
]

{ #category : #private }
GtPharoNewMethodCoderMenu >> ensureCoderViewModel [
self coderViewModel ifNotNil: [ ^ self ].
Expand Down
1 change: 1 addition & 0 deletions src/GToolkit-Pharo-Coder-UI/Behavior.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Behavior >> gtCopyButtonFor: anAction [
Behavior >> gtNewMethodDropdownOn: aButton withViewModel: aMethodsCoderViewModel withNewMethodHolder: aNewMethodCoderHolder [
^ GtPharoNewMethodCoderElement new
behavior: self;
selfObjectHolder: aMethodsCoderViewModel selfObjectHolder;
methodCoderViewModelValueHolder: aNewMethodCoderHolder;
onMethodCoderSaved: (GtPharoNewMethodCodeSavedHandler new
methodsCoderViewModel: aMethodsCoderViewModel;
Expand Down

0 comments on commit 582756c

Please sign in to comment.