diff --git a/browser/main/Detail/SnippetNoteDetail.js b/browser/main/Detail/SnippetNoteDetail.js index 449f45e5..af818b43 100644 --- a/browser/main/Detail/SnippetNoteDetail.js +++ b/browser/main/Detail/SnippetNoteDetail.js @@ -247,25 +247,37 @@ class SnippetNoteDetail extends React.Component { }) } - handleTabButtonClick (index) { - return (e) => { - this.setState({ - snippetIndex: index - }) + handleTabButtonClick (e, index) { + this.setState({ + snippetIndex: index + }) + } + + handleTabDeleteButtonClick (e, index) { + if (this.state.note.snippets.length > 1) { + if (this.state.note.snippets[index].content.trim().length > 0) { + let dialogIndex = dialog.showMessageBox(remote.getCurrentWindow(), { + type: 'warning', + message: 'Delete a snippet', + detail: 'This work cannot be undone.', + buttons: ['Confirm', 'Cancel'] + }) + if (dialogIndex === 0) { + this.deleteSnippetByIndex(index) + } + } else { + this.deleteSnippetByIndex(index) + } } } - handleTabDeleteButtonClick (index) { - return (e) => { - if (this.state.note.snippets.length > 1) { - let snippets = this.state.note.snippets.slice() - snippets.splice(index, 1) - this.state.note.snippets = snippets - this.setState({ - note: this.state.note - }) - } - } + deleteSnippetByIndex (index) { + let snippets = this.state.note.snippets.slice() + snippets.splice(index, 1) + this.state.note.snippets = snippets + this.setState({ + note: this.state.note + }) } handleNameInputChange (e, index) { @@ -344,7 +356,7 @@ class SnippetNoteDetail extends React.Component { key={index} > {note.snippets.length > 1 &&