mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-13 19:49:40 +08:00
fix(drag-drop): Restore support for thread dragging
This commit is contained in:
parent
4affeff58e
commit
e33c10b61e
5 changed files with 23 additions and 22 deletions
|
@ -80,25 +80,32 @@ class SidebarItem
|
||||||
selected: isItemSelected(perspective)
|
selected: isItemSelected(perspective)
|
||||||
collapsed: isItemCollapsed(id) ? true
|
collapsed: isItemCollapsed(id) ? true
|
||||||
counterStyle: counterStyle
|
counterStyle: counterStyle
|
||||||
dataTransferType: 'nylas-threads-data'
|
|
||||||
onDelete: if opts.deletable then onDeleteItem else undefined
|
onDelete: if opts.deletable then onDeleteItem else undefined
|
||||||
onEdited: if opts.editable then onEditItem else undefined
|
onEdited: if opts.editable then onEditItem else undefined
|
||||||
onCollapseToggled: toggleItemCollapsed
|
onCollapseToggled: toggleItemCollapsed
|
||||||
|
|
||||||
onDrop: (item, event) ->
|
onDrop: (item, event) ->
|
||||||
jsonString = event.dataTransfer.getData(item.dataTransferType)
|
jsonString = event.dataTransfer.getData('nylas-threads-data')
|
||||||
data = Utils.jsonParse(jsonString)
|
jsonData = null
|
||||||
return unless data
|
try
|
||||||
item.perspective.receiveThreads(data.threadIds)
|
jsonData = JSON.parse(jsonString)
|
||||||
|
catch err
|
||||||
|
console.error("JSON parse error: #{err}")
|
||||||
|
return unless jsonData
|
||||||
|
item.perspective.receiveThreads(jsonData.threadIds)
|
||||||
|
|
||||||
shouldAcceptDrop: (item, event) ->
|
shouldAcceptDrop: (item, event) ->
|
||||||
target = item.perspective
|
target = item.perspective
|
||||||
current = FocusedPerspectiveStore.current()
|
current = FocusedPerspectiveStore.current()
|
||||||
jsonString = event.dataTransfer.getData(item.dataTransferType)
|
return false unless event.dataTransfer.types.includes('nylas-threads-data')
|
||||||
data = Utils.jsonParse(jsonString)
|
|
||||||
return false unless data
|
|
||||||
return false unless target
|
|
||||||
return false if target.isEqual(current)
|
return false if target.isEqual(current)
|
||||||
return false unless target.canReceiveThreadsFromAccountIds(data.accountIds)
|
|
||||||
return item.dataTransferType in event.dataTransfer.types
|
# We can't inspect the drag payload until drop, so we use a dataTransfer
|
||||||
|
# type to encode the account IDs of threads currently being dragged.
|
||||||
|
accountsType = event.dataTransfer.types.find((t) => t.startsWith('nylas-accounts='))
|
||||||
|
accountIds = (accountsType || "").replace('nylas-accounts=', '').split(',')
|
||||||
|
return target.canReceiveThreadsFromAccountIds(accountIds)
|
||||||
|
|
||||||
onSelect: (item) ->
|
onSelect: (item) ->
|
||||||
Actions.focusMailboxPerspective(item.perspective)
|
Actions.focusMailboxPerspective(item.perspective)
|
||||||
}, opts)
|
}, opts)
|
||||||
|
|
|
@ -70,7 +70,7 @@ class UpdateChannelSection extends React.Component {
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
available.map((channel) => {
|
available.map((channel) => {
|
||||||
return (<option value={channel.name}>
|
return (<option value={channel.name} key={channel.name}>
|
||||||
{channel.name[0].toUpperCase() + channel.name.substr(1)}
|
{channel.name[0].toUpperCase() + channel.name.substr(1)}
|
||||||
</option>);
|
</option>);
|
||||||
})
|
})
|
||||||
|
|
|
@ -197,7 +197,8 @@ class ThreadList extends React.Component
|
||||||
|
|
||||||
canvas = CanvasUtils.canvasWithThreadDragImage(data.threadIds.length)
|
canvas = CanvasUtils.canvasWithThreadDragImage(data.threadIds.length)
|
||||||
event.dataTransfer.setDragImage(canvas, 10, 10)
|
event.dataTransfer.setDragImage(canvas, 10, 10)
|
||||||
event.dataTransfer.setData('nylas-threads-data', JSON.stringify(data))
|
event.dataTransfer.setData("nylas-threads-data", JSON.stringify(data))
|
||||||
|
event.dataTransfer.setData("nylas-accounts=#{data.accountIds.join(',')}", "1")
|
||||||
return
|
return
|
||||||
|
|
||||||
_onDragEnd: (event) =>
|
_onDragEnd: (event) =>
|
||||||
|
|
|
@ -3,11 +3,13 @@ ThreadDragImage.src = """data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgC
|
||||||
|
|
||||||
DragCanvas = document.createElement("canvas")
|
DragCanvas = document.createElement("canvas")
|
||||||
DragCanvas.style.position = "absolute"
|
DragCanvas.style.position = "absolute"
|
||||||
|
DragCanvas.style.zIndex = 0
|
||||||
document.body.appendChild(DragCanvas)
|
document.body.appendChild(DragCanvas)
|
||||||
|
|
||||||
PercentLoadedCache = {}
|
PercentLoadedCache = {}
|
||||||
PercentLoadedCanvas = document.createElement("canvas")
|
PercentLoadedCanvas = document.createElement("canvas")
|
||||||
PercentLoadedCanvas.style.position = "absolute"
|
PercentLoadedCanvas.style.position = "absolute"
|
||||||
|
PercentLoadedCanvas.style.zIndex = 0
|
||||||
document.body.appendChild(PercentLoadedCanvas)
|
document.body.appendChild(PercentLoadedCanvas)
|
||||||
|
|
||||||
SystemTrayCanvas = document.createElement("canvas")
|
SystemTrayCanvas = document.createElement("canvas")
|
||||||
|
|
|
@ -514,15 +514,6 @@ Utils =
|
||||||
fn.apply(@, [fnFinished, fnReinvoked, arguments...])
|
fn.apply(@, [fnFinished, fnReinvoked, arguments...])
|
||||||
fnRun
|
fnRun
|
||||||
|
|
||||||
# Parse json without throwing an error. Logs a sensible message to indicate
|
|
||||||
# the error occurred while parsing
|
|
||||||
jsonParse: (jsonString) =>
|
|
||||||
data = null
|
|
||||||
try
|
|
||||||
data = JSON.parse(jsonString)
|
|
||||||
catch err
|
|
||||||
console.error("JSON parse error: #{err}")
|
|
||||||
return data
|
|
||||||
|
|
||||||
hueForString: (str='') ->
|
hueForString: (str='') ->
|
||||||
str.split('').map((c) -> c.charCodeAt()).reduce((n,a) -> n+a) % 360
|
str.split('').map((c) -> c.charCodeAt()).reduce((n,a) -> n+a) % 360
|
||||||
|
|
Loading…
Reference in a new issue