-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPyramidMoveChildInParentPlugin.class.st
More file actions
163 lines (127 loc) · 4.67 KB
/
Copy pathPyramidMoveChildInParentPlugin.class.st
File metadata and controls
163 lines (127 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
"
This class is used to modify the place of child between each child in his parent.
"
Class {
#name : #PyramidMoveChildInParentPlugin,
#superclass : #Object,
#traits : 'TPyramidPlugin',
#classTraits : 'TPyramidPlugin classTrait',
#instVars : [
'editor',
'projectModel',
'contextMenuPlugin',
'navigationPlugin'
],
#category : #'Pyramid-Bloc-plugin-edit-element-tree'
}
{ #category : #adding }
PyramidMoveChildInParentPlugin >> addPanelsOn: aPyramidSimpleWindow [
aPyramidSimpleWindow
at: #selectionMenu
addItem: [ :builder | self contextMenuMoveChildInParent: builder ].
]
{ #category : #connecting }
PyramidMoveChildInParentPlugin >> connectOn: aPyramidEditor [
editor := aPyramidEditor.
projectModel := aPyramidEditor projectModel.
self navigationFromPyramid: aPyramidEditor.
aPyramidEditor
addShortcutSpecInCollection: KeyboardKey pageUp
action: [ self moveChildIndexUpInParent ]
name: 'Shortcut spec move child index up'.
aPyramidEditor
addShortcutSpecInCollection: KeyboardKey pageDown
action: [ self moveChildIndexDownInParent ]
name: 'Shortcut spec move child index down'.
]
{ #category : #adding }
PyramidMoveChildInParentPlugin >> contextMenuMoveChildInParent: aBuilder [
aBuilder
addGroupSingleSelection: [ :group :single |
group
addItem: [ :item |
item
icon: (Smalltalk ui icons iconNamed: #up);
name: 'Move child up';
action: [ self moveChildIndexDownInParent ];
yourself ];
addItem: [ :item |
item
icon: (Smalltalk ui icons iconNamed: #down);
name: 'Move child down';
action: [self moveChildIndexUpInParent];
yourself ];
yourself ]
order: 10
]
{ #category : #accessing }
PyramidMoveChildInParentPlugin >> editor [
^ editor
]
{ #category : #initialization }
PyramidMoveChildInParentPlugin >> initialize [
"Do nothing"
]
{ #category : #'as yet unclassified' }
PyramidMoveChildInParentPlugin >> moveChildIndexDownCommand: aBlElementParent with: aBlElementChildToMove [
self editor commandExecutor
use: PyramidMoveChildIndexDownCommand new
on: { aBlElementParent }
with: aBlElementChildToMove
]
{ #category : #action }
PyramidMoveChildInParentPlugin >> moveChildIndexDownInParent [
| childToMoveCollection childToMove childIndexToMove parentChild navigationSelectionPanel |
childToMoveCollection := projectModel selection collection.
navigationSelectionPanel := navigationPlugin navigation selectionPanel.
childToMoveCollection size = 1 ifFalse: [ ^ self ].
childToMove := childToMoveCollection first.
childToMove hasParent ifFalse: [ ^ self ].
parentChild := childToMove parent.
childIndexToMove := parentChild childIndexOf: childToMove.
childIndexToMove > 1
ifTrue: [
self moveChildIndexDownCommand: parentChild with: childToMove.
self refreshTreeTable ]
ifFalse: [ "cannot move the child up and the index down"
self inform: 'Cannot move up' ]
]
{ #category : #'as yet unclassified' }
PyramidMoveChildInParentPlugin >> moveChildIndexUpCommand: aBlElementParent with: aBlElementChildToMove [
self editor commandExecutor
use: PyramidMoveChildIndexUpCommand new
on: { aBlElementParent }
with: aBlElementChildToMove
]
{ #category : #action }
PyramidMoveChildInParentPlugin >> moveChildIndexUpInParent [
| childToMoveCollection childToMove childIndexToMove parentChild navigationSelectionPanel |
childToMoveCollection := projectModel selection collection.
navigationSelectionPanel := navigationPlugin navigation selectionPanel.
childToMoveCollection size = 1 ifFalse: [ ^ self ].
childToMove := childToMoveCollection first.
childToMove hasParent ifFalse: [ ^ self ].
parentChild := childToMove parent.
childIndexToMove := parentChild childIndexOf: childToMove.
childIndexToMove < parentChild children size
ifTrue: [
self moveChildIndexUpCommand: parentChild with: childToMove.
self refreshTreeTable ]
ifFalse: [ "cannot move the child down and the index up"
self inform: 'Cannot move down' ]
]
{ #category : #accessing }
PyramidMoveChildInParentPlugin >> navigationFromPyramid: aPyramidEditor [
navigationPlugin := aPyramidEditor findPlugin: PyramidNavigationPlugin.
]
{ #category : #'as yet unclassified' }
PyramidMoveChildInParentPlugin >> refreshTreeTable [
| navigationSelectionPanel selectedItems |
navigationSelectionPanel := navigationPlugin navigation selectionPanel.
"Keep the selection on the movedChild from here"
selectedItems := navigationSelectionPanel treeTable selectedItems first.
navigationSelectionPanel treeTable unselectAll.
"Refresh the treeTable"
navigationSelectionPanel treeTable roots: navigationSelectionPanel treeTable roots.
navigationSelectionPanel treeTable selectItem: selectedItems
]