MCPcopy Create free account
hub / github.com/cogentcore/core / Close

Method Close

texteditor/buffer.go:491–544  ·  view source on GitHub ↗

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))

Source from the content-addressed store, hash-verified

489// from editors. If afterFun is non-nil, then it is called with the status of the user
490// action.
491func (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

Callers

nothing calls this directly

Calls 15

IsNotSavedMethod · 0.95
sceneFromEditorMethod · 0.95
SetTextMethod · 0.95
clearNotSavedMethod · 0.95
AutoSaveDeleteMethod · 0.95
SaveMethod · 0.95
signalEditorsMethod · 0.95
NewBodyFunction · 0.92
NewButtonFunction · 0.92
StopDelayedReMarkupMethod · 0.80
AddTextMethod · 0.80
AddTitleMethod · 0.80

Tested by

no test coverage detected