Skip to content

Commit 8404100

Browse files
committed
Add drag and drop feature to the navigation window and the move of child between each child in his parent -> add to context menu : "Move up child" and "Move down child". add this new feature to the shortcut manager (CTRL + Arrow Up - Move up child | CTRL + Arrow Down - Move down child)
1 parent d658daa commit 8404100

5 files changed

Lines changed: 361 additions & 1 deletion
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
"
2+
This class add to a treetable the possibilities to drag and drop one or many selected element to edit the tree structure of the targeted element.
3+
"
4+
Class {
5+
#name : #PyramidEditElementTreeDragAndDropPlugin,
6+
#superclass : #Object,
7+
#traits : 'TPyramidPlugin',
8+
#classTraits : 'TPyramidPlugin classTrait',
9+
#instVars : [
10+
'editor',
11+
'navigationPlugin',
12+
'navigationSelectionPanel',
13+
'navigationPresenter'
14+
],
15+
#category : #'Pyramid-Bloc-plugin-edit-element-tree'
16+
}
17+
18+
{ #category : #adding }
19+
PyramidEditElementTreeDragAndDropPlugin >> addEditElementTreeDragAndDrop [
20+
21+
| selectionPanelTreeTable |
22+
23+
selectionPanelTreeTable := navigationSelectionPanel treeTable.
24+
selectionPanelTreeTable dragEnabled: true;
25+
dropEnabled: true;
26+
acceptDrop: [ :transfer |
27+
(transfer target)
28+
"Move dragged element to root space (workplace)"
29+
ifNil: [ self navigationPlugin removeSelectedElements.
30+
self moveElementToRootSpace: transfer passenger.
31+
self editor projectModel updateSelection.
32+
selectionPanelTreeTable expandAll. ]
33+
"Move dragged element to targeted element"
34+
ifNotNil: [ (self canMoveSelectedElement: (transfer passenger) target: (transfer target))
35+
"Dragged element put as a child of the targeted element"
36+
ifTrue: [ self navigationPlugin removeSelectedElements.
37+
self moveElementDragToChild: transfer passenger
38+
target: transfer target.
39+
self editor projectModel updateSelection.
40+
selectionPanelTreeTable expandAll. ]
41+
ifFalse: [ self inform: 'cannot move selected element to his child or himself'] ] ].
42+
]
43+
44+
{ #category : #testing }
45+
PyramidEditElementTreeDragAndDropPlugin >> canMoveSelectedElement: anArrayOfElementDragged target: aElementTarget [
46+
47+
| canMove |
48+
canMove := true.
49+
50+
anArrayOfElementDragged do: [ :element |
51+
aElementTarget = element ifTrue: [ ^ canMove := false ] ].
52+
53+
canMove := (self checkParentOfTarget: aElementTarget
54+
draggedBlElement: anArrayOfElementDragged).
55+
56+
^ canMove
57+
]
58+
59+
{ #category : #testing }
60+
PyramidEditElementTreeDragAndDropPlugin >> checkParentOfTarget: aElementTarget draggedBlElement: anArrayOfElementDragged [
61+
62+
aElementTarget hasParent
63+
ifTrue: [ anArrayOfElementDragged do: [ :element | (aElementTarget parent = element)
64+
ifTrue: [ ^ false ]
65+
ifFalse: [ ^ (self checkParentOfTarget: (aElementTarget parent)
66+
draggedBlElement: anArrayOfElementDragged). ] ] ]
67+
ifFalse: [ ^ true ]
68+
69+
]
70+
71+
{ #category : #connecting }
72+
PyramidEditElementTreeDragAndDropPlugin >> connectOn: aPyramidEditor [
73+
74+
editor := aPyramidEditor.
75+
76+
self navigationPluginFromPyramid: aPyramidEditor.
77+
self navigationPlugin ifNil: [ ^ self ].
78+
navigationPresenter := self navigationPlugin navigation.
79+
navigationSelectionPanel := navigationPresenter selectionPanel.
80+
self addEditElementTreeDragAndDrop.
81+
]
82+
83+
{ #category : #accessing }
84+
PyramidEditElementTreeDragAndDropPlugin >> editor [
85+
86+
^ editor
87+
]
88+
89+
{ #category : #initialization }
90+
PyramidEditElementTreeDragAndDropPlugin >> initialize [
91+
92+
"Do nothing"
93+
]
94+
95+
{ #category : #actions }
96+
PyramidEditElementTreeDragAndDropPlugin >> moveElementDragToChild: arrayOfElementDragged target: aElementTarget [
97+
98+
self editor commandExecutor
99+
use: PyramidAddChildrenCommand new
100+
on: { aElementTarget }
101+
with: arrayOfElementDragged.
102+
]
103+
104+
{ #category : #actions }
105+
PyramidEditElementTreeDragAndDropPlugin >> moveElementToRootSpace: arrayOfElementDragged [
106+
107+
self editor commandExecutor
108+
use: PyramidAddAllToCollectionCommand new
109+
on: { self editor projectModel firstLevelElements }
110+
with: arrayOfElementDragged.
111+
]
112+
113+
{ #category : #accessing }
114+
PyramidEditElementTreeDragAndDropPlugin >> navigationPlugin [
115+
116+
^ navigationPlugin
117+
]
118+
119+
{ #category : #accessing }
120+
PyramidEditElementTreeDragAndDropPlugin >> navigationPlugin: aPlugin [
121+
122+
navigationPlugin := aPlugin
123+
]
124+
125+
{ #category : #accessing }
126+
PyramidEditElementTreeDragAndDropPlugin >> navigationPluginFromPyramid: aPyramidEditor [
127+
128+
self navigationPlugin: (aPyramidEditor findPlugin: PyramidNavigationPlugin).
129+
]
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
"
2+
This class is used to modify the place of child between each child in his parent.
3+
"
4+
Class {
5+
#name : #PyramidMoveChildInParentPlugin,
6+
#superclass : #Object,
7+
#traits : 'TPyramidPlugin',
8+
#classTraits : 'TPyramidPlugin classTrait',
9+
#instVars : [
10+
'editor',
11+
'projectModel',
12+
'contextMenuPlugin',
13+
'navigationPlugin'
14+
],
15+
#category : #'Pyramid-Bloc-plugin-edit-element-tree'
16+
}
17+
18+
{ #category : #adding }
19+
PyramidMoveChildInParentPlugin >> addPanelsOn: aPyramidSimpleWindow [
20+
21+
aPyramidSimpleWindow
22+
at: #selectionMenu
23+
addItem: [ :builder | self contextMenuMoveChildInParent: builder ].
24+
]
25+
26+
{ #category : #connecting }
27+
PyramidMoveChildInParentPlugin >> connectOn: aPyramidEditor [
28+
29+
editor := aPyramidEditor.
30+
projectModel := aPyramidEditor projectModel.
31+
self navigationFromPyramid: aPyramidEditor.
32+
]
33+
34+
{ #category : #adding }
35+
PyramidMoveChildInParentPlugin >> contextMenuMoveChildInParent: aBuilder [
36+
37+
aBuilder
38+
addGroupSingleSelection: [ :group :single |
39+
group
40+
addItem: [ :item |
41+
item
42+
icon: (Smalltalk ui icons iconNamed: #up);
43+
name: 'Move child up';
44+
action: [ self moveUpChildIndexInParent ];
45+
yourself ];
46+
47+
addItem: [ :item |
48+
item
49+
icon: (Smalltalk ui icons iconNamed: #down);
50+
name: 'Move child down';
51+
action: [ self moveDownChildIndexInParent ];
52+
yourself ];
53+
yourself ]
54+
order: 10.
55+
]
56+
57+
{ #category : #accessing }
58+
PyramidMoveChildInParentPlugin >> editor [
59+
60+
^ editor
61+
]
62+
63+
{ #category : #initialization }
64+
PyramidMoveChildInParentPlugin >> initialize [
65+
66+
"Do nothing"
67+
]
68+
69+
{ #category : #action }
70+
PyramidMoveChildInParentPlugin >> moveDownChildIndexInParent [
71+
72+
| childToMoveCollection childToMove childIndexToMove parentChild navigationSelectionPanel |
73+
74+
childToMoveCollection := projectModel selection collection.
75+
navigationSelectionPanel := navigationPlugin navigation selectionPanel.
76+
77+
childToMoveCollection size = 1
78+
ifFalse: [ ^ self ].
79+
childToMove := childToMoveCollection first.
80+
81+
childToMove hasParent
82+
ifFalse: [ ^ self ].
83+
parentChild := childToMove parent.
84+
85+
childIndexToMove := (parentChild childIndexOf: childToMove).
86+
87+
childIndexToMove < (parentChild children size)
88+
ifTrue: [ parentChild swapChildAt: childIndexToMove with: (childIndexToMove + 1).
89+
"Keep the selection on the movedChild from here"
90+
navigationSelectionPanel treeTable unselectAll.
91+
"Refresh the treeTable and select the element moved"
92+
navigationSelectionPanel treeTable roots: navigationSelectionPanel treeTable roots.
93+
navigationSelectionPanel treeTable selectItem: childToMove. ]
94+
"to here"
95+
96+
ifFalse: [ self inform: 'Cannot move down' ].
97+
98+
99+
100+
]
101+
102+
{ #category : #action }
103+
PyramidMoveChildInParentPlugin >> moveUpChildIndexInParent [
104+
105+
| childToMoveCollection childToMove childIndexToMove parentChild navigationSelectionPanel |
106+
107+
childToMoveCollection := projectModel selection collection.
108+
navigationSelectionPanel := navigationPlugin navigation selectionPanel.
109+
110+
childToMoveCollection size = 1
111+
ifFalse: [ ^ self ].
112+
childToMove := childToMoveCollection first.
113+
114+
childToMove hasParent
115+
ifFalse: [ ^ self ].
116+
parentChild := childToMove parent.
117+
118+
childIndexToMove := (parentChild childIndexOf: childToMove).
119+
120+
childIndexToMove > 1
121+
ifTrue: [ parentChild swapChildAt: childIndexToMove with: (childIndexToMove - 1).
122+
"Keep the selection on the movedChild from here"
123+
navigationSelectionPanel treeTable unselectAll.
124+
"Refresh the treeTable"
125+
navigationSelectionPanel treeTable roots: navigationSelectionPanel treeTable roots.
126+
navigationSelectionPanel treeTable selectItem: childToMove ]
127+
"to here"
128+
ifFalse: [ self inform: 'Cannot move up' ].
129+
130+
131+
132+
133+
]
134+
135+
{ #category : #accessing }
136+
PyramidMoveChildInParentPlugin >> navigationFromPyramid: aPyramidEditor [
137+
138+
navigationPlugin := aPyramidEditor findPlugin: PyramidNavigationPlugin.
139+
]

src/Pyramid-Bloc/PyramidSpaceShortcutInspectSelectedElement.class.st

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"
2+
This class is use to inspect the current selected element
3+
"
14
Class {
25
#name : #PyramidSpaceShortcutInspectSelectedElement,
36
#superclass : #PyramidSpaceShortcutManagerPlugin,

src/Pyramid-Bloc/PyramidSpaceShortcutManagerPlugin.class.st

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ List of current active shortcut (default value) :
1414
- Select all element -> ctrl + A
1515
- Delete selected element -> delete or suppr
1616
- Inspect one selected element -> ctrl + I
17+
- Move up child (ctrl + Arrow Up)
18+
- Move down child (ctrl + Arrow Down)
1719
"
1820
Class {
1921
#name : #PyramidSpaceShortcutManagerPlugin,
@@ -28,7 +30,8 @@ Class {
2830
'shortcutGrid',
2931
'shortcutRemoveElement',
3032
'shortcutSelectAllElement',
31-
'shortcutInspectSelectedElement'
33+
'shortcutInspectSelectedElement',
34+
'shortcutMoveChildInParent'
3235
],
3336
#category : #'Pyramid-Bloc-plugin-shortcut-manager'
3437
}
@@ -62,6 +65,12 @@ PyramidSpaceShortcutManagerPlugin >> addAllShortcutInCollection [
6265
"Shortcut inspect selected element (ctrl + I)"
6366
shortcutCollection add: shortcutInspectSelectedElement shortcutActionInspect.
6467

68+
"Shortcut Move child in parent"
69+
"Move up (ctrl + Arrow up)"
70+
shortcutCollection add: shortcutMoveChildInParent shortcutActionMoveUp.
71+
"Move down (ctrl + Arrow down)"
72+
shortcutCollection add: shortcutMoveChildInParent shortcutActionMoveDown.
73+
6574
"New shortcut to add under this comment, keep the same patern as before"
6675

6776
]
@@ -107,6 +116,9 @@ PyramidSpaceShortcutManagerPlugin >> connectOn: aPyramidEditor [
107116
"Get projectModelFromPyramid for Inspect selected element"
108117
shortcutInspectSelectedElement projectModelFromPyramid: aPyramidEditor.
109118

119+
"Get navigation plugin for MoveChildInParentPlugin"
120+
shortcutMoveChildInParent moveChildInParentPluginFromPyramid: aPyramidEditor.
121+
110122
"Adding shortcut to Pyramid"
111123
spacePlugin resetShortcutBlock: [ :aSpace | self refreshAllShortcutInSpace: aSpace ].
112124
spacePlugin resetSpace.
@@ -124,6 +136,7 @@ PyramidSpaceShortcutManagerPlugin >> initialize [
124136
shortcutRemoveElement := PyramidSpaceShortcutRemoveElement new.
125137
shortcutSelectAllElement := PyramidSpaceShortcutSelectAllElement new.
126138
shortcutInspectSelectedElement := PyramidSpaceShortcutInspectSelectedElement new.
139+
shortcutMoveChildInParent := PyramidSpaceShortcutMoveChildInParent new.
127140
]
128141

129142
{ #category : #action }

0 commit comments

Comments
 (0)