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))
| 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. |
| 410 | func (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. |
no test coverage detected