mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
Show confirmation dialog when deleting notes from the context menu if set in preferences
This commit is contained in:
@@ -574,22 +574,29 @@ class NoteList extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
confirmDeleteNote (selectedNotes) {
|
||||||
|
const noteExp = selectedNotes.length > 1 ? 'notes' : 'note'
|
||||||
|
const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), {
|
||||||
|
type: 'warning',
|
||||||
|
message: i18n.__('Confirm note deletion'),
|
||||||
|
detail: `This will permanently remove ${selectedNotes.length} ${noteExp}.`,
|
||||||
|
buttons: [i18n.__('Confirm'), i18n.__('Cancel')]
|
||||||
|
})
|
||||||
|
|
||||||
|
return dialogueButtonIndex === 1 ? false : true
|
||||||
|
}
|
||||||
|
|
||||||
deleteNote () {
|
deleteNote () {
|
||||||
const { dispatch } = this.props
|
const { dispatch } = this.props
|
||||||
const { selectedNoteKeys } = this.state
|
const { selectedNoteKeys } = this.state
|
||||||
const notes = this.notes.map((note) => Object.assign({}, note))
|
const notes = this.notes.map((note) => Object.assign({}, note))
|
||||||
const selectedNotes = findNotesByKeys(notes, selectedNoteKeys)
|
const selectedNotes = findNotesByKeys(notes, selectedNoteKeys)
|
||||||
const firstNote = selectedNotes[0]
|
const firstNote = selectedNotes[0]
|
||||||
|
const confirmDeletion = this.props.config.ui.confirmDeletion
|
||||||
|
|
||||||
if (firstNote.isTrashed) {
|
if (firstNote.isTrashed) {
|
||||||
const noteExp = selectedNotes.length > 1 ? 'notes' : 'note'
|
if (!this.confirmDeleteNote(selectedNotes)) return
|
||||||
const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), {
|
|
||||||
type: 'warning',
|
|
||||||
message: i18n.__('Confirm note deletion'),
|
|
||||||
detail: `This will permanently remove ${selectedNotes.length} ${noteExp}.`,
|
|
||||||
buttons: [i18n.__('Confirm'), i18n.__('Cancel')]
|
|
||||||
})
|
|
||||||
if (dialogueButtonIndex === 1) return
|
|
||||||
Promise.all(
|
Promise.all(
|
||||||
selectedNotes.map((note) => {
|
selectedNotes.map((note) => {
|
||||||
return dataApi
|
return dataApi
|
||||||
@@ -610,6 +617,10 @@ class NoteList extends React.Component {
|
|||||||
})
|
})
|
||||||
console.log('Notes were all deleted')
|
console.log('Notes were all deleted')
|
||||||
} else {
|
} else {
|
||||||
|
if (confirmDeletion) {
|
||||||
|
if (!this.confirmDeleteNote(selectedNotes)) return
|
||||||
|
}
|
||||||
|
|
||||||
Promise.all(
|
Promise.all(
|
||||||
selectedNotes.map((note) => {
|
selectedNotes.map((note) => {
|
||||||
note.isTrashed = true
|
note.isTrashed = true
|
||||||
|
|||||||
Reference in New Issue
Block a user