Skip to content

Commit

Permalink
Merge pull request #3 from adri09070/decoupling-ui-and-logic-in-store…
Browse files Browse the repository at this point in the history
…-and-load-commands

[v0.4] Decoupling UI and logic in store and load commands
  • Loading branch information
adri09070 authored Jan 26, 2023
2 parents 87ce56f + b5b4bce commit b6b1967
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 36 deletions.
20 changes: 13 additions & 7 deletions Chest-Commands/ChestLoadObjectIntoCodeCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ ChestLoadObjectIntoCodeCommand >> buildChoicePresenter [
selectedIndexes do: [ :index |
| assoc |
assoc := chestContentTable items at: index.
(context interactionModel hasBindingOf: assoc key)
ifTrue: [
self
warnUserWhenDeletingBindingWithKey: assoc key
withNewValue: assoc value ]
ifFalse: [
self loadIntoContextObject: assoc value named: assoc variableName ] ].
self loadAssocIntoContext: assoc ].
choicePresenter window close ].

^ choicePresenter
Expand Down Expand Up @@ -95,6 +89,18 @@ ChestLoadObjectIntoCodeCommand >> isVisibleForContext: aCodePresenter [
identityIncludes: #addBinding: ]
]

{ #category : #execution }
ChestLoadObjectIntoCodeCommand >> loadAssocIntoContext: assoc [

(context interactionModel hasBindingOf: assoc key)
ifTrue: [
self
warnUserWhenDeletingBindingWithKey: assoc key
withNewValue: assoc value ]
ifFalse: [
self loadIntoContextObject: assoc value named: assoc variableName ]
]

{ #category : #'private - commands' }
ChestLoadObjectIntoCodeCommand >> loadIntoContextObject: anObject named: objectName [

Expand Down
64 changes: 35 additions & 29 deletions Chest-Commands/ChestStoreObjectCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ ChestStoreObjectCommand class >> defaultShortcutKey [
^ $c meta , $s meta
]

{ #category : #'private - commands' }
ChestStoreObjectCommand >> blockToEvaluateToStoreResult: result intoChest: chest withName: objectName withPresenter: choicePresenter [

^ [
objectName = chest nextDefaultNameForObject
ifTrue: [ self storeObject: result intoChest: chest ]
ifFalse: [
self storeObject: result intoChest: chest withName: objectName ].
choicePresenter window close ]
]

{ #category : #initialization }
ChestStoreObjectCommand >> buildChoicePresenter [

Expand All @@ -51,24 +40,22 @@ ChestStoreObjectCommand >> buildChoicePresenter [
| chest objectName |
chest := choicePresenter chestsTable selectedItem.
objectName := choicePresenter inputField text.
self evaluateSelectionAndDo: [ :result |
(self
blockToEvaluateToStoreResult: result
intoChest: chest
withName: objectName
withPresenter: choicePresenter)
on: ChestKeyAlreadyInUseError
do: [
((choicePresenter confirm:
(choicePresenter warningNamingObjectInChest: objectName))
onAccept: [
chest removeObjectNamed: objectName.
(self
blockToEvaluateToStoreResult: result
intoChest: chest
withName: objectName
withPresenter: choicePresenter) value ])
openDialogWithParent: choicePresenter chestContentTable ] ] ].
[
self
storeSelectionInChest: chest
withName: objectName
replacing: false ]
on: ChestKeyAlreadyInUseError
do: [
((choicePresenter confirm:
(choicePresenter warningNamingObjectInChest: objectName))
onAccept: [
self
storeSelectionInChest: chest
withName: objectName
replacing: true ]) openDialogWithParent:
choicePresenter chestContentTable ].
choicePresenter window close ].
choicePresenter layout: choicePresenter storeCommandLayout.
^ choicePresenter
]
Expand All @@ -92,3 +79,22 @@ ChestStoreObjectCommand >> storeObject: result intoChest: chest withName: object

chest ifNotNil: [ chest at: objectName put: result ]
]

{ #category : #execution }
ChestStoreObjectCommand >> storeResult: result intoChest: chest withName: objectName replacing: replacingBoolean [

replacingBoolean ifTrue: [ chest removeObjectNamed: objectName ].

objectName = chest nextDefaultNameForObject
ifTrue: [ self storeObject: result intoChest: chest ]
ifFalse: [
self storeObject: result intoChest: chest withName: objectName ]
]

{ #category : #execution }
ChestStoreObjectCommand >> storeSelectionInChest: aChest withName: objectName replacing: replacingBoolean [

self evaluateSelectionAndDo: [ :result |
self storeResult: result intoChest: aChest withName: objectName replacing: replacingBoolean
]
]

0 comments on commit b6b1967

Please sign in to comment.