Skip to content

Commit 85937d8

Browse files
authored
Merge pull request #1324 from mslourens/confirmation-dialog
show delete confirmation dialog
2 parents ad80b8e + 18649dd commit 85937d8

File tree

4 files changed

+90
-61
lines changed

4 files changed

+90
-61
lines changed

browser/main/Detail/MarkdownNoteDetail.js

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ import { formatDate } from 'browser/lib/date-formatter'
2828
import { getTodoPercentageOfCompleted } from 'browser/lib/getTodoStatus'
2929
import striptags from 'striptags'
3030

31-
const electron = require('electron')
32-
const { remote } = electron
33-
const { dialog } = remote
34-
3531
class MarkdownNoteDetail extends React.Component {
3632
constructor (props) {
3733
super(props)
@@ -187,38 +183,37 @@ class MarkdownNoteDetail extends React.Component {
187183
handleTrashButtonClick (e) {
188184
const { note } = this.state
189185
const { isTrashed } = note
186+
const { confirmDeletion } = this.props
190187

191188
if (isTrashed) {
192-
const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), {
193-
type: 'warning',
194-
message: 'Confirm note deletion',
195-
detail: 'This will permanently remove this note.',
196-
buttons: ['Confirm', 'Cancel']
197-
})
198-
if (dialogueButtonIndex === 1) return
199-
const { note, dispatch } = this.props
200-
dataApi
201-
.deleteNote(note.storage, note.key)
202-
.then((data) => {
203-
const dispatchHandler = () => {
204-
dispatch({
205-
type: 'DELETE_NOTE',
206-
storageKey: data.storageKey,
207-
noteKey: data.noteKey
208-
})
209-
}
210-
ee.once('list:moved', dispatchHandler)
211-
})
189+
if (confirmDeletion(true)) {
190+
const {note, dispatch} = this.props
191+
dataApi
192+
.deleteNote(note.storage, note.key)
193+
.then((data) => {
194+
const dispatchHandler = () => {
195+
dispatch({
196+
type: 'DELETE_NOTE',
197+
storageKey: data.storageKey,
198+
noteKey: data.noteKey
199+
})
200+
}
201+
ee.once('list:moved', dispatchHandler)
202+
})
203+
}
212204
} else {
213-
note.isTrashed = true
205+
if (confirmDeletion()) {
206+
note.isTrashed = true
214207

215-
this.setState({
216-
note
217-
}, () => {
218-
this.save()
219-
})
208+
this.setState({
209+
note
210+
}, () => {
211+
this.save()
212+
})
213+
214+
ee.emit('list:next')
215+
}
220216
}
221-
ee.emit('list:next')
222217
}
223218

224219
handleUndoButtonClick (e) {
@@ -447,7 +442,8 @@ MarkdownNoteDetail.propTypes = {
447442
style: PropTypes.shape({
448443
left: PropTypes.number
449444
}),
450-
ignorePreviewPointerEvents: PropTypes.bool
445+
ignorePreviewPointerEvents: PropTypes.bool,
446+
confirmDeletion: PropTypes.bool.isRequired
451447
}
452448

453449
export default CSSModules(MarkdownNoteDetail, styles)

browser/main/Detail/SnippetNoteDetail.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -176,38 +176,37 @@ class SnippetNoteDetail extends React.Component {
176176
handleTrashButtonClick (e) {
177177
const { note } = this.state
178178
const { isTrashed } = note
179+
const { confirmDeletion } = this.props
179180

180181
if (isTrashed) {
181-
const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), {
182-
type: 'warning',
183-
message: 'Confirm note deletion',
184-
detail: 'This will permanently remove this note.',
185-
buttons: ['Confirm', 'Cancel']
186-
})
187-
if (dialogueButtonIndex === 1) return
188-
const { note, dispatch } = this.props
189-
dataApi
190-
.deleteNote(note.storage, note.key)
191-
.then((data) => {
192-
const dispatchHandler = () => {
193-
dispatch({
194-
type: 'DELETE_NOTE',
195-
storageKey: data.storageKey,
196-
noteKey: data.noteKey
197-
})
198-
}
199-
ee.once('list:moved', dispatchHandler)
200-
})
182+
if (confirmDeletion(true)) {
183+
const {note, dispatch} = this.props
184+
dataApi
185+
.deleteNote(note.storage, note.key)
186+
.then((data) => {
187+
const dispatchHandler = () => {
188+
dispatch({
189+
type: 'DELETE_NOTE',
190+
storageKey: data.storageKey,
191+
noteKey: data.noteKey
192+
})
193+
}
194+
ee.once('list:moved', dispatchHandler)
195+
})
196+
}
201197
} else {
202-
note.isTrashed = true
198+
if (confirmDeletion()) {
199+
note.isTrashed = true
203200

204-
this.setState({
205-
note
206-
}, () => {
207-
this.save()
208-
})
201+
this.setState({
202+
note
203+
}, () => {
204+
this.save()
205+
})
206+
207+
ee.emit('list:next')
208+
}
209209
}
210-
ee.emit('list:next')
211210
}
212211

213212
handleUndoButtonClick (e) {
@@ -731,7 +730,8 @@ SnippetNoteDetail.propTypes = {
731730
style: PropTypes.shape({
732731
left: PropTypes.number
733732
}),
734-
ignorePreviewPointerEvents: PropTypes.bool
733+
ignorePreviewPointerEvents: PropTypes.bool,
734+
confirmDeletion: PropTypes.bool.isRequired
735735
}
736736

737737
export default CSSModules(SnippetNoteDetail, styles)

browser/main/Detail/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ class Detail extends React.Component {
3232
ee.off('detail:delete', this.deleteHandler)
3333
}
3434

35+
confirmDeletion (permanent) {
36+
if (this.props.config.ui.confirmDeletion || permanent) {
37+
const electron = require('electron')
38+
const { remote } = electron
39+
const { dialog } = remote
40+
41+
const alertConfig = {
42+
type: 'warning',
43+
message: 'Confirm note deletion',
44+
detail: 'This will permanently remove this note.',
45+
buttons: ['Confirm', 'Cancel']
46+
}
47+
48+
const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), alertConfig)
49+
return dialogueButtonIndex === 0
50+
}
51+
52+
return true
53+
}
54+
3555
render () {
3656
const { location, data, config } = this.props
3757
let note = null
@@ -64,6 +84,7 @@ class Detail extends React.Component {
6484
<SnippetNoteDetail
6585
note={note}
6686
config={config}
87+
confirmDeletion={(permanent) => this.confirmDeletion(permanent)}
6788
ref='root'
6889
{..._.pick(this.props, [
6990
'dispatch',
@@ -80,6 +101,7 @@ class Detail extends React.Component {
80101
<MarkdownNoteDetail
81102
note={note}
82103
config={config}
104+
confirmDeletion={(permanent) => this.confirmDeletion(permanent)}
83105
ref='root'
84106
{..._.pick(this.props, [
85107
'dispatch',

browser/main/modals/PreferencesModal/UiTab.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class UiTab extends React.Component {
6262
ui: {
6363
theme: this.refs.uiTheme.value,
6464
showCopyNotification: this.refs.showCopyNotification.checked,
65+
confirmDeletion: this.refs.confirmDeletion.checked,
6566
disableDirectWrite: this.refs.uiD2w != null
6667
? this.refs.uiD2w.checked
6768
: false
@@ -173,6 +174,16 @@ class UiTab extends React.Component {
173174
Show &quot;Saved to Clipboard&quot; notification when copying
174175
</label>
175176
</div>
177+
<div styleName='group-checkBoxSection'>
178+
<label>
179+
<input onChange={(e) => this.handleUIChange(e)}
180+
checked={this.state.config.ui.confirmDeletion}
181+
ref='confirmDeletion'
182+
type='checkbox'
183+
/>&nbsp;
184+
Show a confirmation dialog when deleting notes
185+
</label>
186+
</div>
176187
{
177188
global.process.platform === 'win32'
178189
? <div styleName='group-checkBoxSection'>
@@ -182,7 +193,7 @@ class UiTab extends React.Component {
182193
refs='uiD2w'
183194
disabled={OSX}
184195
type='checkbox'
185-
/>
196+
/>&nbsp;
186197
Disable Direct Write(It will be applied after restarting)
187198
</label>
188199
</div>

0 commit comments

Comments
 (0)