Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 1734126

Browse files
authored
Merge pull request #1861 from livecodemichael/feature-datagrid2_edit_swipe
[[ DataGrid 2 ]] Edit mode and swipe actions.
2 parents 7777763 + 8089bd6 commit 1734126

9 files changed

+3805
-27
lines changed

Documentation/dictionary/datagrid.lcdoc

Lines changed: 912 additions & 5 deletions
Large diffs are not rendered by default.
2.09 KB
Binary file not shown.
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
script "RevDataGridLibraryBehaviorsSwipeControlHolderBehavior"
2+
----------------------------------------------------------------------
3+
-- This behavior is applied to a group used to house fully visible swipe
4+
-- controls for a give row and side, dealing with animating the control in an
5+
-- out as well as catching any clicks. (Partially visible - i.e. during a row
6+
-- drag left/right action - are handled in the row's chained behavior). When
7+
-- fully visible, a swipe control takes over the full DataGrid, using the holder
8+
-- group as message catcher, with all clicks in th DataGrid either hiding the
9+
-- swipe control or performing the swipe control click action.
10+
11+
local sRowIndex
12+
local sSwipeControlSide
13+
local sSwipeControl
14+
local sSwipeControlOwner
15+
16+
setProp dgSwipeControlSide pSide
17+
put pSide into sSwipeControlSide
18+
end dgSwipeControlSide
19+
20+
getProp dgSwipeControlSide
21+
return sSwipeControlSide
22+
end dgSwipeControlSide
23+
24+
-- Animate in the swipe control for the given row index using from the
25+
-- previously specified side.
26+
-- Setting to empty will animate out any visible swipe control.
27+
setProp dgSwipeControlRowIndex pIndex
28+
if pIndex is not empty then
29+
local tRowControl
30+
put the dgDataControlOfIndex[pIndex] of the dgControl of me into tRowControl
31+
if tRowControl is empty then
32+
return "Could not find row control"
33+
end if
34+
35+
switch sSwipeControlSide
36+
case "left"
37+
get DG2_CustomisableControlsGetLeftSwipeControlForControl(the long id of tRowControl)
38+
break
39+
case "right"
40+
get DG2_CustomisableControlsGetRightSwipeControlForControl(the long id of tRowControl)
41+
break
42+
default
43+
return "Unknown swipe side" && sSwipeControlSide
44+
end switch
45+
if it is empty then
46+
return "Could not find swipe control"
47+
end if
48+
49+
put it into sSwipeControl
50+
put pIndex into sRowIndex
51+
put the owner of sSwipeControl into sSwipeControlOwner
52+
53+
lock screen
54+
set the rect of me to the rect of group "dgList" of the dgControl of me
55+
set the rect of graphic "Message Catcher" of me to the rect of me
56+
set the visible of me to true
57+
unlock screen
58+
59+
DG2_SwipeControlShow
60+
return the result
61+
else
62+
local tResult
63+
DG2_SwipeControlHide
64+
put empty into sRowIndex
65+
return tResult
66+
end if
67+
end dgSwipeControlRowIndex
68+
69+
getProp dgSwipeControlRowIndex
70+
return sRowIndex
71+
end dgSwipeControlRowIndex
72+
73+
-- A scroll or resize has occurred. Reposition the group inside the the list,
74+
-- the swipe control next to the appropriate row and the row to the left or
75+
-- right of the swipe control.
76+
command DG2_SwipeControlHolderReposition
77+
if not the visible of me then
78+
return empty
79+
end if
80+
if sRowIndex is empty then
81+
return empty
82+
end if
83+
if sSwipeControl is empty then
84+
return empty
85+
end if
86+
87+
local tRowControl
88+
put the dgDataControlOfIndex[sRowIndex] of the dgControl of me into tRowControl
89+
if tRowControl is empty then
90+
set the visible of sSwipeControl to false
91+
return empty
92+
end if
93+
94+
lock screen
95+
set the visible of sSwipeControl to true
96+
set the rect of me to the rect of group "dgList" of the dgControl of me
97+
set the rect of graphic "Message Catcher" of me to the rect of me
98+
set the top of sSwipeControl to the top of tRowControl
99+
switch sSwipeControlSide
100+
case "left"
101+
set the left of tRowControl to the right of sSwipeControl
102+
break
103+
case "right"
104+
set the right of tRowControl to the left of sSwipeControl
105+
break
106+
end switch
107+
unlock screen
108+
109+
return empty
110+
end DG2_SwipeControlHolderReposition
111+
112+
private command DG2_SwipeControlShow
113+
local tRowControl
114+
put the dgDataControlOfIndex[sRowIndex] of the dgControl of me into tRowControl
115+
if tRowControl is empty then
116+
return "Could not find row control"
117+
end if
118+
119+
-- A swipe has been occured so tell the user by sending the
120+
-- appropriate message. If the user handles the message then we
121+
-- can assume they are dealing with the action and on't need to do
122+
-- anything more. If it's not handled, then fully animate in the
123+
-- swipe control.
124+
switch sSwipeControlSide
125+
case "left"
126+
dispatch DG2_GetMessageNameForTag("RowSwipedRight") to tRowControl
127+
if it is not "handled" then
128+
DG2_AnimationsAdd the long id of tRowControl, "left", the left of tRowControl, the right of sSwipeControl, the dgAnimationProp["SwipeCompleteDuration"] of the dgControl of me, the dgAnimationProp["SwipeCompleteEasing"] of the dgControl of me, "DG2_SwipeControlShowComplete", empty, the long id of me
129+
end if
130+
break
131+
case "right"
132+
dispatch DG2_GetMessageNameForTag("RowSwipedLeft") to tRowControl
133+
if it is not "handled" then
134+
DG2_AnimationsAdd the long id of tRowControl, "right", the right of tRowControl, the left of sSwipeControl, the dgAnimationProp["SwipeCompleteDuration"] of the dgControl of me, the dgAnimationProp["SwipeCompleteEasing"] of the dgControl of me, "DG2_SwipeControlShowComplete", empty, the long id of me
135+
end if
136+
break
137+
end switch
138+
139+
return empty
140+
end DG2_SwipeControlShow
141+
142+
on DG2_SwipeControlShowComplete
143+
-- When the animation is complete, the swipe control should be fully visible.
144+
-- This means we can now bring it to the front of the DataGrid allowing it or
145+
-- the holder group to catch all messages.
146+
lock screen
147+
relayer me to front of owner
148+
relayer sSwipeControl to front of me
149+
unlock screen
150+
151+
return empty
152+
end DG2_SwipeControlShowComplete
153+
154+
private command DG2_SwipeControlHide
155+
local tRowControl
156+
put the dgDataControlOfIndex[sRowIndex] of the dgControl of me into tRowControl
157+
if tRowControl is empty then
158+
return "Could not find row control"
159+
end if
160+
161+
local tIsVisible
162+
put the visible of me into tIsVisible
163+
164+
lock screen
165+
relayer sSwipeControl before tRowControl
166+
set the visible of me to false
167+
unlock screen
168+
169+
-- The row script takes care of returning the swipe control.
170+
-- If we're not visible then tell the row control not to bother animating the
171+
-- return.
172+
dispatch "DG2_SwipeReturn" to tRowControl with not tIsVisible
173+
return the result
174+
end DG2_SwipeControlHide
175+
176+
on DG2_SwipeControlHideComplete
177+
local tRowControl
178+
put the dgDataControlOfIndex[sRowIndex] of the dgControl of me into tRowControl
179+
if tRowControl is not empty then
180+
set the left of tRowControl to the left of group "dgList" of the dgControl of me
181+
end if
182+
183+
if sSwipeControl is not empty then
184+
set the visible of sSwipeControl to false
185+
relayer sSwipeControl to back of sSwipeControlOwner
186+
end if
187+
188+
return empty
189+
end DG2_SwipeControlHideComplete
190+
191+
on mouseUp
192+
local tRowControl
193+
put the dgDataControlOfIndex[sRowIndex] of the dgControl of me into tRowControl
194+
if tRowControl is empty then
195+
exit mouseUp
196+
end if
197+
198+
if the long id of the target contains the long id of sSwipeControl then
199+
switch sSwipeControlSide
200+
case "left"
201+
dispatch DG2_GetMessageNameForTag("RowLeftSwipeControlClicked") to tRowControl
202+
break
203+
case "right"
204+
dispatch DG2_GetMessageNameForTag("RowRightSwipeControlClicked") to tRowControl
205+
break
206+
end switch
207+
else
208+
DG2_SwipeControlHide
209+
switch sSwipeControlSide
210+
case "left"
211+
dispatch DG2_GetMessageNameForTag("RowLeftSwipeControlHidden") to tRowControl
212+
break
213+
case "right"
214+
dispatch DG2_GetMessageNameForTag("RowRightSwipeControlHidden") to tRowControl
215+
break
216+
end switch
217+
end if
218+
end mouseUp
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
script "RevDataGridLibraryBehaviorsActionControlHolderBehavior"
2+
----------------------------------------------------------------------
3+
-- This behavior is applied to a group used to house the action control for a
4+
-- given row. It takes care of animating the action control in and out as well
5+
-- as handling any actions when visible: When visible, the action control takes
6+
-- over the full DataGrid, with all clicks either resulting in the action
7+
-- control being hidden or the action control action being applied. The
8+
-- behaviors's group acts as a message catcher, spanning the whole DataGrid.
9+
10+
local sRowIndex
11+
local sActionControl
12+
local sActionControlOwner
13+
14+
-- Animate in the action control for the row with the given index.
15+
-- Setting to empty will animate out any visible action control.
16+
setProp dgActionControlRowIndex pIndex
17+
if pIndex is not empty then
18+
local tRowControl
19+
put the dgDataControlOfIndex[pIndex] of the dgControl of me into tRowControl
20+
if tRowControl is empty then
21+
return "Could not find row control"
22+
end if
23+
24+
get DG2_CustomisableControlsGetEditModeActionControlForControl(the long id of tRowControl)
25+
if it is empty then
26+
return "Could not find action control"
27+
end if
28+
29+
put it into sActionControl
30+
put pIndex into sRowIndex
31+
put the owner of sActionControl into sActionControlOwner
32+
33+
lock screen
34+
set the rect of me to the rect of group "dgList" of the dgControl of me
35+
set the rect of graphic "Message Catcher" of me to the rect of me
36+
set the visible of me to true
37+
unlock screen
38+
39+
DG2_EditModeActionControlShow
40+
return the result
41+
else
42+
local tResult
43+
DG2_EditModeActionControlHide
44+
put the result into tResult
45+
put empty into sRowIndex
46+
return the result
47+
end if
48+
end dgActionControlRowIndex
49+
50+
getProp dgActionControlRowIndex
51+
return sRowIndex
52+
end dgActionControlRowIndex
53+
54+
-- A scroll or resize has occurred. Reposition the group inside the the list,
55+
-- the action control next to the appropriate row and the row to the left of
56+
-- the action control.
57+
command DG2_EditModeActionControlHolderReposition
58+
if not the visible of me then
59+
return empty
60+
end if
61+
if sRowIndex is empty then
62+
return empty
63+
end if
64+
if sActionControl is empty then
65+
return empty
66+
end if
67+
68+
local tRowControl
69+
put the dgDataControlOfIndex[sRowIndex] of the dgControl of me into tRowControl
70+
if tRowControl is empty then
71+
set the visible of sActionControl to false
72+
return empty
73+
end if
74+
75+
lock screen
76+
set the visible of sActionControl to true
77+
set the rect of me to the rect of group "dgList" of the dgControl of me
78+
set the rect of graphic "Message Catcher" of me to the rect of me
79+
set the top of sActionControl to the top of tRowControl
80+
set the right of tRowControl to the left of sActionControl
81+
unlock screen
82+
83+
return empty
84+
end DG2_EditModeActionControlHolderReposition
85+
86+
private command DG2_EditModeActionControlShow
87+
local tRowControl
88+
put the dgDataControlOfIndex[sRowIndex] of the dgControl of me into tRowControl
89+
if tRowControl is empty then
90+
return "Could not find row control"
91+
end if
92+
93+
-- We relayer the action control behind the row so that it is revealed as the
94+
-- row animates left.
95+
lock screen
96+
relayer sActionControl before tRowControl
97+
set the rect of sActionControl to the right of tRowControl - the width of sActionControl, the top of tRowControl, the right of tRowControl, the bottom of tRowControl
98+
set the visible of sActionControl to true
99+
unlock screen
100+
101+
DG2_AnimationsAdd the long id of tRowControl, "left", the left of tRowControl, the left of tRowControl - the width of sActionControl, the dgAnimationProp["EditModeActionControlAnimationDuration"] of the dgControl of me, the dgAnimationProp["EditModeActionControlAnimationEasing"] of the dgControl of me, "DG2_EditModeActionControlShowComplete", empty, the long id of me
102+
103+
return empty
104+
end DG2_EditModeActionControlShow
105+
106+
on DG2_EditModeActionControlShowComplete
107+
-- When the animation is complete, the action control should be fully visible.
108+
-- This means we can now bring it to the front of the DataGrid allowing it or
109+
-- the holder group to catch all messages.
110+
lock screen
111+
relayer me to front of owner
112+
relayer sActionControl to front of me
113+
unlock screen
114+
115+
return empty
116+
end DG2_EditModeActionControlShowComplete
117+
118+
private command DG2_EditModeActionControlHide
119+
local tRowControl
120+
put the dgDataControlOfIndex[sRowIndex] of the dgControl of me into tRowControl
121+
if tRowControl is empty then
122+
return "Could not find row control"
123+
end if
124+
125+
if the visible of me then
126+
-- Put the action control back behind the row control so that it is hidden
127+
-- as the row animates right.
128+
lock screen
129+
relayer sActionControl before tRowControl
130+
set the visible of me to false
131+
unlock screen
132+
133+
DG2_AnimationsAdd the long id of tRowControl, "left", the left of tRowControl, the left of tRowControl + the width of sActionControl, the dgAnimationProp["EditModeActionControlAnimationDuration"] of the dgControl of me, the dgAnimationProp["EditModeActionControlAnimationEasing"] of the dgControl of me, "DG2_EditModeActionControlHideComplete", empty, the long id of me
134+
else
135+
-- If we're not visible, don't bother with any animating.
136+
set the left of tRowControl to the left of group "dgList" of the dgControl of me
137+
DG2_EditModeActionControlHideComplete
138+
end if
139+
140+
return empty
141+
end DG2_EditModeActionControlHide
142+
143+
on DG2_EditModeActionControlHideComplete
144+
-- Return the action control to where it was before being added to the group.
145+
if sActionControl is not empty then
146+
lock screen
147+
set the visible of sActionControl to false
148+
relayer sActionControl to back of sActionControlOwner
149+
unlock screen
150+
end if
151+
152+
return empty
153+
end DG2_EditModeActionControlHideComplete
154+
155+
on mouseUp
156+
local tRowControl
157+
put the dgDataControlOfIndex[sRowIndex] of the dgControl of me into tRowControl
158+
if tRowControl is empty then
159+
exit mouseUp
160+
end if
161+
162+
if the long id of the target contains the long id of sActionControl then
163+
dispatch DG2_GetMessageNameForTag("EditModeActionControlClicked") to tRowControl with the target
164+
else
165+
DG2_EditModeActionControlHide
166+
dispatch DG2_GetMessageNameForTag("EditModeActionControlHidden") to tRowControl
167+
end if
168+
end mouseUp

0 commit comments

Comments
 (0)