From 3bba5442bdec1528256944ffef5a6a7907693842 Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Thu, 21 Dec 2017 15:57:27 +0100 Subject: [PATCH 1/5] show delete confirmation dialog --- browser/main/Detail/MarkdownNoteDetail.js | 10 ++++++++++ browser/main/Detail/SnippetNoteDetail.js | 11 +++++++++++ browser/main/modals/PreferencesModal/UiTab.js | 13 ++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/browser/main/Detail/MarkdownNoteDetail.js b/browser/main/Detail/MarkdownNoteDetail.js index 6b7b8fd46..a85cc12c1 100644 --- a/browser/main/Detail/MarkdownNoteDetail.js +++ b/browser/main/Detail/MarkdownNoteDetail.js @@ -176,6 +176,7 @@ class MarkdownNoteDetail extends React.Component { handleTrashButtonClick (e) { const { note } = this.state const { isTrashed } = note + const { config } = this.props if (isTrashed) { const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), { @@ -199,6 +200,15 @@ class MarkdownNoteDetail extends React.Component { ee.once('list:moved', dispatchHandler) }) } else { + if (config.ui.confirmDeletion) { + const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), { + type: 'warning', + message: 'Confirm note deletion', + detail: 'Are you sure you want to move the note to the trash?', + buttons: ['Confirm', 'Cancel'] + }) + if (dialogueButtonIndex === 1) return + } note.isTrashed = true this.setState({ diff --git a/browser/main/Detail/SnippetNoteDetail.js b/browser/main/Detail/SnippetNoteDetail.js index bec6573ba..8c5feac60 100644 --- a/browser/main/Detail/SnippetNoteDetail.js +++ b/browser/main/Detail/SnippetNoteDetail.js @@ -175,6 +175,7 @@ class SnippetNoteDetail extends React.Component { handleTrashButtonClick (e) { const { note } = this.state const { isTrashed } = note + const { config } = this.props if (isTrashed) { const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), { @@ -198,6 +199,16 @@ class SnippetNoteDetail extends React.Component { ee.once('list:moved', dispatchHandler) }) } else { + if (config.ui.confirmDeletion) { + const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), { + type: 'warning', + message: 'Confirm note deletion', + detail: 'Are you sure you want to move the note to the trash?', + buttons: ['Confirm', 'Cancel'] + }) + if (dialogueButtonIndex === 1) return + } + note.isTrashed = true this.setState({ diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index 42afd8f4e..5ed771991 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -62,6 +62,7 @@ class UiTab extends React.Component { ui: { theme: this.refs.uiTheme.value, showCopyNotification: this.refs.showCopyNotification.checked, + confirmDeletion: this.refs.confirmDeletion.checked, disableDirectWrite: this.refs.uiD2w != null ? this.refs.uiD2w.checked : false @@ -161,6 +162,16 @@ class UiTab extends React.Component { Show "Saved to Clipboard" notification when copying +
+ +
{ global.process.platform === 'win32' ?
@@ -170,7 +181,7 @@ class UiTab extends React.Component { refs='uiD2w' disabled={OSX} type='checkbox' - /> + />  Disable Direct Write(It will be applied after restarting)
From aabfe820acab178b58d1882f94efd3d875c1ad49 Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Thu, 21 Dec 2017 17:41:08 +0100 Subject: [PATCH 2/5] refactored to prevent duplicate code --- browser/main/Detail/MarkdownNoteDetail.js | 61 ++++++++++------------- browser/main/Detail/SnippetNoteDetail.js | 61 ++++++++++------------- browser/main/Detail/index.js | 22 ++++++++ 3 files changed, 72 insertions(+), 72 deletions(-) diff --git a/browser/main/Detail/MarkdownNoteDetail.js b/browser/main/Detail/MarkdownNoteDetail.js index a85cc12c1..fbd8ce5ca 100644 --- a/browser/main/Detail/MarkdownNoteDetail.js +++ b/browser/main/Detail/MarkdownNoteDetail.js @@ -176,46 +176,34 @@ class MarkdownNoteDetail extends React.Component { handleTrashButtonClick (e) { const { note } = this.state const { isTrashed } = note - const { config } = this.props + const { confirmDeletion } = this.props if (isTrashed) { - const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), { - type: 'warning', - message: 'Confirm note deletion', - detail: 'This will permanently remove this note.', - buttons: ['Confirm', 'Cancel'] - }) - if (dialogueButtonIndex === 1) return - const { note, dispatch } = this.props - dataApi - .deleteNote(note.storage, note.key) - .then((data) => { - const dispatchHandler = () => { - dispatch({ - type: 'DELETE_NOTE', - storageKey: data.storageKey, - noteKey: data.noteKey - }) - } - ee.once('list:moved', dispatchHandler) - }) + if (confirmDeletion(true)) { + const {note, dispatch} = this.props + dataApi + .deleteNote(note.storage, note.key) + .then((data) => { + const dispatchHandler = () => { + dispatch({ + type: 'DELETE_NOTE', + storageKey: data.storageKey, + noteKey: data.noteKey + }) + } + ee.once('list:moved', dispatchHandler) + }) + } } else { - if (config.ui.confirmDeletion) { - const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), { - type: 'warning', - message: 'Confirm note deletion', - detail: 'Are you sure you want to move the note to the trash?', - buttons: ['Confirm', 'Cancel'] + if (confirmDeletion()) { + note.isTrashed = true + + this.setState({ + note + }, () => { + this.save() }) - if (dialogueButtonIndex === 1) return } - note.isTrashed = true - - this.setState({ - note - }, () => { - this.save() - }) } ee.emit('list:next') } @@ -457,7 +445,8 @@ MarkdownNoteDetail.propTypes = { style: PropTypes.shape({ left: PropTypes.number }), - ignorePreviewPointerEvents: PropTypes.bool + ignorePreviewPointerEvents: PropTypes.bool, + confirmDeletion: PropTypes.bool.isRequired } export default CSSModules(MarkdownNoteDetail, styles) diff --git a/browser/main/Detail/SnippetNoteDetail.js b/browser/main/Detail/SnippetNoteDetail.js index 8c5feac60..427a0381f 100644 --- a/browser/main/Detail/SnippetNoteDetail.js +++ b/browser/main/Detail/SnippetNoteDetail.js @@ -175,47 +175,35 @@ class SnippetNoteDetail extends React.Component { handleTrashButtonClick (e) { const { note } = this.state const { isTrashed } = note - const { config } = this.props + const { confirmDeletion } = this.props if (isTrashed) { - const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), { - type: 'warning', - message: 'Confirm note deletion', - detail: 'This will permanently remove this note.', - buttons: ['Confirm', 'Cancel'] - }) - if (dialogueButtonIndex === 1) return - const { note, dispatch } = this.props - dataApi - .deleteNote(note.storage, note.key) - .then((data) => { - const dispatchHandler = () => { - dispatch({ - type: 'DELETE_NOTE', - storageKey: data.storageKey, - noteKey: data.noteKey - }) - } - ee.once('list:moved', dispatchHandler) - }) + if (confirmDeletion(true)) { + const {note, dispatch} = this.props + dataApi + .deleteNote(note.storage, note.key) + .then((data) => { + const dispatchHandler = () => { + dispatch({ + type: 'DELETE_NOTE', + storageKey: data.storageKey, + noteKey: data.noteKey + }) + } + ee.once('list:moved', dispatchHandler) + }) + } } else { - if (config.ui.confirmDeletion) { - const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), { - type: 'warning', - message: 'Confirm note deletion', - detail: 'Are you sure you want to move the note to the trash?', - buttons: ['Confirm', 'Cancel'] + if (confirmDeletion()) { + note.isTrashed = true + + this.setState({ + note + }, () => { + this.save() }) - if (dialogueButtonIndex === 1) return } - note.isTrashed = true - - this.setState({ - note - }, () => { - this.save() - }) } ee.emit('list:next') } @@ -740,7 +728,8 @@ SnippetNoteDetail.propTypes = { style: PropTypes.shape({ left: PropTypes.number }), - ignorePreviewPointerEvents: PropTypes.bool + ignorePreviewPointerEvents: PropTypes.bool, + confirmDeletion: PropTypes.bool.isRequired } export default CSSModules(SnippetNoteDetail, styles) diff --git a/browser/main/Detail/index.js b/browser/main/Detail/index.js index 70f37a419..a9a8e4f2c 100644 --- a/browser/main/Detail/index.js +++ b/browser/main/Detail/index.js @@ -32,6 +32,26 @@ class Detail extends React.Component { ee.off('detail:delete', this.deleteHandler) } + confirmDeletion (permanent) { + if (this.props.config.ui.confirmDeletion || permanent) { + const electron = require('electron') + const { remote } = electron + const { dialog } = remote + + const alertConfig = { + type: 'warning', + message: 'Confirm note deletion', + detail: 'This will permanently remove this note.', + buttons: ['Confirm', 'Cancel'] + } + + const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), alertConfig) + return dialogueButtonIndex === 0 + } + + return true + } + render () { const { location, data, config } = this.props let note = null @@ -64,6 +84,7 @@ class Detail extends React.Component { this.confirmDeletion(permanent)} ref='root' {..._.pick(this.props, [ 'dispatch', @@ -80,6 +101,7 @@ class Detail extends React.Component { this.confirmDeletion(permanent)} ref='root' {..._.pick(this.props, [ 'dispatch', From e262d2f19bd839c09bf322bb016c3167ee7b7e37 Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Thu, 21 Dec 2017 19:15:34 +0100 Subject: [PATCH 3/5] fixed lint error --- browser/main/Detail/SnippetNoteDetail.js | 1 - 1 file changed, 1 deletion(-) diff --git a/browser/main/Detail/SnippetNoteDetail.js b/browser/main/Detail/SnippetNoteDetail.js index 427a0381f..cae99a748 100644 --- a/browser/main/Detail/SnippetNoteDetail.js +++ b/browser/main/Detail/SnippetNoteDetail.js @@ -203,7 +203,6 @@ class SnippetNoteDetail extends React.Component { this.save() }) } - } ee.emit('list:next') } From 9f9463f0e8932ae02dec4d4b6bd243e409d71e25 Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Wed, 3 Jan 2018 23:08:42 +0100 Subject: [PATCH 4/5] fixed review comments --- browser/main/Detail/MarkdownNoteDetail.js | 5 +++-- browser/main/Detail/SnippetNoteDetail.js | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/browser/main/Detail/MarkdownNoteDetail.js b/browser/main/Detail/MarkdownNoteDetail.js index fbd8ce5ca..46f58a032 100644 --- a/browser/main/Detail/MarkdownNoteDetail.js +++ b/browser/main/Detail/MarkdownNoteDetail.js @@ -28,7 +28,6 @@ import striptags from 'striptags' const electron = require('electron') const { remote } = electron -const { dialog } = remote class MarkdownNoteDetail extends React.Component { constructor (props) { @@ -203,9 +202,11 @@ class MarkdownNoteDetail extends React.Component { }, () => { this.save() }) + + ee.emit('list:next') } } - ee.emit('list:next') + } handleUndoButtonClick (e) { diff --git a/browser/main/Detail/SnippetNoteDetail.js b/browser/main/Detail/SnippetNoteDetail.js index cae99a748..e58a18703 100644 --- a/browser/main/Detail/SnippetNoteDetail.js +++ b/browser/main/Detail/SnippetNoteDetail.js @@ -202,9 +202,10 @@ class SnippetNoteDetail extends React.Component { }, () => { this.save() }) + + ee.emit('list:next') } } - ee.emit('list:next') } handleUndoButtonClick (e) { From 18649dd0740c78af76776557aff255a0887e62ed Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Thu, 4 Jan 2018 08:32:42 +0100 Subject: [PATCH 5/5] fixed lint errors --- browser/main/Detail/MarkdownNoteDetail.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/browser/main/Detail/MarkdownNoteDetail.js b/browser/main/Detail/MarkdownNoteDetail.js index 46f58a032..4588a6588 100644 --- a/browser/main/Detail/MarkdownNoteDetail.js +++ b/browser/main/Detail/MarkdownNoteDetail.js @@ -26,9 +26,6 @@ import { formatDate } from 'browser/lib/date-formatter' import { getTodoPercentageOfCompleted } from 'browser/lib/getTodoStatus' import striptags from 'striptags' -const electron = require('electron') -const { remote } = electron - class MarkdownNoteDetail extends React.Component { constructor (props) { super(props) @@ -206,7 +203,6 @@ class MarkdownNoteDetail extends React.Component { ee.emit('list:next') } } - } handleUndoButtonClick (e) {