diff --git a/browser/main/Detail/MarkdownNoteDetail.js b/browser/main/Detail/MarkdownNoteDetail.js index 15c584d4..21c9a53f 100644 --- a/browser/main/Detail/MarkdownNoteDetail.js +++ b/browser/main/Detail/MarkdownNoteDetail.js @@ -28,10 +28,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 -const { dialog } = remote - class MarkdownNoteDetail extends React.Component { constructor (props) { super(props) @@ -187,38 +183,37 @@ class MarkdownNoteDetail extends React.Component { handleTrashButtonClick (e) { const { note } = this.state const { isTrashed } = note + 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 { - note.isTrashed = true + if (confirmDeletion()) { + note.isTrashed = true - this.setState({ - note - }, () => { - this.save() - }) + this.setState({ + note + }, () => { + this.save() + }) + + ee.emit('list:next') + } } - ee.emit('list:next') } handleUndoButtonClick (e) { @@ -447,7 +442,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 218b4f87..4f5d7c68 100644 --- a/browser/main/Detail/SnippetNoteDetail.js +++ b/browser/main/Detail/SnippetNoteDetail.js @@ -176,38 +176,37 @@ class SnippetNoteDetail extends React.Component { handleTrashButtonClick (e) { const { note } = this.state const { isTrashed } = note + 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 { - note.isTrashed = true + if (confirmDeletion()) { + note.isTrashed = true - this.setState({ - note - }, () => { - this.save() - }) + this.setState({ + note + }, () => { + this.save() + }) + + ee.emit('list:next') + } } - ee.emit('list:next') } handleUndoButtonClick (e) { @@ -731,7 +730,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 70f37a41..a9a8e4f2 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', diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index c79329d0..1cd696e3 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 @@ -173,6 +174,16 @@ class UiTab extends React.Component { Show "Saved to Clipboard" notification when copying +
+ +
{ global.process.platform === 'win32' ?
@@ -182,7 +193,7 @@ class UiTab extends React.Component { refs='uiD2w' disabled={OSX} type='checkbox' - /> + />  Disable Direct Write(It will be applied after restarting)