Save saves the current text into the current filename associated with this buffer.
()
| 457 | |
| 458 | // Save saves the current text into the current filename associated with this buffer. |
| 459 | func (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 |
no test coverage detected