Skip to content

Commit

Permalink
Merge pull request #18 from adri09070/14-Add-a-real-copy-object-option
Browse files Browse the repository at this point in the history
Adding radio buttons in the choice presenter of the StoreCommand, to be able to choose to copy the object before storing or not
  • Loading branch information
StevenCostiou authored Aug 2, 2023
2 parents ec456f3 + 29a03cf commit 2d6c429
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 11 deletions.
34 changes: 24 additions & 10 deletions src/Chest-Commands/ChestStoreObjectCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,30 @@ ChestStoreObjectCommand >> buildChoicePresenter [

| choicePresenter |
choicePresenter := ChestTableWithContentPresenter new.
choicePresenter confirmButton action: [
| chest objectName |
choicePresenter confirmButton action: [
| chest objectName selectorToSendToSelection |
chest := choicePresenter chestsTable selectedItem.
objectName := choicePresenter inputField text.
[
selectorToSendToSelection := #yourself.
choicePresenter buttonShallowCopy state ifTrue: [
selectorToSendToSelection := #shallowCopy ].
choicePresenter buttonDeepCopy state ifTrue: [
selectorToSendToSelection := #copy ].
[
self
storeSelectionInChest: chest
withName: objectName
withSelector: selectorToSendToSelection
replacing: false ]
on: ChestKeyAlreadyInUseError
do: [
do: [
((choicePresenter confirm:
(choicePresenter warningNamingObjectInChest: objectName))
onAccept: [
(choicePresenter warningNamingObjectInChest: objectName))
onAccept: [
self
storeSelectionInChest: chest
withName: objectName
withSelector: selectorToSendToSelection
replacing: true ]) openDialogWithParent:
choicePresenter chestContentTable ].
choicePresenter window close ].
Expand Down Expand Up @@ -86,9 +93,16 @@ ChestStoreObjectCommand >> storeResult: result intoChest: chest withName: object
]

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

self evaluateSelectionAndDo: [ :result |
self storeResult: result intoChest: aChest withName: objectName replacing: replacingBoolean
]
self evaluateSelectionAndDo: [ :result |
| storedResult |
storedResult := result
perform: selectorSentToSelectionBeforeStoring
withArguments: #( ).
self
storeResult: storedResult
intoChest: aChest
withName: objectName
replacing: replacingBoolean ]
]
46 changes: 45 additions & 1 deletion src/Chest/ChestTableWithContentPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ Class {
'chestWithContentTreeTable',
'chestTableWithContentContainer',
'activePresenter',
'chestWithContentTreeTableToolbar'
'chestWithContentTreeTableToolbar',
'buttonNoCopy',
'buttonShallowCopy',
'buttonDeepCopy'
],
#category : #Chest
}
Expand Down Expand Up @@ -188,6 +191,24 @@ ChestTableWithContentPresenter >> activePresenter [
^ activePresenter
]

{ #category : #accessing }
ChestTableWithContentPresenter >> buttonDeepCopy [

^ buttonDeepCopy
]

{ #category : #accessing }
ChestTableWithContentPresenter >> buttonNoCopy [

^ buttonNoCopy
]

{ #category : #accessing }
ChestTableWithContentPresenter >> buttonShallowCopy [

^ buttonShallowCopy
]

{ #category : #accessing }
ChestTableWithContentPresenter >> cancelButton [

Expand Down Expand Up @@ -400,6 +421,8 @@ ChestTableWithContentPresenter >> initializePresenters [
chestContentsTableToolbar := self makeChestContentsTableToolbar.

chestWithContentTreeTableToolbar := self makeChestTreeTableToolbar.

self makeCopyRadioButtons.

self layout: self defaultLayout
]
Expand Down Expand Up @@ -604,6 +627,22 @@ ChestTableWithContentPresenter >> makeConfirmActionBar [
yourself
]

{ #category : #'presenter building' }
ChestTableWithContentPresenter >> makeCopyRadioButtons [

buttonNoCopy := self newRadioButton.
buttonShallowCopy := self newRadioButton.
buttonDeepCopy := self newRadioButton.

buttonNoCopy associatedRadioButtons: {
buttonShallowCopy.
buttonDeepCopy }.

buttonNoCopy label: 'No copy'.
buttonShallowCopy label: 'Shallow copy'.
buttonDeepCopy label: 'Deep copy'
]

{ #category : #'presenter building' }
ChestTableWithContentPresenter >> makeInputField [

Expand Down Expand Up @@ -863,6 +902,11 @@ ChestTableWithContentPresenter >> storeCommandLayout [
add: chestsTableToolbar;
add: chestContentsTableToolbar;
yourself);
add: (SpBoxLayout newHorizontal
add: buttonNoCopy;
add: buttonShallowCopy;
add: buttonDeepCopy;
yourself);
add: confirmActionBar;
yourself
]
Expand Down

0 comments on commit 2d6c429

Please sign in to comment.