Skip to content

Commit

Permalink
Add copy and paste
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyan11 committed Jun 14, 2024
1 parent 533ddb4 commit 5b135bf
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/Pyramid-Bloc/PyramidCopyPastePlugin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Class {
#superclass : 'Object',
#traits : 'TPyramidPlugin',
#classTraits : 'TPyramidPlugin classTrait',
#instVars : [
'projectModel'
],
#category : 'Pyramid-Bloc-plugin-copy-paste',
#package : 'Pyramid-Bloc',
#tag : 'plugin-copy-paste'
Expand All @@ -16,6 +19,12 @@ PyramidCopyPastePlugin >> addPanelsOn: aPyramidSimpleWindow [
addItem: [ :builder | self copyAsStonMenu: builder ]
]

{ #category : 'connecting' }
PyramidCopyPastePlugin >> connectOn: aPyramidEditor [

self projectModel: aPyramidEditor projectModel
]

{ #category : 'copying' }
PyramidCopyPastePlugin >> copyAsStonInClipboard: aCollection [

Expand All @@ -25,6 +34,24 @@ PyramidCopyPastePlugin >> copyAsStonInClipboard: aCollection [
{ #category : 'copying' }
PyramidCopyPastePlugin >> copyAsStonMenu: aBuilder [

aBuilder
addGroupEmptySelection: [ :group :empty |
group
addItem: [ :item |
item
icon: (Smalltalk ui icons iconNamed: #smallCopy);
name: 'Copy (select only one element)';
enabled: false;
yourself ];
addItem: [ :item |
item
icon: (Smalltalk ui icons iconNamed: #smallPaste);
name: 'Paste';
action: [ self pasteAsStonInClipboardOnRoots ];
yourself ];
yourself ]
order: 20.

aBuilder
addGroupSingleSelection: [ :group :single |
group
Expand All @@ -34,6 +61,12 @@ PyramidCopyPastePlugin >> copyAsStonMenu: aBuilder [
name: 'Copy';
action: [ self copyAsStonInClipboard: { single } ];
yourself ];
addItem: [ :item |
item
icon: (Smalltalk ui icons iconNamed: #smallPaste);
name: 'Paste';
action: [ self pasteAsStonInClipboard: single ];
yourself ];
yourself ]
order: 20.

Expand All @@ -46,6 +79,50 @@ PyramidCopyPastePlugin >> copyAsStonMenu: aBuilder [
name: 'Copy (select only one element)';
enabled: false;
yourself ];
addItem: [ :item |
item
icon: (Smalltalk ui icons iconNamed: #smallPaste);
name: 'Paste (select only one element)';
enabled: false;
yourself ];
yourself ]
order: 20
]

{ #category : 'copying' }
PyramidCopyPastePlugin >> pasteAsStonInClipboard: aBlElement [

| copiedElement |
[ copiedElement := BlSerializer materialize: Clipboard clipboardText ]
on: BlocMaterializationError
do: [
UIManager default inform: 'Cannot paste the clipboard.'.
^ self ].
aBlElement addChildren: copiedElement.
self projectModel informElementsChanged
]

{ #category : 'copying' }
PyramidCopyPastePlugin >> pasteAsStonInClipboardOnRoots [

| copiedElement |
[ copiedElement := BlSerializer materialize: Clipboard clipboardText ]
on: BlocMaterializationError
do: [
UIManager default inform: 'Cannot paste the clipboard.'.
^ self ].
self projectModel firstLevelElements addAll: copiedElement.
self projectModel informFirstLevelElementsChanged
]

{ #category : 'accessing' }
PyramidCopyPastePlugin >> projectModel [

^ projectModel
]

{ #category : 'accessing' }
PyramidCopyPastePlugin >> projectModel: anObject [

projectModel := anObject
]

0 comments on commit 5b135bf

Please sign in to comment.