Skip to content

Commit 8e4c3a3

Browse files
committed
show confirmation dialog when deleting snippet with content
1 parent a4160d2 commit 8e4c3a3

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

browser/main/Detail/SnippetNoteDetail.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -247,27 +247,39 @@ class SnippetNoteDetail extends React.Component {
247247
})
248248
}
249249

250-
handleTabButtonClick (index) {
251-
return (e) => {
252-
this.setState({
253-
snippetIndex: index
254-
})
255-
}
250+
handleTabButtonClick (e, index) {
251+
this.setState({
252+
snippetIndex: index
253+
})
256254
}
257255

258-
handleTabDeleteButtonClick (index) {
259-
return (e) => {
260-
if (this.state.note.snippets.length > 1) {
261-
let snippets = this.state.note.snippets.slice()
262-
snippets.splice(index, 1)
263-
this.state.note.snippets = snippets
264-
this.setState({
265-
note: this.state.note
256+
handleTabDeleteButtonClick (e, index) {
257+
if (this.state.note.snippets.length > 1) {
258+
if (this.state.note.snippets[index].content.trim().length > 0) {
259+
let dialogIndex = dialog.showMessageBox(remote.getCurrentWindow(), {
260+
type: 'warning',
261+
message: 'Delete a snippet',
262+
detail: 'This work cannot be undone.',
263+
buttons: ['Confirm', 'Cancel']
266264
})
265+
if (dialogIndex === 0) {
266+
this.deleteSnippetByIndex(index)
267+
}
268+
} else {
269+
this.deleteSnippetByIndex(index)
267270
}
268271
}
269272
}
270273

274+
deleteSnippetByIndex (index) {
275+
let snippets = this.state.note.snippets.slice()
276+
snippets.splice(index, 1)
277+
this.state.note.snippets = snippets
278+
this.setState({
279+
note: this.state.note
280+
})
281+
}
282+
271283
handleNameInputChange (e, index) {
272284
let snippets = this.state.note.snippets.slice()
273285
snippets[index].name = e.target.value
@@ -344,7 +356,7 @@ class SnippetNoteDetail extends React.Component {
344356
key={index}
345357
>
346358
<button styleName='tabList-item-button'
347-
onClick={(e) => this.handleTabButtonClick(index)(e)}
359+
onClick={(e) => this.handleTabButtonClick(e, index)}
348360
>
349361
{snippet.name.trim().length > 0
350362
? snippet.name
@@ -355,7 +367,7 @@ class SnippetNoteDetail extends React.Component {
355367
</button>
356368
{note.snippets.length > 1 &&
357369
<button styleName='tabList-item-deleteButton'
358-
onClick={(e) => this.handleTabDeleteButtonClick(index)(e)}
370+
onClick={(e) => this.handleTabDeleteButtonClick(e, index)}
359371
>
360372
<i className='fa fa-times'/>
361373
</button>

0 commit comments

Comments
 (0)