Skip to content

Commit

Permalink
Draggable list (#141)
Browse files Browse the repository at this point in the history
* Allow items from the regular browser to be dragged and dropped into the material browser.

* Temporary working version of drag and drop

* nearly finished version of draggable lists
  • Loading branch information
westphal-jan committed Jul 25, 2018
1 parent dd55b49 commit 24a5712
Show file tree
Hide file tree
Showing 26 changed files with 89 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
event handling
forVisibleItemIndicesDo: aBlock

self lastVisibleItem = 0 ifTrue: [^ self].
self firstVisibleItem to: self lastVisibleItem do: aBlock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ globalPositionToIndex: aPoint

| position index |
position := aPoint - self position + self scrollOffset.
index := (position y / (self listItemHeight + self listItemPadding)) ceiling.
index := (position y / (self listItemHeight + self listItemPadding)) ceiling min: self filteredListItems size.

^ index
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
event handling
ifInBounds: anIndex do: aBlock

self filteredListItems size >= anIndex
(self filteredListItems size >= anIndex and: anIndex > 0)
ifTrue: [aBlock value: (self filteredListItems at: anIndex)]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ event handling
newSelectedItem: aListItem

self selectedItem ifNotNil: [:item | item toggleOff].
self selectedItem: aListItem.
"Find out why this crashs the image"
self flag: #todo
"self selectedItem toggleOn"
self selectedItem: aListItem
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
"filteredListItems" : "CG 7/1/2018 12:07",
"filteredListItems:" : "CG 7/1/2018 12:07",
"firstVisibleItem" : "mats 7/10/2018 12:51",
"forVisibleItemIndicesDo:" : "LS 6/28/2018 17:37",
"forVisibleItemIndicesDo:" : "JW 7/10/2018 00:00",
"globalBoundsOfLabelOfItem:at:" : "LS 7/10/2018 12:15",
"globalPositionOfFirstVisibleItem" : "LS 6/28/2018 17:37",
"globalPositionOfItemAt:" : "LS 6/28/2018 17:36",
"globalPositionToIndex:" : "mats 7/10/2018 12:51",
"globalPositionToIndex:" : "JW 7/25/2018 14:18",
"globalPositionToPositionInListItem:" : "mats 6/14/2018 12:07",
"handlesMouseDown:" : "mats 5/30/2018 11:46",
"handlesMouseMove:" : "mats 5/30/2018 13:19",
Expand All @@ -46,7 +46,7 @@
"handlesMouseWheel:" : "mats 5/29/2018 21:43",
"hasDenseLayout" : "mats 7/10/2018 12:49",
"hasFilter" : "CG 7/1/2018 12:08",
"ifInBounds:do:" : "mats 7/3/2018 15:30",
"ifInBounds:do:" : "JW 7/19/2018 12:31",
"initialize" : "Max 7/25/2018 11:43",
"lastKeystrokes" : "CG 7/1/2018 12:08",
"lastKeystrokes:" : "CG 7/1/2018 12:08",
Expand All @@ -61,9 +61,9 @@
"maxScrollDelta" : "LS 6/28/2018 17:27",
"mouseDown:" : "LS 6/28/2018 21:20",
"mouseLeave:" : "mats 6/14/2018 12:08",
"mouseMove:" : "mats 7/9/2018 15:09",
"mouseMove:" : "JW 7/20/2018 11:58",
"mouseUp:" : "mats 7/3/2018 15:18",
"newSelectedItem:" : "JW 6/21/2018 01:03",
"newSelectedItem:" : "JW 7/25/2018 14:32",
"relativePositionOfFirstVisibleItem" : "LS 6/28/2018 17:37",
"relativePositionOfItemAt:" : "mats 7/10/2018 12:51",
"removeFilter" : "mats 7/10/2018 11:17",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
as yet unclassified
doubleClick: event
| index |
doubleClickSelector ifNil: [^super doubleClick: event].
index := self rowAtLocation: event position.
index = 0 ifTrue: [^super doubleClick: event].
^ self model perform: doubleClickSelector
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
event handling
modelSelect: anIndex

(self model perform: self selected) = 0
ifFalse: [(self listItems at: (self model perform: self selected)) deselect].

self ifInBounds: anIndex do: [:listitem |
self model perform: self changeSelected with: anIndex.
listitem select]
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
event handling
mouseDown: evt

super mouseDown: evt.
| selectors |
self selectListItem: evt.

evt yellowButtonPressed "First check for option (menu) click"
ifTrue: [^ self yellowButtonActivity: evt shiftPressed]
ifTrue: [^ self yellowButtonActivity: evt shiftPressed].

selectors := Array
with: #click:
with: (doubleClickSelector ifNotNil:[#doubleClick:])
with: nil
with: (self dragEnabled ifTrue:[#startDrag:] ifFalse:[nil]).
evt hand waitForClicksOrDrag: self event: evt selectors: selectors threshold: HandMorph dragThreshold "pixels".
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ mouseEnterDragging: evt
(evt hand hasSubmorphs and:[self dropEnabled]) ifFalse: ["no d&d"
^super mouseEnterDragging: evt].

(self wantsDroppedMorph: evt hand firstSubmorph event: evt )
ifTrue:[
(self wantsDroppedMorph: evt hand firstSubmorph event: evt)
ifTrue: [
potentialDropRow := self rowAtLocation: evt position.
evt hand newMouseFocus: self.
self changed.
"above is ugly but necessary for now"
]
self changed]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
event handling
mouseLeaveDragging: anEvent

(self dropEnabled and:[anEvent hand hasSubmorphs]) ifFalse: ["no d&d"
(self dropEnabled and: [anEvent hand hasSubmorphs]) ifFalse: ["no d&d"
^ super mouseLeaveDragging: anEvent].
self resetPotentialDropRow.
anEvent hand releaseMouseFocus: self
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
event handling
selectListItem: evt

| index mouseEvent mouseEvtPos |
self filteredListItems ifEmpty: [^ self].

index := self globalPositionToIndex: evt position.
self modelSelect: index.
mouseEvtPos := self globalPositionToPositionInListItem: evt position.
mouseEvent := evt copy position: mouseEvtPos.

self ifInBounds: index do: [:listItem |
listItem mouseDown: mouseEvent.
listItem select.
self newSelectedItem: listItem].
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
selection

^ self selectedItem
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"clearFilterAutomatically" : "CG 7/11/2018 17:40",
"clearFilterAutomatically:" : "CG 7/11/2018 17:40",
"commandKeyTypedIntoMenu:" : "mats 7/9/2018 15:31",
"doubleClick:" : "JW 7/25/2018 14:20",
"doubleClickSelector" : "CG 7/11/2018 17:41",
"doubleClickSelector:" : "CG 7/11/2018 17:41",
"filterableList" : "mats 7/9/2018 16:51",
Expand Down Expand Up @@ -54,23 +55,26 @@
"menu:" : "CG 7/11/2018 17:55",
"model" : "CG 7/11/2018 17:55",
"model:" : "mats 7/10/2018 11:07",
"modelSelect:" : "JW 7/25/2018 14:29",
"modifierKeyPressed:" : "CG 7/11/2018 17:56",
"mouseDown:" : "mats 7/9/2018 16:43",
"mouseDown:" : "JW 7/25/2018 14:25",
"mouseEnter:" : "LS 7/12/2018 11:45",
"mouseEnterDragging:" : "CG 7/11/2018 17:56",
"mouseEnterDragging:" : "JW 7/25/2018 14:29",
"mouseLeave:" : "LS 7/12/2018 11:37",
"mouseLeaveDragging:" : "CG 7/11/2018 17:56",
"mouseMove:" : "CG 7/11/2018 17:56",
"mouseLeaveDragging:" : "JW 7/25/2018 11:06",
"mouseMove:" : "JW 7/25/2018 11:12",
"numSelectionsInView" : "mats 7/10/2018 11:33",
"potentialDropRow" : "CG 7/11/2018 17:57",
"previewKeystroke:" : "CG 7/11/2018 17:57",
"priorSelection" : "CG 7/11/2018 17:57",
"priorSelection:" : "CG 7/11/2018 17:57",
"resetPotentialDropRow" : "CG 7/11/2018 17:57",
"rowAtLocation:" : "JW 7/6/2018 16:58",
"selectListItem:" : "JW 7/25/2018 14:27",
"selected" : "CG 7/11/2018 17:58",
"selected:" : "CG 7/11/2018 17:58",
"selectionIndex" : "mats 7/9/2018 16:53",
"selection" : "JW 7/9/2018 23:29",
"selectionIndex" : "JW 7/19/2018 12:29",
"specialKeyPressed:" : "LS 7/12/2018 13:27",
"update:" : "mats 7/10/2018 14:00",
"updateList" : "mats 7/10/2018 13:54",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ drag and drop
acceptDroppingMorph: aTransferMorph event: evt

dropItemSelector ifNil: [^ self].
Transcript show: potentialDropRow.
potentialDropRow ifNil: [^ self].

model
perform: dropItemSelector
withEnoughArguments: {
aTransferMorph passenger.
"self modelIndexFor: self potentialDropRow."
self potentialDropRow.
aTransferMorph shouldCopy.
aTransferMorph}.

self resetPotentialDropRow.
evt hand releaseMouseFocus: self.
Cursor normal show
Cursor normal show.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing
dragItemSelector: anObject

dragItemSelector := anObject
dragItemSelector: aSymbol
dragItemSelector := aSymbol.
aSymbol ifNotNil:[self dragEnabled: true].
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
accessing
dragItemSelector

^ dragItemSelector
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
accessing
dragStartedSelector: anObject

dragStartedSelector := anObject
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
accessing
dragStartedSelector

^ dragStartedSelector
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
accessing
dragTypeSelector: anObject

dragTypeSelector := anObject
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
accessing
dragTypeSelector

^ dragTypeSelector
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
accessing
dropItemSelector: aSymbol

dropItemSelector := aSymbol.
aSymbol ifNotNil:[self dropEnabled: true]
aSymbol ifNotNil:[self dropEnabled: true].
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
accessing
dropItemSelector

^ dropItemSelector
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
drag and drop
startDrag: evt

| item itemMorph modelIndex |
| item itemMorph modelIndex |
dragItemSelector ifNil:[^self].
evt hand hasSubmorphs ifTrue: [^ self].
self model okToChange ifFalse: [^ self].

"Ensure selection to save additional click."
(self modelIndexFor: (self rowAtLocation: evt position)) in: [:evtIndex |
self selectionIndex = evtIndex ifFalse: [self changeModelSelection: evtIndex]].

item := self selection ifNil: [^ self].
itemMorph := StringMorph contents: item asStringOrText.
modelIndex := self modelIndexFor: self selectionIndex.

[ "Initiate drag."
modelIndex := self selectionIndex.
modelIndex = 0 ifTrue: [^ self].
[ "Initiate drag."
(self model perform: dragItemSelector with: modelIndex) ifNotNil: [:passenger | | ddm |
ddm := (self valueOfProperty: #dragTransferClass ifAbsent: [TransferMorph]) withPassenger: passenger from: self.
ddm dragTransferType: (self dragTypeSelector ifNotNil: [:s | self model perform: s with: modelIndex]).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
accessing
wantsDropSelector: anObject

wantsDropSelector := anObject
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
accessing
wantsDropSelector

^ wantsDropSelector
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"class" : {
},
"instance" : {
"acceptDroppingMorph:event:" : "CG 7/11/2018 18:00",
"dragItemSelector" : "CG 7/11/2018 18:00",
"dragItemSelector:" : "CG 7/11/2018 18:00",
"dragStartedSelector" : "CG 7/11/2018 18:01",
"dragStartedSelector:" : "CG 7/11/2018 18:01",
"dragTypeSelector" : "CG 7/11/2018 18:01",
"dragTypeSelector:" : "CG 7/11/2018 18:01",
"dropItemSelector" : "CG 7/11/2018 18:01",
"dropItemSelector:" : "CG 7/11/2018 18:02",
"startDrag:" : "JW 7/6/2018 16:32",
"wantsDropSelector" : "CG 7/11/2018 18:02",
"wantsDropSelector:" : "CG 7/11/2018 18:02",
"acceptDroppingMorph:event:" : "JW 7/25/2018 14:30",
"dragItemSelector" : "JW 7/6/2018 15:14",
"dragItemSelector:" : "JW 7/10/2018 00:11",
"dragStartedSelector" : "JW 7/6/2018 15:15",
"dragStartedSelector:" : "JW 7/6/2018 15:15",
"dragTypeSelector" : "JW 7/6/2018 15:15",
"dragTypeSelector:" : "JW 7/6/2018 15:15",
"dropItemSelector" : "JW 7/6/2018 15:14",
"dropItemSelector:" : "JW 7/6/2018 16:50",
"startDrag:" : "JW 7/25/2018 14:32",
"wantsDropSelector" : "JW 7/6/2018 15:14",
"wantsDropSelector:" : "JW 7/6/2018 15:14",
"wantsDroppedMorph:event:" : "JW 7/6/2018 15:44" } }

0 comments on commit 24a5712

Please sign in to comment.