Close closes the buffer, prompting to save if there are changes, and disconnects from editors. If afterFun is non-nil, then it is called with the status of the user action.
(afterFun func(canceled bool))
| 489 | // from editors. If afterFun is non-nil, then it is called with the status of the user |
| 490 | // action. |
| 491 | func (tb *Buffer) Close(afterFun func(canceled bool)) bool { |
| 492 | if tb.IsNotSaved() { |
| 493 | tb.StopDelayedReMarkup() |
| 494 | sc := tb.sceneFromEditor() |
| 495 | if tb.Filename != "" { |
| 496 | d := core.NewBody().AddTitle("Close without saving?"). |
| 497 | AddText(fmt.Sprintf("Do you want to save your changes to file: %v?", tb.Filename)) |
| 498 | d.AddBottomBar(func(parent core.Widget) { |
| 499 | core.NewButton(parent).SetText("Cancel").OnClick(func(e events.Event) { |
| 500 | d.Close() |
| 501 | if afterFun != nil { |
| 502 | afterFun(true) |
| 503 | } |
| 504 | }) |
| 505 | core.NewButton(parent).SetText("Close without saving").OnClick(func(e events.Event) { |
| 506 | d.Close() |
| 507 | tb.clearNotSaved() |
| 508 | tb.AutoSaveDelete() |
| 509 | tb.Close(afterFun) |
| 510 | }) |
| 511 | core.NewButton(parent).SetText("Save").OnClick(func(e events.Event) { |
| 512 | tb.Save() |
| 513 | tb.Close(afterFun) // 2nd time through won't prompt |
| 514 | }) |
| 515 | }) |
| 516 | d.RunDialog(sc) |
| 517 | } else { |
| 518 | d := core.NewBody().AddTitle("Close without saving?"). |
| 519 | AddText("Do you want to save your changes (no filename for this buffer yet)? If so, Cancel and then do Save As") |
| 520 | d.AddBottomBar(func(parent core.Widget) { |
| 521 | d.AddCancel(parent).OnClick(func(e events.Event) { |
| 522 | if afterFun != nil { |
| 523 | afterFun(true) |
| 524 | } |
| 525 | }) |
| 526 | d.AddOK(parent).SetText("Close without saving").OnClick(func(e events.Event) { |
| 527 | tb.clearNotSaved() |
| 528 | tb.AutoSaveDelete() |
| 529 | tb.Close(afterFun) |
| 530 | }) |
| 531 | }) |
| 532 | d.RunDialog(sc) |
| 533 | } |
| 534 | return false // awaiting decisions.. |
| 535 | } |
| 536 | tb.signalEditors(bufferClosed, nil) |
| 537 | tb.SetText(nil) |
| 538 | tb.Filename = "" |
| 539 | tb.clearNotSaved() |
| 540 | if afterFun != nil { |
| 541 | afterFun(false) |
| 542 | } |
| 543 | return true |
| 544 | } |
| 545 | |
| 546 | //////////////////////////////////////////////////////////////////////////////////////// |
| 547 | // AutoSave |
nothing calls this directly
no test coverage detected