Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiselection support for variants #135

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 62 additions & 10 deletions packages/Sandblocks-Smalltalk/SBStGrammarHandler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ SBStGrammarHandler >> debugExpression [
receiver: (context ifNil: [artefact ifNotNil: #evaluationReceiver] ifNotNil: #receiver)) debugWithTitle: 'Debug it'
]

{ #category : #'action helpers' }
SBStGrammarHandler >> defaultAlternativesForBlocks: aCollectionOfBlocks [

^ {
SBNamedBlock block: (SBStBlockBody new statements: aCollectionOfBlocks) named: 'original'.
SBNamedBlock block: (SBStBlockBody new statements: aCollectionOfBlocks veryDeepCopy) named: 'alternative'. }
]

{ #category : #'action helpers' }
SBStGrammarHandler >> defaultOptionalAlternativesForBlocks: aCollectionOfBlocks [

^ {
SBNamedBlock block: (SBStBlockBody new statements: aCollectionOfBlocks) named:'with'.
SBNamedBlock block: (SBStBlockBody empty) named:'without'.}
]

{ #category : #actions }
SBStGrammarHandler >> doExpression [
<action>
Expand Down Expand Up @@ -401,6 +417,44 @@ SBStGrammarHandler >> wrapAsArgument [
startInput: msg receiver at: 0 replacingContents: false
]

{ #category : #actions }
SBStGrammarHandler >> wrapEachInOptionalVariant [
<multiSelectAction>
<actionValidIf: #isSandblock>

self assert: self block isSelected.
self block sandblockEditor doMultiSelectionEach: [:selected | | variant |
variant := SBVariant new.
SBWrapCommand new
outer: variant;
inner: selected;
wrap: [:outer :inner |
variant
named: inner printString
alternatives: (self defaultOptionalAlternativesForBlocks: {inner})
activeIndex: 2];
yourself]
]

{ #category : #actions }
SBStGrammarHandler >> wrapEachInVariant [
<multiSelectAction>
<actionValidIf: #isSandblock>

self assert: self block isSelected.
self block sandblockEditor doMultiSelectionEach: [:selected | | variant |
variant := SBVariant new.
SBWrapCommand new
outer: variant;
inner: selected;
wrap: [:outer :inner |
variant
named: inner printString
alternatives: (self defaultAlternativesForBlocks: {inner})
activeIndex: 2];
yourself]
]

{ #category : #'action helpers' }
SBStGrammarHandler >> wrapInArrayType: aSymbol [

Expand Down Expand Up @@ -527,12 +581,11 @@ SBStGrammarHandler >> wrapInOptionalVariant [
selectAfter: #block;
outer: variant;
targets: selected;
wrap: [:outer :inner |
wrap: [:outer :inner |
variant
named: inner printString
alternatives:{
SBNamedBlock block: (SBStBlockBody new statements: inner) named:'with'.
SBNamedBlock block: (SBStBlockBody empty) named:'without'} activeIndex: 2];
alternatives: (self defaultOptionalAlternativesForBlocks: inner)
activeIndex: 2];
yourself]
]

Expand Down Expand Up @@ -582,12 +635,11 @@ SBStGrammarHandler >> wrapInVariant [
selectAfter: #block;
outer: variant;
targets: selected;
wrap: [:outer :inner | variant
named: inner printString
alternatives: {
SBNamedBlock block: (SBStBlockBody new statements: inner) named: 'original'.
SBNamedBlock block: (SBStBlockBody new statements: inner veryDeepCopy) named: 'alternative'. }
activeIndex: 2];
wrap: [:outer :inner |
variant
named: inner printString
alternatives: (self defaultAlternativesForBlocks: inner)
activeIndex: 2];
yourself]
]

Expand Down
Loading