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

Method Save

texteditor/buffer.go:459–486  ·  view source on GitHub ↗

Save saves the current text into the current filename associated with this buffer.

()

Source from the content-addressed store, hash-verified

457
458// Save saves the current text into the current filename associated with this buffer.
459func (tb *Buffer) Save() error { //types:add
460 if tb.Filename == "" {
461 return fmt.Errorf("core.Buf: filename is empty for Save")
462 }
463 tb.editDone()
464 info, err := os.Stat(string(tb.Filename))
465 if err == nil && info.ModTime() != time.Time(tb.Info.ModTime) {
466 sc := tb.sceneFromEditor()
467 d := core.NewBody().AddTitle("File Changed on Disk").
468 AddText(fmt.Sprintf("File has changed on disk since you opened or saved it; what do you want to do? File: %v", tb.Filename))
469 d.AddBottomBar(func(parent core.Widget) {
470 core.NewButton(parent).SetText("Save to different file").OnClick(func(e events.Event) {
471 d.Close()
472 core.CallFunc(sc, tb.SaveAs)
473 })
474 core.NewButton(parent).SetText("Open from disk, losing changes").OnClick(func(e events.Event) {
475 d.Close()
476 tb.Revert()
477 })
478 core.NewButton(parent).SetText("Save file, overwriting").OnClick(func(e events.Event) {
479 d.Close()
480 tb.saveFile(tb.Filename)
481 })
482 })
483 d.RunDialog(sc)
484 }
485 return tb.saveFile(tb.Filename)
486}
487
488// Close closes the buffer, prompting to save if there are changes, and disconnects
489// from editors. If afterFun is non-nil, then it is called with the status of the user

Callers 1

CloseMethod · 0.95

Calls 15

editDoneMethod · 0.95
sceneFromEditorMethod · 0.95
RevertMethod · 0.95
saveFileMethod · 0.95
NewBodyFunction · 0.92
NewButtonFunction · 0.92
CallFuncFunction · 0.92
ModTimeMethod · 0.80
AddTextMethod · 0.80
AddTitleMethod · 0.80
AddBottomBarMethod · 0.80
RunDialogMethod · 0.80

Tested by

no test coverage detected