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

Method SaveAsFunc

texteditor/buffer.go:410–436  ·  view source on GitHub ↗

SaveAsFunc saves the current text into the given file. Does an editDone first to save edits and checks for an existing file. If it does exist then prompts to overwrite or not. If afterFunc is non-nil, then it is called with the status of the user action.

(filename core.Filename, afterFunc func(canceled bool))

Source from the content-addressed store, hash-verified

408// If it does exist then prompts to overwrite or not.
409// If afterFunc is non-nil, then it is called with the status of the user action.
410func (tb *Buffer) SaveAsFunc(filename core.Filename, afterFunc func(canceled bool)) {
411 tb.editDone()
412 if !errors.Log1(fsx.FileExists(string(filename))) {
413 tb.saveFile(filename)
414 if afterFunc != nil {
415 afterFunc(false)
416 }
417 } else {
418 sc := tb.sceneFromEditor()
419 d := core.NewBody().AddTitle("File exists").
420 AddText(fmt.Sprintf("The file already exists; do you want to overwrite it? File: %v", filename))
421 d.AddBottomBar(func(parent core.Widget) {
422 d.AddCancel(parent).OnClick(func(e events.Event) {
423 if afterFunc != nil {
424 afterFunc(true)
425 }
426 })
427 d.AddOK(parent).OnClick(func(e events.Event) {
428 tb.saveFile(filename)
429 if afterFunc != nil {
430 afterFunc(false)
431 }
432 })
433 })
434 d.RunDialog(sc)
435 }
436}
437
438// SaveAs saves the current text into given file; does an editDone first to save edits
439// and checks for an existing file; if it does exist then prompts to overwrite or not.

Callers 1

SaveAsMethod · 0.95

Calls 13

editDoneMethod · 0.95
saveFileMethod · 0.95
sceneFromEditorMethod · 0.95
Log1Function · 0.92
FileExistsFunction · 0.92
NewBodyFunction · 0.92
AddTextMethod · 0.80
AddTitleMethod · 0.80
AddBottomBarMethod · 0.80
AddCancelMethod · 0.80
AddOKMethod · 0.80
RunDialogMethod · 0.80

Tested by

no test coverage detected