mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-12-10 22:46:26 +08:00
Basic fixes for drag and drop
This commit is contained in:
parent
470fbae6a3
commit
53390fbd5c
5 changed files with 34 additions and 46 deletions
|
|
@ -60,15 +60,26 @@ class SidebarItem
|
|||
dataTransferType: 'nylas-thread-ids'
|
||||
onDelete: onDeleteItem
|
||||
onToggleCollapsed: toggleItemCollapsed
|
||||
onDrop: (item, ids) ->
|
||||
onDrop: (item, event) ->
|
||||
jsonString = event.dataTransfer.getData(item.dataTransferType)
|
||||
ids = null
|
||||
try
|
||||
ids = JSON.parse(jsonString);
|
||||
catch err
|
||||
console.error('OutlineViewItem onDrop: JSON parse #{err}');
|
||||
return unless ids
|
||||
item.perspective.applyToThreads(ids)
|
||||
shouldAcceptDrop: (item, event) ->
|
||||
perspective = item.perspective
|
||||
return false unless perspective
|
||||
return false if perspective.isEqual(FocusedPerspectiveStore.current())
|
||||
return false unless perspective.canApplyToThreads()
|
||||
item.dataTransferType in event.dataTransfer.types
|
||||
target = item.perspective
|
||||
current = FocusedPerspectiveStore.current()
|
||||
|
||||
return false unless target
|
||||
return false if target.isEqual(current)
|
||||
return false unless _.isEqual(target.accountIds, current.accountIds)
|
||||
return false unless target.canApplyToThreads()
|
||||
|
||||
return item.dataTransferType in event.dataTransfer.types
|
||||
|
||||
onSelect: (item) ->
|
||||
Actions.selectRootSheet(WorkspaceStore.Sheet.Threads)
|
||||
Actions.focusMailboxPerspective(item.perspective)
|
||||
|
|
|
|||
|
|
@ -108,6 +108,8 @@ class ListTabular extends React.Component
|
|||
@setState(@buildStateForRange(start: rangeStart, end: rangeEnd))
|
||||
|
||||
render: =>
|
||||
otherProps = _.omit(@props, _.keys(@constructor.propTypes))
|
||||
|
||||
innerStyles =
|
||||
height: @state.count * @props.itemHeight
|
||||
|
||||
|
|
@ -122,7 +124,7 @@ class ListTabular extends React.Component
|
|||
tabIndex="-1"
|
||||
className="list-container list-tabular"
|
||||
scrollTooltipComponent={@props.scrollTooltipComponent}>
|
||||
<div className="list-rows" style={innerStyles}>
|
||||
<div className="list-rows" style={innerStyles} {...otherProps}>
|
||||
{@_rows()}
|
||||
</div>
|
||||
</ScrollRegion>
|
||||
|
|
|
|||
|
|
@ -64,8 +64,9 @@ class OutlineViewItem extends Component {
|
|||
_runCallback = (method, ...args)=> {
|
||||
const item = this.props.item;
|
||||
if (item[method]) {
|
||||
item[method](item, ...args);
|
||||
return item[method](item, ...args);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -76,17 +77,7 @@ class OutlineViewItem extends Component {
|
|||
}
|
||||
|
||||
_onDrop = (event)=> {
|
||||
const item = this.props.item;
|
||||
const jsonString = event.dataTransfer.getData(item.dataTransferType);
|
||||
let ids;
|
||||
try {
|
||||
ids = JSON.parse(jsonString);
|
||||
} catch (err) {
|
||||
console.error('OutlineViewItem onDrop: JSON parse #{err}');
|
||||
}
|
||||
if (!ids) return;
|
||||
|
||||
this._runCallback('onDrop', ids);
|
||||
this._runCallback('onDrop', event);
|
||||
}
|
||||
|
||||
_onToggleCollapsed = ()=> {
|
||||
|
|
@ -103,7 +94,7 @@ class OutlineViewItem extends Component {
|
|||
}
|
||||
|
||||
_shouldAcceptDrop = (event)=> {
|
||||
this._runCallback('shouldAcceptDrop', event);
|
||||
return this._runCallback('shouldAcceptDrop', event);
|
||||
}
|
||||
|
||||
_onShowContextMenu = ()=> {
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ class QueryResultSet
|
|||
if @_idToIndexHash is null
|
||||
@buildIdToIndexHash()
|
||||
|
||||
if @_idToIndexHash[id]
|
||||
if @_idToIndexHash[id] isnt undefined
|
||||
return @_idToIndexHash[id] + @_offset
|
||||
else
|
||||
return -1
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
_ = require 'underscore'
|
||||
|
||||
TaskFactory = require './flux/tasks/task-factory'
|
||||
AccountStore = require './flux/stores/account-store'
|
||||
CategoryStore = require './flux/stores/category-store'
|
||||
DatabaseStore = require './flux/stores/database-store'
|
||||
|
|
@ -233,31 +234,14 @@ class CategoryMailboxPerspective extends MailboxPerspective
|
|||
super
|
||||
|
||||
applyToThreads: (threadsOrIds) =>
|
||||
# TODO:
|
||||
# categoryToApplyForAccount = {}
|
||||
# for cat in @_categories
|
||||
# categoryToApplyForAccount[cat.accountId] = cat
|
||||
#
|
||||
# @_categories.forEach (cat) ->
|
||||
#
|
||||
# if @account.usesLabels()
|
||||
# FocusedPerspectiveStore = require './flux/stores/focused-perspective-store'
|
||||
# currentLabel = FocusedPerspectiveStore.current().category
|
||||
# if currentLabel and not (currentLabel.isLockedCategory())
|
||||
# labelsToRemove = [currentLabel]
|
||||
#
|
||||
# ChangeLabelsTask = require './flux/tasks/change-labels-task'
|
||||
# task = new ChangeLabelsTask
|
||||
# threads: threadsOrIds
|
||||
# labelsToAdd: [@category]
|
||||
# labelsToRemove: labelsToRemove
|
||||
# else
|
||||
# ChangeFolderTask = require './flux/tasks/change-folder-task'
|
||||
# task = new ChangeFolderTask
|
||||
# threads: threadsOrIds
|
||||
# folder: @category
|
||||
#
|
||||
# Actions.queueTask(task)
|
||||
FocusedPerspectiveStore = require './flux/stores/focused-perspective-store'
|
||||
currentCategories = FocusedPerspectiveStore.current().categories()
|
||||
|
||||
DatabaseStore.modelify(Thread, threadsOrIds).then (threads) =>
|
||||
tasks = TaskFactory.tasksForApplyingCategories
|
||||
threads: threads
|
||||
categoriesToRemove: (accountId) -> _.filter(currentCategories, _.matcher({accountId}))
|
||||
categoryToAdd: (accountId) => _.findWhere(@_categories, {accountId})
|
||||
Actions.queueTasks(tasks)
|
||||
|
||||
module.exports = MailboxPerspective
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue