From 26bd5b6ef272e09d5849cdf02c85f404f8ed275c Mon Sep 17 00:00:00 2001 From: jom Date: Tue, 16 Mar 2021 12:51:42 +0100 Subject: [PATCH] Change cursor over maillist when drag and drop modifier is held, #2850 For some reason `cursor: grab` doesn't work in electron. Ideally we would set it to that, but `cursor: copy` seems good too --- src/gui/main-styles.js | 4 +++- src/mail/view/MailListView.js | 43 +++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/gui/main-styles.js b/src/gui/main-styles.js index 5b85fc44384..4f3ddd9273d 100644 --- a/src/gui/main-styles.js +++ b/src/gui/main-styles.js @@ -1351,7 +1351,9 @@ styles.registerStyle('main', () => { left: "3px", }, }, - + '.drag-mod-key *': { + cursor: "copy !important" + }, //We us this class to hide contents that should just be visible for printing ".noscreen": { "display": "none", diff --git a/src/mail/view/MailListView.js b/src/mail/view/MailListView.js index 236ccf8e895..6cb643ec958 100644 --- a/src/mail/view/MailListView.js +++ b/src/mail/view/MailListView.js @@ -22,7 +22,7 @@ import {ButtonColors, ButtonN, ButtonType} from "../../gui/base/ButtonN" import {Dialog} from "../../gui/base/Dialog" import {MonitorService} from "../../api/entities/monitor/Services" import {createWriteCounterData} from "../../api/entities/monitor/WriteCounterData" -import {assertNotNull, debounce, neverNull} from "../../api/common/utils/Utils" +import {assertNotNull, debounce, downcast, neverNull} from "../../api/common/utils/Utils" import {worker} from "../../api/main/WorkerClient" import {locator} from "../../api/main/MainLocator" import {getLetId, haveSameId, sortCompareByReverseId} from "../../api/common/utils/EntityUtils"; @@ -279,7 +279,7 @@ export class MailListView implements Component { }) }) - view(): Children { + view(vnode: Vnode): Children { // Save the folder before showing the dialog so that there's no chance that it will change const folder = this.mailView.selectedFolder const purgeButtonAttrs: ButtonAttrs = { @@ -300,7 +300,36 @@ export class MailListView implements Component { } } - return this.showingTrashOrSpamFolder() + // listeners to indicate the when mod key is held, dragging will do something + const onKeyDown = (event: KeyboardEvent) => { + if (isDragAndDropModifierHeld(event)) { + // first child give us a ChildNode but in the case we know that it's an Element + const listDom: HTMLElement = downcast(vnode.dom.firstChild) + listDom.classList.add("drag-mod-key") + } + } + const onKeyUp = (event: KeyboardEvent) => { + if (isDragAndDropModifierHeld(event)) { + // first child give us a ChildNode but in the case we know that it's an Element + const listDom: HTMLElement = downcast(vnode.dom.firstChild) + listDom.classList.remove("drag-mod-key") + } + } + + return m(".mail-list-wrapper", { + oncreate: vnode => { + if (canDoDragAndDropExport()) { + assertNotNull(document.body).addEventListener("keydown", onKeyDown) + assertNotNull(document.body).addEventListener("keyup", onKeyUp) + } + }, + onbeforeremove: vnode => { + if (canDoDragAndDropExport()) { + assertNotNull(document.body).removeEventListener("keydown", onKeyDown) + assertNotNull(document.body).removeEventListener("keyup", onKeyUp) + } + } + }, this.showingTrashOrSpamFolder() ? m(".flex.flex-column.fill-absolute", [ m(".flex.flex-column.justify-center.plr-l.list-border-right.list-bg.list-header", [ m(".small.flex-grow.pt", lang.get("storageDeletion_msg")), @@ -308,7 +337,7 @@ export class MailListView implements Component { ]), m(".rel.flex-grow", m(this.list)) ]) - : m(this.list) + : m(this.list)) } targetInbox(): boolean { @@ -356,7 +385,11 @@ export class MailListView implements Component { } export function isExportDragEvent(event: DragEvent): boolean { - return canDoDragAndDropExport() && (event.ctrlKey || event.altKey) + return canDoDragAndDropExport() && isDragAndDropModifierHeld(event) +} + +function isDragAndDropModifierHeld(event: DragEvent | KeyboardEvent): boolean { + return (event.ctrlKey || event.altKey) }