From 45466a18b0aabf9ed7724877517697a6b9cf72a4 Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Fri, 23 Oct 2015 14:45:28 -0700 Subject: [PATCH] fix(archive): can archive and trash from focused message --- .../message-list/lib/message-list.cjsx | 8 --- .../message-list/spec/message-list-spec.cjsx | 5 -- .../thread-list/lib/draft-list.cjsx | 2 +- .../thread-list/lib/thread-list.cjsx | 66 ++++++++++++------- keymaps/base.cson | 4 +- keymaps/templates/Apple Mail.cson | 4 +- keymaps/templates/Gmail.cson | 29 ++++---- keymaps/templates/Outlook.cson | 4 +- src/flux/tasks/task-factory.coffee | 16 ++--- 9 files changed, 72 insertions(+), 66 deletions(-) diff --git a/internal_packages/message-list/lib/message-list.cjsx b/internal_packages/message-list/lib/message-list.cjsx index 28c44ae86..19efcff08 100755 --- a/internal_packages/message-list/lib/message-list.cjsx +++ b/internal_packages/message-list/lib/message-list.cjsx @@ -74,7 +74,6 @@ class MessageList extends React.Component @_unsubscribers.push MessageStore.listen @_onChange commands = _.extend {}, - 'core:star-item': => @_onStar() 'application:reply': => @_createReplyOrUpdateExistingDraft('reply') 'application:reply-all': => @_createReplyOrUpdateExistingDraft('reply-all') 'application:forward': => @_onForward() @@ -178,13 +177,6 @@ class MessageList extends React.Component session.changes.add(updated) @_focusDraft(@_getMessageContainer(draft.clientId)) - _onStar: => - return unless @state.currentThread - threads = [@state.currentThread] - starred = not @state.currentThread.starred - task = new ChangeStarredTask({threads, starred}) - Actions.queueTask(task) - _onForward: => return unless @state.currentThread Actions.composeForward(thread: @state.currentThread) diff --git a/internal_packages/message-list/spec/message-list-spec.cjsx b/internal_packages/message-list/spec/message-list-spec.cjsx index 0b1c8d491..69e88c1b1 100644 --- a/internal_packages/message-list/spec/message-list-spec.cjsx +++ b/internal_packages/message-list/spec/message-list-spec.cjsx @@ -206,11 +206,6 @@ describe "MessageList", -> MessageParticipants) expect(items.length).toBe 1 - it "toggles star on a thread if 'core:star-item' is fired", -> - spyOn(@messageList, "_onStar") - atom.keymaps.dispatchCommandEvent('core:star-item', document.body, new KeyboardEvent('keydown')) - expect(@messageList._onStar).toHaveBeenCalled() - it "focuses new composers when a draft is added", -> spyOn(@messageList, "_focusDraft") msgs = @messageList.state.messages diff --git a/internal_packages/thread-list/lib/draft-list.cjsx b/internal_packages/thread-list/lib/draft-list.cjsx index 3698f97b4..874dc5406 100644 --- a/internal_packages/thread-list/lib/draft-list.cjsx +++ b/internal_packages/thread-list/lib/draft-list.cjsx @@ -50,7 +50,7 @@ class DraftList extends React.Component @columns = [c1, c2, c3] @commands = - 'core:remove-item': @_onDelete + 'core:remove-from-view': @_onDelete render: => - _shift(offset: 1, afterRunning: @_onBackspace) + _shift(offset: 1, afterRunning: @_onRemoveFromView) 'core:remove-and-next': => - _shift(offset: -1, afterRunning: @_onBackspace) + _shift(offset: -1, afterRunning: @_onRemoveFromView) @itemPropsProvider = (item) -> className: classNames @@ -260,40 +262,58 @@ class ThreadList extends React.Component # Additional Commands - _onStarItem: => - return unless ThreadListStore.view() - + _threadsForKeyboardAction: -> + return null unless ThreadListStore.view() focused = FocusedContentStore.focused('thread') - - if WorkspaceStore.layoutMode() is "list" and WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread - threads = [focused] + if focused + return [focused] else if ThreadListStore.view().selection.count() > 0 - threads = ThreadListStore.view().selection.items() + return ThreadListStore.view().selection.items() else - threads = [focused] + return null + _onStarItem: => + threads = @_threadsForKeyboardAction() + return unless threads task = TaskFactory.taskForInvertingStarred({threads}) Actions.queueTask(task) - _onBackspace: => - return unless ThreadListStore.view() + _onRemoveFromView: => + threads = @_threadsForKeyboardAction() + if threads + if FocusedMailViewStore.mailView().canArchiveThreads() + removeMethod = TaskFactory.taskForArchiving + else if FocusedMailViewStore.mailView().canTrashThreads() + removeMethod = TaskFactory.taskForMovingToTrash + else + return - focused = FocusedContentStore.focused('thread') - - if WorkspaceStore.layoutMode() is "split" and focused - task = TaskFactory.taskForMovingToTrash - threads: [focused] + task = removeMethod + threads: threads fromView: FocusedMailViewStore.mailView() Actions.queueTask(task) - else if ThreadListStore.view().selection.count() > 0 - task = TaskFactory.taskForMovingToTrash - threads: ThreadListStore.view().selection.items() + Actions.popSheet() + + _onArchiveItem: => + return unless FocusedMailViewStore.mailView().canArchiveThreads() + threads = @_threadsForKeyboardAction() + if threads + task = TaskFactory.taskForArchiving + threads: threads fromView: FocusedMailViewStore.mailView() Actions.queueTask(task) + Actions.popSheet() - else if WorkspaceStore.layoutMode() is "list" and WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread - Actions.popSheet() + _onDeleteItem: => + return unless FocusedMailViewStore.mailView().canTrashThreads() + threads = @_threadsForKeyboardAction() + if threads + task = TaskFactory.taskForMovingToTrash + threads: threads + fromView: FocusedMailViewStore.mailView() + Actions.queueTask(task) + Actions.popSheet() module.exports = ThreadList diff --git a/keymaps/base.cson b/keymaps/base.cson index 31b02ec62..4ced4683c 100644 --- a/keymaps/base.cson +++ b/keymaps/base.cson @@ -9,8 +9,9 @@ 'cmd-,' : 'application:open-preferences' 'up' : 'core:previous-item' 'down' : 'core:next-item' - 'backspace': 'core:remove-item' 'enter' : 'core:focus-item' + 'delete': 'core:remove-from-view' + 'backspace': 'core:remove-from-view' # Default cross-platform core behaviors 'left': 'core:move-left' @@ -21,7 +22,6 @@ 'shift-right': 'core:select-right' 'shift-pageup': 'core:select-page-up' 'shift-pagedown': 'core:select-page-down' - 'delete': 'core:delete' 'shift-delete': 'core:cut' # Inputs are native by default. diff --git a/keymaps/templates/Apple Mail.cson b/keymaps/templates/Apple Mail.cson index a4f1fd467..85853b9ac 100644 --- a/keymaps/templates/Apple Mail.cson +++ b/keymaps/templates/Apple Mail.cson @@ -9,7 +9,7 @@ 'cmd-alt-f': 'application:focus-search' 'cmd-D': 'application:send-message' 'cmd-V': 'application:change-category' - 'delete' : 'core:remove-item' + 'cmd-e' : 'core:archive-item' 'body.platform-linux, body.platform-win32': 'ctrl-n' : 'application:new-message' @@ -19,4 +19,4 @@ 'ctrl-alt-f': 'application:focus-search' 'ctrl-D': 'application:send-message' 'ctrl-shift-v': 'application:change-category' - 'delete' : 'core:remove-item' + 'ctrl-e' : 'core:archive-item' diff --git a/keymaps/templates/Gmail.cson b/keymaps/templates/Gmail.cson index 3d4e6b639..73e99613a 100644 --- a/keymaps/templates/Gmail.cson +++ b/keymaps/templates/Gmail.cson @@ -5,23 +5,22 @@ # darwin-gmail.cson, darwin-macmail.cson, win32-gmail.cson... 'body': - 'c' : 'application:new-message' # Gmail - '/' : 'application:focus-search' # Gmail + 'c' : 'application:new-message' + '/' : 'application:focus-search' - 'r' : 'application:reply' # Gmail - 'R' : 'application:reply-all' # N1 - 'a' : 'application:reply-all' # Gmail - 'f' : 'application:forward' # Gmail - 'l' : 'application:change-category' # Gmail - 'u' : 'application:pop-sheet' # Gmail - 'delete' : 'application:pop-sheet' + 'r' : 'application:reply' + 'a' : 'application:reply-all' + 'f' : 'application:forward' + 'l' : 'application:change-category' + 'u' : 'application:pop-sheet' - 'k' : 'core:previous-item' # Gmail - 'j' : 'core:next-item' # Gmail - ']' : 'core:remove-and-previous' # Gmail - '[' : 'core:remove-and-next' # Gmail - 'e' : 'core:remove-item' # Gmail - 's' : 'core:star-item' #Gmail + 'k' : 'core:previous-item' + 'j' : 'core:next-item' + ']' : 'core:remove-and-previous' + '[' : 'core:remove-and-next' + '#' : 'core:delete-item' + 'e' : 'core:archive-item' + 's' : 'core:star-item' 'x' : 'core:select-item' # Gmail also includes some more basic ones that users expect from desktop software. diff --git a/keymaps/templates/Outlook.cson b/keymaps/templates/Outlook.cson index b99832e2d..8047a77fe 100644 --- a/keymaps/templates/Outlook.cson +++ b/keymaps/templates/Outlook.cson @@ -8,7 +8,7 @@ 'cmd-e': 'application:focus-search' 'cmd-f': 'application:forward' 'cmd-shift-v': 'application:change-category' - 'cmd-d': 'core:remove-item' + 'cmd-d': 'core:delete-item' 'alt-backspace':'core:undo' 'alt-s': 'application:send-message' 'cmd-r': 'application:reply' @@ -24,7 +24,7 @@ 'ctrl-e': 'application:focus-search' 'ctrl-f': 'application:forward' 'ctrl-shift-v': 'application:change-category' - 'ctrl-d': 'core:remove-item' + 'ctrl-d': 'core:delete-item' 'alt-backspace':'core:undo' 'alt-s': 'application:send-message' 'ctrl-r': 'application:reply' diff --git a/src/flux/tasks/task-factory.coffee b/src/flux/tasks/task-factory.coffee index 3e6b6e1c7..6bc4ef8f3 100644 --- a/src/flux/tasks/task-factory.coffee +++ b/src/flux/tasks/task-factory.coffee @@ -8,7 +8,7 @@ CategoryStore = require '../stores/category-store' class TaskFactory - taskForApplyingCategory: ({threads, fromView, category, exclusive}) -> + taskForApplyingCategory: ({threads, fromView, category, exclusive}) => account = AccountStore.current() if account.usesFolders() return null unless category @@ -27,7 +27,7 @@ class TaskFactory labelsToRemove: labelsToRemove labelsToAdd: [category] - taskForRemovingCategory: ({threads, fromView, category, exclusive}) -> + taskForRemovingCategory: ({threads, fromView, category, exclusive}) => account = AccountStore.current() if account.usesFolders() return new ChangeFolderTask @@ -45,27 +45,27 @@ class TaskFactory labelsToRemove: [category] labelsToAdd: labelsToAdd - taskForArchiving: ({threads, fromView}) -> + taskForArchiving: ({threads, fromView}) => category = CategoryStore.getArchiveCategory() @taskForApplyingCategory({threads, fromView, category, exclusive: true}) - taskForUnarchiving: ({threads, fromView}) -> + taskForUnarchiving: ({threads, fromView}) => category = CategoryStore.getArchiveCategory() @taskForRemovingCategory({threads, fromView, category, exclusive: true}) - taskForMovingToTrash: ({threads, fromView}) -> + taskForMovingToTrash: ({threads, fromView}) => category = CategoryStore.getTrashCategory() @taskForApplyingCategory({threads, fromView, category, exclusive: true}) - taskForMovingFromTrash: ({threads, fromView}) -> + taskForMovingFromTrash: ({threads, fromView}) => category = CategoryStore.getTrashCategory() @taskForRemovingCategory({threads, fromView, category, exclusive: true}) - taskForInvertingUnread: ({threads}) -> + taskForInvertingUnread: ({threads}) => unread = _.every threads, (t) -> _.isMatch(t, {unread: false}) return new ChangeUnreadTask({threads, unread}) - taskForInvertingStarred: ({threads}) -> + taskForInvertingStarred: ({threads}) => starred = _.every threads, (t) -> _.isMatch(t, {starred: false}) return new ChangeStarredTask({threads, starred})